anon.crypto
Class XMLSignatureElement

java.lang.Object
  extended by anon.crypto.XMLSignatureElement
All Implemented Interfaces:
IXMLEncodable

public class XMLSignatureElement
extends java.lang.Object
implements IXMLEncodable

Holds a single -Element which is held in an XMLSignature-object. Only instances of XMLSignature should use the methods of this class.

Author:
Robert Hirschberger

Field Summary
private static java.lang.String ATTR_ALGORITHM
           
private static java.lang.String ATTR_URI
           
private static java.lang.String DIGEST_METHOD_ALGORITHM
           
private static java.lang.String ELEM_CANONICALIZATION_METHOD
           
private static java.lang.String ELEM_DIGEST_METHOD
           
private static java.lang.String ELEM_DIGEST_VALUE
           
private static java.lang.String ELEM_KEY_INFO
           
private static java.lang.String ELEM_REFERENCE
           
private static java.lang.String ELEM_SIGNATURE_METHOD
           
private static java.lang.String ELEM_SIGNATURE_VALUE
           
private static java.lang.String ELEM_SIGNED_INFO
           
private  java.util.Vector m_appendedCerts
          Stores all appended certificates It is very important, that whenever this Vector is changed, we also have to change m_appendedCertXMLElements, because the values have to be at the same index of the Vectors
private  java.util.Vector m_appendedCertXMLElements
          Stores the XML representation of the appended certificates
private  CertPath m_certPath
          Stores the certification Path of this Signature
private  java.lang.String m_digestMethod
           
private  java.lang.String m_digestValue
           
private  org.w3c.dom.Element m_elemSignature
           
private  XMLSignature m_parent
           
private  java.lang.String m_referenceURI
           
private  java.lang.String m_signatureMethod
           
private  java.lang.String m_signatureValue
           
private  byte[] m_signedInfoCanonical
           
private static java.lang.String XML_ELEMENT_NAME
           
 
Fields inherited from interface anon.util.IXMLEncodable
FIELD_XML_ELEMENT_CONTAINER_NAME, FIELD_XML_ELEMENT_NAME, XML_ATTR_ID, XML_ATTR_LANGUAGE, XML_ATTR_VERSION
 
Constructor Summary
protected XMLSignatureElement(XMLSignature a_parent)
           
protected XMLSignatureElement(XMLSignature a_parent, org.w3c.dom.Element a_element)
          Creates a new signature from a signature element.
protected XMLSignatureElement(XMLSignature a_parent, org.w3c.dom.Element a_element, IMyPrivateKey a_signKey, byte[] a_digestValue)
           
 
Method Summary
 boolean addCertificate(JAPCertificate a_certificate)
          Adds a certificate to the signature.
private  boolean checkMessageDigest(org.w3c.dom.Node a_node)
           
private  boolean checkSignature(IMyPublicKey a_publicKey)
          Checks if the signature of the XMLSignatureElement's SIGNED_INFO is valid.
 void clearCertificates()
          Deletes all certificates from this signature.
 boolean containsCertificate(JAPCertificate a_certificate)
          Returns if the specified certificate is already contained in this signature element.
 int countCertificates()
          Returns the number of certificates appended to this signature.
private  void createSignatureElement(IMyPrivateKey a_signKey, org.w3c.dom.Element a_elementToSign, byte[] a_digestValue)
           
private  void findCertificates(org.w3c.dom.Element a_xmlSignature)
           
private  java.util.Vector getCertificates()
          Returns all X509 certificates that are embedded in this SignatureElement.
 CertPath getCertPath()
           
 java.lang.String getDigestMethod()
          Returns the digest method that was used for creating this signature.
 java.lang.String getReferenceURI()
          Returns the reference attribute URI.
protected  org.w3c.dom.Element getSignatureElement()
           
 java.lang.String getSignatureMethod()
          Returns the signature method that was used for creating this signature.
 boolean removeCertificate(JAPCertificate a_certificate)
          Removes a certificate from this signature.
 org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc)
          Creates a new XML element from this signature.
