APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.org.apache.xml.internal.security.signature

public Class Reference

extends SignatureElementProxy
Class Inheritance
Imports
java.io.IOException, .OutputStream, java.security.AccessController, .PrivilegedAction, java.util.Collections, .HashSet, .Iterator, .Set, com.sun.org.apache.xml.internal.security.algorithms.Algorithm, .MessageDigestAlgorithm, com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException, com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException, com.sun.org.apache.xml.internal.security.signature.reference.ReferenceData, .ReferenceNodeSetData, .ReferenceOctetStreamData, .ReferenceSubTreeData, com.sun.org.apache.xml.internal.security.transforms.InvalidTransformException, .Transform, .TransformationException, .Transforms, com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces, com.sun.org.apache.xml.internal.security.utils.Constants, .DigesterOutputStream, .SignatureElementProxy, .UnsyncBufferedOutputStream, .XMLUtils, com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver, .ResourceResolverContext, .ResourceResolverException, org.w3c.dom.Attr, .Document, .Element, .Node, .Text

Handles <ds:Reference> elements. This includes: Construct a ds:Reference from an org.w3c.dom.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 Summary

Modifier and TypeField and Description
private Element
private Element
private static final Logger
private Manifest
public static final String
MANIFEST_URI

Field MANIFEST_URI

public static final int
MAXIMUM_TRANSFORM_COUNT

The maximum number of transforms per reference, if secure validation is enabled.

public static final String
OBJECT_URI

Field OBJECT_URI

private ReferenceData
private boolean
private static final Set<String>
private Transforms
private XMLSignatureInput
private static boolean
useC14N11

Look up useC14N11 system property.

Constructor Summary

AccessConstructor and Description
protected
Reference(Document
the Document in which XMLsignature is placed
doc
,
String
the URI of the resource where the XML instance will be stored
baseURI
,
String
URI indicate where is data which will digested
referenceURI
,
Manifest manifest, Transforms
Transforms applied to data
transforms
,
String
Digest algorithm which is applied to the data TODO should we throw XMLSignatureException if MessageDigestAlgoURI is wrong?
messageDigestAlgorithm
)

Constructor Reference

protected
Reference(Element
Reference element
element
,
String
the URI of the resource where the XML instance was stored
baseURI
,
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
manifest
)

Build a Reference from an Element

protected
Reference(Element
Reference element
element
,
String
the URI of the resource where the XML instance was stored
baseURI
,
Manifest
is the Manifest of SignedInfo in which the Reference occurs.
manifest
,
boolean
whether secure validation is enabled or not We need this because the Manifest has the individual ResourceResolvers which have been set by the user
secureValidation
)

Build a Reference from an Element

Method Summary

Modifier and TypeMethod and Description
private void
cacheDereferencedElement(XMLSignatureInput input)

Store the dereferenced Element(s) so that it/they can be retrieved later.

private byte[]

Returns:

reference Calculate the digest of this reference.
calculateDigest
(boolean
true if validating the reference
validating
)

Method calculateDigest

protected XMLSignatureInput

Returns:

the element to digest
dereferenceURIandPerformTransforms
(OutputStream
where to write the transformation can be null.
os
)

This method returns the XMLSignatureInput which is referenced by the URI Attribute.

public void
generateDigestValue()

Method generateDigestValue

public String
getBaseLocalName()

Implements abstract com.sun.org.apache.xml.internal.security.utils.ElementProxy.getBaseLocalName.

Method getBaseLocalName Returns the localname of the Elements of the sub-class.

private XMLSignatureInput
public XMLSignatureInput

Returns:

a XMLSignatureInput with all transformations applied.
getContentsAfterTransformation
()

Returns the XMLSignatureInput which is the result of the Transforms.

public XMLSignatureInput

Returns:

the XMLSignatureInput of the source of this reference
getContentsBeforeTransformation
()

Returns the XMLSignatureInput which is created by de-referencing the URI attribute.

public byte[]

Returns:

the digest value.
getDigestValue
()

Returns the digest value.

public String

Returns:

The HTML of the transformation
getHTMLRepresentation
()

Method getHTMLRepresentation

public String

Returns:

Id the Id attribute of this Reference element
getId
()

Returns the Id attribute of this Reference element

public MessageDigestAlgorithm
public XMLSignatureInput

Returns:

Gets a the node doing everything till the first c14n is needed
getNodesetBeforeFirstCanonicalization
()

This method returns the XMLSignatureInput which represents the node set before some kind of canonicalization is applied for the first time.

private byte[]

Returns:

a pre-calculated digest value.
getPreCalculatedDigest
(XMLSignatureInput
XMLSignature
input
)

Get the pre-calculated digest value from the XMLSignatureInput.

public ReferenceData
getReferenceData()

Get the ReferenceData that corresponds to the cached representation of the dereferenced object before transformation.

public byte[]

Returns:

the bytes that will be used to generated digest.
getReferencedBytes
()

Method getReferencedBytes

public Transforms

Returns:

The transforms that applied this reference.
getTransforms
()

