public class Reference extends SignatureElementProxy
<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>
ObjectContainer
,
Manifest
Modifier and Type | Field and Description |
---|---|
static String |
MANIFEST_URI
Field MANIFEST_URI
|
static int |
MAXIMUM_TRANSFORM_COUNT
The maximum number of transforms per reference, if secure validation is enabled.
|
static String |
OBJECT_URI
Field OBJECT_URI
|
baseURI
Modifier | Constructor and Description |
---|---|
protected |
Reference(Document doc,
String baseURI,
String referenceURI,
Manifest manifest,
Transforms transforms,
String messageDigestAlgorithm)
Constructor Reference
|
protected |
Reference(Element element,
String baseURI,
Manifest manifest)
|
protected |
Reference(Element element,
String baseURI,
Manifest manifest,
boolean secureValidation)
|
Modifier and Type | Method and Description |
---|---|
protected XMLSignatureInput |
dereferenceURIandPerformTransforms(OutputStream os)
This method returns the
XMLSignatureInput which is referenced by the
URI Attribute. |
void |
generateDigestValue()
Method generateDigestValue
|
String |
getBaseLocalName()
Method getBaseLocalName
Returns the localname of the Elements of the sub-class.
|
XMLSignatureInput |
getContentsAfterTransformation()
Returns the XMLSignatureInput which is the result of the Transforms.
|
XMLSignatureInput |
getContentsBeforeTransformation()
Returns the XMLSignatureInput which is created by de-referencing the URI attribute.
|
byte[] |
getDigestValue()
Returns the digest value.
|
String |
getHTMLRepresentation()
Method getHTMLRepresentation
|
String |
getId()
Returns the
Id attribute of this Reference element |
MessageDigestAlgorithm |
getMessageDigestAlgorithm()
Returns
MessageDigestAlgorithm |
XMLSignatureInput |
getNodesetBeforeFirstCanonicalization()
This method returns the XMLSignatureInput which represents the node set before
some kind of canonicalization is applied for the first time.
|
ReferenceData |
getReferenceData()
Get the ReferenceData that corresponds to the cached representation of the dereferenced
object before transformation.
|
byte[] |
getReferencedBytes()
Method getReferencedBytes
|
Transforms |
getTransforms()
Method getTransforms
|
XMLSignatureInput |
getTransformsOutput()
This method only works after a call to verify.
|
String |
getType()
Return the
type attribute of the Reference indicate whether an
ds:Object , ds:SignatureProperty , or ds:Manifest
element |
String |
getURI()
Returns the
URI of this Reference element |
void |
setId(String id)
Sets the
Id attribute of this Reference element |
void |
setType(String type)
Sets the
type atttibute of the Reference indicate whether an
ds:Object , ds:SignatureProperty , or ds:Manifest
element. |
void |
setURI(String uri)
Sets the
URI of this Reference element |
boolean |
typeIsReferenceToManifest()
Method isReferenceToManifest
This returns true if the
Type attribute of the
Reference element points to a #Manifest element |
boolean |
typeIsReferenceToObject()
Method isReferenceToObject
This returns true if the
Type attribute of the
Reference element points to a #Object element |
boolean |
verify()
Tests reference validation is success or false
|
getBaseNamespace
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
public static final String OBJECT_URI
public static final String MANIFEST_URI
public static final int MAXIMUM_TRANSFORM_COUNT
protected Reference(Document doc, String baseURI, String referenceURI, Manifest manifest, Transforms transforms, String messageDigestAlgorithm) throws XMLSignatureException
doc
- the Document
in which XMLsignature
is placedbaseURI
- the URI of the resource where the XML instance will be storedreferenceURI
- URI indicate where is data which will digestedmanifest
- transforms
- Transforms
applied to datamessageDigestAlgorithm
- Digest algorithm
which is
applied to the data
TODO should we throw XMLSignatureException if MessageDigestAlgoURI is wrong?XMLSignatureException
protected Reference(Element element, String baseURI, Manifest manifest) throws XMLSecurityException
element
- Reference
elementbaseURI
- the URI of the resource where the XML instance was storedmanifest
- is the Manifest
of SignedInfo
in which the Reference occurs.
We need this because the Manifest has the individual ResourceResolver
s which have
been set by the userXMLSecurityException
protected Reference(Element element, String baseURI, Manifest manifest, boolean secureValidation) throws XMLSecurityException
element
- Reference
elementbaseURI
- the URI of the resource where the XML instance was storedmanifest
- 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 ResourceResolver
s which have
been set by the userXMLSecurityException
public MessageDigestAlgorithm getMessageDigestAlgorithm() throws XMLSignatureException
MessageDigestAlgorithm
MessageDigestAlgorithm
XMLSignatureException
public void setURI(String uri)
URI
of this Reference
elementuri
- the URI
of this Reference
elementpublic String getURI()
URI
of this Reference
elementURI
of this Reference
elementpublic void setId(String id)
Id
attribute of this Reference
elementid
- the Id
attribute of this Reference
elementpublic String getId()
Id
attribute of this Reference
elementId
attribute of this Reference
elementpublic void setType(String type)
type
atttibute of the Reference indicate whether an
ds:Object
, ds:SignatureProperty
, or ds:Manifest
element.type
- the type
attribute of the Referencepublic String getType()
type
attribute of the Reference indicate whether an
ds:Object
, ds:SignatureProperty
, or ds:Manifest
elementtype
attribute of the Referencepublic boolean typeIsReferenceToObject()
Type
attribute of the
Reference
element points to a #Object
elementObject
public boolean typeIsReferenceToManifest()
Type
attribute of the
Reference
element points to a #Manifest
elementManifest
public void generateDigestValue() throws XMLSignatureException, ReferenceNotInitializedException
public XMLSignatureInput getContentsBeforeTransformation() throws ReferenceNotInitializedException
ReferenceNotInitializedException
- If the resolver found any
problem resolving the referencepublic XMLSignatureInput getContentsAfterTransformation() throws XMLSignatureException
XMLSignatureException
public XMLSignatureInput getNodesetBeforeFirstCanonicalization() throws XMLSignatureException
XMLSignatureException
public String getHTMLRepresentation() throws XMLSignatureException
XMLSignatureException
public XMLSignatureInput getTransformsOutput()
public ReferenceData getReferenceData()
protected XMLSignatureInput dereferenceURIandPerformTransforms(OutputStream os) throws XMLSignatureException
XMLSignatureInput
which is referenced by the
URI
Attribute.os
- where to write the transformation can be null.XMLSignatureException
Manifest.verifyReferences()
public Transforms getTransforms() throws XMLSignatureException, InvalidTransformException, TransformationException, XMLSecurityException
InvalidTransformException
TransformationException
XMLSecurityException
XMLSignatureException
public byte[] getReferencedBytes() throws ReferenceNotInitializedException, XMLSignatureException
ReferenceNotInitializedException
XMLSignatureException
public byte[] getDigestValue() throws XMLSecurityException
XMLSecurityException
- if the Reference does not contain a DigestValue elementpublic boolean verify() throws ReferenceNotInitializedException, XMLSecurityException
ReferenceNotInitializedException
XMLSecurityException
public String getBaseLocalName()
getBaseLocalName
in class ElementProxy
Copyright © 2000–2020 The Apache Software Foundation. All rights reserved.