private  org.w3c.dom.Element toXmlElementInternal(org.w3c.dom.Document a_doc)
          Transforms this XMLSignature to an XML element.
private  boolean verify(org.w3c.dom.Node a_node, IMyPublicKey a_publicKey)
          This method is used to verify a node with a previously created XMLSignature.
 boolean verify(org.w3c.dom.Node a_node, int a_documentType, java.util.Vector a_directCertPaths)
          Verifies this Signature Element with either the appended certs or with the directCertPaths, if there are no appended certs.
 boolean verifyFast(org.w3c.dom.Node a_node, IMyPublicKey a_publicKey)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_ELEMENT_NAME

private static final java.lang.String XML_ELEMENT_NAME
See Also:
Constant Field Values

ELEM_CANONICALIZATION_METHOD

private static final java.lang.String ELEM_CANONICALIZATION_METHOD
See Also:
Constant Field Values

ELEM_SIGNATURE_METHOD

private static final java.lang.String ELEM_SIGNATURE_METHOD
See Also:
Constant Field Values

ELEM_SIGNATURE_VALUE

private static final java.lang.String ELEM_SIGNATURE_VALUE
See Also:
Constant Field Values

ELEM_KEY_INFO

private static final java.lang.String ELEM_KEY_INFO
See Also:
Constant Field Values

ELEM_SIGNED_INFO

private static final java.lang.String ELEM_SIGNED_INFO
See Also:
Constant Field Values

ELEM_REFERENCE

private static final java.lang.String ELEM_REFERENCE
See Also:
Constant Field Values

ELEM_DIGEST_VALUE

private static final java.lang.String ELEM_DIGEST_VALUE
See Also:
Constant Field Values

ELEM_DIGEST_METHOD

private static final java.lang.String ELEM_DIGEST_METHOD
See Also:
Constant Field Values

ATTR_URI

private static final java.lang.String ATTR_URI
See Also:
Constant Field Values

ATTR_ALGORITHM

private static final java.lang.String ATTR_ALGORITHM
See Also:
Constant Field Values

DIGEST_METHOD_ALGORITHM

private static final java.lang.String DIGEST_METHOD_ALGORITHM
See Also:
Constant Field Values

m_parent

private XMLSignature m_parent

m_elemSignature

private org.w3c.dom.Element m_elemSignature

m_signatureMethod

private java.lang.String m_signatureMethod

m_signatureValue

private java.lang.String m_signatureValue

m_referenceURI

private java.lang.String m_referenceURI

m_digestMethod

private java.lang.String m_digestMethod

m_digestValue

private java.lang.String m_digestValue

m_signedInfoCanonical

private byte[] m_signedInfoCanonical

m_appendedCerts

private java.util.Vector m_appendedCerts
Stores all appended certificates It is very important, that whenever this Vector is changed, we also have to change m_appendedCertXMLElements, because the values have to be at the same index of the Vectors


m_appendedCertXMLElements

private java.util.Vector m_appendedCertXMLElements
Stores the XML representation of the appended certificates


m_certPath

private CertPath m_certPath
Stores the certification Path of this Signature

Constructor Detail

XMLSignatureElement

protected XMLSignatureElement(XMLSignature a_parent)

XMLSignatureElement

protected XMLSignatureElement(XMLSignature a_parent,
                              org.w3c.dom.Element a_element,
                              IMyPrivateKey a_signKey,
                              byte[] a_digestValue)
                       throws java.lang.Exception
Throws:
java.lang.Exception

XMLSignatureElement

protected XMLSignatureElement(XMLSignature a_parent,
                              org.w3c.dom.Element a_element)
                       throws XMLParseException
Creates a new signature from a signature element.

Parameters:
a_element - an XML Element
Throws:
XMLParseException - if the element is no valid signature element
Method Detail

createSignatureElement

private void createSignatureElement(IMyPrivateKey a_signKey,
                                    org.w3c.dom.Element a_elementToSign,
                                    byte[] a_digestValue)
                             throws java.lang.Exception
