Class DefaultDocumentAnalyzer
java.lang.Object
eu.europa.esig.dss.spi.validation.analyzer.DefaultDocumentAnalyzer
- All Implemented Interfaces:
DocumentAnalyzer
- Direct Known Subclasses:
AbstractASiCContainerAnalyzer
,AbstractJWSDocumentAnalyzer
,CMSDocumentAnalyzer
,DefaultEvidenceRecordAnalyzer
,DetachedTimestampAnalyzer
,PDFDocumentAnalyzer
,XMLDocumentAnalyzer
This class contains a common code for processing of signed documents
-
Field Summary
Modifier and TypeFieldDescriptionprotected CertificateVerifier
The reference to the certificate verifier.protected List
<DSSDocument> In case of an ASiC signature thisList
of container documents.protected List
<DSSDocument> In case of a detached signature thisList
contains the signed documents.protected List
<DSSDocument> Contains a list of evidence record documents detached from the signatureprotected DSSDocument
The document to be validated (with the signature(s) or timestamp(s))protected ManifestFile
A relatedManifestFile
to the provideddocument
protected CertificateSource
Certificate source to find signing certificate -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
addReference
(SignatureScope signatureScope) Checks if the signature scope shall be added as a timestamped reference NOTE: used to avoid duplicates in ASiC with CAdES validator, due to covered signature/timestamp filesprotected void
appendCounterSignatures
(List<AdvancedSignature> allSignatureList, AdvancedSignature signature) The util method to link counter signatures with the related master signaturesprotected void
appendExternalEvidenceRecords
(TimestampToken timestampToken) Appends the detached evidence records covering the time-stampprotected void
appendExternalEvidenceRecords
(List<AdvancedSignature> allSignatureList) Appends detached evidence record provided to the validator to the corresponding signatures covering by the evidence record documentprotected List
<EvidenceRecord> Builds a list of detachedEvidenceRecord
s extracted from the documentprotected List
<TimestampToken> Builds a list of detachedTimestampToken
s extracted from the documentprotected EvidenceRecord
buildEvidenceRecord
(DSSDocument evidenceRecordDocument) Builds an evidence record from the givenDSSDocument
protected List
<AdvancedSignature> This method build a list of signatures to be extracted from a documentprotected boolean
coversSignature
(AdvancedSignature signature, EvidenceRecord evidenceRecord) Verifies whether anevidenceRecord
covers thesignature
protected ValidationContext
This method creates a new instance ofValidationContext
performing preparation of validation data, certificate chain building, revocation request, as well as custom validation checks execution.static DocumentAnalyzer
fromDocument
(DSSDocument dssDocument) This method guesses the document format and returns an appropriate document reader.protected List
<EvidenceRecord> getAllEvidenceRecords
(List<AdvancedSignature> signatures, List<EvidenceRecord> detachedEvidenceRecords) Returns a list of all found evidence records (embedded and detached)protected List
<AdvancedSignature> Returns a list of all signatures from the validating documentRetrieves the detached evidence records found in the documentRetrieves the detached timestamps found in the documentGets document to be validatedprotected EvidenceRecord
getEvidenceRecord
(EvidenceRecordAnalyzer evidenceRecordReader) Gets an evidence record from aevidenceRecordReader
protected List
<SignatureScope> getEvidenceRecordScopes
(EvidenceRecord evidenceRecord) Finds evidence record scopesgetOriginalDocuments
(String signatureId) This method returns the signed document(s) without their signature(s)getSignatureById
(String signatureId) Returns the signature with the given id.protected SignaturePolicyProvider
Returns a signaturePolicyProvider If not defined, returns a default providerReturns an instance of a corresponding to the formatSignaturePolicyValidatorLoader
Retrieves the signatures found in the documentprotected List
<TimestampedReference> getTimestampedReferences
(List<SignatureScope> signatureScopes) Returns a list of timestamped references from the given list ofSignatureScope
sprotected List
<TimestampAnalyzer> Returns a list of timestamp validators for timestamps embedded into the containerGetsTokenIdentifierProvider
<T extends AdvancedSignature>
ValidationDataContainergetValidationData
(Collection<T> signatures) Extracts a validation data for provided collection of signatures<T extends AdvancedSignature>
ValidationDataContainergetValidationData
(Collection<T> signatures, Collection<TimestampToken> detachedTimestamps) Extracts a validation data for provided collection of signatures and/or timestampsReturns validation time In case if the validation time is not provided, initialize the current time value from the systemprotected ValidationDataContainer
Creates a new instance ofValidationDataContainer
protected boolean
isTimestampCoveredByEvidenceRecord
(TimestampToken timestampToken, EvidenceRecord evidenceRecord) Checks whether thetimestampToken
is covered by the givenevidenceRecord
protected void
prepareDetachedEvidenceRecordValidationContext
(ValidationContext validationContext, Collection<EvidenceRecord> evidenceRecords) Prepares thevalidationContext
for the evidence record validation processprotected void
prepareDetachedTimestampValidationContext
(ValidationContext validationContext, Collection<TimestampToken> timestamps) Prepares thevalidationContext
for a timestamp validation processprotected <T extends AdvancedSignature>
voidprepareSignatureForVerification
(ValidationContext validationContext, Collection<T> allSignatureList) This method prepares aSignatureValidationContext
for signatures validationprotected <T extends AdvancedSignature>
voidprepareSignatureValidationContext
(ValidationContext validationContext, Collection<T> allSignatures) Prepares thevalidationContext
for signature validation processprotected <T extends AdvancedSignature>
ValidationContextprepareValidationContext
(Collection<T> signatures, Collection<TimestampToken> detachedTimestamps, Collection<EvidenceRecord> detachedEvidenceRecords, CertificateVerifier certificateVerifier) Initializes and fillsValidationContext
with necessary data sourcesprotected <T extends AdvancedSignature>
voidprocessSignaturesValidation
(Collection<T> allSignatureList) Performs cryptographic validation of the signaturesvoid
setCertificateVerifier
(CertificateVerifier certificateVerifier) To carry out the validation process of the signature(s) some external sources of certificates and of revocation data can be needed.void
setContainerContents
(List<DSSDocument> containerContents) Sets theList
ofDSSDocument
containing the original container content for ASiC-S signatures.void
setDetachedContents
(List<DSSDocument> detachedContents) Sets theList
ofDSSDocument
containing the original contents to sign, for detached signature scenarios.void
setDetachedEvidenceRecordDocuments
(List<DSSDocument> detachedEvidenceRecordDocuments) Sets aList
ofDSSDocument
containing the evidence record documents covering the signature document.void
setDetachedEvidenceRecords
(List<EvidenceRecord> evidenceRecords) Sets a list of detached evidence recordsvoid
setManifestFile
(ManifestFile manifestFile) Sets a relatedManifestFile
to the document to be validated.void
setSignaturePolicyProvider
(SignaturePolicyProvider signaturePolicyProvider) This method allows to set a provider for Signature policiesvoid
setSigningCertificateSource
(CertificateSource signingCertificateSource) Set a certificate source which allows to find the signing certificate by kid or certificate's digestvoid
setTokenIdentifierProvider
(TokenIdentifierProvider tokenIdentifierProvider) Sets the TokenIdentifierProvidervoid
setValidationContextExecutor
(ValidationContextExecutor validationContextExecutor) This method setsValidationContextExecutor
for validation of the preparedValidationContext
Default:eu.europa.esig.dss.validation.executor.context.DefaultValidationContextExecutor
(performs basic validation of tokens, including certificate chain building and revocation data extraction, without processing of validity checks)void
setValidationTime
(Date validationTime) Allows to define a custom validation timevalidate()
This method performs validation of the documentprotected void
validateContext
(ValidationContext validationContext) Process the validationprotected void
validateSignaturePolicy
(AdvancedSignature signature) This method is used to perform validation of the signature policy's identifier, when presentMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface eu.europa.esig.dss.spi.validation.analyzer.DocumentAnalyzer
getOriginalDocuments, isSupported
-
Field Details
-
document
The document to be validated (with the signature(s) or timestamp(s)) -
detachedContents
In case of a detached signature thisList
contains the signed documents. -
detachedEvidenceRecordDocuments
Contains a list of evidence record documents detached from the signature -
containerContents
In case of an ASiC signature thisList
of container documents. -
manifestFile
A relatedManifestFile
to the provideddocument
-
signingCertificateSource
Certificate source to find signing certificate -
certificateVerifier
The reference to the certificate verifier. The current DSS implementation proposesCommonCertificateVerifier
. This verifier encapsulates the references to different sources used in the signature validation process.
-
-
Constructor Details
-
DefaultDocumentAnalyzer
protected DefaultDocumentAnalyzer()The default constructor
-
-
Method Details
-
fromDocument
This method guesses the document format and returns an appropriate document reader.- Parameters:
dssDocument
- The instance ofDSSDocument
to validate- Returns:
- returns the specific instance of
DocumentReader
in terms of the document type
-
getDocument
Description copied from interface:DocumentAnalyzer
Gets document to be validated- Specified by:
getDocument
in interfaceDocumentAnalyzer
- Returns:
DSSDocument
-
setSigningCertificateSource
Description copied from interface:DocumentAnalyzer
Set a certificate source which allows to find the signing certificate by kid or certificate's digest- Specified by:
setSigningCertificateSource
in interfaceDocumentAnalyzer
- Parameters:
signingCertificateSource
- the certificate source
-
setCertificateVerifier
To carry out the validation process of the signature(s) some external sources of certificates and of revocation data can be needed. The certificate verifier is used to pass these values. Note that once this setter is called any change in the content of theCommonTrustedCertificateSource
or in adjunct certificate source is not taken into account.- Specified by:
setCertificateVerifier
in interfaceDocumentAnalyzer
- Parameters:
certificateVerifier
-CertificateVerifier
-
setValidationContextExecutor
Description copied from interface:DocumentAnalyzer
This method setsValidationContextExecutor
for validation of the preparedValidationContext
Default:eu.europa.esig.dss.validation.executor.context.DefaultValidationContextExecutor
(performs basic validation of tokens, including certificate chain building and revocation data extraction, without processing of validity checks)- Specified by:
setValidationContextExecutor
in interfaceDocumentAnalyzer
- Parameters:
validationContextExecutor
-ValidationContextExecutor
-
getTokenIdentifierProvider
GetsTokenIdentifierProvider
- Specified by:
getTokenIdentifierProvider
in interfaceDocumentAnalyzer
- Returns:
TokenIdentifierProvider
-
setTokenIdentifierProvider
Description copied from interface:DocumentAnalyzer
Sets the TokenIdentifierProvider- Specified by:
setTokenIdentifierProvider
in interfaceDocumentAnalyzer
- Parameters:
tokenIdentifierProvider
-TokenIdentifierProvider
-
setDetachedContents
Description copied from interface:DocumentAnalyzer
Sets theList
ofDSSDocument
containing the original contents to sign, for detached signature scenarios.- Specified by:
setDetachedContents
in interfaceDocumentAnalyzer
- Parameters:
detachedContents
- theList
ofDSSDocument
to set
-
setDetachedEvidenceRecordDocuments
Description copied from interface:DocumentAnalyzer
Sets aList
ofDSSDocument
containing the evidence record documents covering the signature document.- Specified by:
setDetachedEvidenceRecordDocuments
in interfaceDocumentAnalyzer
- Parameters:
detachedEvidenceRecordDocuments
- theList
ofDSSDocument
to set
-
setContainerContents
Description copied from interface:DocumentAnalyzer
Sets theList
ofDSSDocument
containing the original container content for ASiC-S signatures.- Specified by:
setContainerContents
in interfaceDocumentAnalyzer
- Parameters:
containerContents
- theList
ofDSSDocument
to set
-
setManifestFile
Description copied from interface:DocumentAnalyzer
Sets a relatedManifestFile
to the document to be validated.- Specified by:
setManifestFile
in interfaceDocumentAnalyzer
- Parameters:
manifestFile
- aManifestFile
to set
-
getValidationTime
Returns validation time In case if the validation time is not provided, initialize the current time value from the system- Specified by:
getValidationTime
in interfaceDocumentAnalyzer
- Returns:
Date
validation time
-
setValidationTime
Allows to define a custom validation time- Specified by:
setValidationTime
in interfaceDocumentAnalyzer
- Parameters:
validationTime
-Date
-
setDetachedEvidenceRecords
Sets a list of detached evidence records- Parameters:
evidenceRecords
- a list ofEvidenceRecord
s
-
getSignaturePolicyProvider
Returns a signaturePolicyProvider If not defined, returns a default provider- Returns:
SignaturePolicyProvider
-
setSignaturePolicyProvider
Description copied from interface:DocumentAnalyzer
This method allows to set a provider for Signature policies- Specified by:
setSignaturePolicyProvider
in interfaceDocumentAnalyzer
- Parameters:
signaturePolicyProvider
-SignaturePolicyProvider
-
validate
Description copied from interface:DocumentAnalyzer
This method performs validation of the document- Specified by:
validate
in interfaceDocumentAnalyzer
- Returns:
ValidationContext
-
prepareValidationContext
protected <T extends AdvancedSignature> ValidationContext prepareValidationContext(Collection<T> signatures, Collection<TimestampToken> detachedTimestamps, Collection<EvidenceRecord> detachedEvidenceRecords, CertificateVerifier certificateVerifier) Initializes and fillsValidationContext
with necessary data sources- Type Parameters:
T
-AdvancedSignature
implementation- Parameters:
signatures
- a collection ofAdvancedSignature
sdetachedTimestamps
- a collection of detachedTimestampToken
sdetachedEvidenceRecords
- a collection of detachedEvidenceRecord
scertificateVerifier
-CertificateVerifier
to be used for the validation- Returns:
ValidationContext
-
createValidationContext
This method creates a new instance ofValidationContext
performing preparation of validation data, certificate chain building, revocation request, as well as custom validation checks execution.- Returns:
ValidationContext
-
getValidationData
public <T extends AdvancedSignature> ValidationDataContainer getValidationData(Collection<T> signatures) Description copied from interface:DocumentAnalyzer
Extracts a validation data for provided collection of signatures- Specified by:
getValidationData
in interfaceDocumentAnalyzer
- Type Parameters:
T
-AdvancedSignature
implementation- Parameters:
signatures
- a collection ofAdvancedSignature
s- Returns:
ValidationDataContainer
-
getValidationData
public <T extends AdvancedSignature> ValidationDataContainer getValidationData(Collection<T> signatures, Collection<TimestampToken> detachedTimestamps) Description copied from interface:DocumentAnalyzer
Extracts a validation data for provided collection of signatures and/or timestamps- Specified by:
getValidationData
in interfaceDocumentAnalyzer
- Type Parameters:
T
-AdvancedSignature
implementation- Parameters:
signatures
- a collection ofAdvancedSignature
sdetachedTimestamps
- a collection of detachedTimestampToken
s- Returns:
ValidationDataContainer
-
instantiateValidationDataContainer
Creates a new instance ofValidationDataContainer
- Returns:
ValidationDataContainer
-
getAllEvidenceRecords
protected List<EvidenceRecord> getAllEvidenceRecords(List<AdvancedSignature> signatures, List<EvidenceRecord> detachedEvidenceRecords) Returns a list of all found evidence records (embedded and detached)- Parameters:
signatures
- a list ofAdvancedSignature
sdetachedEvidenceRecords
- a list of detachedEvidenceRecord
s- Returns:
- a list of all
EvidenceRecord
s
-
prepareSignatureValidationContext
protected <T extends AdvancedSignature> void prepareSignatureValidationContext(ValidationContext validationContext, Collection<T> allSignatures) Prepares thevalidationContext
for signature validation process- Type Parameters:
T
-AdvancedSignature
implementation- Parameters:
validationContext
-ValidationContext
allSignatures
- a collection of allAdvancedSignature
s to be validated
-
prepareSignatureForVerification
protected <T extends AdvancedSignature> void prepareSignatureForVerification(ValidationContext validationContext, Collection<T> allSignatureList) This method prepares aSignatureValidationContext
for signatures validation- Type Parameters:
T
-AdvancedSignature
implementation- Parameters:
validationContext
-ValidationContext
is the implementation of the validators for: certificates, timestamps and revocation data.allSignatureList
-Collection
ofAdvancedSignature
s to validate including the countersignatures
-
prepareDetachedTimestampValidationContext
protected void prepareDetachedTimestampValidationContext(ValidationContext validationContext, Collection<TimestampToken> timestamps) Prepares thevalidationContext
for a timestamp validation process- Parameters:
validationContext
-ValidationContext
timestamps
- a collection of detached timestamps
-
prepareDetachedEvidenceRecordValidationContext
protected void prepareDetachedEvidenceRecordValidationContext(ValidationContext validationContext, Collection<EvidenceRecord> evidenceRecords) Prepares thevalidationContext
for the evidence record validation process- Parameters:
validationContext
-ValidationContext
evidenceRecords
- a collection of detached evidence records
-
validateContext
Process the validation- Parameters:
validationContext
-ValidationContext
to process
-
getSignaturePolicyValidatorLoader
Returns an instance of a corresponding to the formatSignaturePolicyValidatorLoader
- Returns:
SignaturePolicyValidatorLoader
-
getAllSignatures
Returns a list of all signatures from the validating document- Returns:
- a list of
AdvancedSignature
s
-
appendCounterSignatures
protected void appendCounterSignatures(List<AdvancedSignature> allSignatureList, AdvancedSignature signature) The util method to link counter signatures with the related master signatures- Parameters:
allSignatureList
- a list ofAdvancedSignature
ssignature
- currentAdvancedSignature
-
appendExternalEvidenceRecords
Appends detached evidence record provided to the validator to the corresponding signatures covering by the evidence record document- Parameters:
allSignatureList
- a list ofAdvancedSignature
s
-
appendExternalEvidenceRecords
Appends the detached evidence records covering the time-stamp- Parameters:
timestampToken
-TimestampToken
-
isTimestampCoveredByEvidenceRecord
protected boolean isTimestampCoveredByEvidenceRecord(TimestampToken timestampToken, EvidenceRecord evidenceRecord) Checks whether thetimestampToken
is covered by the givenevidenceRecord
- Parameters:
timestampToken
-TimestampToken
evidenceRecord
-EvidenceRecord
- Returns:
- TRUE if the time-stamp is covered by the evidence record, FALSE otherwise
-
coversSignature
Verifies whether anevidenceRecord
covers thesignature
- Parameters:
signature
-AdvancedSignature
evidenceRecord
-EvidenceRecord
- Returns:
- TRUE if the evidence record covers the signature file, FALSE otherwise
-
getSignatures
Description copied from interface:DocumentAnalyzer
Retrieves the signatures found in the document- Specified by:
getSignatures
in interfaceDocumentAnalyzer
- Returns:
- a list of AdvancedSignatures for validation purposes
-
buildSignatures
This method build a list of signatures to be extracted from a document- Returns:
- a list of
AdvancedSignature
s
-
getDetachedTimestamps
Description copied from interface:DocumentAnalyzer
Retrieves the detached timestamps found in the document- Specified by:
getDetachedTimestamps
in interfaceDocumentAnalyzer
- Returns:
- a list of TimestampToken for validation purposes
-
buildDetachedTimestamps
Builds a list of detachedTimestampToken
s extracted from the document- Returns:
- a list of
TimestampToken
s
-
getTimestampReaders
Returns a list of timestamp validators for timestamps embedded into the container- Returns:
- a list of
TimestampAnalyzer
s
-
getDetachedEvidenceRecords
Description copied from interface:DocumentAnalyzer
Retrieves the detached evidence records found in the document- Specified by:
getDetachedEvidenceRecords
in interfaceDocumentAnalyzer
- Returns:
- a list of Evidence Records for validation purposes
-
buildDetachedEvidenceRecords
Builds a list of detachedEvidenceRecord
s extracted from the document- Returns:
- a list of
EvidenceRecord
s
-
buildEvidenceRecord
Builds an evidence record from the givenDSSDocument
- Parameters:
evidenceRecordDocument
-DSSDocument
containing an evidence record- Returns:
EvidenceRecord
-
getEvidenceRecord
Gets an evidence record from aevidenceRecordReader
- Parameters:
evidenceRecordReader
-EvidenceRecordAnalyzer
- Returns:
EvidenceRecord
-
getEvidenceRecordScopes
Finds evidence record scopes- Parameters:
evidenceRecord
-EvidenceRecord
- Returns:
- a list of
SignatureScope
s
-
processSignaturesValidation
protected <T extends AdvancedSignature> void processSignaturesValidation(Collection<T> allSignatureList) Performs cryptographic validation of the signatures- Type Parameters:
T
-AdvancedSignature
- Parameters:
allSignatureList
- a collection ofAdvancedSignature
s
-
getTimestampedReferences
Returns a list of timestamped references from the given list ofSignatureScope
s- Parameters:
signatureScopes
- a list ofSignatureScope
s- Returns:
- a list of
TimestampedReference
s
-
addReference
Checks if the signature scope shall be added as a timestamped reference NOTE: used to avoid duplicates in ASiC with CAdES validator, due to covered signature/timestamp files- Parameters:
signatureScope
-SignatureScope
to check- Returns:
- TRUE if the timestamped reference shall be created for the given
SignatureScope
, FALSE otherwise
-
getOriginalDocuments
Description copied from interface:DocumentAnalyzer
This method returns the signed document(s) without their signature(s)- Specified by:
getOriginalDocuments
in interfaceDocumentAnalyzer
- Parameters:
signatureId
- the DSS ID of the signature to extract original signer data for- Returns:
- list of
DSSDocument
s
-
getSignatureById
Returns the signature with the given id. Processes customTokenIdentifierProvider
and counter signatures- Parameters:
signatureId
-String
id of a signature to be extracted- Returns:
AdvancedSignature
with the given id if found, NULL otherwise
-
validateSignaturePolicy
This method is used to perform validation of the signature policy's identifier, when present- Parameters:
signature
-AdvancedSignature
, which policy will be verified
-