|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object anon.crypto.XMLSignature
public final class XMLSignature
This class stores and creates signatures of XML nodes. The signing and verification processes and the underlying XML signature structure are completely transparent to the using code. Therefore, the XML_ELEMENT_NAME is not public. Just sign and verify what you want, you do not need to know how it works! It is not allowed to change the structure of an element`s signature node for other code than methods of this class. Otherwise, some methods could give false results. XMLSignature objects can only be created by signing or verifying XML nodes, or by getting an unverified signature from an XML node.
http://www.w3.org/TR/xmldsig-core/
Field Summary | |
---|---|
private MultiCertPath |
m_multiCertPath
The MultiCertPath assoicated with this signature |
private java.util.Vector |
m_signatureElements
The Vector of XMLSignatureElements kept by this object |
private java.lang.String |
m_xoredID
The XORed SKIs of all Certs that verified a signature |
private static java.lang.String |
XML_ELEMENT_NAME
|
Constructor Summary | |
---|---|
private |
XMLSignature()
Creates a new and empty signature. |
Method Summary | |
---|---|
boolean |
addCertificate(JAPCertificate a_certificate)
|
private void |
calculateXORofSKIs()
Calculates the XOR of the SKIs once and stores it. |
void |
clearCertificates()
|
int |
countSignatures()
Returns how many signatures the document has. |
private static XMLSignature |
findXMLSignature(org.w3c.dom.Node a_node)
Finds the signature elements of the given node if present. |
private CertPath[] |
getCertPaths()
Create an array of the CertPaths from all the XMLSignatureElements. |
static java.lang.String |
getEncodedHashValue(org.w3c.dom.Element nodeToHash)
Same method as getHashValueOfElement, except the String returned is already Base64-encoded necessary to avoid discrepancies between the results of getHashValueOfElement between the BI(Java) and PIG (Ruby/Java-bridge) |
static java.lang.String |
getHashValueOfElement(org.w3c.dom.Node nodeToHash)
getHashValueOfElement: takes an XML node and returns its hash value |
MultiCertPath |
getMultiCertPath()
|
protected java.util.Vector |
getSignatureElements()
Return a Vector of the |
static XMLSignature |
getUnverified(org.w3c.dom.Node a_node)
Gets the signature from a node if present. |
static XMLSignature |
getVerified(org.w3c.dom.Node a_node,
int a_documentType,
java.util.Vector a_directCertificatePaths)
Creates a new XMLSignature from the node and creates a new MultiCertPath object. |
org.w3c.dom.Element[] |
getXMLElements(org.w3c.dom.Document a_doc)
Returns all |
java.lang.String |
getXORofSKIs()
This method is used by the checkId()-methods of the database classes, that compare the id of a given entry with the SubjectKeyIdentifier of the associated cert(s). |
boolean |
isVerified()
The Signature is verified if the MultiCertPath is verified. |
private static int |
makeCanonical(org.w3c.dom.Node node,
java.io.OutputStream o,
boolean bSiblings,
org.w3c.dom.Node excludeNode)
|
private static int |
makeCanonical(org.w3c.dom.Node node,
java.io.OutputStream o,
boolean bSiblings,
org.w3c.dom.Node excludeNode,
boolean a_bKeepSpaces)
|
private static int |
makeCanonical(org.w3c.dom.Node node,
java.io.OutputStream o,
boolean bSiblings,
java.util.Vector excludedNodes,
boolean a_bKeepSpaces,
java.lang.String charsetName)
|
static XMLSignature |
multiSign(org.w3c.dom.Node a_node,
java.util.Vector a_privateKeys)
Signs an XML node with multiple keys and creates a new XMLSignature from the signature. |
static boolean |
removeSignatureFrom(org.w3c.dom.Node a_node)
Removes the signature from an XML node if a signature exists. |
private static java.util.Vector |
removeSignatureFromInternal(org.w3c.dom.Node a_node)
Removes the signature from an XML node if a signature exists. |
static XMLSignature |
sign(org.w3c.dom.Node a_node,
IMyPrivateKey a_privateKey)
Signs an XML node and creates a new XMLSignature from the signature. |
static XMLSignature |
sign(org.w3c.dom.Node a_node,
PKCS12 a_certificate)
Signs an XML node and creates a new XMLSignature from the signature. |
private static XMLSignature |
signInternal(org.w3c.dom.Node a_node,
java.util.Vector a_privateKeys)
Signs an XML node with all supplied private keys and creates a new XMLSignature from the signature. |
static byte[] |
toCanonical(org.w3c.dom.Node inputNode)
|
static byte[] |
toCanonical(org.w3c.dom.Node inputNode,
boolean a_bKeepSpaces)
Creates a byte array from an XML node tree. |
static byte[] |
toCanonical(org.w3c.dom.Node a_inputNode,
java.util.Vector a_excludedNodes)
|
static byte[] |
toCanonicalDeprecated(org.w3c.dom.Node a_inputNode)
Is only used if no digest value is found. |
static java.lang.String |
toCanonicalString(org.w3c.dom.Element input)
same as toCanonical(Node):byte[], except returning a String only necessary for use in Ruby (since handling a Java byte array in Ruby wouldnt work) |
static XMLSignature |
verify(org.w3c.dom.Node a_node,
IMyPublicKey a_publicKey)
Verifies the signature of an XML node and creates a new XMLSignature from a valid signature. |
static boolean |
verifyFast(org.w3c.dom.Node a_node,
IMyPublicKey a_publicKey)
Only verifies the signatures of an XML node with the given key. |
static boolean |
verifyFast(org.w3c.dom.Node a_node,
java.util.Vector a_publicKeys)
Only verifies the signatures of an XML node with the given keys. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String XML_ELEMENT_NAME
private java.util.Vector m_signatureElements
private MultiCertPath m_multiCertPath
private java.lang.String m_xoredID
Constructor Detail |
---|
private XMLSignature()
Method Detail |
---|
public int countSignatures()
protected java.util.Vector getSignatureElements()
public MultiCertPath getMultiCertPath()
private CertPath[] getCertPaths()
anon.crypto.XMLSignature.verify()
,
anon.crypto.XMLSignatureElement.verify();
public java.lang.String getXORofSKIs()
anon.infoservice.AbstractCertifiedDatabaseEntry.checkId()
,
anon.infoservice.AbstractDistributableCertifiedDatabaseEntry.checkId()
private void calculateXORofSKIs()
public boolean isVerified()
true
if the MultiCertPath is verified.public static XMLSignature sign(org.w3c.dom.Node a_node, PKCS12 a_certificate) throws XMLParseException
a_node
- an XML nodea_certificate
- a certificate to sign the signature
XMLParseException
- if the node could not be signed because it could not be
properly transformed into bytespublic boolean addCertificate(JAPCertificate a_certificate)
public static XMLSignature sign(org.w3c.dom.Node a_node, IMyPrivateKey a_privateKey) throws XMLParseException
a_node
- an XML nodea_privateKey
- a private key to sign the signature
XMLParseException
- if the node could not be signed because it could not be
properly transformed into bytespublic static XMLSignature multiSign(org.w3c.dom.Node a_node, java.util.Vector a_privateKeys) throws XMLParseException
a_node
- an XML nodea_privateKey
- a private key to sign the signature
XMLParseException
- if the node could not be signed because it could not be
properly transformed into bytespublic static java.lang.String getHashValueOfElement(org.w3c.dom.Node nodeToHash)
nodeToHash
- Node
public static java.lang.String getEncodedHashValue(org.w3c.dom.Element nodeToHash)
nodeToHash
- Node
private static XMLSignature signInternal(org.w3c.dom.Node a_node, java.util.Vector a_privateKeys) throws XMLParseException
a_node
- an XML nodea_privateKeys
- the private keys or private certs to sign the signature
XMLParseException
- if the node could not be signed because it could not be
properly transformed into bytespublic static XMLSignature getVerified(org.w3c.dom.Node a_node, int a_documentType, java.util.Vector a_directCertificatePaths) throws XMLParseException, java.security.SignatureException
a_node
- Node A signed XML node.a_documentType
- The document-Type of the node.a_directCertificates
- A Vector of CertPaths to verify the signature, if there are no
appended certificates
XMLParseException
- if a signature element exists, but the element
has an invalid structure
java.security.SignatureException
- if we found no verifier for one Signature, because the right cert was not
appended or cached or the Signature is wrong. In either way we do not know
which cert to take for calculating the the XORed ID.public static boolean verifyFast(org.w3c.dom.Node a_node, java.util.Vector a_publicKeys)
true
is returned.
a_node
- an XML nodea_publicKey
- a public key to verify the signature
public static boolean verifyFast(org.w3c.dom.Node a_node, IMyPublicKey a_publicKey)
true
is returned.
a_node
- an XML nodea_publicKey
- a public key to verify the signature
public static XMLSignature verify(org.w3c.dom.Node a_node, IMyPublicKey a_publicKey) throws XMLParseException
a_node
- an XML nodea_publicKey
- a public key to verify the signature
XMLParseException
- if a signature element exists, but the element
has an invalid structurepublic static XMLSignature getUnverified(org.w3c.dom.Node a_node) throws XMLParseException
a_node
- an XML node
XMLParseException
- if the signature is present but has an invalid XML structurepublic static boolean removeSignatureFrom(org.w3c.dom.Node a_node)
a_node
- an XML Node
private static java.util.Vector removeSignatureFromInternal(org.w3c.dom.Node a_node)
a_node
- an XML Node
private static XMLSignature findXMLSignature(org.w3c.dom.Node a_node) throws XMLParseException
a_node
- an XML Node
XMLParseException
- if the node has an invalid valid XML signature element structurepublic void clearCertificates()
public static byte[] toCanonical(org.w3c.dom.Node a_inputNode, java.util.Vector a_excludedNodes) throws XMLParseException
XMLParseException
public static byte[] toCanonicalDeprecated(org.w3c.dom.Node a_inputNode)
a_inputNode
- Node
public static byte[] toCanonical(org.w3c.dom.Node inputNode) throws XMLParseException
XMLParseException
public static byte[] toCanonical(org.w3c.dom.Node inputNode, boolean a_bKeepSpaces) throws XMLParseException
inputNode
- The node (incl. the whole tree) which is flattened to a byte array.
XMLParseException
- if the node could not be properly transformed into bytespublic static java.lang.String toCanonicalString(org.w3c.dom.Element input)
inputNode
- Node
XMLParseException
private static int makeCanonical(org.w3c.dom.Node node, java.io.OutputStream o, boolean bSiblings, org.w3c.dom.Node excludeNode)
private static int makeCanonical(org.w3c.dom.Node node, java.io.OutputStream o, boolean bSiblings, org.w3c.dom.Node excludeNode, boolean a_bKeepSpaces)
node
- Nodeo
- OutputStreambSiblings
- booleanexcludeNode
- Node
http://www.w3.org/TR/xmldsig-core/#sec-CanonicalizationMethod
,
http://www.w3.org/TR/xml-c14n
private static int makeCanonical(org.w3c.dom.Node node, java.io.OutputStream o, boolean bSiblings, java.util.Vector excludedNodes, boolean a_bKeepSpaces, java.lang.String charsetName)
node
- Nodeo
- OutputStreambSiblings
- booleanexcludeNode
- Node
http://www.w3.org/TR/xmldsig-core/#sec-CanonicalizationMethod
,
http://www.w3.org/TR/xml-c14n
public org.w3c.dom.Element[] getXMLElements(org.w3c.dom.Document a_doc)
a_doc
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |