Class Reference


  • public class Reference
    extends SignatureElementProxy
    Handles <ds:Reference> elements. This includes: Construct a ds:Reference from an Element.

    Create a new reference

     Document doc;
     MessageDigestAlgorithm sha1 = MessageDigestAlgorithm.getInstance("http://#sha1");
     Reference ref = new Reference(new XMLSignatureInput(new FileInputStream("1.gif"),
                                   "http://localhost/1.gif",
                                   (Transforms) null, sha1);
     Element refElem = ref.toElement(doc);
     

    Verify a reference

     Element refElem = doc.getElement("Reference"); // PSEUDO
     Reference ref = new Reference(refElem);
     String url = ref.getURI();
     ref.setData(new XMLSignatureInput(new FileInputStream(url)));
     if (ref.verify()) {
        System.out.println("verified");
     }
     
     <element name="Reference" type="ds:ReferenceType"/>
      <complexType name="ReferenceType">
        <sequence>
          <element ref="ds:Transforms" minOccurs="0"/>
          <element ref="ds:DigestMethod"/>
          <element ref="ds:DigestValue"/>
        </sequence>
        <attribute name="Id" type="ID" use="optional"/>
        <attribute name="URI" type="anyURI" use="optional"/>
        <attribute name="Type" type="anyURI" use="optional"/>
      </complexType>
     
    See Also:
    ObjectContainer, Manifest
    • Field Detail

      • OBJECT_URI

        public static final java.lang.String OBJECT_URI
        Field OBJECT_URI
        See Also:
        Constant Field Values
      • MANIFEST_URI

        public static final java.lang.String MANIFEST_URI
        Field MANIFEST_URI
        See Also:
        Constant Field Values
      • MAXIMUM_TRANSFORM_COUNT

        public static final int MAXIMUM_TRANSFORM_COUNT
        The maximum number of transforms per reference, if secure validation is enabled.
        See Also:
        Constant Field Values
      • secureValidation

        private boolean secureValidation
      • useC14N11

        private static boolean useC14N11
        Look up useC14N11 system property. If true, an explicit C14N11 transform will be added if necessary when generating the signature. See section 3.1.1 of http://www.w3.org/2007/xmlsec/Drafts/xmldsig-core/ for more info.
      • LOG

        private static final org.slf4j.Logger LOG
      • digestMethodElem

        private org.w3c.dom.Element digestMethodElem
      • digestValueElement

        private org.w3c.dom.Element digestValueElement
    • Constructor Detail

      • Reference

        protected Reference​(org.w3c.dom.Document doc,
                            java.lang.String baseURI,
                            java.lang.String referenceURI,
                            Manifest manifest,
                            Transforms transforms,
                            java.lang.String messageDigestAlgorithm)
                     throws XMLSignatureException
        Constructor Reference
        Parameters:
        doc - the Document in which XMLsignature is placed
        baseURI - the URI of the resource where the XML instance will be stored
        referenceURI - URI indicate where is data which will digested
        manifest -
        transforms - Transforms applied to data
        messageDigestAlgorithm - Digest algorithm which is applied to the data TODO should we throw XMLSignatureException if MessageDigestAlgoURI is wrong?
        Throws:
        XMLSignatureException
      • Reference

        protected Reference​(org.w3c.dom.Element element,
                            java.lang.String baseURI,
                            Manifest manifest)
                     throws XMLSecurityException
        Build a Reference from an Element
        Parameters:
        element - Reference element
        baseURI - the URI of the resource where the XML instance was stored
        manifest - is the Manifest of SignedInfo in which the Reference occurs. We need this because the Manifest has the individual ResourceResolvers which have been set by the user
        Throws:
        XMLSecurityException
      • Reference

        protected Reference​(org.w3c.dom.Element element,
                            java.lang.String baseURI,
                            Manifest manifest,
                            boolean secureValidation)
                     throws XMLSecurityException
        Build a Reference from an Element
        Parameters:
        element - Reference element
        baseURI - the URI of the resource where the XML instance was stored
        manifest - is the Manifest of SignedInfo in which the Reference occurs.
        secureValidation - whether secure validation is enabled or not We need this because the Manifest has the individual ResourceResolvers which have been set by the user
        Throws:
        XMLSecurityException