Class Reference
java.lang.Object
org.apache.xml.security.utils.ElementProxy
org.apache.xml.security.utils.SignatureElementProxy
org.apache.xml.security.signature.Reference
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Elementprivate Elementprivate static final org.slf4j.Loggerprivate Manifeststatic final StringField MANIFEST_URIstatic final intThe maximum number of transforms per reference, if secure validation is enabled.static final StringField OBJECT_URIprivate ReferenceDataprivate booleanprivate Transformsprivate XMLSignatureInputprivate static booleanLook up useC14N11 system property.Fields inherited from class ElementProxy
baseURI -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidStore the dereferenced Element(s) so that it/they can be retrieved later.private byte[]calculateDigest(boolean validating) Method calculateDigestprotected XMLSignatureInputThis method returns theXMLSignatureInputwhich is referenced by theURIAttribute.voidMethod generateDigestValueMethod getBaseLocalName Returns the localname of the Elements of the sub-class.Returns the XMLSignatureInput which is the result of the Transforms.private XMLSignatureInputReturns the XMLSignatureInput which is created by de-referencing the URI attribute.byte[]Returns the digest value.Method getHTMLRepresentationgetId()Returns theIdattribute of thisReferenceelementReturnsMessageDigestAlgorithmThis method returns the XMLSignatureInput which represents the node set before some kind of canonicalization is applied for the first time.private byte[]Get the pre-calculated digest value from the XMLSignatureInput.Get the ReferenceData that corresponds to the cached representation of the dereferenced object before transformation.byte[]Method getReferencedBytesMethod getTransformsThis method only works after a call to verify.getType()Return thetypeatttibute of the Reference indicate whether ands:Object,ds:SignatureProperty, ords:ManifestelementgetURI()Returns theURIof thisReferenceelementprivate voidsetDigestValueElement(byte[] digestValue) Method setDigestValueElementvoidSets theIdattribute of thisReferenceelementvoidSets thetypeatttibute of the Reference indicate whether ands:Object,ds:SignatureProperty, ords:Manifestelement.voidSets theURIof thisReferenceelementbooleanMethod isReferenceToManifest This returns true if theTypeattribute of theReferenceelement points to a#ManifestelementbooleanMethod isReferenceToObject This returns true if theTypeattribute of theReferenceelement points to a#Objectelementbooleanverify()Tests reference validation is success or falseMethods inherited from class SignatureElementProxy
getBaseNamespaceMethods inherited from class ElementProxy
addBase64Element, addBase64Text, addBigIntegerElement, addReturnToSelf, addText, addTextElement, appendOther, appendSelf, appendSelf, createElementForFamily, createElementForFamilyLocal, createText, getBaseURI, getBigIntegerFromChildElement, getBytesFromTextChild, getDefaultPrefix, getDocument, getElement, getElementPlusReturns, getFirstChild, getLocalAttribute, getTextFromChildElement, getTextFromTextChild, length, registerDefaultPrefixes, setDefaultPrefix, setDocument, setElement, setElement, setLocalAttribute, setLocalIdAttribute, setXPathNamespaceContext
-
Field Details
-
OBJECT_URI
-
MANIFEST_URI
-
MAXIMUM_TRANSFORM_COUNT
public static final int MAXIMUM_TRANSFORM_COUNTThe maximum number of transforms per reference, if secure validation is enabled.- See Also:
-
secureValidation
private boolean secureValidation -
useC14N11
private static boolean useC14N11Look 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 -
manifest
-
transformsOutput
-
transforms
-
digestMethodElem
-
digestValueElement
-
referenceData
-
-
Constructor Details
-
Reference
protected Reference(Document doc, String baseURI, String referenceURI, Manifest manifest, Transforms transforms, String messageDigestAlgorithm) throws XMLSignatureException Constructor Reference- Parameters:
doc- theDocumentin whichXMLsignatureis placedbaseURI- the URI of the resource where the XML instance will be storedreferenceURI- URI indicate where is data which will digestedmanifest-transforms-Transformsapplied to datamessageDigestAlgorithm-Digest algorithmwhich is applied to the data TODO should we throw XMLSignatureException if MessageDigestAlgoURI is wrong?- Throws:
XMLSignatureException
-
Reference
- Parameters:
element-ReferenceelementbaseURI- the URI of the resource where the XML instance was storedmanifest- is theManifestofSignedInfoin which the Reference occurs. We need this because the Manifest has the individualResourceResolvers which have been set by the user- Throws:
XMLSecurityException
-
Reference
protected Reference(Element element, String baseURI, Manifest manifest, boolean secureValidation) throws XMLSecurityException - Parameters:
element-ReferenceelementbaseURI- the URI of the resource where the XML instance was storedmanifest- is theManifestofSignedInfoin which the Reference occurs.secureValidation- whether secure validation is enabled or not We need this because the Manifest has the individualResourceResolvers which have been set by the user- Throws:
XMLSecurityException
-
-
Method Details
-
getMessageDigestAlgorithm
ReturnsMessageDigestAlgorithm- Returns:
MessageDigestAlgorithm- Throws:
XMLSignatureException
-
setURI
Sets theURIof thisReferenceelement- Parameters:
uri- theURIof thisReferenceelement
-
getURI
Returns theURIof thisReferenceelement- Returns:
- URI the
URIof thisReferenceelement
-
setId
Sets theIdattribute of thisReferenceelement- Parameters:
id- theIdattribute of thisReferenceelement
-
getId
Returns theIdattribute of thisReferenceelement- Returns:
- Id the
Idattribute of thisReferenceelement
-
setType
Sets thetypeatttibute of the Reference indicate whether ands:Object,ds:SignatureProperty, ords:Manifestelement.- Parameters:
type- thetypeattribute of the Reference
-
getType
Return thetypeatttibute of the Reference indicate whether ands:Object,ds:SignatureProperty, ords:Manifestelement- Returns:
- the
typeattribute of the Reference
-
typeIsReferenceToObject
public boolean typeIsReferenceToObject()Method isReferenceToObject This returns true if theTypeattribute of theReferenceelement points to a#Objectelement- Returns:
- true if the Reference type indicates that this Reference points to an
Object
-
typeIsReferenceToManifest
public boolean typeIsReferenceToManifest()Method isReferenceToManifest This returns true if theTypeattribute of theReferenceelement points to a#Manifestelement- Returns:
- true if the Reference type indicates that this Reference points to a
Manifest
-
setDigestValueElement
private void setDigestValueElement(byte[] digestValue) Method setDigestValueElement- Parameters:
digestValue-
-
generateDigestValue
Method generateDigestValue -
getContentsBeforeTransformation
Returns the XMLSignatureInput which is created by de-referencing the URI attribute.- Returns:
- the XMLSignatureInput of the source of this reference
- Throws:
ReferenceNotInitializedException- If the resolver found any problem resolving the reference
-
getContentsAfterTransformation
private XMLSignatureInput getContentsAfterTransformation(XMLSignatureInput input, OutputStream os) throws XMLSignatureException - Throws:
XMLSignatureException
-
getContentsAfterTransformation
Returns the XMLSignatureInput which is the result of the Transforms.- Returns:
- a XMLSignatureInput with all transformations applied.
- Throws:
XMLSignatureException
-
getNodesetBeforeFirstCanonicalization
This method returns the XMLSignatureInput which represents the node set before some kind of canonicalization is applied for the first time.- Returns:
- Gets a the node doing everything till the first c14n is needed
- Throws:
XMLSignatureException
-
getHTMLRepresentation
Method getHTMLRepresentation- Returns:
- The HTML of the transformation
- Throws:
XMLSignatureException
-
getTransformsOutput
This method only works after a call to verify.- Returns:
- the transformed output(i.e. what is going to be digested).
-
getReferenceData
Get the ReferenceData that corresponds to the cached representation of the dereferenced object before transformation. -
dereferenceURIandPerformTransforms
protected XMLSignatureInput dereferenceURIandPerformTransforms(OutputStream os) throws XMLSignatureException This method returns theXMLSignatureInputwhich is referenced by theURIAttribute.- Parameters:
os- where to write the transformation can be null.- Returns:
- the element to digest
- Throws:
XMLSignatureException- See Also:
-
cacheDereferencedElement
Store the dereferenced Element(s) so that it/they can be retrieved later. -
getTransforms
public Transforms getTransforms() throws XMLSignatureException, InvalidTransformException, TransformationException, XMLSecurityExceptionMethod getTransforms- Returns:
- The transforms that applied this reference.
- Throws:
InvalidTransformExceptionTransformationExceptionXMLSecurityExceptionXMLSignatureException
-
getReferencedBytes
Method getReferencedBytes- Returns:
- the bytes that will be used to generated digest.
- Throws:
ReferenceNotInitializedExceptionXMLSignatureException
-
calculateDigest
private byte[] calculateDigest(boolean validating) throws ReferenceNotInitializedException, XMLSignatureException Method calculateDigest- Parameters:
validating- true if validating the reference- Returns:
- reference Calculate the digest of this reference.
- Throws:
ReferenceNotInitializedExceptionXMLSignatureException
-
getPreCalculatedDigest
private byte[] getPreCalculatedDigest(XMLSignatureInput input) throws ReferenceNotInitializedException Get the pre-calculated digest value from the XMLSignatureInput.- Parameters:
input- XMLSignature- Returns:
- a pre-calculated digest value.
- Throws:
ReferenceNotInitializedException- if there is an error decoding digest value in Base64. Properly encoded pre-calculated digest value must be set.
-
getDigestValue
Returns the digest value.- Returns:
- the digest value.
- Throws:
XMLSecurityException- if the Reference does not contain a DigestValue element
-
verify
Tests reference validation is success or false- Returns:
- true if reference validation is success, otherwise false
- Throws:
ReferenceNotInitializedExceptionXMLSecurityException
-
getBaseLocalName
Method getBaseLocalName Returns the localname of the Elements of the sub-class.- Specified by:
getBaseLocalNamein classElementProxy- Returns:
- the localname of the Elements of the sub-class.
-