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
FieldsModifier and TypeFieldDescriptionprotected CertificateVerifierThe reference to the certificate verifier.protected List<DSSDocument> In case of an ASiC signature thisListof container documents.protected List<DSSDocument> In case of a detached signature thisListcontains the signed documents.protected List<DSSDocument> Contains a list of evidence record documents detached from the signatureprotected DSSDocumentThe document to be validated (with the signature(s) or timestamp(s))protected ManifestFileA relatedManifestFileto the provideddocumentprotected CertificateSourceCertificate source to find signing certificate -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanaddReference(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 voidappendCounterSignatures(List<AdvancedSignature> allSignatureList, AdvancedSignature signature) The util method to link counter signatures with the related master signaturesprotected voidappendExternalEvidenceRecords(TimestampToken timestampToken) Appends the detached evidence records covering the time-stampprotected voidappendExternalEvidenceRecords(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 detachedEvidenceRecords extracted from the documentprotected List<TimestampToken> Builds a list of detachedTimestampTokens extracted from the documentprotected EvidenceRecordbuildEvidenceRecord(DSSDocument evidenceRecordDocument) Builds an evidence record from the givenDSSDocumentprotected List<AdvancedSignature> This method build a list of signatures to be extracted from a documentprotected booleancoversSignature(AdvancedSignature signature, EvidenceRecord evidenceRecord) Verifies whether anevidenceRecordcovers thesignatureprotected ValidationContextThis method creates a new instance ofValidationContextperforming preparation of validation data, certificate chain building, revocation request, as well as custom validation checks execution.static DocumentAnalyzerfromDocument(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 EvidenceRecordgetEvidenceRecord(EvidenceRecordAnalyzer evidenceRecordReader) Gets an evidence record from aevidenceRecordReaderprotected 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 SignaturePolicyProviderReturns a signaturePolicyProvider If not defined, returns a default providerReturns an instance of a corresponding to the formatSignaturePolicyValidatorLoaderRetrieves the signatures found in the documentprotected List<TimestampedReference> getTimestampedReferences(List<SignatureScope> signatureScopes) Returns a list of timestamped references from the given list ofSignatureScopesprotected 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 ValidationDataContainerCreates a new instance ofValidationDataContainerprotected booleanisTimestampCoveredByEvidenceRecord(TimestampToken timestampToken, EvidenceRecord evidenceRecord) Checks whether thetimestampTokenis covered by the givenevidenceRecordprotected voidprepareDetachedEvidenceRecordValidationContext(ValidationContext validationContext, Collection<EvidenceRecord> evidenceRecords) Prepares thevalidationContextfor the evidence record validation processprotected voidprepareDetachedTimestampValidationContext(ValidationContext validationContext, Collection<TimestampToken> timestamps) Prepares thevalidationContextfor a timestamp validation processprotected <T extends AdvancedSignature>
voidprepareSignatureForVerification(ValidationContext validationContext, Collection<T> allSignatureList) This method prepares aSignatureValidationContextfor signatures validationprotected <T extends AdvancedSignature>
voidprepareSignatureValidationContext(ValidationContext validationContext, Collection<T> allSignatures) Prepares thevalidationContextfor signature validation processprotected <T extends AdvancedSignature>
ValidationContextprepareValidationContext(Collection<T> signatures, Collection<TimestampToken> detachedTimestamps, Collection<EvidenceRecord> detachedEvidenceRecords, CertificateVerifier certificateVerifier) Initializes and fillsValidationContextwith necessary data sourcesprotected <T extends AdvancedSignature>
voidprocessSignaturesValidation(Collection<T> allSignatureList) Performs cryptographic validation of the signaturesvoidsetCertificateVerifier(CertificateVerifier certificateVerifier) To carry out the validation process of the signature(s) some external sources of certificates and of revocation data can be needed.voidsetContainerContents(List<DSSDocument> containerContents) Sets theListofDSSDocumentcontaining the original container content for ASiC-S signatures.voidsetDetachedContents(List<DSSDocument> detachedContents) Sets theListofDSSDocumentcontaining the original contents to sign, for detached signature scenarios.voidsetDetachedEvidenceRecordDocuments(List<DSSDocument> detachedEvidenceRecordDocuments) Sets aListofDSSDocumentcontaining the evidence record documents covering the signature document.voidsetDetachedEvidenceRecords(List<EvidenceRecord> evidenceRecords) Sets a list of detached evidence recordsvoidsetManifestFile(ManifestFile manifestFile) Sets a relatedManifestFileto the document to be validated.voidsetSignaturePolicyProvider(SignaturePolicyProvider signaturePolicyProvider) This method allows to set a provider for Signature policiesvoidsetSigningCertificateSource(CertificateSource signingCertificateSource) Set a certificate source which allows to find the signing certificate by kid or certificate's digestvoidsetTokenIdentifierProvider(TokenIdentifierProvider tokenIdentifierProvider) Sets the TokenIdentifierProvidervoidsetValidationContextExecutor(ValidationContextExecutor validationContextExecutor) This method setsValidationContextExecutorfor validation of the preparedValidationContextDefault: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)voidsetValidationTime(Date validationTime) Allows to define a custom validation timevalidate()This method performs validation of the documentprotected voidvalidateContext(ValidationContext validationContext) Process the validationprotected voidvalidateSignaturePolicy(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, waitMethods 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 thisListcontains the signed documents. -
detachedEvidenceRecordDocuments
Contains a list of evidence record documents detached from the signature -
containerContents
In case of an ASiC signature thisListof container documents. -
manifestFile
A relatedManifestFileto 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 ofDSSDocumentto validate- Returns:
- returns the specific instance of
DocumentReaderin terms of the document type
-
getDocument
Description copied from interface:DocumentAnalyzerGets document to be validated- Specified by:
getDocumentin interfaceDocumentAnalyzer- Returns:
DSSDocument
-
setSigningCertificateSource
Description copied from interface:DocumentAnalyzerSet a certificate source which allows to find the signing certificate by kid or certificate's digest- Specified by:
setSigningCertificateSourcein 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 theCommonTrustedCertificateSourceor in adjunct certificate source is not taken into account.- Specified by:
setCertificateVerifierin interfaceDocumentAnalyzer- Parameters:
certificateVerifier-CertificateVerifier
-
setValidationContextExecutor
Description copied from interface:DocumentAnalyzerThis method setsValidationContextExecutorfor validation of the preparedValidationContextDefault: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:
setValidationContextExecutorin interfaceDocumentAnalyzer- Parameters:
validationContextExecutor-ValidationContextExecutor
-
getTokenIdentifierProvider
GetsTokenIdentifierProvider- Specified by:
getTokenIdentifierProviderin interfaceDocumentAnalyzer- Returns:
TokenIdentifierProvider
-
setTokenIdentifierProvider
Description copied from interface:DocumentAnalyzerSets the TokenIdentifierProvider- Specified by:
setTokenIdentifierProviderin interfaceDocumentAnalyzer- Parameters:
tokenIdentifierProvider-TokenIdentifierProvider
-
setDetachedContents
Description copied from interface:DocumentAnalyzerSets theListofDSSDocumentcontaining the original contents to sign, for detached signature scenarios.- Specified by:
setDetachedContentsin interfaceDocumentAnalyzer- Parameters:
detachedContents- theListofDSSDocumentto set
-
setDetachedEvidenceRecordDocuments
Description copied from interface:DocumentAnalyzerSets aListofDSSDocumentcontaining the evidence record documents covering the signature document.- Specified by:
setDetachedEvidenceRecordDocumentsin interfaceDocumentAnalyzer- Parameters:
detachedEvidenceRecordDocuments- theListofDSSDocumentto set
-
setContainerContents
Description copied from interface:DocumentAnalyzerSets theListofDSSDocumentcontaining the original container content for ASiC-S signatures.- Specified by:
setContainerContentsin interfaceDocumentAnalyzer- Parameters:
containerContents- theListofDSSDocumentto set
-
setManifestFile
Description copied from interface:DocumentAnalyzerSets a relatedManifestFileto the document to be validated.- Specified by:
setManifestFilein interfaceDocumentAnalyzer- Parameters:
manifestFile- aManifestFileto set
-
getValidationTime
Returns validation time In case if the validation time is not provided, initialize the current time value from the system- Specified by:
getValidationTimein interfaceDocumentAnalyzer- Returns:
Datevalidation time
-
setValidationTime
Allows to define a custom validation time- Specified by:
setValidationTimein interfaceDocumentAnalyzer- Parameters:
validationTime-Date
-
setDetachedEvidenceRecords
Sets a list of detached evidence records- Parameters:
evidenceRecords- a list ofEvidenceRecords
-
getSignaturePolicyProvider
Returns a signaturePolicyProvider If not defined, returns a default provider- Returns:
SignaturePolicyProvider
-
setSignaturePolicyProvider
Description copied from interface:DocumentAnalyzerThis method allows to set a provider for Signature policies- Specified by:
setSignaturePolicyProviderin interfaceDocumentAnalyzer- Parameters:
signaturePolicyProvider-SignaturePolicyProvider
-
validate
Description copied from interface:DocumentAnalyzerThis method performs validation of the document- Specified by:
validatein interfaceDocumentAnalyzer- Returns:
ValidationContext
-
prepareValidationContext
protected <T extends AdvancedSignature> ValidationContext prepareValidationContext(Collection<T> signatures, Collection<TimestampToken> detachedTimestamps, Collection<EvidenceRecord> detachedEvidenceRecords, CertificateVerifier certificateVerifier) Initializes and fillsValidationContextwith necessary data sources- Type Parameters:
T-AdvancedSignatureimplementation- Parameters:
signatures- a collection ofAdvancedSignaturesdetachedTimestamps- a collection of detachedTimestampTokensdetachedEvidenceRecords- a collection of detachedEvidenceRecordscertificateVerifier-CertificateVerifierto be used for the validation- Returns:
ValidationContext
-
createValidationContext
This method creates a new instance ofValidationContextperforming 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:DocumentAnalyzerExtracts a validation data for provided collection of signatures- Specified by:
getValidationDatain interfaceDocumentAnalyzer- Type Parameters:
T-AdvancedSignatureimplementation- Parameters:
signatures- a collection ofAdvancedSignatures- Returns:
ValidationDataContainer
-
getValidationData
public <T extends AdvancedSignature> ValidationDataContainer getValidationData(Collection<T> signatures, Collection<TimestampToken> detachedTimestamps) Description copied from interface:DocumentAnalyzerExtracts a validation data for provided collection of signatures and/or timestamps- Specified by:
getValidationDatain interfaceDocumentAnalyzer- Type Parameters:
T-AdvancedSignatureimplementation- Parameters:
signatures- a collection ofAdvancedSignaturesdetachedTimestamps- a collection of detachedTimestampTokens- 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 ofAdvancedSignaturesdetachedEvidenceRecords- a list of detachedEvidenceRecords- Returns:
- a list of all
EvidenceRecords
-
prepareSignatureValidationContext
protected <T extends AdvancedSignature> void prepareSignatureValidationContext(ValidationContext validationContext, Collection<T> allSignatures) Prepares thevalidationContextfor signature validation process- Type Parameters:
T-AdvancedSignatureimplementation- Parameters:
validationContext-ValidationContextallSignatures- a collection of allAdvancedSignatures to be validated
-
prepareSignatureForVerification
protected <T extends AdvancedSignature> void prepareSignatureForVerification(ValidationContext validationContext, Collection<T> allSignatureList) This method prepares aSignatureValidationContextfor signatures validation- Type Parameters:
T-AdvancedSignatureimplementation- Parameters:
validationContext-ValidationContextis the implementation of the validators for: certificates, timestamps and revocation data.allSignatureList-CollectionofAdvancedSignatures to validate including the countersignatures
-
prepareDetachedTimestampValidationContext
protected void prepareDetachedTimestampValidationContext(ValidationContext validationContext, Collection<TimestampToken> timestamps) Prepares thevalidationContextfor a timestamp validation process- Parameters:
validationContext-ValidationContexttimestamps- a collection of detached timestamps
-
prepareDetachedEvidenceRecordValidationContext
protected void prepareDetachedEvidenceRecordValidationContext(ValidationContext validationContext, Collection<EvidenceRecord> evidenceRecords) Prepares thevalidationContextfor the evidence record validation process- Parameters:
validationContext-ValidationContextevidenceRecords- a collection of detached evidence records
-
validateContext
Process the validation- Parameters:
validationContext-ValidationContextto 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
AdvancedSignatures
-
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 ofAdvancedSignaturessignature- currentAdvancedSignature
-
appendExternalEvidenceRecords
Appends detached evidence record provided to the validator to the corresponding signatures covering by the evidence record document- Parameters:
allSignatureList- a list ofAdvancedSignatures
-
appendExternalEvidenceRecords
Appends the detached evidence records covering the time-stamp- Parameters:
timestampToken-TimestampToken
-
isTimestampCoveredByEvidenceRecord
protected boolean isTimestampCoveredByEvidenceRecord(TimestampToken timestampToken, EvidenceRecord evidenceRecord) Checks whether thetimestampTokenis covered by the givenevidenceRecord- Parameters:
timestampToken-TimestampTokenevidenceRecord-EvidenceRecord- Returns:
- TRUE if the time-stamp is covered by the evidence record, FALSE otherwise
-
coversSignature
Verifies whether anevidenceRecordcovers thesignature- Parameters:
signature-AdvancedSignatureevidenceRecord-EvidenceRecord- Returns:
- TRUE if the evidence record covers the signature file, FALSE otherwise
-
getSignatures
Description copied from interface:DocumentAnalyzerRetrieves the signatures found in the document- Specified by:
getSignaturesin 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
AdvancedSignatures
-
getDetachedTimestamps
Description copied from interface:DocumentAnalyzerRetrieves the detached timestamps found in the document- Specified by:
getDetachedTimestampsin interfaceDocumentAnalyzer- Returns:
- a list of TimestampToken for validation purposes
-
buildDetachedTimestamps
Builds a list of detachedTimestampTokens extracted from the document- Returns:
- a list of
TimestampTokens
-
getTimestampReaders
Returns a list of timestamp validators for timestamps embedded into the container- Returns:
- a list of
TimestampAnalyzers
-
getDetachedEvidenceRecords
Description copied from interface:DocumentAnalyzerRetrieves the detached evidence records found in the document- Specified by:
getDetachedEvidenceRecordsin interfaceDocumentAnalyzer- Returns:
- a list of Evidence Records for validation purposes
-
buildDetachedEvidenceRecords
Builds a list of detachedEvidenceRecords extracted from the document- Returns:
- a list of
EvidenceRecords
-
buildEvidenceRecord
Builds an evidence record from the givenDSSDocument- Parameters:
evidenceRecordDocument-DSSDocumentcontaining 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
SignatureScopes
-
processSignaturesValidation
protected <T extends AdvancedSignature> void processSignaturesValidation(Collection<T> allSignatureList) Performs cryptographic validation of the signatures- Type Parameters:
T-AdvancedSignature- Parameters:
allSignatureList- a collection ofAdvancedSignatures
-
getTimestampedReferences
Returns a list of timestamped references from the given list ofSignatureScopes- Parameters:
signatureScopes- a list ofSignatureScopes- Returns:
- a list of
TimestampedReferences
-
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-SignatureScopeto check- Returns:
- TRUE if the timestamped reference shall be created for the given
SignatureScope, FALSE otherwise
-
getOriginalDocuments
Description copied from interface:DocumentAnalyzerThis method returns the signed document(s) without their signature(s)- Specified by:
getOriginalDocumentsin interfaceDocumentAnalyzer- Parameters:
signatureId- the DSS ID of the signature to extract original signer data for- Returns:
- list of
DSSDocuments
-
getSignatureById
Returns the signature with the given id. Processes customTokenIdentifierProviderand counter signatures- Parameters:
signatureId-Stringid of a signature to be extracted- Returns:
AdvancedSignaturewith 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
-