public class XMLSignatureImpl extends XmldsigDOMStructure implements XMLSignature
Signature element that supports the DOM
XML representation and processing mechanism.| Modifier and Type | Class and Description |
|---|---|
protected class |
XMLSignatureImpl.SignatureValueImpl
An implementation of the
SignatureValue element that supports
the DOM XML representation and marshaling mechanism. |
DOMStructure.NodeWrapperXMLSignature.SignatureValue| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
calculatedSignatureValue_
The calculated and cached signature value.
|
protected String |
id_
The
Id attribute value. |
protected KeyInfo |
keyInfo_
The
KeyInfo. |
protected KeySelectorResult |
keySelectorResult_
The result returned by the key selector.
|
protected List |
objects_
The list of
Objects. |
static XMLSignatureProcessingHook |
POST_SIGN_HOOK |
static XMLSignatureProcessingHook |
POST_VERIFY_HOOK |
static XMLSignatureProcessingHook |
PRE_SIGN_HOOK |
static XMLSignatureProcessingHook |
PRE_VERIFY_HOOK |
protected XMLSignatureImpl.SignatureValueImpl |
signatureValue_
The
SignatureValue. |
protected SignedInfoImpl |
signedInfo_
The
SignedInfo. |
static int |
STATE_SIGNED
The state SIGNED.
|
protected boolean |
valid_
Is this signature valid?
|
protected boolean |
validated_
Has this signature been validated?
|
implMap_, state_, STATE_CREATED, STATE_MARSHALED, STATE_UNINITIALIZED, STATE_UNMARSHALEDXMLNS| Modifier | Constructor and Description |
|---|---|
|
XMLSignatureImpl(DOMCryptoContext context,
Node node)
Creates a new instance of this
XMLSignatureImpl with the
specified provider config, context and node to unmarshal from. |
protected |
XMLSignatureImpl(Node node)
Creates a new instance of this
XMLSignatureImpl with the
specified provider config and node. |
|
XMLSignatureImpl(SignedInfoImpl signedInfo,
KeyInfo keyInfo,
List objects,
String id,
String signatureValueId)
Creates a new instance of this
XMLSignatureImpl with the
specified provider config, SignedInfo, KeyInfo,
list of XMLObjectImpls, id-attribute value and
id-attribute value of the SignatureValue element. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
assureDefaults(XMLCryptoContext context)
This method assures, that the default values of certain properties have
been set in the context.
|
protected void |
calculateAndMarshalSignatureValue(DOMCryptoContext context,
Key key)
Calculates the signature value of this
Signature and appends a
SignatureValue element with the calculated signature value. |
protected void |
generateCore(DOMCryptoContext context)
Generates the Signature according to the Core Generation rules defined in
XML-Signature Syntax and
Processing section 3.1 Core
Generation.
|
protected List |
getChildStructures()
Returns the list of child structures of this
DOMStructure. |
String |
getId()
Returns the optional Id of this
XMLSignature. |
KeyInfo |
getKeyInfo()
Returns the key info of this
XMLSignature. |
KeySelectorResult |
getKeySelectorResult()
Returns the result of the
KeySelector, if specified, after this
XMLSignature has been signed or validated. |
String |
getLocalName()
Returns the local name of the represented XML element.
|
List |
getObjects()
|
XMLSignature.SignatureValue |
getSignatureValue()
Returns the signature value of this
XMLSignature. |
SignedInfo |
getSignedInfo()
Returns the signed info of this
XMLSignature. |
Node |
marshal(DOMCryptoContext context,
Node parent,
Node nextSibling)
Marshal the DOM node representation of this
DOMStructure and
all its child DOMStructures. |
protected void |
marshalAttributes(DOMCryptoContext context,
Element parent)
Marshals the XML representation of all
Attributes
represented by this DOMStrucuture. |
protected Attr |
marshalIDAttribute(DOMCryptoContext context,
Element parent)
Marshals the XML representation of an optional
Id-attribute
represented by this DOMStructure. |
protected void |
putChildStructure(DOMStructure childStructure)
Put an unmarshalled child structure.
|
protected void |
selectKey(XMLCryptoContext context,
KeySelector.Purpose purpose)
Select the appropriate key for signing or validating the signature.
|
protected void |
selectKeyAndGenerateSignature(DOMCryptoContext context)
Selects a signing key and generates the Signature according to the
Signature Generation rules defined in XML-Signature Syntax and
Processing section 3.1.2
Signature Generation by calling
calculateAndMarshalSignatureValue(javax.xml.crypto.dom.DOMCryptoContext, Key) |
protected boolean |
selectKeyAndValidateSignature(XMLValidateContext validateContext)
Selects a verifying key and validates the Signature according to the
Signature Validation rules defined in XML-Signature Syntax and
Processing section 3.2.2
Signature Validation by calling
validateSignatureValue(XMLValidateContext, Key) |
void |
sign(XMLSignContext signContext)
Signs this
XMLSignature. |
void |
unmarshal(DOMCryptoContext context)
Unmarshals this
DOMStructure from its XML representation. |
protected void |
unmarshalAttributes(NamedNodeMap attributes,
DOMCryptoContext context)
Unmarshal the given
attributes. |
protected void |
unmarshalStructures(NodeList nodes,
DOMCryptoContext context)
Unmarshals
DOMStructures from the given nodes. |
boolean |
validate(XMLValidateContext validateContext)
Validates the signature according to the core
validation processing rules .
|
protected boolean |
validateCore(XMLValidateContext validateContext)
Validates the Signature according to the Core Validation rules defined in
XML-Signature Syntax and
Processing section 3.2 Core
Validation.
|
protected boolean |
validateSignatureValue(XMLValidateContext validateContext,
Key key)
Validates the Signature according to the Signature Validation rules defined
in XML-Signature Syntax and
Processing section 3.2.2
Signature Validation by calling
validateSignatureValue(XMLValidateContext, Key) |
getNamespace, initaddBytesToElement, addBytesToElement, clearMarshalling, clearMarshalling, getBytesFromElement, getBytesFromElementStream, getChildStructureVersion, getHere, getImplClass, getInstance, getInstance, getNode, getParentStructure, getParentStructureOf, getQualifiedName, getQualifiedName, hasNSDeclAttrInScope, isFeatureSupported, isNSDeclInScope, marshalElement, newIDforLookUp, putImplClass, setBackToCompatibilityPrior1_14, setNode, setParentStructure, toString, unmarshalElement, unmarshalIDAttribute, wrapNodeclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisFeatureSupportedpublic static final int STATE_SIGNED
public static XMLSignatureProcessingHook PRE_SIGN_HOOK
public static XMLSignatureProcessingHook POST_SIGN_HOOK
public static XMLSignatureProcessingHook PRE_VERIFY_HOOK
public static XMLSignatureProcessingHook POST_VERIFY_HOOK
protected String id_
Id attribute value.protected SignedInfoImpl signedInfo_
SignedInfo. (may not be null)protected XMLSignatureImpl.SignatureValueImpl signatureValue_
SignatureValue. (may not be null)protected KeyInfo keyInfo_
KeyInfo.protected List objects_
Objects. (may not be null)protected KeySelectorResult keySelectorResult_
protected byte[] calculatedSignatureValue_
protected boolean valid_
protected boolean validated_
protected XMLSignatureImpl(Node node) throws MarshalException
XMLSignatureImpl with the
specified provider config and node.node - the nodeMarshalException - if an exception occurs during unmarshalingpublic XMLSignatureImpl(DOMCryptoContext context, Node node) throws MarshalException
XMLSignatureImpl with the
specified provider config, context and node to unmarshal from.context - the contextnode - the node to unmarshal fromMarshalException - if an exception occurs during unmarshalingpublic XMLSignatureImpl(SignedInfoImpl signedInfo, KeyInfo keyInfo, List objects, String id, String signatureValueId)
XMLSignatureImpl with the
specified provider config, SignedInfo, KeyInfo,
list of XMLObjectImpls, id-attribute value and
id-attribute value of the SignatureValue element.signedInfo - the SignedInfokeyInfo - the KeyInfo (may be null)objects - a list of XMLObjectImpls (may be null or empty)id - the id-attribute value (may be null)signatureValueId - the id-attribute value of the
SignatureValue element (may be null)NullPointerException - if config or signedInfo is
nullClassCastException - if any of the objects is not of type
XMLObjectImplpublic String getLocalName()
DOMStructuregetLocalName in class DOMStructureDOMStructure.getLocalName()public KeyInfo getKeyInfo()
javax.xml.crypto.dsig.XMLSignatureXMLSignature.getKeyInfo in interface XMLSignaturenull if not specified)XMLSignature.getKeyInfo()public SignedInfo getSignedInfo()
javax.xml.crypto.dsig.XMLSignatureXMLSignature.getSignedInfo in interface XMLSignaturenull)XMLSignature.getSignedInfo()public List getObjects()
javax.xml.crypto.dsig.XMLSignaturegetObjects in interface XMLSignatureXMLObject s (may be empty but
never null)XMLSignature.getObjects()public String getId()
javax.xml.crypto.dsig.XMLSignatureXMLSignature.getId in interface XMLSignaturenull if not specified)XMLSignature.getId()public XMLSignature.SignatureValue getSignatureValue()
javax.xml.crypto.dsig.XMLSignatureXMLSignature.getSignatureValue in interface XMLSignatureXMLSignature.getSignatureValue()protected void selectKey(XMLCryptoContext context, KeySelector.Purpose purpose) throws XMLSignatureException, KeySelectorException
context - the XMLCryptoContext to get the KeySelector
frompurpose - the KeySelector.Purpose (may be
KeySelector.Purpose.SIGN or
KeySelector.Purpose.VERIFY)XMLSignatureException - if no signature method has been specifiedKeySelectorException - if selecting the key fails for any reasonpublic KeySelectorResult getKeySelectorResult()
javax.xml.crypto.dsig.XMLSignatureKeySelector, if specified, after this
XMLSignature has been signed or validated.getKeySelectorResult in interface XMLSignaturenull if a key selector has
not been specified or this XMLSignature has not been
signed or validatedXMLSignature.getKeySelectorResult()protected List getChildStructures()
DOMStructureDOMStructure.
This method is called by DOMStructure.marshal(DOMCryptoContext, Node, Node).
A subclass has to overwrite this method to return a list of
DOMStrucutres represented by this subclass.
getChildStructures in class DOMStructureDOMStructures (may be empty, but never
null)DOMStructure.getChildStructures()protected void putChildStructure(DOMStructure childStructure) throws MarshalException
DOMStructure
This method is called by
DOMStructure.unmarshalStructures(NodeList, DOMCryptoContext) for every
unmarshalled child structure.
A subclass has to overwrite this method to store the given child structure in its the corresponding field.
putChildStructure in class DOMStructurechildStructure - the unmarshalled child structureMarshalExceptionDOMStructure.putChildStructure(iaik.xml.crypto.dom.DOMStructure)protected void marshalAttributes(DOMCryptoContext context, Element parent) throws MarshalException
DOMStructureAttributes
represented by this DOMStrucuture.
This method is called by DOMStructure.marshal(DOMCryptoContext, Node, Node).
If no namespace prefix is set in the context for the namespace
of the Element represented by this DOMStructure an
namespace declaration is marshaled and returned. Otherwise, an empty list
is returned.
A subclass has to overwrite this method in order to marshal any additional attributes.
marshalAttributes in class DOMStructurecontext - the marshal contextparent - the element is the parent of the attribute node created however, an
the attribute node is not a child of it's parent element. see XPath.MarshalException - if an exception occurs during marshalingDOMStructure.marshalAttributes(DOMCryptoContext,
Element)protected Attr marshalIDAttribute(DOMCryptoContext context, Element parent)
DOMStructureId-attribute
represented by this DOMStructure.
This method is called by DOMStructure.marshal(DOMCryptoContext, Node, Node).
A subclass has to overwrite this method in order to marshal an
Id-attribute.
marshalIDAttribute in class DOMStructurecontext - the marshal contextparent - the element is the parent of the attribute node created however, an
the attribute node is not a child of it's parent element. see XPath.Id-attribute if any, otherwise
nullDOMStructure.marshalIDAttribute(javax.xml.crypto.dom.DOMCryptoContext,
Element)protected void unmarshalAttributes(NamedNodeMap attributes, DOMCryptoContext context) throws MarshalException
DOMStructureattributes.
This method is called by DOMStructure.unmarshal(DOMCryptoContext).
A subclass has to overwrite this method to perform any special unmarshaling required.
unmarshalAttributes in class DOMStructureattributes - the Attributes to unmarshalcontext - the marshal contextMarshalException - if an exception occurs during unmarshalingDOMStructure.unmarshalAttributes(org.w3c.dom.NamedNodeMap,
javax.xml.crypto.dom.DOMCryptoContext)public Node marshal(DOMCryptoContext context, Node parent, Node nextSibling) throws MarshalException
DOMStructureDOMStructure and
all its child DOMStructures.
marshal in class DOMStructurecontext - the DOMMarshalContext holding context information about
the marshaling of this DOMStructureparent - where to place the marshalled nodenextSibling - before wich to place the marshalled nodeDOMStrucuture and
all its child DOMStructuruesMarshalException - if the marshaling fails for any reasonDOMStructure.marshal(DOMCryptoContext, Node, Node)public void unmarshal(DOMCryptoContext context) throws MarshalException
DOMStructureDOMStructure from its XML representation.
unmarshal in class DOMStructurecontext - the marshaling contextMarshalException - if an exception occurs during marshalingDOMStructure.unmarshal(javax.xml.crypto.dom.DOMCryptoContext)protected void unmarshalStructures(NodeList nodes, DOMCryptoContext context) throws MarshalException
DOMStructureDOMStructures from the given nodes.
This method is called by DOMStructure.unmarshal(DOMCryptoContext).
This method calls DOMStructure.getInstance(Node, DOMCryptoContext) for every
Element in the list of nodes. If
DOMStructure.getInstance(Node, DOMCryptoContext) returns a
DOMStructure DOMStructure.putChildStructure(DOMStructure) is
called with the returned DOMStructure as parameter.
unmarshalStructures in class DOMStructurenodes - the nodes to unmarshal fromcontext - the marshal contextMarshalException - if an exception occurs during marshalingDOMStructure.unmarshalStructures(org.w3c.dom.NodeList,
javax.xml.crypto.dom.DOMCryptoContext)public void sign(XMLSignContext signContext) throws MarshalException, XMLSignatureException
javax.xml.crypto.dsig.XMLSignatureXMLSignature.
If this method throws an exception, this XMLSignature and the
signContext parameter will be left in the state that it was in
prior to the invocation.
sign in interface XMLSignaturesignContext - the signing contextMarshalException - if an exception occurs while marshallingXMLSignatureException - if an unexpected exception occurs while generating the signatureXMLSignature.sign(javax.xml.crypto.dsig.XMLSignContext)protected void generateCore(DOMCryptoContext context) throws XMLSignatureException, MarshalException
NOTE: THIS METHOD ASSUMES THAT THE TREE MODEL WORKAROUND HAS ALREADY BEEN APPLIED!
context - XMLSignatureExceptionMarshalExceptionprotected void selectKeyAndGenerateSignature(DOMCryptoContext context) throws XMLSignatureException, MarshalException
calculateAndMarshalSignatureValue(javax.xml.crypto.dom.DOMCryptoContext, Key)
context - XMLSignatureExceptionMarshalExceptionprotected void calculateAndMarshalSignatureValue(DOMCryptoContext context, Key key) throws XMLSignatureException, MarshalException
Signature and appends a
SignatureValue element with the calculated signature value.context - the DOMMarshalContext for the signature value
calculation and element marshalingkey - the Key for the signature value calculationXMLSignatureException - if calculating the signature value fails for any reasonMarshalException - if marshaling the SingnatureValue element fails for
any reasonpublic boolean validate(XMLValidateContext validateContext) throws XMLSignatureException
javax.xml.crypto.dsig.XMLSignatureXMLSignature using the location information specified in
the context.
This method only validates the signature the first time it is invoked. On subsequent invocations, it returns a cached result.
validate in interface XMLSignaturevalidateContext - the validating contexttrue if the signature passed core validation, otherwise
falseXMLSignatureException - if an unexpected error occurs during validation that prevented the
validation operation from completingXMLSignature.validate(javax.xml.crypto.dsig.XMLValidateContext)protected void assureDefaults(XMLCryptoContext context)
context - the context to set the properties.DOMCryptoContext.setDefaultsIfNotSet(XMLCryptoContext),
DOMCryptoContext.DOMCryptoContext()protected boolean validateCore(XMLValidateContext validateContext) throws XMLSignatureException
NOTE: THIS METHOD ASSUMES THAT THE TREE MODEL WORKAROUND HAS ALREADY BEEN APPLIED!
validateContext - true if this signature is core-valid, otherwise
falseXMLSignatureExceptionprotected boolean selectKeyAndValidateSignature(XMLValidateContext validateContext) throws XMLSignatureException
validateSignatureValue(XMLValidateContext, Key)
NOTE: THIS METHOD ASSUMES THAT THE TREE MODEL WORKAROUND HAS ALREADY BEEN APPLIED!
validateContext - XMLSignatureExceptionprotected boolean validateSignatureValue(XMLValidateContext validateContext, Key key) throws XMLSignatureException
validateSignatureValue(XMLValidateContext, Key)
NOTE: THIS METHOD ASSUMES THAT THE TREE MODEL WORKAROUND HAS ALREADY BEEN APPLIED!
validateContext - XMLSignatureException© 2002-2005 IAIK, © 2004, 2006 - 2019 Stiftung SIC