Method getTransforms

public XMLSignatureInput

Returns:

the transformed output(i.e. what is going to be digested).
getTransformsOutput
()

This method only works after a call to verify.

public String

Returns:

the type attribute of the Reference
getType
()

Return the type attribute of the Reference indicate whether an ds:Object, ds:SignatureProperty, or ds:Manifest element

public String

Returns:

URI the URI of this Reference element
getURI
()

Returns the URI of this Reference element

private void
setDigestValueElement(byte[] digestValue)

Method setDigestValueElement

public void
setId(String
the Id attribute of this Reference element
id
)

Sets the Id attribute of this Reference element

public void
setType(String
the type attribute of the Reference
type
)

Sets the type atttibute of the Reference indicate whether an ds:Object, ds:SignatureProperty, or ds:Manifest element.

public void
setURI(String
the URI of this Reference element
uri
)

Sets the URI of this Reference element

public boolean

Returns:

true if the Reference type indicates that this Reference points to a Manifest
typeIsReferenceToManifest
()

Method isReferenceToManifest This returns true if the Type attribute of the Reference element points to a #Manifest element

public boolean

Returns:

true if the Reference type indicates that this Reference points to an Object
typeIsReferenceToObject
()

Method isReferenceToObject This returns true if the Type attribute of the Reference element points to a #Object element

public boolean

Returns:

true if reference validation is success, otherwise false
verify
()

Tests reference validation is success or false

Inherited from com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy:
getBaseNamespace

Field Detail

digestMethodElemback to summary
private Element digestMethodElem
digestValueElementback to summary
private Element digestValueElement
LOGback to summary
private static final Logger LOG

Hides com.sun.org.apache.xml.internal.security.utils.ElementProxy.LOG.

manifestback to summary
private Manifest manifest
MANIFEST_URIback to summary
public static final String MANIFEST_URI

Field MANIFEST_URI

MAXIMUM_TRANSFORM_COUNTback to summary
public static final int MAXIMUM_TRANSFORM_COUNT

The maximum number of transforms per reference, if secure validation is enabled.

OBJECT_URIback to summary
public static final String OBJECT_URI

Field OBJECT_URI

referenceDataback to summary
private ReferenceData referenceData
secureValidationback to summary
private boolean secureValidation
TRANSFORM_ALGORITHMSback to summary
private static final Set<String> TRANSFORM_ALGORITHMS
transformsback to summary
private Transforms transforms
transformsOutputback to summary
private XMLSignatureInput transformsOutput
useC14N11back to summary
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.

Annotations
@SuppressWarnings:removal

Constructor Detail

Referenceback to summary
protected Reference(Document doc, String baseURI, String referenceURI, Manifest manifest, Transforms transforms, String messageDigestAlgorithm) throws XMLSignatureException

Constructor Reference

Parameters
doc:Document

the Document in which XMLsignature is placed

baseURI:String

the URI of the resource where the XML instance will be stored

referenceURI:String

URI indicate where is data which will digested

transforms:Transforms

Transforms applied to data

messageDigestAlgorithm:String

Digest algorithm which is applied to the data TODO should we throw XMLSignatureException if MessageDigestAlgoURI is wrong?

Referenceback to summary
protected Reference(Element element, String baseURI, Manifest manifest) throws XMLSecurityException

Build a Reference from an Element

Parameters
element:Element

Reference element

baseURI:String

the URI of the resource where the XML instance was stored

manifest: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

Referenceback to summary
protected Reference(Element element, String baseURI, Manifest manifest, boolean secureValidation) throws XMLSecurityException

Build a Reference from an Element

Parameters
element:Element

Reference element

baseURI:String

the URI of the resource where the XML instance was stored

manifest:Manifest

is the Manifest of SignedInfo in which the Reference occurs.

secureValidation:boolean

whether secure validation is enabled or not We need this because the Manifest has the individual ResourceResolvers which have been set by the user

Method Detail

cacheDereferencedElementback to summary
private void cacheDereferencedElement(XMLSignatureInput input)

Store the dereferenced Element(s) so that it/they can be retrieved later.

calculateDigestback to summary
private byte[] calculateDigest(boolean validating) throws ReferenceNotInitializedException, XMLSignatureException

Method calculateDigest

Parameters
validating:boolean

true if validating the reference

Returns:byte[]

reference Calculate the digest of this reference.

dereferenceURIandPerformTransformsback to summary
protected XMLSignatureInput dereferenceURIandPerformTransforms(OutputStream os) throws XMLSignatureException

This method returns the XMLSignatureInput which is referenced by the URI Attribute.

Parameters
os:OutputStream

where to write the transformation can be null.

Returns:XMLSignatureInput

the element to digest

See Also
Manifest#verifyReferences()
generateDigestValueback to summary
public void generateDigestValue() throws XMLSignatureException, ReferenceNotInitializedException

Method generateDigestValue

getBaseLocalNameback to summary
public String getBaseLocalName()

Implements abstract com.sun.org.apache.xml.internal.security.utils.ElementProxy.getBaseLocalName.

