Package es.gob.afirma.utils
Class UtilsSignatureOp
- java.lang.Object
-
- es.gob.afirma.utils.UtilsSignatureOp
-
- All Implemented Interfaces:
IUtilsSignature
public final class UtilsSignatureOp extends java.lang.Object implements IUtilsSignature
Class that contains methods related to the manage of signatures.
Project:Library for the integration with the services of @Firma, eVisor and TS@.
- Version:
- 1.6, 18/04/2022.
-
-
Field Summary
Fields Modifier and Type Field Description static com.lowagie.text.pdf.PdfNameCADES_SUBFILTER_VALUEConstant attribute that represents the value for the key SubFilter of the signature dictionary for a PAdES Enhanced signature.static com.lowagie.text.pdf.PdfNameDOC_TIME_STAMP_DICTIONARY_NAMEConstant attribute that represents the value to identify the type of a Document Time-stamp.static com.lowagie.text.pdf.PdfNameDSS_DICTIONARY_NAMEConstant attribute that represents the value to identify the DSS entry in a PDF's Catalog.static com.lowagie.text.pdf.PdfNameTST_SUBFILTER_VALUEConstant attribute that represents the value for the key SubFilter of a Document Time-stamp dictionary.-
Fields inherited from interface es.gob.afirma.utils.IUtilsSignature
DETACHED_SIGNATURE_MODE, ENVELOPED_SIGNATURE_MODE, ENVELOPING_SIGNATURE_MODE, EXPLICIT_SIGNATURE_MODE, IMPLICIT_SIGNATURE_MODE, VALIDATION_LEVEL_COMPLETE, VALIDATION_LEVEL_NONE, VALIDATION_LEVEL_SIMPLE
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.bouncycastle.util.Store<org.bouncycastle.cert.X509CertificateHolder>addCertificateToStore(org.bouncycastle.util.Store<org.bouncycastle.cert.X509CertificateHolder> certificates, java.security.cert.X509Certificate certificate)Method that adds a certificate to a certificates store.static voidappendXMLDocument(org.w3c.dom.Document xmlDocument, org.w3c.dom.Document documentToAppend)Method that appends a XML document to certain signed XML document.static java.util.DatecalculateExpirationDate(java.util.List<PDFSignatureDictionary> signatureDictionaries, java.util.List<PDFDocumentTimestampDictionary> timestampDictionaries)Method that calculates the expiration date of a PAdES signature, that is, the moment in which the signature will become invalid.static java.util.DatecalculateExpirationDateForValidations(SignerValidationResult signerValidationResult, java.util.Date currentDate)Auxiliary method that calculate the expiration date of a validation or update response.static booleancheckExtraParamsSignWithRubric(java.util.Properties externalParams)Method that checks if the signature includes a rubric.static voidcheckPDFCertificationLevel(java.util.Map<java.lang.Integer,java.io.InputStream> mapRevisions)Method that validates if some approval signature was added to a PDF document after that it was defined as certified.static voidcheckSubFilterConditionsISO320001(PDFSignatureDictionary dictionarySignature, org.bouncycastle.cms.CMSSignedData signedData)The ISO 32000-1 specifies in section 12.8.3.3.1: - adbe.pkcs7.detached: The original signed message digest over the document’s byte range shall be incorporated as the normal PKCS#7 SignedData field.static org.w3c.dom.DocumentcomposeCoSignaturesDocument(org.w3c.dom.Document xmlDocument, javax.xml.parsers.DocumentBuilderFactory dBFactory)Method that composes and obtains a XML document with the root node <ROOT_COSIGNATURES> for adding new cosigns over that (on enveloping signature mode).static booleanequalsHash(com.lowagie.text.pdf.PdfArray pdfArrayByteRange, java.security.MessageDigest messageDigestSignature, byte[] pdfDocument, byte[] hashSignature)Method that compares two bytes arrays and indicates if the hash of each is equals (true) or not (false).static java.util.List<ReferenceDataBaseline>fromNodeListToReferenceDataBaselineList(org.w3c.dom.Node manifestNode, org.w3c.dom.Node signedDataObjectPropertiesNode)Method that parse a manifest and signedDataObjectProperties element into a list of ReferenceDataBaseline objects.static java.util.List<CAdESSignerInfo>getCAdESListSigners(org.bouncycastle.cms.CMSSignedData signedData)Method that obtains a list with the principal information related to the signers of a CAdES signature.static org.bouncycastle.cms.CMSSignedDatagetCMSSignature(PDFSignatureDictionary signatureDictionary)Method that obtains theSignedDatacontained inside of a signature dictionary of a PDF document.static org.bouncycastle.cms.CMSSignedDatagetCMSSignedData(byte[] signature)Method that obtains the CAdES structure of an ASN.1 signature.static java.util.DategetExpirationDate(byte[] signature)Method that calculates the expiration date of a signature.static java.util.List<org.w3c.dom.Element>getListSignatures(org.w3c.dom.Document doc)Method that obtains the list ofds:Signatureelements, as signatures, contained inside of a XML document.static java.util.List<org.w3c.dom.Element>getListSignaturesToCounterSign(org.w3c.dom.Element rootElement)Method that obtains from a root element the list ofds:Signatureelements to addxades:CounterSignatureelement.static byte[]getOriginalDataFromSignedXMLDocument(org.w3c.dom.Document xmlDocument)Method that obtains the original data from a signed XML document.static org.bouncycastle.asn1.x509.AlgorithmIdentifiergetSignatureAlgorithm(java.lang.String encryptionAlgOid, java.lang.String hashAlgOid)Obtiene el identificador de algoritmo de firma que se corresponde al usar el algoritmo de encriptación con el algoritmo de hash indicados.static org.bouncycastle.asn1.x509.AlgorithmIdentifiergetSignatureAlgorithm(org.bouncycastle.cms.SignerInformation signerInformation)Obtiene el OID del algoritmo de firma empleado.static java.lang.StringgetSignedElementIdValue(org.w3c.dom.Document xmlDocument)Method that obtains the value of the attributeIdof theContentnode of the wrapper, or an empty String if the signed XML document doesn't contain that attribute (wrapper signed on enveloped mode).static java.security.cert.X509CertificategetSigningCertificate(org.bouncycastle.cms.CMSSignedData signedData, org.bouncycastle.cms.SignerInformation signerInformation)Method that obtains the singing certificate of a signer of a signature.static java.lang.StringgetTypeOfXMLSignature(org.w3c.dom.Document xmlDocument)Method that obtains the signature mode of a signed XML document.static org.bouncycastle.cert.X509CertificateHoldergetX509CertificateHolderBySignerId(org.bouncycastle.util.Store certificatesStore, org.bouncycastle.cms.SignerId signerId)Method that obtains the structure of a certificate from a certificates store.static java.util.List<XAdESSignerInfo>getXAdESListSigners(org.w3c.dom.Document doc)Method that obtains a list with the principal information related to the signers of a XAdES signature.static org.w3c.dom.ElementgetXMLSignatureById(org.w3c.dom.Document document, java.lang.String signatureId)Method that obtains aSignatureelement from a XML document.static org.w3c.dom.DocumentinsertAfirmaRootNode(org.w3c.dom.Document xmlDocument, javax.xml.parsers.DocumentBuilderFactory dBFactory)Method that defines theAFIRMAnode as root node of a signed XML document.static voidinsertRubric(com.lowagie.text.pdf.PdfReader reader, com.lowagie.text.pdf.PdfSignatureAppearance signatureAppearance, java.util.Properties externalParams)Method that inserts the rubric in a document.static booleanisDocumentTimeStampDictionary(java.lang.String pdfType, java.lang.String subFilter)Method that indicates whether a pdf dictionary is a document Time-stamp dictionary (true) or not (false).static booleanisDSSTimestamp(org.w3c.dom.Node eSignature)Method that indicates if the signature is an XMLTimeStamp element by the OASIS-DSS specifications (true) or not (false).static booleanisImplicit(org.bouncycastle.cms.CMSSignedData cmsSignedData)Method that indicates whether the signature includes the original document (true) or not (false).static booleanisNotPAdESEnhancedPDF(com.lowagie.text.pdf.PdfDictionary pdfDic)Method that indicates whether a signature dictionary refers to a PDF or PAdES-Basic signature (true) or to a PAdES-BES or PAdES-EPES signature (false).static booleanisSignatureDictionary(java.lang.String pdfType, java.lang.String subFilter)Method that indicates whether a pdf dictionary is a signature dictionary (true) or not (false).static java.security.cert.X509CertificateobtainCertificateArchiveTimestamps(org.bouncycastle.asn1.cms.AttributeTable unsignedAttributes)Method that gets the last archive timestamp certificate from the the list of archive timestamps of a signature.static java.security.cert.X509CertificateobtainCertificateArchiveTimestampsXAdES(XAdESSignerInfo signerInfo)Method that obtains the signing certificate of the last archiveTimestamp of a XAdES signature.static byte[]obtainFirstRevision(byte[] pdfDocument)Method that obtains the first revision of the signature dictionary.static com.lowagie.text.pdf.PdfReaderobtainLatestRevision(com.lowagie.text.pdf.PdfReader reader)Method that obtains the revision of the signature dictionary most recent.static PDFSignatureDictionaryobtainLatestSignatureFromPDF(com.lowagie.text.pdf.PdfReader reader)Method that obtains the signature dictionary with major review.static org.w3c.dom.ElementretrieveNode(org.w3c.dom.Element parentNode, java.lang.String nodeName, java.lang.String namespaceURI, boolean isRequired)Method that obtains an element from a XML document.static java.security.cert.X509CertificateretrieveSigningCertificateOfXMLSigner(org.w3c.dom.Element signedSignaturePropertiesElement, java.lang.String signatureId, org.w3c.dom.Element signatureElement)Method that retrieves the signing certificate of a signer contained inside of a XML signature.static voidvalidateCAdESPublicKeyInfo(org.bouncycastle.cms.CMSSignedData signedData, org.bouncycastle.cms.SignerInformation signerInformation, java.security.cert.X509Certificate signingCertificate)Method that checks if the signer includes aSigningCertificatesigned attribute, or aSigningCertificateV2signed attribute, and this matches to the signing certificate.static voidvalidateCAdESSignatureCore(org.bouncycastle.cms.SignerInformation signerInformation, java.security.cert.X509Certificate signingCertificate, boolean isPadesSignature)Method that validates the CAdES signature core associated to a signer.static voidvalidateCAdESSigningTime(org.bouncycastle.cms.CMSSignedData signedData, org.bouncycastle.cms.SignerInformation signerInformation, boolean isRequired, java.util.Date validationDate, java.security.cert.X509Certificate signingCertificate)Method that validates if the signing time of a signature is previous than certain date.static voidvalidateCertificate(java.security.cert.X509Certificate certificate, java.util.Date validationDate, boolean isUpgradeOperation, java.lang.String idClient, boolean isTimestampCertificate)Method that validates the validity period of a certificate and the revocation status of a certificate (if the validation level for the certificates is defined with the valueIUtilsSignature.VALIDATION_LEVEL_COMPLETE).static voidvalidateCMSPublicKeyInfo(org.bouncycastle.cms.SignerInformation signerInformation, java.security.cert.X509Certificate signingCertificate)Method that checks if the value of the signed attributeSerialNumberof a signature matches to the serial number of the signing certificate.static voidvalidateDocumentTimeStampDictionaryStructurally(PDFDocumentTimestampDictionary pdfDocumentTimestampDictionary, byte[] pdfDocument)Method that validates for a Document Time-stamp dictionary: The ByteRange entry of the Document Time-stamp dictionary isn't null. The ByteRange entry represents the exact byte range for the digest calculation. The entry with the key Cert in the Document Time-stamp dictionary isn't used. The entry with the key Reference in the Document Time-stamp dictionary isn't used. The entry with the key Changes in the Document Time-stamp dictionary isn't used. The entry with the key R in the Document Time-stamp dictionary isn't used. The entry with the key Prop_AuthTime in the Document Time-stamp dictionary isn't used. The entry with the key Prop_AuthType in the Document Time-stamp dictionary isn't used. The entry with the key V in the Document Time-stamp dictionary, if present, has the value: 0.static voidvalidateDocumentTimeStampSigningTime(PDFDocumentTimestampDictionary pdfDocumentTimeStampDictionary, java.util.Date validationDate)Method that checks if the generation date of a time-stamp contained inside of a Document Time-stamp dictionary is previous than a validation date.static voidvalidatePAdESBaselineMandatoryAttributes(PDFSignatureDictionary signatureDictionary, org.bouncycastle.cms.CMSSignedData signedData, java.util.Date validationDate)Method that checks, for the signature contained inside of a signature dictionary of a PDF document: If the SignedData field is explicit. If the signature contains thecontent-typeattribute and it has the value "id-data". If the signature dictionary doesn't contain/Certentry. If the signature dictionary contain the signing time inside of/Mentry and it's after than the validation date.static voidvalidatePAdESBaselineOptionalAttributes(PDFSignatureDictionary signatureDictionary, org.bouncycastle.cms.CMSSignedData signedData)Method that checks, for the signature contained inside of a signature dictionary of a PDF document: If the signature doesn't contain thesigning-timeattribute. If the signature doesn't contain thecounter-signatureattribute. If the signature doesn't contain thecontent-referenceattribute. If the signature doesn't contain thecontent-identifierattribute. If the signature doesn't contain thecontent-hintsattribute. If the signature doesn't contain thecommitment-type-indicationattribute. If the signature doesn't contain thesigner-locationattribute.static booleanvalidatePAdESBaselineStructurally(PDFSignatureDictionary signatureDictionary, byte[] pdfDocument, org.bouncycastle.cms.CMSSignedData signedData)Method that checks if a signature dictionary is valid against PAdES Baseline profile.static voidvalidatePAdESBasicSigningTime(org.bouncycastle.cms.SignerInformation signerInformation, java.util.Date validationDate, java.security.cert.X509Certificate signingCertificate, PDFSignatureDictionary signatureDictionary)Method that validates the signing time of a PAdES-Basic signature.static voidvalidatePAdESBasicStructurally(PDFSignatureDictionary signatureDictionary, byte[] pdfDocument, org.bouncycastle.cms.CMSSignedData signedData)Method that validates the structure of a signature dictionary by PAdES-Basic signature form.static voidvalidatePAdESEnhancedMandatoryAttributes(PDFSignatureDictionary signatureDictionary, org.bouncycastle.cms.CMSSignedData signedData)Method that validates the mandatory attributes for a PAdES enhanced signature.static voidvalidatePAdESEnhancedStructurally(PDFSignatureDictionary signatureDictionary, byte[] pdfDocument, org.bouncycastle.cms.CMSSignedData signedData, boolean isEPES)Method that checks if a signature dictionary is valid against PAdES Enhanced profile.static voidvalidatePAdESOptionalAttributes(PDFSignatureDictionary signatureDictionary, org.bouncycastle.cms.CMSSignedData signedData, boolean isEPES, boolean isBasic)Method that validates the optional attributes for a PAdES signature.static voidvalidatePAdESSigningTime(PDFSignatureDictionary signatureDictionary, java.util.Date validationDate, boolean isRequired)Method that validates if the signature dictionary has /M entry that entry must be a date with a valid format by PDF Referente and that date must be before of the validation date.static voidvalidatePDFSigner(org.bouncycastle.cms.CMSSignedData signedData, org.bouncycastle.cms.SignerInformation signerInformation, com.lowagie.text.pdf.PdfDictionary pdfSignatureDictionary, java.util.Date validationDate, java.lang.String idClient)Method that validates the signer of a signature contained inside of a PDF document.static voidvalidateXAdESPublicKeyInfo(java.lang.String signatureId, org.w3c.dom.Element signatureElement, org.apache.xml.security.signature.XMLSignature xmlSignature, boolean isBaseline, boolean isCounterSignature)Method that validates if the public key information contained inside of a XML signature is valid.static voidvalidateXAdESSignatureCore(org.w3c.dom.Element qualifyingPropertiesElement, java.lang.String signatureId, org.w3c.dom.Element signatureElement, org.apache.xml.security.signature.XMLSignature xmlSignature, byte[] signedFile, java.lang.String signedFileName, java.security.cert.X509Certificate signingCertificate, org.w3c.dom.Element signedSignaturePropertiesElement, org.w3c.dom.Element signedPropertiesElement, boolean isBaseline, boolean isCounterSignature)Method that validates the XAdES signature core associated to a signer.static voidvalidateXAdESSigner(org.apache.xml.security.signature.XMLSignature xmlSignature, java.security.cert.X509Certificate signingCertificate, org.bouncycastle.tsp.TimeStampToken tst, org.w3c.dom.Element xmlTst, java.lang.String signingMode, byte[] signedFile, java.lang.String signedFileName, java.lang.String idClient)Method that validates the signer of a XAdES signature.static voidvalidateXAdESSigningTime(org.w3c.dom.Element signedSignaturePropertiesElement, boolean isRequired, java.lang.String signatureId, java.util.Date validationDate)Method that validates if the signing time of a XML signature is previous than certain validation date.
-
-
-
Field Detail
-
CADES_SUBFILTER_VALUE
public static final com.lowagie.text.pdf.PdfName CADES_SUBFILTER_VALUE
Constant attribute that represents the value for the key SubFilter of the signature dictionary for a PAdES Enhanced signature.
-
TST_SUBFILTER_VALUE
public static final com.lowagie.text.pdf.PdfName TST_SUBFILTER_VALUE
Constant attribute that represents the value for the key SubFilter of a Document Time-stamp dictionary.
-
DOC_TIME_STAMP_DICTIONARY_NAME
public static final com.lowagie.text.pdf.PdfName DOC_TIME_STAMP_DICTIONARY_NAME
Constant attribute that represents the value to identify the type of a Document Time-stamp.
-
DSS_DICTIONARY_NAME
public static final com.lowagie.text.pdf.PdfName DSS_DICTIONARY_NAME
Constant attribute that represents the value to identify the DSS entry in a PDF's Catalog.
-
-
Method Detail
-
validateCertificate
public static void validateCertificate(java.security.cert.X509Certificate certificate, java.util.Date validationDate, boolean isUpgradeOperation, java.lang.String idClient, boolean isTimestampCertificate) throws SigningExceptionMethod that validates the validity period of a certificate and the revocation status of a certificate (if the validation level for the certificates is defined with the valueIUtilsSignature.VALIDATION_LEVEL_COMPLETE). If the validation level for the certificates is defined with the valueIUtilsSignature.VALIDATION_LEVEL_COMPLETEthe validation of the revocation status will be via OCSP.- Parameters:
certificate- Parameter that represents the certificate to validate.validationDate- Parameter that represents the validation date.isUpgradeOperation- Parameter that indicates if the origin operation is an upgrade signature operation (true) or not (false).idClient- Parameter that represents the client application identifier.isTimestampCertificate- Parameter that indicates if the certificate is the signing certificate of a time-stamp (true) or not (false).- Throws:
SigningException- If the certificate isn't valid or the method fails.
-
obtainLatestSignatureFromPDF
public static PDFSignatureDictionary obtainLatestSignatureFromPDF(com.lowagie.text.pdf.PdfReader reader)
Method that obtains the signature dictionary with major review.- Parameters:
reader- Parameter that represents the reader for the PDF document.- Returns:
- the signature dictionary with major review.
-
isNotPAdESEnhancedPDF
public static boolean isNotPAdESEnhancedPDF(com.lowagie.text.pdf.PdfDictionary pdfDic)
Method that indicates whether a signature dictionary refers to a PDF or PAdES-Basic signature (true) or to a PAdES-BES or PAdES-EPES signature (false).- Parameters:
pdfDic- Parameter that represents the signature dictionary.- Returns:
- a boolean that indicates whether a signature dictionary refers to a PDF or PAdES-Basic signature (true) or to a PAdES-BES or PAdES-EPES signature (false).
-
getCMSSignature
public static org.bouncycastle.cms.CMSSignedData getCMSSignature(PDFSignatureDictionary signatureDictionary) throws SigningException
Method that obtains theSignedDatacontained inside of a signature dictionary of a PDF document.- Parameters:
signatureDictionary- Parameter that represents the signature dictionary.- Returns:
- an object that represents the
SignedData. - Throws:
SigningException- If the method fails.
-
isImplicit
public static boolean isImplicit(org.bouncycastle.cms.CMSSignedData cmsSignedData)
Method that indicates whether the signature includes the original document (true) or not (false).- Parameters:
cmsSignedData- Parameter that represents the pkcs7-signature message.- Returns:
- a boolean that indicates whether the signature includes the original document (true) or not (false).
-
equalsHash
public static boolean equalsHash(com.lowagie.text.pdf.PdfArray pdfArrayByteRange, java.security.MessageDigest messageDigestSignature, byte[] pdfDocument, byte[] hashSignature)Method that compares two bytes arrays and indicates if the hash of each is equals (true) or not (false).- Parameters:
pdfArrayByteRange- Parameter that represents the exact byte range for the digest calculation.messageDigestSignature- Parameter that represents the message digest algorithm.pdfDocument- Parameter that represents the first bytes array to compare.hashSignature- Parameter that represents the second bytes array to compare.- Returns:
- a boolean that indicates if the hash of each is equals (true) or not (false).
-
checkSubFilterConditionsISO320001
public static void checkSubFilterConditionsISO320001(PDFSignatureDictionary dictionarySignature, org.bouncycastle.cms.CMSSignedData signedData) throws SigningException
The ISO 32000-1 specifies in section 12.8.3.3.1: - adbe.pkcs7.detached: The original signed message digest over the document’s byte range shall be incorporated as the normal PKCS#7 SignedData field. No data shall be encapsulated in the PKCS#7 SignedData field. - adbe.pkcs7.sha1: The SHA1 digest of the document’s byte range shall be encapsulated in the PKCS#7 SignedData field with ContentInfo of type Data. The digest of that SignedData shall be incorporated as the normal PKCS#7 digest. This method checks if that conditions are valid.- Parameters:
dictionarySignature- Parameter that represents the signature dictionary.signedData- Parameter that represents the signed data.- Throws:
SigningException- If one of the conditiones isn't valid.
-
validatePAdESEnhancedMandatoryAttributes
public static void validatePAdESEnhancedMandatoryAttributes(PDFSignatureDictionary signatureDictionary, org.bouncycastle.cms.CMSSignedData signedData) throws SigningException
Method that validates the mandatory attributes for a PAdES enhanced signature. The method verifies that:- The content-type attribute cannot be null and must have the value
id-data. - The entry with the key Cert in the signature dictionary isn't used.
- Parameters:
signatureDictionary- Parameter that represents the signature dictionary.signedData- Parameter that represents the signed data.- Throws:
SigningException- If the validation fails.
- The content-type attribute cannot be null and must have the value
-
validatePAdESOptionalAttributes
public static void validatePAdESOptionalAttributes(PDFSignatureDictionary signatureDictionary, org.bouncycastle.cms.CMSSignedData signedData, boolean isEPES, boolean isBasic) throws SigningException
Method that validates the optional attributes for a PAdES signature. The method verifies that:- The counter-signature attribute isn't used if the signature has PAdES-EPES or PAdES-BES profile.
- The content-reference attribute isn't used if the signature has PAdES-EPES or PAdES-BES profile.
- The content-identifier attribute isn't used if the signature has PAdES-EPES or PAdES-BES profile.
- The Reason key isn't present in the signature dictionary if the signature has PAdES-EPES profile.
- The commitment-type-indication attribute isn't used if the signature has PAdES-BES profile.
- The signer-location attribute isn't used if the signature has PAdES-EPES or PAdES-BES profile.
- The signing-time attribute isn't used if the signature has PAdES-EPES or PAdES-BES profile.
- The content-hints attribute isn't used if the signature has PAdES-EPES or PAdES-BES profile.
- If the signature dictionary has /M entry that entry must be a date with a valid format by PDF Reference and that date must be before of the validation date if the signature has PAdES-Basic, PAdES-EPES or PAdES-BES profile.
- Parameters:
signatureDictionary- Parameter that represents the signature dictionary.signedData- Parameter that represents the signed data.isEPES- Parameter that indicates if the signature has PAdES-EPES profile (true) or PAdES-BES profile (false).isBasic- Parameter that indicates if the signature has PAdES-Basic profile (true) or PAdES Enhanced profile (false).- Throws:
SigningException- If the validation fails.
-
getX509CertificateHolderBySignerId
public static org.bouncycastle.cert.X509CertificateHolder getX509CertificateHolderBySignerId(org.bouncycastle.util.Store certificatesStore, org.bouncycastle.cms.SignerId signerId)Method that obtains the structure of a certificate from a certificates store.- Parameters:
certificatesStore- Parameter that represents the certificates store.signerId- Parameter that represents the identifier of the signer used to find the certificate.- Returns:
- an object that represents the structure of the certificate.
-
validatePDFSigner
public static void validatePDFSigner(org.bouncycastle.cms.CMSSignedData signedData, org.bouncycastle.cms.SignerInformation signerInformation, com.lowagie.text.pdf.PdfDictionary pdfSignatureDictionary, java.util.Date validationDate, java.lang.String idClient) throws SigningExceptionMethod that validates the signer of a signature contained inside of a PDF document.- Parameters:
signedData- Parameter that represents the signed data.signerInformation- Parameter that represents the signer information.pdfSignatureDictionary- Parameter that represents the PDF signature dictionary.validationDate- Parameter that represents the validation date.idClient- Parameter that represents the client application identifier.- Throws:
SigningException- If the validation fails.
-
getCAdESListSigners
public static java.util.List<CAdESSignerInfo> getCAdESListSigners(org.bouncycastle.cms.CMSSignedData signedData)
Method that obtains a list with the principal information related to the signers of a CAdES signature.- Parameters:
signedData- Parameter that represents the signed data.- Returns:
- a list with the principal information related to the signers of a CAdES signature.
-
getSigningCertificate
public static java.security.cert.X509Certificate getSigningCertificate(org.bouncycastle.cms.CMSSignedData signedData, org.bouncycastle.cms.SignerInformation signerInformation) throws SigningExceptionMethod that obtains the singing certificate of a signer of a signature.- Parameters:
signedData- Parameter that represents the signed data.signerInformation- Parameter that represents the information about the signer of the signature.- Returns:
- an object that represents the signing certificate.
- Throws:
SigningException- If the certificate hasn't could be retrieved.
-
obtainLatestRevision
public static com.lowagie.text.pdf.PdfReader obtainLatestRevision(com.lowagie.text.pdf.PdfReader reader) throws SigningExceptionMethod that obtains the revision of the signature dictionary most recent.- Parameters:
reader- Parameter that represents the reader for the PDF document.- Returns:
- an input stream that represents the revision, or
nullif the PDF document doesn't contain any signature dictionary. - Throws:
SigningException- If cannot access to some revision.
-
checkPDFCertificationLevel
public static void checkPDFCertificationLevel(java.util.Map<java.lang.Integer,java.io.InputStream> mapRevisions) throws SigningExceptionMethod that validates if some approval signature was added to a PDF document after that it was defined as certified.- Parameters:
mapRevisions- Parameter that represents a map with the revisions of the PDF document. Each revision represents a signature dictionary. The key is the revision number, and the value is the revision.- Throws:
SigningException- If the method fails or some approval signature was added to a PDF document after that it was defined as certified.
-
getXAdESListSigners
public static java.util.List<XAdESSignerInfo> getXAdESListSigners(org.w3c.dom.Document doc)
Method that obtains a list with the principal information related to the signers of a XAdES signature.- Parameters:
doc- Parameter that represents the XML document.- Returns:
- a list with the principal information related to the signers of a XAdES signature.
-
getListSignatures
public static java.util.List<org.w3c.dom.Element> getListSignatures(org.w3c.dom.Document doc)
Method that obtains the list ofds:Signatureelements, as signatures, contained inside of a XML document.- Parameters:
doc- Parameter that represents the XML document.- Returns:
- a list with the
ds:Signatureelements.
-
validateXAdESSigner
public static void validateXAdESSigner(org.apache.xml.security.signature.XMLSignature xmlSignature, java.security.cert.X509Certificate signingCertificate, org.bouncycastle.tsp.TimeStampToken tst, org.w3c.dom.Element xmlTst, java.lang.String signingMode, byte[] signedFile, java.lang.String signedFileName, java.lang.String idClient) throws SigningExceptionMethod that validates the signer of a XAdES signature.- Parameters:
xmlSignature- Parameter that represents the XAdES signature.signingCertificate- Parameter that represents the signing certificatetst- Parameter that represents the RFC 3161 timestamp associated to the signer.xmlTst- Parameter that represents the XML timestamp associated to the signer.signingMode- Parameter that represents the signing mode of the XAdES signature. The possible values are:signedFile- Parameter that represents the file signed by the XML signature when the signed data isn't included into the signed XML document.signedFileName- Parameter that represents the name of the file signed by the XML signature when the signed data isn't included into the signed XML document.idClient- Parameter that represents the client application identifier.- Throws:
SigningException- If the validation fails.
-
addCertificateToStore
public static org.bouncycastle.util.Store<org.bouncycastle.cert.X509CertificateHolder> addCertificateToStore(org.bouncycastle.util.Store<org.bouncycastle.cert.X509CertificateHolder> certificates, java.security.cert.X509Certificate certificate) throws SigningExceptionMethod that adds a certificate to a certificates store.- Parameters:
certificates- Parameter that represents the certificates store.certificate- Parameter that represents the certificate to add.- Returns:
- the upgraded certificates store.
- Throws:
SigningException- If the method fails.
-
getCMSSignedData
public static org.bouncycastle.cms.CMSSignedData getCMSSignedData(byte[] signature) throws SigningExceptionMethod that obtains the CAdES structure of an ASN.1 signature.- Parameters:
signature- Parameter that represents the ASN.1 signature.- Returns:
- an object that represents the CAdES structure.
- Throws:
SigningException- If the method fails.
-
isDocumentTimeStampDictionary
public static boolean isDocumentTimeStampDictionary(java.lang.String pdfType, java.lang.String subFilter)Method that indicates whether a pdf dictionary is a document Time-stamp dictionary (true) or not (false).- Parameters:
pdfType- Parameter that represents the value of /Type entry.subFilter- Parameter that represents the value of /SubFilter entry.- Returns:
- a boolean that indicates whether a pdf dictionary is a document Time-stamp dictionary (true) or not (false).
-
isSignatureDictionary
public static boolean isSignatureDictionary(java.lang.String pdfType, java.lang.String subFilter)Method that indicates whether a pdf dictionary is a signature dictionary (true) or not (false).- Parameters:
pdfType- Parameter that represents the value of /Type entry.subFilter- Parameter that represents the value of /SubFilter entry.- Returns:
- a boolean that indicates whether a pdf dictionary is a signature dictionary (true) or not (false).
-
validatePAdESBaselineMandatoryAttributes
public static void validatePAdESBaselineMandatoryAttributes(PDFSignatureDictionary signatureDictionary, org.bouncycastle.cms.CMSSignedData signedData, java.util.Date validationDate) throws SigningException
Method that checks, for the signature contained inside of a signature dictionary of a PDF document:- If the SignedData field is explicit.
- If the signature contains the
content-typeattribute and it has the value "id-data". - If the signature dictionary doesn't contain
/Certentry. - If the signature dictionary contain the signing time inside of
/Mentry and it's after than the validation date.
- Parameters:
signatureDictionary- Parameter that represents the signature dictionary.signedData- Parameter that represents the signed data.validationDate- Parameter that represents the date defined for validating the signature. If this values isnullthe validation date will be the current date.- Throws:
SigningException- If the validation fails.
-
validatePAdESBaselineOptionalAttributes
public static void validatePAdESBaselineOptionalAttributes(PDFSignatureDictionary signatureDictionary, org.bouncycastle.cms.CMSSignedData signedData) throws SigningException
Method that checks, for the signature contained inside of a signature dictionary of a PDF document:- If the signature doesn't contain the
signing-timeattribute. - If the signature doesn't contain the
counter-signatureattribute. - If the signature doesn't contain the
content-referenceattribute. - If the signature doesn't contain the
content-identifierattribute. - If the signature doesn't contain the
content-hintsattribute. - If the signature doesn't contain the
commitment-type-indicationattribute. - If the signature doesn't contain the
signer-locationattribute.
- Parameters:
signatureDictionary- Parameter that represents the signature dictionary.signedData- Parameter that represents the signed data.- Throws:
SigningException- If the validation fails.
- If the signature doesn't contain the
-
getXMLSignatureById
public static org.w3c.dom.Element getXMLSignatureById(org.w3c.dom.Document document, java.lang.String signatureId) throws SigningExceptionMethod that obtains aSignatureelement from a XML document.- Parameters:
document- Parameter that represents the XML document.signatureId- Parameter that represents the attributeIdof the element to obtain.- Returns:
- an objects that represents the
Signatureelement, ornull. - Throws:
SigningException- If the element isnull.
-
getTypeOfXMLSignature
public static java.lang.String getTypeOfXMLSignature(org.w3c.dom.Document xmlDocument) throws SigningExceptionMethod that obtains the signature mode of a signed XML document.- Parameters:
xmlDocument- Parameter that represents the signed XML document.- Returns:
- four possible values:
- Throws:
SigningException- If the method fails.
-
getOriginalDataFromSignedXMLDocument
public static byte[] getOriginalDataFromSignedXMLDocument(org.w3c.dom.Document xmlDocument) throws SigningExceptionMethod that obtains the original data from a signed XML document.- Parameters:
xmlDocument- Parameter that represents the signed XML document.- Returns:
- the original unsigned data.
- Throws:
SigningException- If the method fails.
-
composeCoSignaturesDocument
public static org.w3c.dom.Document composeCoSignaturesDocument(org.w3c.dom.Document xmlDocument, javax.xml.parsers.DocumentBuilderFactory dBFactory) throws SigningExceptionMethod that composes and obtains a XML document with the root node <ROOT_COSIGNATURES> for adding new cosigns over that (on enveloping signature mode). If the received signature is wrapped in this element, the element is returned without modifications. In another case, the wrapper is created and the sign is added, if isn't null.- Parameters:
xmlDocument- Parameter that represents the XML signature. It can benull.dBFactory- Parameter that represents a factory for building XML documents.- Returns:
- a XML document with the root node <ROOT_COSIGNATURES> and the signature as a children node.
- Throws:
SigningException- If the method fails.
-
appendXMLDocument
public static void appendXMLDocument(org.w3c.dom.Document xmlDocument, org.w3c.dom.Document documentToAppend) throws SigningExceptionMethod that appends a XML document to certain signed XML document.- Parameters:
xmlDocument- Parameter that represents the signed XML document.documentToAppend- Parameter that represents the XML document to append to the signed XML document.- Throws:
SigningException- If the method fails.
-
getSignedElementIdValue
public static java.lang.String getSignedElementIdValue(org.w3c.dom.Document xmlDocument) throws SigningExceptionMethod that obtains the value of the attributeIdof theContentnode of the wrapper, or an empty String if the signed XML document doesn't contain that attribute (wrapper signed on enveloped mode).- Parameters:
xmlDocument- Parameter that represents the signed XML document.- Returns:
- the value of the attribute
Idof theContentnode of the wrapper, or an empty String if the signed XML document doesn't contain that attribute (wrapper signed on enveloped mode). - Throws:
SigningException- If the method fails.
-
insertAfirmaRootNode
public static org.w3c.dom.Document insertAfirmaRootNode(org.w3c.dom.Document xmlDocument, javax.xml.parsers.DocumentBuilderFactory dBFactory) throws SigningExceptionMethod that defines theAFIRMAnode as root node of a signed XML document.- Parameters:
xmlDocument- Parameter that represents the signed XML document.dBFactory- Parameter that represents a factory for building XML documents.- Returns:
- the updated signed XML document.
- Throws:
SigningException- If the method fails.
-
getListSignaturesToCounterSign
public static java.util.List<org.w3c.dom.Element> getListSignaturesToCounterSign(org.w3c.dom.Element rootElement)
Method that obtains from a root element the list ofds:Signatureelements to addxades:CounterSignatureelement. The method only obtains the signature element withouth any signature element child.- Parameters:
rootElement- Parameter that represents the root element of the XML document.- Returns:
- a list with the
ds:Signatureelements to addxades:CounterSignatureelement.
-
retrieveNode
public static org.w3c.dom.Element retrieveNode(org.w3c.dom.Element parentNode, java.lang.String nodeName, java.lang.String namespaceURI, boolean isRequired) throws SigningExceptionMethod that obtains an element from a XML document.- Parameters:
parentNode- Parameter that represents the parent node of the element to retrieve.nodeName- Parameter that represents the name of the element to retrieve.namespaceURI- Parameter that represents the namespace URI of the element to match on. The special value "*" matches all namespaces.isRequired- Parameter that indicates if the element to retrieve is required (true) or not (false).- Returns:
- an object that represents the XML element.
- Throws:
SigningException- If the XML document doesn't contain the required element.
-
isDSSTimestamp
public static boolean isDSSTimestamp(org.w3c.dom.Node eSignature)
Method that indicates if the signature is an XMLTimeStamp element by the OASIS-DSS specifications (true) or not (false).- Parameters:
eSignature- Parameter that represents the XML signature.- Returns:
- a boolean that indicates if the signature is an XMLTimeStamp element by the OASIS-DSS specifications (true) or not (false).
-
obtainFirstRevision
public static byte[] obtainFirstRevision(byte[] pdfDocument) throws SigningExceptionMethod that obtains the first revision of the signature dictionary.- Parameters:
pdfDocument- Parameter that represents the PDF document.- Returns:
- an input stream that represents the revision, or
nullif the PDF document doesn't contain any signature dictionary. - Throws:
SigningException- exception if any error
-
checkExtraParamsSignWithRubric
public static boolean checkExtraParamsSignWithRubric(java.util.Properties externalParams)
Method that checks if the signature includes a rubric.- Parameters:
externalParams- Represents the optional input parameters.- Returns:
- boolean true if the signature includes rubric.
-
insertRubric
public static void insertRubric(com.lowagie.text.pdf.PdfReader reader, com.lowagie.text.pdf.PdfSignatureAppearance signatureAppearance, java.util.Properties externalParams) throws SigningExceptionMethod that inserts the rubric in a document.- Parameters:
reader- Parameter representing the PDF to be signed.signatureAppearance- Parameter that represents the appearances that form a signature.externalParams- Represents the optional input parameters.- Throws:
SigningException- If the method fails.
-
validateCAdESSignatureCore
public static void validateCAdESSignatureCore(org.bouncycastle.cms.SignerInformation signerInformation, java.security.cert.X509Certificate signingCertificate, boolean isPadesSignature) throws SigningExceptionMethod that validates the CAdES signature core associated to a signer.- Parameters:
signerInformation- Parameter that represents the information about the signer.signingCertificate- Parameter that represents the certificate of the signer.isPadesSignature- Parameter that indicates if the signature is contained inside of a signature dictionary (true) or not (false).- Throws:
SigningException- If the validation fails.
-
validateCAdESPublicKeyInfo
public static void validateCAdESPublicKeyInfo(org.bouncycastle.cms.CMSSignedData signedData, org.bouncycastle.cms.SignerInformation signerInformation, java.security.cert.X509Certificate signingCertificate) throws SigningExceptionMethod that checks if the signer includes aSigningCertificatesigned attribute, or aSigningCertificateV2signed attribute, and this matches to the signing certificate.- Parameters:
signedData- Parameter that represents the signed data.signerInformation- Parameter that represents the information about the signer.signingCertificate- Parameter that represents the signing certificate.- Throws:
SigningException- If the validation fails.
-
validateCAdESSigningTime
public static void validateCAdESSigningTime(org.bouncycastle.cms.CMSSignedData signedData, org.bouncycastle.cms.SignerInformation signerInformation, boolean isRequired, java.util.Date validationDate, java.security.cert.X509Certificate signingCertificate) throws SigningExceptionMethod that validates if the signing time of a signature is previous than certain date.- Parameters:
signedData- Parameter that represents the signed data.signerInformation- Parameter that represents the information about the signer.isRequired- Parameter that indicates if theSigningTimeattribute shall be included as a signed attribute for the signer (true) or not (false).validationDate- Parameter that represents the validation date.signingCertificate- Parameter that represents the signing certificate.- Throws:
SigningException- If the validation fails.
-
validateXAdESSignatureCore
public static void validateXAdESSignatureCore(org.w3c.dom.Element qualifyingPropertiesElement, java.lang.String signatureId, org.w3c.dom.Element signatureElement, org.apache.xml.security.signature.XMLSignature xmlSignature, byte[] signedFile, java.lang.String signedFileName, java.security.cert.X509Certificate signingCertificate, org.w3c.dom.Element signedSignaturePropertiesElement, org.w3c.dom.Element signedPropertiesElement, boolean isBaseline, boolean isCounterSignature) throws SigningExceptionMethod that validates the XAdES signature core associated to a signer.- Parameters:
qualifyingPropertiesElement- Parameter that representsxades:QualifyingPropertieselement.signatureId- Parameter that represents the value ofIdattribute ofds:Signatureelement.signatureElement- Parameter that representsds:Signatureelement.xmlSignature- Parameter that represents the XML signature.signedFile- Parameter that represents the file signed by the XML signature when the signed data isn't included into the signed XML document.signedFileName- Parameter that represents the name of the file signed by the XML signature when the signed data isn't included into the signed XML document.signingCertificate- Parameter that represents the signing certificate.signedSignaturePropertiesElement- Parameter that representsxades:SignedSignaturePropertieselement.signedPropertiesElement- Parameter that representsxades:SignedPropertieselement.isBaseline- Parameter that indicates if the signature to validate has Baseline form (true) or not (false).isCounterSignature- Parameter that indicates if the signature to validate is a countersignature (true) or not (false).- Throws:
SigningException- If the validation fails.
-
retrieveSigningCertificateOfXMLSigner
public static java.security.cert.X509Certificate retrieveSigningCertificateOfXMLSigner(org.w3c.dom.Element signedSignaturePropertiesElement, java.lang.String signatureId, org.w3c.dom.Element signatureElement) throws SigningExceptionMethod that retrieves the signing certificate of a signer contained inside of a XML signature.- Parameters:
signedSignaturePropertiesElement- Parameter that representsxades:SignedSignaturePropertieselement.signatureId- Parameter that represents the value ofIdattribute ofds:Signatureelement.signatureElement- Parameter that representsds:Signatureelement.- Returns:
- an object that represents the signing certificate.
- Throws:
SigningException- If the method fails of the certificate cannot be retrieved.
-
validateXAdESPublicKeyInfo
public static void validateXAdESPublicKeyInfo(java.lang.String signatureId, org.w3c.dom.Element signatureElement, org.apache.xml.security.signature.XMLSignature xmlSignature, boolean isBaseline, boolean isCounterSignature) throws SigningExceptionMethod that validates if the public key information contained inside of a XML signature is valid.- Parameters:
signatureId- Parameter that represents the value ofIdattribute ofds:Signatureelement.signatureElement- Parameter that representsds:Signatureelement.xmlSignature- Parameter that represents the XML signature.isBaseline- Parameter that indicates if the XML signature has Baseline form (true) or not (false).isCounterSignature- Parameter that indicates if the element to validate is a signer (false) or a counter-signer (true).- Throws:
SigningException- If the validation fails.
-
validateXAdESSigningTime
public static void validateXAdESSigningTime(org.w3c.dom.Element signedSignaturePropertiesElement, boolean isRequired, java.lang.String signatureId, java.util.Date validationDate) throws SigningExceptionMethod that validates if the signing time of a XML signature is previous than certain validation date.- Parameters:
signedSignaturePropertiesElement- Parameter that representsxades:SignedSignaturePropertieselement.isRequired- Parameter that indicates if the XML signature must containxades:SigningTimeelement (true) or not (false).signatureId- Parameter that represents the value ofIdattribute ofds:Signatureelement.validationDate- Parameter that represents the validation date.- Throws:
SigningException- if the validation fails.
-
validatePAdESBasicStructurally
public static void validatePAdESBasicStructurally(PDFSignatureDictionary signatureDictionary, byte[] pdfDocument, org.bouncycastle.cms.CMSSignedData signedData) throws SigningException
Method that validates the structure of a signature dictionary by PAdES-Basic signature form. The validations to execute will be:- Check if the CMS signature contains only one signer.
- /Contents key of the signature dictionary is required and the content matches to the CMS signature.
- /ByteRange key of the signature dictionary is required and the content matches to the digest of the CMS signature.
- /SubFilter key of the signature dictionary has "adbe.pkcs7.detached" or "adbe.pkcs7.sha1" value.
- Parameters:
signatureDictionary- Parameter that represents the signature dictionary.pdfDocument- Parameter that represents the PDF document.signedData- Parameter that represents the signature message.- Throws:
SigningException- If the validation fails.
-
validateCMSPublicKeyInfo
public static void validateCMSPublicKeyInfo(org.bouncycastle.cms.SignerInformation signerInformation, java.security.cert.X509Certificate signingCertificate) throws SigningExceptionMethod that checks if the value of the signed attributeSerialNumberof a signature matches to the serial number of the signing certificate.- Parameters:
signerInformation- Parameter that represents the information about the signer.signingCertificate- Parameter that represents the signing certificate.- Throws:
SigningException- If the validation fails.
-
validatePAdESBasicSigningTime
public static void validatePAdESBasicSigningTime(org.bouncycastle.cms.SignerInformation signerInformation, java.util.Date validationDate, java.security.cert.X509Certificate signingCertificate, PDFSignatureDictionary signatureDictionary) throws SigningExceptionMethod that validates the signing time of a PAdES-Basic signature.- Parameters:
signerInformation- Parameter that represents the information about the first signer of the signature.validationDate- Parameter that represents the validation date.signingCertificate- Parameter that represents the signing certificate.signatureDictionary- Parameter that represents the information about the signature dictionary.- Throws:
SigningException- If the validation fails.
-
validatePAdESEnhancedStructurally
public static void validatePAdESEnhancedStructurally(PDFSignatureDictionary signatureDictionary, byte[] pdfDocument, org.bouncycastle.cms.CMSSignedData signedData, boolean isEPES) throws SigningException
Method that checks if a signature dictionary is valid against PAdES Enhanced profile.- Parameters:
signatureDictionary- Parameter that represents the information about the signature dictionary.pdfDocument- Parameter that represents the signed PDF document.signedData- Parameter that represents the signature message of the signature contained inside of the signature dictionary.isEPES- Parameter that indicates if the signature dictionary represents a PAdES-EPES signature (true) or a PAdES-BES signature (false).- Throws:
SigningException- If the validation fails.
-
validatePAdESSigningTime
public static void validatePAdESSigningTime(PDFSignatureDictionary signatureDictionary, java.util.Date validationDate, boolean isRequired) throws SigningException
Method that validates if the signature dictionary has /M entry that entry must be a date with a valid format by PDF Referente and that date must be before of the validation date.- Parameters:
signatureDictionary- Parameter that represents the information about the signature dictionary.validationDate- Parameter that represents the validation date.isRequired- Parameter that indicates if the /M is required for the signature dictionary (true) or not (false).- Throws:
SigningException- If the validation fails.
-
validateDocumentTimeStampDictionaryStructurally
public static void validateDocumentTimeStampDictionaryStructurally(PDFDocumentTimestampDictionary pdfDocumentTimestampDictionary, byte[] pdfDocument) throws SigningException
Method that validates for a Document Time-stamp dictionary:- The ByteRange entry of the Document Time-stamp dictionary isn't null.
- The ByteRange entry represents the exact byte range for the digest calculation.
- The entry with the key Cert in the Document Time-stamp dictionary isn't used.
- The entry with the key Reference in the Document Time-stamp dictionary isn't used.
- The entry with the key Changes in the Document Time-stamp dictionary isn't used.
- The entry with the key R in the Document Time-stamp dictionary isn't used.
- The entry with the key Prop_AuthTime in the Document Time-stamp dictionary isn't used.
- The entry with the key Prop_AuthType in the Document Time-stamp dictionary isn't used.
- The entry with the key V in the Document Time-stamp dictionary, if present, has the value: 0.
- Parameters:
pdfDocumentTimestampDictionary- Parameter that represents the information about the Document Time-stamp dictionary.pdfDocument- Parameter that represents the PDF document.- Throws:
SigningException- If the validation fails.
-
validateDocumentTimeStampSigningTime
public static void validateDocumentTimeStampSigningTime(PDFDocumentTimestampDictionary pdfDocumentTimeStampDictionary, java.util.Date validationDate) throws SigningException
Method that checks if the generation date of a time-stamp contained inside of a Document Time-stamp dictionary is previous than a validation date.- Parameters:
pdfDocumentTimeStampDictionary- Parameter that represents the information about the Document Time-stamp dictionary.validationDate- Parameter that represents the validation date.- Throws:
SigningException- If the generation date of a time-stamp contained inside of a Document Time-stamp dictionary is after than the validation date.
-
validatePAdESBaselineStructurally
public static boolean validatePAdESBaselineStructurally(PDFSignatureDictionary signatureDictionary, byte[] pdfDocument, org.bouncycastle.cms.CMSSignedData signedData) throws SigningException
Method that checks if a signature dictionary is valid against PAdES Baseline profile.- Parameters:
signatureDictionary- Parameter that represents the information about the signature dictionary.pdfDocument- Parameter that represents the signed PDF document.signedData- Parameter that represents the signature message of the signature contained inside of the signature dictionary.- Returns:
- a boolean that indicates if the first signer of the signature contained inside of the signature dictionary includes
signature-policy-idattribute (true) or not (false). - Throws:
SigningException- If the validation fails.
-
calculateExpirationDateForValidations
public static java.util.Date calculateExpirationDateForValidations(SignerValidationResult signerValidationResult, java.util.Date currentDate)
Auxiliary method that calculate the expiration date of a validation or update response. The expiration date will be the closer expiration date between every signer and/or timestamp of the signature.- Parameters:
signerValidationResult- Result of the signature validation/update.currentDate- The current closest expiration date.- Returns:
- the expiration date of the signature.
-
obtainCertificateArchiveTimestamps
public static java.security.cert.X509Certificate obtainCertificateArchiveTimestamps(org.bouncycastle.asn1.cms.AttributeTable unsignedAttributes)
Method that gets the last archive timestamp certificate from the the list of archive timestamps of a signature.- Parameters:
unsignedAttributes- Unsigned attributes of the signature.- Returns:
- the signing certificate if the last archive timestamp.
-
getExpirationDate
public static java.util.Date getExpirationDate(byte[] signature)
Method that calculates the expiration date of a signature.- Parameters:
signature- Signature to analyze.- Returns:
- the expiration date, that is, the date in which the signature will be invalid, or null if its not possible to determinate the date.
-
obtainCertificateArchiveTimestampsXAdES
public static java.security.cert.X509Certificate obtainCertificateArchiveTimestampsXAdES(XAdESSignerInfo signerInfo)
Method that obtains the signing certificate of the last archiveTimestamp of a XAdES signature.- Parameters:
signerInfo- Unsigned properties element of the signer.- Returns:
- the X509Certificate of the last archiveTimestamp or null of there is not one archiveTimestamp.
-
calculateExpirationDate
public static java.util.Date calculateExpirationDate(java.util.List<PDFSignatureDictionary> signatureDictionaries, java.util.List<PDFDocumentTimestampDictionary> timestampDictionaries)
Method that calculates the expiration date of a PAdES signature, that is, the moment in which the signature will become invalid.- Parameters:
signatureDictionaries- Signature dictionaries from the PAdES signature.timestampDictionaries- Timestamp dictionaries from the PAdES signature.- Returns:
- the expiration date of the signature.
-
fromNodeListToReferenceDataBaselineList
public static java.util.List<ReferenceDataBaseline> fromNodeListToReferenceDataBaselineList(org.w3c.dom.Node manifestNode, org.w3c.dom.Node signedDataObjectPropertiesNode) throws SigningException
Method that parse a manifest and signedDataObjectProperties element into a list of ReferenceDataBaseline objects.- Parameters:
manifestNode- Node Element that represents the manifest node.signedDataObjectPropertiesNode- Element taht represents the signed data object properties node.- Returns:
- a list with the elements data parse into a list of reference data baseline objects.
- Throws:
SigningException- if the signature is invalid, that is, the elements has a invalid structure or the data are not correct.
-
getSignatureAlgorithm
public static org.bouncycastle.asn1.x509.AlgorithmIdentifier getSignatureAlgorithm(org.bouncycastle.cms.SignerInformation signerInformation) throws SignaturePolicyExceptionObtiene el OID del algoritmo de firma empleado. Este algoritmo puede haberse declarado directamente en la firma o puede que deba construirse a partir del algoritmo de encriptación y el algoritmo de hash.- Parameters:
signerInformation- Información de la firma.- Returns:
- OID del algoritmo de firma.
- Throws:
SignaturePolicyException- Cuando no se puede identificar el algoritmo de firma a través del de encriptación y huella.
-
getSignatureAlgorithm
public static org.bouncycastle.asn1.x509.AlgorithmIdentifier getSignatureAlgorithm(java.lang.String encryptionAlgOid, java.lang.String hashAlgOid) throws SignaturePolicyExceptionObtiene el identificador de algoritmo de firma que se corresponde al usar el algoritmo de encriptación con el algoritmo de hash indicados. En caso de no haberse indicado un algoritmo de encriptación reconocido, se interpretará que este es en realidad el algoritmo de firma.- Parameters:
encryptionAlgOid- OID del algoritmo de encriptación.hashAlgOid- OID del algoritmo de huella.- Returns:
- Identificador del algorimo de firma.
- Throws:
SignaturePolicyException- Cuando no se conozca el OID del algoritmo correspondiente a utilizar el algoritmo de encriptación y el algoritmo de hash indicados.
-
-