Package eu.europa.esig.dss.validation
Class SignedDocumentValidator
java.lang.Object
eu.europa.esig.dss.validation.SignedDocumentValidator
- All Implemented Interfaces:
DocumentValidator
,ProcessExecutorProvider<DocumentProcessExecutor>
- Direct Known Subclasses:
AbstractASiCContainerValidator
,CMSDocumentValidator
,DetachedTimestampValidator
,PDFDocumentValidator
,XMLDocumentValidator
public abstract class SignedDocumentValidator extends Object implements DocumentValidator
Validates a signed document. The content of the document is determined
automatically. It can be: XML, CAdES(p7m), PDF or ASiC(zip).
SignatureScopeFinder can be set using the appropriate setter (ex.
setCadesSignatureScopeFinder). By default, this class will use the default
SignatureScopeFinder as defined by
eu.europa.esig.dss.validation.scope.SignatureScopeFinderFactory
-
Field Summary
Fields Modifier and Type Field Description protected CertificateVerifier
certificateVerifier
The reference to the certificate verifier.protected List<DSSDocument>
containerContents
In case of an ASiC signature thisList
of container documents.protected List<DSSDocument>
detachedContents
In case of a detached signature thisList
contains the signed documents.protected DSSDocument
document
The document to be validated (with the signature(s) or timestamp(s))protected List<ManifestFile>
manifestFiles
List of all foundManifestFile
sprotected DocumentProcessExecutor
processExecutor
This variable can hold a specificDocumentProcessExecutor
protected CertificateToken
providedSigningCertificateToken
protected SignatureScopeFinder
signatureScopeFinder
protected boolean
skipValidationContextExecution
-
Constructor Summary
Constructors Modifier Constructor Description protected
SignedDocumentValidator()
protected
SignedDocumentValidator(SignatureScopeFinder signatureScopeFinder)
-
Method Summary
Modifier and Type Method Description protected void
assertConfigurationValid()
Checks if the Validator configuration is validvoid
defineSigningCertificate(CertificateToken token)
This method allows to define the signing certificate.void
findSignatureScopes(List<AdvancedSignature> allSignatures)
Finds and assigns SignatureScopes for a list of signaturesstatic SignedDocumentValidator
fromDocument(DSSDocument dssDocument)
This method guesses the document format and returns an appropriate document validator.protected List<AdvancedSignature>
getAllSignatures()
protected DigestAlgorithm
getDefaultDigestAlgorithm()
Returns a default digest algorithm defined for a digest calculationDocumentProcessExecutor
getDefaultProcessExecutor()
Returns a default for a validator process executorList<TimestampToken>
getDetachedTimestamps()
Retrieves the detached timestamps found in the documentprotected DiagnosticDataBuilder
getDiagnosticDataBuilderConfiguration(ValidationContext validationContext, List<AdvancedSignature> signatures, ListRevocationSource<CRL> listCRLSource, ListRevocationSource<OCSP> listOCSPSource)
protected SignaturePolicyProvider
getSignaturePolicyProvider()
Returns a signaturePolicyProvider If not defined, returns a default providerList<AdvancedSignature>
getSignatures()
Retrieves the signatures found in the documentprotected Date
getValidationTime()
Returns validation time In case if the validation time is not provided, initialize the current time value from the systemabstract boolean
isSupported(DSSDocument dssDocument)
protected ListCertificateSource
mergeCertificateSource(Collection<AdvancedSignature> allSignatureList, Collection<TimestampToken> detachedTimestamps)
For all signatures to be validated this method merges the Certificate sources.protected ListRevocationSource<CRL>
mergeCRLSources(Collection<AdvancedSignature> allSignatureList, Collection<TimestampToken> detachedTimestamps)
For all signatures to be validated this method merges the CRL sources.protected ListRevocationSource<OCSP>
mergeOCSPSources(Collection<AdvancedSignature> allSignatureList, Collection<TimestampToken> detachedTimestamps)
For all signatures to be validated this method merges the OCSP sources.protected void
prepareCertificatesAndTimestamps(ValidationContext validationContext, List<AdvancedSignature> allSignatureList)
protected void
prepareCertificateVerifier(ListRevocationSource<CRL> listCRLSource, ListRevocationSource<OCSP> listOCSPSource, ListCertificateSource listCertificateSource)
Sets revocation sources for a following certificate validationvoid
prepareDetachedTimestampValidationContext(ValidationContext validationContext, List<TimestampToken> timestamps)
Prepares thevalidationContext
for a timestamp validation processprotected DiagnosticDataBuilder
prepareDiagnosticDataBuilder(ValidationContext validationContext)
Creates a DiagnosticData to pass to the validation processvoid
prepareSignatureValidationContext(ValidationContext validationContext, List<AdvancedSignature> allSignatureList)
Prepares thevalidationContext
for signature validation process and returns a list of signatures to validatevoid
processSignaturesValidation(List<AdvancedSignature> allSignatureList)
This method process the signature validation on the givenallSignatureList
protected Reports
processValidationPolicy(XmlDiagnosticData diagnosticData, ValidationPolicy validationPolicy)
Executes the validation regarding to the givenvalidationPolicy
protected DocumentProcessExecutor
provideProcessExecutorInstance()
This method returns the process executor.void
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 signatures.void
setDetachedContents(List<DSSDocument> detachedContents)
Sets theList
ofDSSDocument
containing the original contents to sign, for detached signature scenarios.void
setEnableEtsiValidationReport(boolean enableEtsiValidationReport)
This method allows to specify if the ETSI Validation Report must be generated.void
setIncludeSemantics(boolean include)
This method allows to enable/disable the semantics inclusion in the reports (Indication / SubIndication meanings) Disabled by defaultvoid
setLocale(Locale locale)
void
setManifestFiles(List<ManifestFile> manifestFiles)
Sets theList
ofManifestFile
s found in the signature file.void
setProcessExecutor(DocumentProcessExecutor processExecutor)
This method provides the possibility to set the specificCustomProcessExecutor
void
setSignaturePolicyProvider(SignaturePolicyProvider signaturePolicyProvider)
This method allows to set a provider for Signature policiesprotected void
setSignedScopeFinderDefaultDigestAlgorithm(DigestAlgorithm digestAlgorithm)
void
setSkipValidationContextExecution(boolean skipValidationContextExecution)
void
setTokenExtractionStategy(TokenExtractionStategy tokenExtractionStategy)
This method allows to set the token extraction strategy to follow in the diagnostic data generation.void
setValidationLevel(ValidationLevel validationLevel)
This method allows to specify the validation level (Basic / Timestamp / Long Term / Archival).void
setValidationTime(Date validationTime)
Allows to define a custom validation timeprotected void
validateContext(ValidationContext validationContext)
Process the validationReports
validateDocument()
Validates the document and all its signatures.Reports
validateDocument(ConstraintsParameters validationPolicyJaxb)
Validates the document and all its signatures.Reports
validateDocument(ValidationPolicy validationPolicy)
Validates the document and all its signatures.Reports
validateDocument(File policyFile)
Validates the document and all its signatures.Reports
validateDocument(InputStream policyDataStream)
Validates the document and all its signatures.Reports
validateDocument(String policyResourcePath)
Validates the document and all its signatures.Reports
validateDocument(URL validationPolicyURL)
Validates the document and all its signatures.Methods 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.validation.DocumentValidator
getOriginalDocuments, getOriginalDocuments
-
Field Details
-
processExecutor
This variable can hold a specificDocumentProcessExecutor
-
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. -
containerContents
In case of an ASiC signature thisList
of container documents. -
manifestFiles
List of all foundManifestFile
s -
providedSigningCertificateToken
-
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. -
signatureScopeFinder
-
skipValidationContextExecution
protected boolean skipValidationContextExecution
-
-
Constructor Details
-
SignedDocumentValidator
protected SignedDocumentValidator() -
SignedDocumentValidator
-
-
Method Details
-
setSignedScopeFinderDefaultDigestAlgorithm
-
fromDocument
This method guesses the document format and returns an appropriate document validator.- Parameters:
dssDocument
- The instance ofDSSDocument
to validate- Returns:
- returns the specific instance of SignedDocumentValidator in terms of the document type
-
isSupported
-
defineSigningCertificate
Description copied from interface:DocumentValidator
This method allows to define the signing certificate. It is useful in the case of non AdES signatures.- Specified by:
defineSigningCertificate
in interfaceDocumentValidator
-
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 interfaceDocumentValidator
- Parameters:
certificateVerifier
-
-
setTokenExtractionStategy
Description copied from interface:DocumentValidator
This method allows to set the token extraction strategy to follow in the diagnostic data generation.- Specified by:
setTokenExtractionStategy
in interfaceDocumentValidator
- Parameters:
tokenExtractionStategy
- theTokenExtractionStategy
-
setIncludeSemantics
public void setIncludeSemantics(boolean include)Description copied from interface:DocumentValidator
This method allows to enable/disable the semantics inclusion in the reports (Indication / SubIndication meanings) Disabled by default- Specified by:
setIncludeSemantics
in interfaceDocumentValidator
- Parameters:
include
- true to enable the inclusion of the semantics
-
setDetachedContents
Description copied from interface:DocumentValidator
Sets theList
ofDSSDocument
containing the original contents to sign, for detached signature scenarios.- Specified by:
setDetachedContents
in interfaceDocumentValidator
- Parameters:
detachedContents
- theList
ofDSSDocument
to set
-
setContainerContents
Description copied from interface:DocumentValidator
Sets theList
ofDSSDocument
containing the original container content for ASiC signatures.- Specified by:
setContainerContents
in interfaceDocumentValidator
- Parameters:
containerContents
- theList
ofDSSDocument
to set
-
setManifestFiles
Description copied from interface:DocumentValidator
Sets theList
ofManifestFile
s found in the signature file.- Specified by:
setManifestFiles
in interfaceDocumentValidator
- Parameters:
manifestFiles
- theList
ofManifestFile
to set
-
getDefaultDigestAlgorithm
Returns a default digest algorithm defined for a digest calculation- Returns:
DigestAlgorithm
-
setValidationTime
Allows to define a custom validation time- Specified by:
setValidationTime
in interfaceDocumentValidator
- Parameters:
validationTime
-Date
-
getValidationTime
Returns validation time In case if the validation time is not provided, initialize the current time value from the system- Returns:
Date
validation time
-
setValidationLevel
Description copied from interface:DocumentValidator
This method allows to specify the validation level (Basic / Timestamp / Long Term / Archival). By default, the selected validation is ARCHIVAL- Specified by:
setValidationLevel
in interfaceDocumentValidator
- Parameters:
validationLevel
-ValidationLevel
-
setEnableEtsiValidationReport
public void setEnableEtsiValidationReport(boolean enableEtsiValidationReport)Description copied from interface:DocumentValidator
This method allows to specify if the ETSI Validation Report must be generated. By default the value if TRUE (the ETSI Validation report will be generated).- Specified by:
setEnableEtsiValidationReport
in interfaceDocumentValidator
- Parameters:
enableEtsiValidationReport
- - TRUE if the report must be generated, FALSE otherwise
-
validateDocument
Description copied from interface:DocumentValidator
Validates the document and all its signatures. The default constraint file is used.- Specified by:
validateDocument
in interfaceDocumentValidator
- Returns:
Reports
: diagnostic data, detailed report and simple report
-
validateDocument
Description copied from interface:DocumentValidator
Validates the document and all its signatures. If the validation policy URL is set then the policy constraints are retrieved from this location. If null or empty the default file is used.- Specified by:
validateDocument
in interfaceDocumentValidator
- Returns:
Reports
: diagnostic data, detailed report and simple report
-
validateDocument
Description copied from interface:DocumentValidator
Validates the document and all its signatures. The policyResourcePath specifies the constraint file. If null or empty the default file is used.- Specified by:
validateDocument
in interfaceDocumentValidator
- Parameters:
policyResourcePath
- is located against the classpath (getClass().getResourceAsStream), and NOT the filesystem- Returns:
Reports
: diagnostic data, detailed report and simple report
-
validateDocument
Description copied from interface:DocumentValidator
Validates the document and all its signatures. TheFile
parameter specifies the constraint file. If null or empty the default file is used.- Specified by:
validateDocument
in interfaceDocumentValidator
- Parameters:
policyFile
- contains the validation policy (xml) asFile
- Returns:
Reports
: diagnostic data, detailed report and simple report
-
validateDocument
Validates the document and all its signatures. The policyDataStream contains the constraint file. If null or empty the default file is used.- Specified by:
validateDocument
in interfaceDocumentValidator
- Parameters:
policyDataStream
- theInputStream
with the validation policy- Returns:
- the validation reports
-
validateDocument
Validates the document and all its signatures. ThevalidationPolicyDom
contains the constraint file. If null or empty the default file is used.- Specified by:
validateDocument
in interfaceDocumentValidator
- Parameters:
validationPolicyJaxb
- theConstraintsParameters
to use in the validation process- Returns:
- the validation reports
-
validateDocument
Validates the document and all its signatures. ThevalidationPolicyDom
contains the constraint file. If null or empty the default file is used.- Specified by:
validateDocument
in interfaceDocumentValidator
- Parameters:
validationPolicy
- theValidationPolicy
to use in the validation process- Returns:
- the validation reports
-
assertConfigurationValid
protected void assertConfigurationValid()Checks if the Validator configuration is valid -
prepareDiagnosticDataBuilder
Creates a DiagnosticData to pass to the validation process- Parameters:
validationContext
-ValidationContext
- Returns:
DiagnosticData
-
getDiagnosticDataBuilderConfiguration
protected DiagnosticDataBuilder getDiagnosticDataBuilderConfiguration(ValidationContext validationContext, List<AdvancedSignature> signatures, ListRevocationSource<CRL> listCRLSource, ListRevocationSource<OCSP> listOCSPSource) -
prepareCertificateVerifier
protected void prepareCertificateVerifier(ListRevocationSource<CRL> listCRLSource, ListRevocationSource<OCSP> listOCSPSource, ListCertificateSource listCertificateSource)Sets revocation sources for a following certificate validation- Parameters:
listCRLSource
-ListRevocationSource
listOCSPSource
-ListRevocationSource
listCertificateSource
-ListCertificateSource
-
mergeCRLSources
protected ListRevocationSource<CRL> mergeCRLSources(Collection<AdvancedSignature> allSignatureList, Collection<TimestampToken> detachedTimestamps)For all signatures to be validated this method merges the CRL sources.- Parameters:
allSignatureList
-Collection
ofAdvancedSignature
s to validate including the counter-signaturesdetachedTimestamps
-Collection
ofTimestampToken
s detached to a validating file- Returns:
- merged CRL Source
-
mergeOCSPSources
protected ListRevocationSource<OCSP> mergeOCSPSources(Collection<AdvancedSignature> allSignatureList, Collection<TimestampToken> detachedTimestamps)For all signatures to be validated this method merges the OCSP sources.- Parameters:
allSignatureList
-Collection
ofAdvancedSignature
s to validate including the counter-signaturesdetachedTimestamps
-Collection
ofTimestampToken
s detached to a validating file- Returns:
- merged OCSP Source
-
mergeCertificateSource
protected ListCertificateSource mergeCertificateSource(Collection<AdvancedSignature> allSignatureList, Collection<TimestampToken> detachedTimestamps)For all signatures to be validated this method merges the Certificate sources.- Parameters:
allSignatureList
-Collection
ofAdvancedSignature
s to validate including the counter-signaturesdetachedTimestamps
-Collection
ofTimestampToken
s detached to a validating file- Returns:
- merged Certificate Source
-
prepareSignatureValidationContext
public void prepareSignatureValidationContext(ValidationContext validationContext, List<AdvancedSignature> allSignatureList)Description copied from interface:DocumentValidator
Prepares thevalidationContext
for signature validation process and returns a list of signatures to validate- Specified by:
prepareSignatureValidationContext
in interfaceDocumentValidator
- Parameters:
validationContext
-ValidationContext
allSignatureList
- a list of allAdvancedSignature
s to be validated
-
prepareCertificatesAndTimestamps
protected void prepareCertificatesAndTimestamps(ValidationContext validationContext, List<AdvancedSignature> allSignatureList)- Parameters:
allSignatureList
-List
ofAdvancedSignature
s to validate including the countersignaturesvalidationContext
-ValidationContext
is the implementation of the validators for: certificates, timestamps and revocation data.
-
prepareDetachedTimestampValidationContext
public void prepareDetachedTimestampValidationContext(ValidationContext validationContext, List<TimestampToken> timestamps)Prepares thevalidationContext
for a timestamp validation process- Specified by:
prepareDetachedTimestampValidationContext
in interfaceDocumentValidator
- Parameters:
validationContext
-ValidationContext
timestamps
- a list of timestamps
-
validateContext
Process the validation- Parameters:
validationContext
-ValidationContext
to process
-
setSignaturePolicyProvider
Description copied from interface:DocumentValidator
This method allows to set a provider for Signature policies- Specified by:
setSignaturePolicyProvider
in interfaceDocumentValidator
-
getSignaturePolicyProvider
Returns a signaturePolicyProvider If not defined, returns a default provider- Returns:
SignaturePolicyProvider
-
setProcessExecutor
Description copied from interface:ProcessExecutorProvider
This method provides the possibility to set the specificCustomProcessExecutor
- Specified by:
setProcessExecutor
in interfaceProcessExecutorProvider<DocumentProcessExecutor>
-
provideProcessExecutorInstance
This method returns the process executor. If the instance of this class is not yet instantiated then the new instance is created.- Returns:
SignatureProcessExecutor
-
getDefaultProcessExecutor
Description copied from interface:ProcessExecutorProvider
Returns a default for a validator process executor- Specified by:
getDefaultProcessExecutor
in interfaceProcessExecutorProvider<DocumentProcessExecutor>
- Returns:
- Process Executor
-
processValidationPolicy
protected final Reports processValidationPolicy(XmlDiagnosticData diagnosticData, ValidationPolicy validationPolicy)Executes the validation regarding to the givenvalidationPolicy
- Parameters:
diagnosticData
-DiagnosticData
contained a data to be validatedvalidationPolicy
-ValidationPolicy
- Returns:
- validation
Reports
-
getAllSignatures
-
getSignatures
Description copied from interface:DocumentValidator
Retrieves the signatures found in the document- Specified by:
getSignatures
in interfaceDocumentValidator
- Returns:
- a list of AdvancedSignatures for validation purposes
-
getDetachedTimestamps
Description copied from interface:DocumentValidator
Retrieves the detached timestamps found in the document- Specified by:
getDetachedTimestamps
in interfaceDocumentValidator
- Returns:
- a list of TimestampToken for validation purposes
-
processSignaturesValidation
Description copied from interface:DocumentValidator
This method process the signature validation on the givenallSignatureList
- Specified by:
processSignaturesValidation
in interfaceDocumentValidator
- Parameters:
allSignatureList
- list ofAdvancedSignature
s to be validated
-
findSignatureScopes
Finds and assigns SignatureScopes for a list of signatures- Specified by:
findSignatureScopes
in interfaceDocumentValidator
- Parameters:
allSignatures
- a list ofAdvancedSignature
s to get a SignatureScope list
-
setSkipValidationContextExecution
public void setSkipValidationContextExecution(boolean skipValidationContextExecution) -
setLocale
-