Doc from com.sun.org.apache.xml.internal.security.utils.ElementProxy.getBaseLocalName.

Method getBaseLocalName Returns the localname of the Elements of the sub-class.

Annotations
@Override
getContentsAfterTransformationback to summary
private XMLSignatureInput getContentsAfterTransformation(XMLSignatureInput input, OutputStream os) throws XMLSignatureException
getContentsAfterTransformationback to summary
public XMLSignatureInput getContentsAfterTransformation() throws XMLSignatureException

Returns the XMLSignatureInput which is the result of the Transforms.

Returns:XMLSignatureInput

a XMLSignatureInput with all transformations applied.

getContentsBeforeTransformationback to summary
public XMLSignatureInput getContentsBeforeTransformation() throws ReferenceNotInitializedException

Returns the XMLSignatureInput which is created by de-referencing the URI attribute.

Returns:XMLSignatureInput

the XMLSignatureInput of the source of this reference

Exceptions
ReferenceNotInitializedException:
If the resolver found any problem resolving the reference
getDigestValueback to summary
public byte[] getDigestValue() throws XMLSecurityException

Returns the digest value.

Returns:byte[]

the digest value.

Exceptions
XMLSecurityException:
if the Reference does not contain a DigestValue element
getHTMLRepresentationback to summary
public String getHTMLRepresentation() throws XMLSignatureException

Method getHTMLRepresentation

Returns:String

The HTML of the transformation

getIdback to summary
public String getId()

Returns the Id attribute of this Reference element

Returns:String

Id the Id attribute of this Reference element

getMessageDigestAlgorithmback to summary
public MessageDigestAlgorithm getMessageDigestAlgorithm() throws XMLSignatureException

Returns MessageDigestAlgorithm

Returns:MessageDigestAlgorithm

MessageDigestAlgorithm

getNodesetBeforeFirstCanonicalizationback to summary
public XMLSignatureInput getNodesetBeforeFirstCanonicalization() throws XMLSignatureException

This method returns the XMLSignatureInput which represents the node set before some kind of canonicalization is applied for the first time.

Returns:XMLSignatureInput

Gets a the node doing everything till the first c14n is needed

getPreCalculatedDigestback to summary
private byte[] getPreCalculatedDigest(XMLSignatureInput input) throws ReferenceNotInitializedException

Get the pre-calculated digest value from the XMLSignatureInput.

Parameters
input:XMLSignatureInput

XMLSignature

Returns:byte[]

a pre-calculated digest value.

Exceptions
ReferenceNotInitializedException:
if there is an error decoding digest value in Base64. Properly encoded pre-calculated digest value must be set.
getReferenceDataback to summary
public ReferenceData getReferenceData()

Get the ReferenceData that corresponds to the cached representation of the dereferenced object before transformation.

getReferencedBytesback to summary
public byte[] getReferencedBytes() throws ReferenceNotInitializedException, XMLSignatureException

Method getReferencedBytes

Returns:byte[]

the bytes that will be used to generated digest.

getTransformsback to summary
public Transforms getTransforms() throws XMLSignatureException, InvalidTransformException, TransformationException, XMLSecurityException

Method getTransforms

Returns:Transforms

The transforms that applied this reference.

getTransformsOutputback to summary
public XMLSignatureInput getTransformsOutput()

This method only works after a call to verify.

Returns:XMLSignatureInput

the transformed output(i.e. what is going to be digested).

getTypeback to summary
public String getType()

Return the type attribute of the Reference indicate whether an ds:Object, ds:SignatureProperty, or ds:Manifest element

Returns:String

the type attribute of the Reference

getURIback to summary
public String getURI()

Returns the URI of this Reference element

Returns:String

URI the URI of this Reference element

setDigestValueElementback to summary
private void setDigestValueElement(byte[] digestValue)

Method setDigestValueElement

setIdback to summary
public void setId(String id)

Sets the Id attribute of this Reference element

Parameters
id:String

the Id attribute of this Reference element

setTypeback to summary
public void setType(String type)

Sets the type atttibute of the Reference indicate whether an ds:Object, ds:SignatureProperty, or ds:Manifest element.

Parameters
type:String

the type attribute of the Reference

setURIback to summary
public void setURI(String uri)

Sets the URI of this Reference element

Parameters
uri:String

the URI of this Reference element

typeIsReferenceToManifestback to summary
public boolean typeIsReferenceToManifest()

Method isReferenceToManifest This returns true if the Type attribute of the Reference element points to a #Manifest element

Returns:boolean

true if the Reference type indicates that this Reference points to a Manifest

typeIsReferenceToObjectback to summary
public boolean typeIsReferenceToObject()

Method isReferenceToObject This returns true if the Type attribute of the Reference element points to a #Object element

Returns:boolean

true if the Reference type indicates that this Reference points to an Object

verifyback to summary
public boolean verify() throws ReferenceNotInitializedException, XMLSecurityException

Tests reference validation is success or false

Returns:boolean

true if reference validation is success, otherwise false