Throws:
java.lang.Exception

findCertificates

private void findCertificates(org.w3c.dom.Element a_xmlSignature)

verifyFast

public boolean verifyFast(org.w3c.dom.Node a_node,
                          IMyPublicKey a_publicKey)
                   throws XMLParseException
Throws:
XMLParseException

verify

public boolean verify(org.w3c.dom.Node a_node,
                      int a_documentType,
                      java.util.Vector a_directCertPaths)
               throws XMLParseException
Verifies this Signature Element with either the appended certs or with the directCertPaths, if there are no appended certs.

Parameters:
a_node -
a_documentType -
a_directCertPaths -
Returns:
Throws:
XMLParseException

verify

private boolean verify(org.w3c.dom.Node a_node,
                       IMyPublicKey a_publicKey)
                throws XMLParseException
This method is used to verify a node with a previously created XMLSignature.

Parameters:
a_node - an XML node
a_signature - an XMLSignature
a_publicKey - a public key
Returns:
true if the node could be verified with this signature; false otherwise
Throws:
XMLParseException - if a signature element exists, but the element has an invalid structure

checkSignature

private boolean checkSignature(IMyPublicKey a_publicKey)
Checks if the signature of the XMLSignatureElement's SIGNED_INFO is valid.

Parameters:
a_publicKey - a public key
Returns:
true if the signature of the XMLSignature`s SIGNED_INFO is valid; false otherwise

checkMessageDigest

private boolean checkMessageDigest(org.w3c.dom.Node a_node)
                            throws XMLParseException
Parameters:
a_node -
a_signature -
Returns:
Throws:
XMLParseException

getSignatureElement

protected org.w3c.dom.Element getSignatureElement()

getSignatureMethod

public java.lang.String getSignatureMethod()
Returns the signature method that was used for creating this signature.

Returns:
the signature method that was used for creating this signature

getDigestMethod

public java.lang.String getDigestMethod()
Returns the digest method that was used for creating this signature.

Returns:
the digest method that was used for creating this signature

getReferenceURI

public java.lang.String getReferenceURI()
Returns the reference attribute URI.

Returns:
the reference attribute URI

getCertPath

public CertPath getCertPath()

getCertificates

private java.util.Vector getCertificates()
Returns all X509 certificates that are embedded in this SignatureElement.

Returns:
all X509 certificates that are emmbeded in this SignatureElement;

containsCertificate

public boolean containsCertificate(JAPCertificate a_certificate)
Returns if the specified certificate is already contained in this signature element.

Parameters:
a_certificate - an X509 certificate
Returns:
true if the specified certificate is already contained in this signature element; false otherwise

countCertificates

public int countCertificates()
Returns the number of certificates appended to this signature.

Returns:
the number of certificates appended to this signature

clearCertificates

public void clearCertificates()
Deletes all certificates from this signature.


removeCertificate

public boolean removeCertificate(JAPCertificate a_certificate)
Removes a certificate from this signature.

Parameters:
a_certificate - an X509 certificate
Returns:
true if the certificate has been removed; false otherwise

addCertificate

public boolean addCertificate(JAPCertificate a_certificate)
Adds a certificate to the signature. The certificate is not added if the signature cannot be verified with it, or if the signature already contains the specified certificate.

Parameters:
a_certificate - JAPCertificate
Returns:
true if the certificate was added; false otherwise

toXmlElement

public org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc)
Creates a new XML element from this signature. The element is not connected with this XMLSignature object and should be used with care (or better: it should never be used, as it is not necessary...)

Specified by:
toXmlElement in interface IXMLEncodable
Parameters:
a_doc - an XML document
Returns:
the signature as XML element

toXmlElementInternal

private org.w3c.dom.Element toXmlElementInternal(org.w3c.dom.Document a_doc)
Transforms this XMLSignature to an XML element. If the given XML document already is the owner document of the signature element kept by this XMLSignature, this signature element is returned. Otherwise, a new element is created.

Parameters:
a_doc - an XML document
Returns:
the signature as XML element