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,AbstractJWSDocumentValidator,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 CertificateVerifiercertificateVerifierThe reference to the certificate verifier.protected List<DSSDocument>containerContentsIn case of an ASiC signature thisListof container documents.protected List<DSSDocument>detachedContentsIn case of a detached signature thisListcontains the signed documents.protected DSSDocumentdocumentThe document to be validated (with the signature(s) or timestamp(s))protected ManifestFilemanifestFileA relatedManifestFileto the provideddocumentprotected DocumentProcessExecutorprocessExecutorThis variable can hold a specificDocumentProcessExecutorprotected SignatureScopeFindersignatureScopeFinderThe class to extract a list ofSignatureScopes from a signatureprotected CertificateSourcesigningCertificateSourceCertificate source to find signing certificateprotected booleanskipValidationContextExecutionDefines if the validation context processing shall be skipped (Disable certificate chain building, revocation data collection,...) -
Constructor Summary
Constructors Modifier Constructor Description protectedSignedDocumentValidator()The constructor with a nullsignatureScopeFinderprotectedSignedDocumentValidator(SignatureScopeFinder signatureScopeFinder)The default constructor -
Method Summary
Modifier and Type Method Description protected voidappendCounterSignatures(List<AdvancedSignature> allSignatureList, AdvancedSignature signature)The util method to link counter signatures with the related master signaturesprotected voidassertConfigurationValid()Checks if the Validator configuration is validprotected DiagnosticDataBuildercreateDiagnosticDataBuilder(ValidationContext validationContext, List<AdvancedSignature> signatures, ListRevocationSource<CRL> listCRLSource, ListRevocationSource<OCSP> listOCSPSource)Creates and fills theDiagnosticDataBuilderwith a relevant datavoiddefineSigningCertificate(CertificateToken token)Deprecated.voidfindSignatureScopes(List<AdvancedSignature> allSignatures)Finds and assigns SignatureScopes for a list of signaturesstatic SignedDocumentValidatorfromDocument(DSSDocument dssDocument)This method guesses the document format and returns an appropriate document validator.protected List<AdvancedSignature>getAllSignatures()Returns a list of all signatures from the valdiating documentprotected DigestAlgorithmgetDefaultDigestAlgorithm()Returns a default digest algorithm defined for a digest calculationDocumentProcessExecutorgetDefaultProcessExecutor()Returns a default for a validator process executorList<TimestampToken>getDetachedTimestamps()Retrieves the detached timestamps found in the documentprotected SignaturePolicyProvidergetSignaturePolicyProvider()Returns a signaturePolicyProvider If not defined, returns a default providerList<AdvancedSignature>getSignatures()Retrieves the signatures found in the documentprotected DategetValidationTime()Returns validation time In case if the validation time is not provided, initialize the current time value from the systemprotected SignedDocumentDiagnosticDataBuilderinitializeDiagnosticDataBuilder()Initializes a relevantDiagnosticDataBuilderfor the given implementationabstract booleanisSupported(DSSDocument dssDocument)Checks if the document is supported by the current validatorprotected ListCertificateSourcemergeCertificateSource(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 voidprepareCertificatesAndTimestamps(ValidationContext validationContext, List<AdvancedSignature> allSignatureList)protected voidprepareCertificateVerifier(ListRevocationSource<CRL> listCRLSource, ListRevocationSource<OCSP> listOCSPSource, ListCertificateSource listCertificateSource)Sets revocation sources for a following certificate validationvoidprepareDetachedTimestampValidationContext(ValidationContext validationContext, List<TimestampToken> timestamps)Prepares thevalidationContextfor a timestamp validation processprotected DiagnosticDataBuilderprepareDiagnosticDataBuilder(ValidationContext validationContext)Creates aDiagnosticDataBuildervoidprepareSignatureValidationContext(ValidationContext validationContext, List<AdvancedSignature> allSignatureList)Prepares thevalidationContextfor signature validation process and returns a list of signatures to validatevoidprocessSignaturesValidation(List<AdvancedSignature> allSignatureList)This method process the signature validation on the givenallSignatureListprotected ReportsprocessValidationPolicy(XmlDiagnosticData diagnosticData, ValidationPolicy validationPolicy)Executes the validation regarding to the givenvalidationPolicyprotected DocumentProcessExecutorprovideProcessExecutorInstance()This method returns the process executor.voidsetCertificateVerifier(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.voidsetEnableEtsiValidationReport(boolean enableEtsiValidationReport)This method allows to specify if the ETSI Validation Report must be generated.voidsetIncludeSemantics(boolean include)This method allows to enable/disable the semantics inclusion in the reports (Indication / SubIndication meanings) Disabled by defaultvoidsetLocale(Locale locale)Sets Locale for report messages generationvoidsetManifestFile(ManifestFile manifestFile)Sets a relatedManifestFileto the document to be validated.voidsetProcessExecutor(DocumentProcessExecutor processExecutor)This method provides the possibility to set the specificCustomProcessExecutorvoidsetSignaturePolicyProvider(SignaturePolicyProvider signaturePolicyProvider)This method allows to set a provider for Signature policiesprotected voidsetSignedScopeFinderDefaultDigestAlgorithm(DigestAlgorithm digestAlgorithm)Sets the default algorithm to use for aSignatureScopeFindervoidsetSigningCertificateSource(CertificateSource signingCertificateSource)Set a certificate source which allows to find the signing certificate by kid or certificate's digestvoidsetSkipValidationContextExecution(boolean skipValidationContextExecution)Sets if the validation context execution shall be skipped (skips certificate chain building, revocation requests, ...)voidsetTokenExtractionStrategy(TokenExtractionStrategy tokenExtractionStrategy)This method allows to set the token extraction strategy to follow in the diagnostic data generation.voidsetValidationLevel(ValidationLevel validationLevel)This method allows to specify the validation level (Basic / Timestamp / Long Term / Archival).voidsetValidationTime(Date validationTime)Allows to define a custom validation timeprotected voidvalidateContext(ValidationContext validationContext)Process the validationReportsvalidateDocument()Validates the document and all its signatures.ReportsvalidateDocument(ConstraintsParameters validationPolicyJaxb)Validates the document and all its signatures.ReportsvalidateDocument(ValidationPolicy validationPolicy)Validates the document and all its signatures.ReportsvalidateDocument(File policyFile)Validates the document and all its signatures.ReportsvalidateDocument(InputStream policyDataStream)Validates the document and all its signatures.ReportsvalidateDocument(String policyResourcePath)Validates the document and all its signatures.ReportsvalidateDocument(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, waitMethods 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 thisListcontains the signed documents. -
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. -
signatureScopeFinder
The class to extract a list ofSignatureScopes from a signature -
skipValidationContextExecution
protected boolean skipValidationContextExecutionDefines if the validation context processing shall be skipped (Disable certificate chain building, revocation data collection,...) Default: false
-
-
Constructor Details
-
SignedDocumentValidator
protected SignedDocumentValidator()The constructor with a nullsignatureScopeFinder -
SignedDocumentValidator
The default constructor- Parameters:
signatureScopeFinder-SignatureScopeFinder
-
-
Method Details
-
setSignedScopeFinderDefaultDigestAlgorithm
Sets the default algorithm to use for aSignatureScopeFinder- Parameters:
digestAlgorithm-DigestAlgorithm
-
fromDocument
This method guesses the document format and returns an appropriate document validator.- Parameters:
dssDocument- The instance ofDSSDocumentto validate- Returns:
- returns the specific instance of SignedDocumentValidator in terms of the document type
-
isSupported
Checks if the document is supported by the current validator- Parameters:
dssDocument-DSSDocumentto check- Returns:
- TRUE if the document is supported, FALSE otherwise
-
defineSigningCertificate
Deprecated.Description copied from interface:DocumentValidatorThis method allows to define the signing certificate. It is useful in the case of non AdES signatures.- Specified by:
defineSigningCertificatein interfaceDocumentValidator- Parameters:
token-CertificateToken
-
setSigningCertificateSource
Description copied from interface:DocumentValidatorSet a certificate source which allows to find the signing certificate by kid or certificate's digest- Specified by:
setSigningCertificateSourcein interfaceDocumentValidator- 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 interfaceDocumentValidator- Parameters:
certificateVerifier-CertificateVerifier
-
setTokenExtractionStrategy
Description copied from interface:DocumentValidatorThis method allows to set the token extraction strategy to follow in the diagnostic data generation.- Specified by:
setTokenExtractionStrategyin interfaceDocumentValidator- Parameters:
tokenExtractionStrategy- theTokenExtractionStrategy
-
setIncludeSemantics
public void setIncludeSemantics(boolean include)Description copied from interface:DocumentValidatorThis method allows to enable/disable the semantics inclusion in the reports (Indication / SubIndication meanings) Disabled by default- Specified by:
setIncludeSemanticsin interfaceDocumentValidator- Parameters:
include- true to enable the inclusion of the semantics
-
setDetachedContents
Description copied from interface:DocumentValidatorSets theListofDSSDocumentcontaining the original contents to sign, for detached signature scenarios.- Specified by:
setDetachedContentsin interfaceDocumentValidator- Parameters:
detachedContents- theListofDSSDocumentto set
-
setContainerContents
Description copied from interface:DocumentValidatorSets theListofDSSDocumentcontaining the original container content for ASiC-S signatures.- Specified by:
setContainerContentsin interfaceDocumentValidator- Parameters:
containerContents- theListofDSSDocumentto set
-
setManifestFile
Description copied from interface:DocumentValidatorSets a relatedManifestFileto the document to be validated.- Specified by:
setManifestFilein interfaceDocumentValidator- Parameters:
manifestFile- aManifestFileto set
-
getDefaultDigestAlgorithm
Returns a default digest algorithm defined for a digest calculation- Returns:
DigestAlgorithm
-
setValidationTime
Allows to define a custom validation time- Specified by:
setValidationTimein 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:
Datevalidation time
-
setValidationLevel
Description copied from interface:DocumentValidatorThis method allows to specify the validation level (Basic / Timestamp / Long Term / Archival). By default, the selected validation is ARCHIVAL- Specified by:
setValidationLevelin interfaceDocumentValidator- Parameters:
validationLevel-ValidationLevel
-
setEnableEtsiValidationReport
public void setEnableEtsiValidationReport(boolean enableEtsiValidationReport)Description copied from interface:DocumentValidatorThis 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:
setEnableEtsiValidationReportin interfaceDocumentValidator- Parameters:
enableEtsiValidationReport- - TRUE if the report must be generated, FALSE otherwise
-
validateDocument
Description copied from interface:DocumentValidatorValidates the document and all its signatures. The default constraint file is used.- Specified by:
validateDocumentin interfaceDocumentValidator- Returns:
Reports: diagnostic data, detailed report and simple report
-
validateDocument
Description copied from interface:DocumentValidatorValidates 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:
validateDocumentin interfaceDocumentValidator- Parameters:
validationPolicyURL-URL- Returns:
Reports: diagnostic data, detailed report and simple report
-
validateDocument
Description copied from interface:DocumentValidatorValidates the document and all its signatures. The policyResourcePath specifies the constraint file. If null or empty the default file is used.- Specified by:
validateDocumentin 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:DocumentValidatorValidates the document and all its signatures. TheFileparameter specifies the constraint file. If null or empty the default file is used.- Specified by:
validateDocumentin 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:
validateDocumentin interfaceDocumentValidator- Parameters:
policyDataStream- theInputStreamwith the validation policy- Returns:
- the validation reports
-
validateDocument
Validates the document and all its signatures. ThevalidationPolicyDomcontains the constraint file. If null or empty the default file is used.- Specified by:
validateDocumentin interfaceDocumentValidator- Parameters:
validationPolicyJaxb- theConstraintsParametersto use in the validation process- Returns:
- the validation reports
-
validateDocument
Validates the document and all its signatures. ThevalidationPolicyDomcontains the constraint file. If null or empty the default file is used.- Specified by:
validateDocumentin interfaceDocumentValidator- Parameters:
validationPolicy- theValidationPolicyto use in the validation process- Returns:
- the validation reports
-
assertConfigurationValid
protected void assertConfigurationValid()Checks if the Validator configuration is valid -
prepareDiagnosticDataBuilder
Creates aDiagnosticDataBuilder- Parameters:
validationContext-ValidationContext- Returns:
DiagnosticDataBuilder
-
initializeDiagnosticDataBuilder
Initializes a relevantDiagnosticDataBuilderfor the given implementation- Returns:
SignedDocumentDiagnosticDataBuilder
-
createDiagnosticDataBuilder
protected DiagnosticDataBuilder createDiagnosticDataBuilder(ValidationContext validationContext, List<AdvancedSignature> signatures, ListRevocationSource<CRL> listCRLSource, ListRevocationSource<OCSP> listOCSPSource)Creates and fills theDiagnosticDataBuilderwith a relevant data- Parameters:
validationContext-ValidationContextused for the validationsignatures- a list ofAdvancedSignatures to be validatedlistCRLSource-ListRevocationSourceused for CRL collectionlistOCSPSource-ListRevocationSourceused for OCSP collection- Returns:
- filled
DiagnosticDataBuilder
-
prepareCertificateVerifier
protected void prepareCertificateVerifier(ListRevocationSource<CRL> listCRLSource, ListRevocationSource<OCSP> listOCSPSource, ListCertificateSource listCertificateSource)Sets revocation sources for a following certificate validation- Parameters:
listCRLSource-ListRevocationSourcelistOCSPSource-ListRevocationSourcelistCertificateSource-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-CollectionofAdvancedSignatures to validate including the counter-signaturesdetachedTimestamps-CollectionofTimestampTokens 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-CollectionofAdvancedSignatures to validate including the counter-signaturesdetachedTimestamps-CollectionofTimestampTokens 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-CollectionofAdvancedSignatures to validate including the counter-signaturesdetachedTimestamps-CollectionofTimestampTokens detached to a validating file- Returns:
- merged Certificate Source
-
prepareSignatureValidationContext
public void prepareSignatureValidationContext(ValidationContext validationContext, List<AdvancedSignature> allSignatureList)Description copied from interface:DocumentValidatorPrepares thevalidationContextfor signature validation process and returns a list of signatures to validate- Specified by:
prepareSignatureValidationContextin interfaceDocumentValidator- Parameters:
validationContext-ValidationContextallSignatureList- a list of allAdvancedSignatures to be validated
-
prepareCertificatesAndTimestamps
protected void prepareCertificatesAndTimestamps(ValidationContext validationContext, List<AdvancedSignature> allSignatureList)- Parameters:
allSignatureList-ListofAdvancedSignatures to validate including the countersignaturesvalidationContext-ValidationContextis the implementation of the validators for: certificates, timestamps and revocation data.
-
prepareDetachedTimestampValidationContext
public void prepareDetachedTimestampValidationContext(ValidationContext validationContext, List<TimestampToken> timestamps)Prepares thevalidationContextfor a timestamp validation process- Specified by:
prepareDetachedTimestampValidationContextin interfaceDocumentValidator- Parameters:
validationContext-ValidationContexttimestamps- a list of timestamps
-
validateContext
Process the validation- Parameters:
validationContext-ValidationContextto process
-
setSignaturePolicyProvider
Description copied from interface:DocumentValidatorThis method allows to set a provider for Signature policies- Specified by:
setSignaturePolicyProviderin interfaceDocumentValidator- Parameters:
signaturePolicyProvider-SignaturePolicyProvider
-
getSignaturePolicyProvider
Returns a signaturePolicyProvider If not defined, returns a default provider- Returns:
SignaturePolicyProvider
-
setProcessExecutor
Description copied from interface:ProcessExecutorProviderThis method provides the possibility to set the specificCustomProcessExecutor- Specified by:
setProcessExecutorin interfaceProcessExecutorProvider<DocumentProcessExecutor>- Parameters:
processExecutor-ProcessExecutor
-
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:ProcessExecutorProviderReturns a default for a validator process executor- Specified by:
getDefaultProcessExecutorin interfaceProcessExecutorProvider<DocumentProcessExecutor>- Returns:
- Process Executor
-
processValidationPolicy
protected final Reports processValidationPolicy(XmlDiagnosticData diagnosticData, ValidationPolicy validationPolicy)Executes the validation regarding to the givenvalidationPolicy- Parameters:
diagnosticData-DiagnosticDatacontained a data to be validatedvalidationPolicy-ValidationPolicy- Returns:
- validation
Reports
-
getAllSignatures
Returns a list of all signatures from the valdiating 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
-
getSignatures
Description copied from interface:DocumentValidatorRetrieves the signatures found in the document- Specified by:
getSignaturesin interfaceDocumentValidator- Returns:
- a list of AdvancedSignatures for validation purposes
-
getDetachedTimestamps
Description copied from interface:DocumentValidatorRetrieves the detached timestamps found in the document- Specified by:
getDetachedTimestampsin interfaceDocumentValidator- Returns:
- a list of TimestampToken for validation purposes
-
processSignaturesValidation
Description copied from interface:DocumentValidatorThis method process the signature validation on the givenallSignatureList- Specified by:
processSignaturesValidationin interfaceDocumentValidator- Parameters:
allSignatureList- list ofAdvancedSignatures to be validated
-
findSignatureScopes
Finds and assigns SignatureScopes for a list of signatures- Specified by:
findSignatureScopesin interfaceDocumentValidator- Parameters:
allSignatures- a list ofAdvancedSignatures to get a SignatureScope list
-
setSkipValidationContextExecution
public void setSkipValidationContextExecution(boolean skipValidationContextExecution)Sets if the validation context execution shall be skipped (skips certificate chain building, revocation requests, ...)- Parameters:
skipValidationContextExecution- if the context validation shall be skipped
-
setLocale
Sets Locale for report messages generation- Parameters:
locale-Locale
-