Methods Summary |
---|
private byte[] | calculateDigest()Method resolverResult
try {
MessageDigestAlgorithm mda = this.getMessageDigestAlgorithm();
mda.reset();
DigesterOutputStream diOs=new DigesterOutputStream(mda);
OutputStream os=new UnsyncBufferedOutputStream(diOs);
XMLSignatureInput output=this.dereferenceURIandPerformTransforms(os);
output.updateOutputStream(os);
os.flush();
//this.getReferencedBytes(diOs);
//mda.update(data);
return diOs.getDigestValue();
} catch (XMLSecurityException ex) {
throw new ReferenceNotInitializedException("empty", ex);
} catch (IOException ex) {
throw new ReferenceNotInitializedException("empty", ex);
}
|
protected com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput | dereferenceURIandPerformTransforms(java.io.OutputStream os)This method returns the {@link XMLSignatureInput} which is referenced by the
URI Attribute.
try {
XMLSignatureInput input = this.getContentsBeforeTransformation();
XMLSignatureInput output = this.getContentsAfterTransformation(input, os);
/* at this stage, this._transformsInput and this._transformsOutput
* contain a huge amount of nodes. When we do not cache these nodes
* but only preserve the octets, the memory footprint is dramatically
* reduced.
*/
this._transformsOutput = output;
return output;
} catch (XMLSecurityException ex) {
throw new ReferenceNotInitializedException("empty", ex);
}
|
public void | generateDigestValue()Method generateDigestValue
if (this._state == MODE_SIGN) {
this.setDigestValueElement(this.calculateDigest());
}
|
public java.lang.String | getBaseLocalName()Method getBaseLocalName
return Constants._TAG_REFERENCE;
|
private com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput | getContentsAfterTransformation(com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput input, java.io.OutputStream os)
try {
Transforms transforms = this.getTransforms();
XMLSignatureInput output = null;
if (transforms != null) {
output = transforms.performTransforms(input,os);
this._transformsOutput = output;//new XMLSignatureInput(output.getBytes());
//this._transformsOutput.setSourceURI(output.getSourceURI());
} else {
output = input;
}
return output;
} catch (ResourceResolverException ex) {
throw new XMLSignatureException("empty", ex);
} catch (CanonicalizationException ex) {
throw new XMLSignatureException("empty", ex);
} catch (InvalidCanonicalizerException ex) {
throw new XMLSignatureException("empty", ex);
} catch (TransformationException ex) {
throw new XMLSignatureException("empty", ex);
} catch (XMLSecurityException ex) {
throw new XMLSignatureException("empty", ex);
}
|
public com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput | getContentsAfterTransformation()Returns the XMLSignatureInput which is the result of the Transforms.
XMLSignatureInput input = this.getContentsBeforeTransformation();
return this.getContentsAfterTransformation(input, null);
|
public com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput | getContentsBeforeTransformation()Returns the XMLSignatureInput which is created by de-referencing the URI attribute.
try {
Attr URIAttr = this._constructionElement.getAttributeNodeNS(null,
Constants._ATT_URI);
String URI;
if (URIAttr == null) {
URI = null;
} else {
URI = URIAttr.getNodeValue();
}
ResourceResolver resolver = ResourceResolver.getInstance(URIAttr,
this._baseURI, this._manifest._perManifestResolvers);
if (resolver == null) {
Object exArgs[] = { URI };
throw new ReferenceNotInitializedException(
"signature.Verification.Reference.NoInput", exArgs);
}
resolver.addProperties(this._manifest._resolverProperties);
XMLSignatureInput input = resolver.resolve(URIAttr, this._baseURI);
return input;
} catch (ResourceResolverException ex) {
throw new ReferenceNotInitializedException("empty", ex);
} catch (XMLSecurityException ex) {
throw new ReferenceNotInitializedException("empty", ex);
}
|
public byte[] | getDigestValue()Returns the digest value.
Element digestValueElem = XMLUtils.selectDsNode(this._constructionElement.getFirstChild()
,Constants._TAG_DIGESTVALUE,0);
if (digestValueElem == null) {
// The required element is not in the XML!
Object[] exArgs ={ Constants._TAG_DIGESTVALUE,
Constants.SignatureSpecNS };
throw new XMLSecurityException(
"signature.Verification.NoSignatureElement",
exArgs);
}
byte[] elemDig = Base64.decode(digestValueElem);
return elemDig;
|
public java.lang.String | getHTMLRepresentation()Method getHTMLRepresentation
try {
XMLSignatureInput nodes = this.getNodesetBeforeFirstCanonicalization();
Set inclusiveNamespaces = new HashSet();
{
Transforms transforms = this.getTransforms();
Transform c14nTransform = null;
if (transforms != null) {
doTransforms: for (int i = 0; i < transforms.getLength(); i++) {
Transform t = transforms.item(i);
String URI = t.getURI();
if (URI.equals(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS)
|| URI.equals(
Transforms.TRANSFORM_C14N_EXCL_WITH_COMMENTS)) {
c14nTransform = t;
break doTransforms;
}
}
}
if (c14nTransform != null) {
if (c14nTransform
.length(InclusiveNamespaces
.ExclusiveCanonicalizationNamespace, InclusiveNamespaces
._TAG_EC_INCLUSIVENAMESPACES) == 1) {
// there is one InclusiveNamespaces element
InclusiveNamespaces in = new InclusiveNamespaces(
XMLUtils.selectNode(
c14nTransform.getElement().getFirstChild(),
InclusiveNamespaces.ExclusiveCanonicalizationNamespace,
InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES,0), this.getBaseURI());
inclusiveNamespaces = InclusiveNamespaces.prefixStr2Set(
in.getInclusiveNamespaces());
}
}
}
return nodes.getHTMLRepresentation(inclusiveNamespaces);
} catch (TransformationException ex) {
throw new XMLSignatureException("empty", ex);
} catch (InvalidTransformException ex) {
throw new XMLSignatureException("empty", ex);
} catch (XMLSecurityException ex) {
throw new XMLSignatureException("empty", ex);
}
|
public java.lang.String | getId()Returns the Id attribute of this Reference element
return this._constructionElement.getAttributeNS(null, Constants._ATT_ID);
|
public com.sun.org.apache.xml.internal.security.algorithms.MessageDigestAlgorithm | getMessageDigestAlgorithm()Returns {@link MessageDigestAlgorithm}
Element digestMethodElem = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(),
Constants._TAG_DIGESTMETHOD,0);
if (digestMethodElem == null) {
return null;
}
String uri = digestMethodElem.getAttributeNS(null,
Constants._ATT_ALGORITHM);
if (uri == null) {
return null;
}
return MessageDigestAlgorithm.getInstance(this._doc, uri);
|
public com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput | getNodesetBeforeFirstCanonicalization()This method returns the XMLSignatureInput which represents the node set before
some kind of canonicalization is applied for the first time.
try {
XMLSignatureInput input = this.getContentsBeforeTransformation();
XMLSignatureInput output = input;
Transforms transforms = this.getTransforms();
if (transforms != null) {
doTransforms: for (int i = 0; i < transforms.getLength(); i++) {
Transform t = transforms.item(i);
String URI = t.getURI();
if (URI.equals(Transforms
.TRANSFORM_C14N_EXCL_OMIT_COMMENTS) || URI
.equals(Transforms
.TRANSFORM_C14N_EXCL_WITH_COMMENTS) || URI
.equals(Transforms
.TRANSFORM_C14N_OMIT_COMMENTS) || URI
.equals(Transforms
.TRANSFORM_C14N_WITH_COMMENTS)) {
break doTransforms;
}
output = t.performTransform(output, null);
}
output.setSourceURI(input.getSourceURI());
}
return output;
} catch (IOException ex) {
throw new XMLSignatureException("empty", ex);
} catch (ResourceResolverException ex) {
throw new XMLSignatureException("empty", ex);
} catch (CanonicalizationException ex) {
throw new XMLSignatureException("empty", ex);
} catch (InvalidCanonicalizerException ex) {
throw new XMLSignatureException("empty", ex);
} catch (TransformationException ex) {
throw new XMLSignatureException("empty", ex);
} catch (XMLSecurityException ex) {
throw new XMLSignatureException("empty", ex);
}
|
public byte[] | getReferencedBytes()Method getReferencedBytes
try {
XMLSignatureInput output=this.dereferenceURIandPerformTransforms(null);
byte[] signedBytes = output.getBytes();
return signedBytes;
} catch (IOException ex) {
throw new ReferenceNotInitializedException("empty", ex);
} catch (CanonicalizationException ex) {
throw new ReferenceNotInitializedException("empty", ex);
}
|
public com.sun.org.apache.xml.internal.security.transforms.Transforms | getTransforms()Method getTransforms
Element transformsElement = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(),
Constants._TAG_TRANSFORMS,0);
if (transformsElement != null) {
Transforms transforms = new Transforms(transformsElement,
this._baseURI);
return transforms;
}
return null;
|
public com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput | getTransformsInput()Returns the data which is referenced by the URI attribute. This method
only works works after a call to verify.
XMLSignatureInput input=getContentsBeforeTransformation();
XMLSignatureInput result;
try {
result = new XMLSignatureInput(input.getBytes());
} catch (CanonicalizationException ex) {
throw new ReferenceNotInitializedException("empty", ex);
} catch (IOException ex) {
throw new ReferenceNotInitializedException("empty", ex);
}
result.setSourceURI(input.getSourceURI());
return result;
|
public com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput | getTransformsOutput()This method only works works after a call to verify.
return this._transformsOutput;
|
public java.lang.String | getType()Return the type atttibute of the Reference indicate whether an ds:Object , ds:SignatureProperty , or ds:Manifest element
return this._constructionElement.getAttributeNS(null,
Constants._ATT_TYPE);
|
public java.lang.String | getURI()Returns the URI of this Reference element
return this._constructionElement.getAttributeNS(null, Constants._ATT_URI);
|
private void | setDigestValueElement(byte[] digestValue)Method setDigestValueElement
if (this._state == MODE_SIGN) {
Element digestValueElement =XMLUtils.selectDsNode(this._constructionElement.getFirstChild(),
Constants._TAG_DIGESTVALUE,0);
Node n=digestValueElement.getFirstChild();
while (n!=null) {
digestValueElement.removeChild(n);
n = n.getNextSibling();
}
String base64codedValue = Base64.encode(digestValue);
Text t = this._doc.createTextNode(base64codedValue);
digestValueElement.appendChild(t);
}
|
public void | setId(java.lang.String Id)Sets the Id attribute of this Reference element
if ((this._state == MODE_SIGN) && (Id != null)) {
this._constructionElement.setAttributeNS(null, Constants._ATT_ID, Id);
IdResolver.registerElementById(this._constructionElement, Id);
}
|
public void | setType(java.lang.String Type)Sets the type atttibute of the Reference indicate whether an ds:Object , ds:SignatureProperty , or ds:Manifest element
if ((this._state == MODE_SIGN) && (Type != null)) {
this._constructionElement.setAttributeNS(null, Constants._ATT_TYPE,
Type);
}
|
public void | setURI(java.lang.String URI)Sets the URI of this Reference element
if ((this._state == MODE_SIGN) && (URI != null)) {
this._constructionElement.setAttributeNS(null, Constants._ATT_URI,
URI);
}
|
public boolean | typeIsReferenceToManifest()Method isReferenceToManifest
This returns true if the Type attribute of the
Refernce element points to a #Manifest element
if ((this.getType() != null)
&& this.getType().equals(Reference.MANIFEST_URI)) {
return true;
}
return false;
|
public boolean | typeIsReferenceToObject()Method isReferenceToObject
This returns true if the Type attribute of the
Refernce element points to a #Object element
if ((this.getType() != null)
&& this.getType().equals(Reference.OBJECT_URI)) {
return true;
}
return false;
|
public boolean | verify()Tests reference valdiation is success or false
byte[] elemDig = this.getDigestValue();
byte[] calcDig = this.calculateDigest();
boolean equal = MessageDigestAlgorithm.isEqual(elemDig, calcDig);
if (!equal) {
log.log(java.util.logging.Level.WARNING, "Verification failed for URI \"" + this.getURI() + "\"");
} else {
if (log.isLoggable(java.util.logging.Level.INFO)) log.log(java.util.logging.Level.INFO, "Verification successful for URI \"" + this.getURI() + "\"");
}
return equal;
|