Class XAdESSignatureBuilder
java.lang.Object
eu.europa.esig.dss.xades.signature.XAdESBuilder
eu.europa.esig.dss.xades.signature.XAdESSignatureBuilder
- All Implemented Interfaces:
SignatureBuilder
public abstract class XAdESSignatureBuilder extends XAdESBuilder implements SignatureBuilder
This class implements all the necessary mechanisms to build each form of the XML signature.
-
Field Summary
Fields inherited from class eu.europa.esig.dss.xades.signature.XAdESBuilder
certificateVerifier, documentDom, params, REFERENCED_DATA, SIGNATURE, TARGET, URI, xadesPaths
-
Constructor Summary
Constructors Constructor Description XAdESSignatureBuilder(XAdESSignatureParameters params, DSSDocument detachedDocument, CertificateVerifier certificateVerifier)
The default constructor for SignatureBuilder. -
Method Summary
Modifier and Type Method Description protected void
addTimestamp(Element timestampElement, TimestampToken token)
Adds the content of a timestamp into a given timestamp elementprotected void
alignNodes()
protected byte[]
applyTransformations(DSSReference reference, Node nodeToTransform)
Applies transforms on a node and returns the byte array to be used for a reference digest computationbyte[]
build()
This is the main method which is called to build the XML signatureprotected Document
buildRootDocumentDom()
protected abstract DSSReference
createReference(DSSDocument document, int referenceIndex)
protected Node
getNodeToCanonicalize(Node node)
protected Node
getParentNodeOfSignature()
protected DigestAlgorithm
getReferenceDigestAlgorithmOrDefault(XAdESSignatureParameters params)
Returns params.referenceDigestAlgorithm if exists, params.digestAlgorithm otherwisestatic XAdESSignatureBuilder
getSignatureBuilder(XAdESSignatureParameters params, DSSDocument document, CertificateVerifier certificateVerifier)
Creates the signature according to the packagingprotected void
incorporateFiles()
protected void
incorporateKeyInfo()
Creates KeyInfo tag.protected void
incorporateObject()
This method incorporates the ds:Object tagprotected void
incorporateReferenceKeyInfo()
Method incorporates KeyInfo ds:References.protected void
incorporateReferenceSignedProperties()
This method incorporates ds:Referencesvoid
incorporateSignatureDom()
This method creates a new instance of Signature element.protected void
incorporateSignatureDom(Node parentNodeOfSignature)
protected void
incorporateSignatureValue()
This method incorporates the signature value.void
incorporateSignedInfo()
This method incorporates the SignedInfo tagprotected void
incorporateSignedProperties()
Creates the SignedProperties DOM object element.protected void
incorporateSignedSignatureProperties()
Creates the SignedSignatureProperties DOM object element.DSSDocument
signDocument(byte[] signatureValue)
Adds signature value to the signature and returns XML signature (InMemoryDocument)protected abstract DSSDocument
transformReference(DSSReference reference)
This method performs the reference transformation.Methods inherited from class eu.europa.esig.dss.xades.signature.XAdESBuilder
createXmlDocument, getCurrentXAdESElements, getCurrentXAdESPaths, getXades141Namespace, getXadesNamespace, getXmldsigNamespace, incorporateCert, incorporateCertificateRef, incorporateDigestMethod, incorporateDigestValue, incorporateDigestValue, incorporateIssuerV1, incorporateIssuerV2
-
Field Details
-
built
protected boolean builtIndicates if the signature was already built. (Two steps building) -
detachedDocument
This is the reference to the original document to sign -
keyInfoCanonicalizationMethod
-
signedInfoCanonicalizationMethod
-
signedPropertiesCanonicalizationMethod
-
deterministicId
-
signatureDom
-
keyInfoDom
-
signedInfoDom
-
signatureValueDom
-
qualifyingPropertiesDom
-
signedPropertiesDom
-
signedSignaturePropertiesDom
-
signedDataObjectPropertiesDom
-
unsignedSignaturePropertiesDom
-
KEYINFO_SUFFIX
id-suffixes for DOM elements- See Also:
- Constant Field Values
-
TIMESTAMP_SUFFIX
- See Also:
- Constant Field Values
-
VALUE_SUFFIX
- See Also:
- Constant Field Values
-
XADES_SUFFIX
- See Also:
- Constant Field Values
-
OBJECT_ID_SUFFIX
- See Also:
- Constant Field Values
-
REFERENCE_ID_SUFFIX
- See Also:
- Constant Field Values
-
-
Constructor Details
-
XAdESSignatureBuilder
public XAdESSignatureBuilder(XAdESSignatureParameters params, DSSDocument detachedDocument, CertificateVerifier certificateVerifier)The default constructor for SignatureBuilder.- Parameters:
params
- The set of parameters relating to the structure and process of the creation or extension of the electronic signature.detachedDocument
- The original document to sign.certificateVerifier
- the certificate verifier with its OCSPSource,...
-
-
Method Details
-
getSignatureBuilder
public static XAdESSignatureBuilder getSignatureBuilder(XAdESSignatureParameters params, DSSDocument document, CertificateVerifier certificateVerifier)Creates the signature according to the packaging- Parameters:
params
- The set of parameters relating to the structure and process of the creation or extension of the electronic signature.document
- The original document to sign.certificateVerifier
- the certificate verifier with its OCSPSource,...- Returns:
- the signature builder linked to the packaging
-
build
This is the main method which is called to build the XML signature- Returns:
- A byte array is returned with XML that represents the canonicalized SignedInfo segment of signature. This data are used to define the SignatureValue element.
- Throws:
DSSException
- if an error occurred
-
incorporateFiles
protected void incorporateFiles() -
buildRootDocumentDom
-
incorporateSignatureDom
public void incorporateSignatureDom()This method creates a new instance of Signature element. -
getParentNodeOfSignature
-
incorporateSignatureDom
-
incorporateSignedInfo
public void incorporateSignedInfo()This method incorporates the SignedInfo tag<ds:SignedInfo> <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/> ... </ds:SignedInfo>
-
incorporateKeyInfo
Creates KeyInfo tag. NOTE: when trust anchor baseline profile policy is defined only the certificates previous to the trust anchor are included.<ds:KeyInfo> <ds:X509Data> <ds:X509Certificate> MIIB.... </ds:X509Certificate> <ds:X509Certificate> MIIB+... </ds:X509Certificate> </ds:X509Data> </ds:KeyInfo>
<ds:KeyInfo> <ds:X509Data> <ds:X509Certificate> MIIB.... </ds:X509Certificate> <ds:X509Certificate> MIIB+... </ds:X509Certificate> </ds:X509Data> </ds:KeyInfo>
- Throws:
DSSException
- if an error occurred
-
incorporateObject
protected void incorporateObject()This method incorporates the ds:Object tag<ds:Object> <xades:QualifyingProperties> <xades:SignedProperties> ... </xades:SignedProperties> </xades:QualifyingProperties> </ds:Object>
-
incorporateReferenceSignedProperties
protected void incorporateReferenceSignedProperties()This method incorporates ds:References<ds:Reference Type="http://uri.etsi.org/01903#SignedProperties" URI= "#xades-id-A43023AFEB149830C242377CC941360F"> <ds:Transforms> <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> </ds:Transforms> <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> <ds:DigestValue>uijX/nvuu8g10ZVEklEnYatvFe8=</ds:DigestValue> </ds:Reference>
-
incorporateReferenceKeyInfo
protected void incorporateReferenceKeyInfo()Method incorporates KeyInfo ds:References.<ds:Reference URI="#keyInfo-id-A43023AFEB149830C242377CC941360F"> <ds:Transforms> <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> </ds:Transforms> <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> <ds:DigestValue>uijX/nvuu2g10ZVEklEnYatvFe4=</ds:DigestValue> </ds:Reference>
-
getReferenceDigestAlgorithmOrDefault
Returns params.referenceDigestAlgorithm if exists, params.digestAlgorithm otherwise- Returns:
DigestAlgorithm
-
createReference
-
transformReference
This method performs the reference transformation.- Parameters:
reference
-DSSReference
to be transformed- Returns:
DSSDocument
containing transformed reference's data
-
incorporateSignatureValue
protected void incorporateSignatureValue()This method incorporates the signature value. -
incorporateSignedProperties
protected void incorporateSignedProperties()Creates the SignedProperties DOM object element.<SignedProperties Id="xades-ide5c549340079fe19f3f90f03354a5965">
-
incorporateSignedSignatureProperties
protected void incorporateSignedSignatureProperties()Creates the SignedSignatureProperties DOM object element.<SignedSignatureProperties> ... </SignedSignatureProperties>
-
signDocument
Adds signature value to the signature and returns XML signature (InMemoryDocument)- Specified by:
signDocument
in interfaceSignatureBuilder
- Parameters:
signatureValue
-- Returns:
DSSDocument
representing the signature- Throws:
DSSException
-
addTimestamp
Adds the content of a timestamp into a given timestamp element- Parameters:
timestampElement
-
-
applyTransformations
Applies transforms on a node and returns the byte array to be used for a reference digest computation- Parameters:
reference
- aDSSReference
to apply transforms fromnodeToTransform
-Node
to apply transforms on- Returns:
- a byte array, representing a content obtained after transformations
-
getNodeToCanonicalize
-
alignNodes
protected void alignNodes()- Specified by:
alignNodes
in classXAdESBuilder
-