Class PdfPadesSigner
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ICrlClientprivate static final Stringprivate intprivate IExternalDigestprivate static final IBouncyCastleFactoryprivate static longprivate IIssuingCertificateRetrieverprivate static final Objectprivate IOcspClientprivate final OutputStreamprivate final PdfReaderprivate StampingPropertiesprivate StampingPropertiesprivate static final Stringprivate Fileprivate Stringprivate ByteArrayOutputStreamprivate String -
Constructor Summary
ConstructorsConstructorDescriptionPdfPadesSigner(PdfReader reader, OutputStream outputStream) Create an instance of PdfPadesSigner class. -
Method Summary
Modifier and TypeMethodDescription(package private) InputStream(package private) OutputStream(package private) PdfSignercreatePdfSigner(SignerProperties signerProperties, boolean isFinal) (package private) voidcreateRevocationClients(Certificate signingCert, boolean clientsRequired) (package private) voidprivate StringgetDigestAlgorithm(PrivateKey privateKey) private File(package private) voidperformLtvVerification(PdfDocument pdfDocument, List<String> signatureNames, LtvVerification.RevocationDataNecessity revocationDataNecessity) private voidperformSignDetached(SignerProperties signerProperties, boolean isFinal, IExternalSignature externalSignature, Certificate[] chain, ITSAClient tsaClient) (package private) voidperformTimestamping(PdfDocument document, OutputStream outputStream, ITSAClient tsaClient) voidAdd revocation information for all the signatures which could be found in the provided document.voidprolongSignatures(ITSAClient tsaClient) Add revocation information for all the signatures which could be found in the provided document.setCrlClient(ICrlClient crlClient) SetICrlClientto be used for LTV Verification.setEstimatedSize(int estimatedSize) Set estimated size of a signature to be applied.setExternalDigest(IExternalDigest externalDigest) SetIExternalDigestto be used for main signing operation.setIssuingCertificateRetriever(IIssuingCertificateRetriever issuingCertificateRetriever) SetIIssuingCertificateRetrieverto be used before main signing operation.setOcspClient(IOcspClient ocspClient) SetIOcspClientto be used for LTV Verification.setStampingProperties(StampingProperties stampingProperties) Set stamping properties to be used during main signing operation.setTemporaryDirectoryPath(String temporaryDirectoryPath) Set temporary directory to be used for temporary files creation.setTimestampSignatureName(String timestampSignatureName) Set the name to be used for timestamp signature creation.setTrustedCertificates(List<Certificate> certificateList) Set certificate list to be used by theIIssuingCertificateRetrieverto retrieve missing certificates.voidsignWithBaselineBProfile(SignerProperties signerProperties, Certificate[] chain, IExternalSignature externalSignature) Sign the document provided inPdfSignerinstance with PaDES Baseline-B Profile.voidsignWithBaselineBProfile(SignerProperties signerProperties, Certificate[] chain, PrivateKey privateKey) Sign the document provided inPdfSignerinstance with PaDES Baseline-B Profile.voidsignWithBaselineLTAProfile(SignerProperties signerProperties, Certificate[] chain, IExternalSignature externalSignature, ITSAClient tsaClient) Sign the document provided inPdfSignerinstance with PaDES Baseline-LTA Profile.voidsignWithBaselineLTAProfile(SignerProperties signerProperties, Certificate[] chain, PrivateKey privateKey, ITSAClient tsaClient) Sign the document provided inPdfSignerinstance with PaDES Baseline-LTA Profile.voidsignWithBaselineLTProfile(SignerProperties signerProperties, Certificate[] chain, IExternalSignature externalSignature, ITSAClient tsaClient) Sign the document provided inPdfSignerinstance with PaDES Baseline-LT Profile.voidsignWithBaselineLTProfile(SignerProperties signerProperties, Certificate[] chain, PrivateKey privateKey, ITSAClient tsaClient) Sign the document provided inPdfSignerinstance with PaDES Baseline-LT Profile.voidsignWithBaselineTProfile(SignerProperties signerProperties, Certificate[] chain, IExternalSignature externalSignature, ITSAClient tsaClient) Sign the document provided inPdfSignerinstance with PaDES Baseline-T Profile.voidsignWithBaselineTProfile(SignerProperties signerProperties, Certificate[] chain, PrivateKey privateKey, ITSAClient tsaClient) Sign the document provided inPdfSignerinstance with PaDES Baseline-T Profile.
-
Field Details
-
TEMP_FILE_NAME
- See Also:
-
FACTORY
-
DEFAULT_DIGEST_ALGORITHM
- See Also:
-
LOCK_OBJECT
-
increment
private static long increment -
ocspClient
-
crlClient
-
issuingCertificateRetriever
-
estimatedSize
private int estimatedSize -
timestampSignatureName
-
temporaryDirectoryPath
-
externalDigest
-
stampingProperties
-
stampingPropertiesWithMetaInfo
-
tempOutputStream
-
tempFile
-
tempFiles
-
reader
-
outputStream
-
-
Constructor Details
-
PdfPadesSigner
Create an instance of PdfPadesSigner class. One instance shall be used for one signing operation.- Parameters:
reader-PdfReaderinstance to read original PDF fileoutputStream-OutputStreamoutput stream to write the resulting PDF file into
-
-
Method Details
-
signWithBaselineBProfile
public void signWithBaselineBProfile(SignerProperties signerProperties, Certificate[] chain, IExternalSignature externalSignature) throws GeneralSecurityException, IOException Sign the document provided inPdfSignerinstance with PaDES Baseline-B Profile.- Parameters:
signerProperties-SignerPropertiesproperties to be used for main signing operationchain- the chain of certificates to be used for signing operationexternalSignature-IExternalSignatureinstance to be used for main signing operation- Throws:
GeneralSecurityException- in case of signing related exceptionsIOException- in case of files related exceptions
-
signWithBaselineBProfile
public void signWithBaselineBProfile(SignerProperties signerProperties, Certificate[] chain, PrivateKey privateKey) throws GeneralSecurityException, IOException Sign the document provided inPdfSignerinstance with PaDES Baseline-B Profile.- Parameters:
signerProperties-SignerPropertiesproperties to be used for main signing operationchain- the chain of certificates to be used for signing operationprivateKey-PrivateKeyinstance to be used for main signing operation- Throws:
GeneralSecurityException- in case of signing related exceptionsIOException- in case of files related exceptions
-
signWithBaselineTProfile
public void signWithBaselineTProfile(SignerProperties signerProperties, Certificate[] chain, IExternalSignature externalSignature, ITSAClient tsaClient) throws GeneralSecurityException, IOException Sign the document provided inPdfSignerinstance with PaDES Baseline-T Profile.- Parameters:
signerProperties-SignerPropertiesproperties to be used for main signing operationchain- the chain of certificates to be used for signing operationexternalSignature-IExternalSignatureinstance to be used for main signing operationtsaClient-ITSAClientinstance to be used for timestamp creation- Throws:
GeneralSecurityException- in case of signing related exceptionsIOException- in case of files related exceptions
-
signWithBaselineTProfile
public void signWithBaselineTProfile(SignerProperties signerProperties, Certificate[] chain, PrivateKey privateKey, ITSAClient tsaClient) throws GeneralSecurityException, IOException Sign the document provided inPdfSignerinstance with PaDES Baseline-T Profile.- Parameters:
signerProperties-SignerPropertiesproperties to be used for main signing operationchain- the chain of certificates to be used for signing operationprivateKey-PrivateKeyinstance to be used for main signing operationtsaClient-ITSAClientinstance to be used for timestamp creation- Throws:
GeneralSecurityException- in case of signing related exceptionsIOException- in case of files related exceptions
-
signWithBaselineLTProfile
public void signWithBaselineLTProfile(SignerProperties signerProperties, Certificate[] chain, IExternalSignature externalSignature, ITSAClient tsaClient) throws GeneralSecurityException, IOException Sign the document provided inPdfSignerinstance with PaDES Baseline-LT Profile.- Parameters:
signerProperties-SignerPropertiesproperties to be used for main signing operationchain- the chain of certificates to be used for signing operationexternalSignature-IExternalSignatureinstance to be used for main signing operationtsaClient-ITSAClientinstance to be used for timestamp creation- Throws:
GeneralSecurityException- in case of signing related exceptionsIOException- in case of files related exceptions
-
signWithBaselineLTProfile
public void signWithBaselineLTProfile(SignerProperties signerProperties, Certificate[] chain, PrivateKey privateKey, ITSAClient tsaClient) throws GeneralSecurityException, IOException Sign the document provided inPdfSignerinstance with PaDES Baseline-LT Profile.- Parameters:
signerProperties-SignerPropertiesproperties to be used for main signing operationchain- the chain of certificates to be used for signing operationprivateKey-PrivateKeyinstance to be used for main signing operationtsaClient-ITSAClientinstance to be used for timestamp creation- Throws:
GeneralSecurityException- in case of signing related exceptionsIOException- in case of files related exceptions
-
signWithBaselineLTAProfile
public void signWithBaselineLTAProfile(SignerProperties signerProperties, Certificate[] chain, IExternalSignature externalSignature, ITSAClient tsaClient) throws IOException, GeneralSecurityException Sign the document provided inPdfSignerinstance with PaDES Baseline-LTA Profile.- Parameters:
signerProperties-SignerPropertiesproperties to be used for main signing operationchain- the chain of certificates to be used for signing operationexternalSignature-IExternalSignatureinstance to be used for main signing operationtsaClient-ITSAClientinstance to be used for timestamp creation- Throws:
GeneralSecurityException- in case of signing related exceptionsIOException- in case of files related exceptions
-
signWithBaselineLTAProfile
public void signWithBaselineLTAProfile(SignerProperties signerProperties, Certificate[] chain, PrivateKey privateKey, ITSAClient tsaClient) throws GeneralSecurityException, IOException Sign the document provided inPdfSignerinstance with PaDES Baseline-LTA Profile.- Parameters:
signerProperties-SignerPropertiesproperties to be used for main signing operationchain- the chain of certificates to be used for signing operationprivateKey-PrivateKeyinstance to be used for main signing operationtsaClient-ITSAClientinstance to be used for timestamp creation- Throws:
GeneralSecurityException- in case of signing related exceptionsIOException- in case of files related exceptions
-
prolongSignatures
Add revocation information for all the signatures which could be found in the provided document. Also add timestamp signature on top of that.- Parameters:
tsaClient-ITSAClientTSA Client to be used for timestamp signature creation- Throws:
IOException- in case of files related exceptionsGeneralSecurityException- in case of signing related exceptions
-
prolongSignatures
Add revocation information for all the signatures which could be found in the provided document.- Throws:
IOException- in case of files related exceptionsGeneralSecurityException- in case of signing related exceptions
-
setTemporaryDirectoryPath
Set temporary directory to be used for temporary files creation.If none is set, temporary documents will be created in memory.
- Parameters:
temporaryDirectoryPath-Stringrepresenting relative or absolute path to the directory- Returns:
- same instance of
PdfPadesSigner
-
setTimestampSignatureName
Set the name to be used for timestamp signature creation.This setter is only relevant if
signWithBaselineLTAProfile(SignerProperties, Certificate[], IExternalSignature, ITSAClient)orprolongSignatures(ITSAClient)methods are used.If none is set, randomly generated signature name will be used.
- Parameters:
timestampSignatureName-Stringrepresenting the name of a timestamp signature to be applied- Returns:
- same instance of
PdfPadesSigner
-
setStampingProperties
Set stamping properties to be used during main signing operation.If none is set, stamping properties with append mode enabled will be used
- Parameters:
stampingProperties-StampingPropertiesinstance to be used during main signing operation- Returns:
- same instance of
PdfPadesSigner
-
setEstimatedSize
Set estimated size of a signature to be applied.This parameter represents estimated amount of bytes to be preserved for the signature.
If none is set, 0 will be used and the required space will be calculated during the signing.
- Parameters:
estimatedSize- amount of bytes to be used as estimated value- Returns:
- same instance of
PdfPadesSigner
-
setOcspClient
SetIOcspClientto be used for LTV Verification.This setter is only relevant if Baseline-LT Profile level or higher is used.
If none is set, there will be an attempt to create default OCSP Client instance using the certificate chain.
- Parameters:
ocspClient-IOcspClientinstance to be used for LTV Verification- Returns:
- same instance of
PdfPadesSigner
-
setCrlClient
SetICrlClientto be used for LTV Verification.This setter is only relevant if Baseline-LT Profile level or higher is used.
If none is set, there will be an attempt to create default CRL Client instance using the certificate chain.
- Parameters:
crlClient-ICrlClientinstance to be used for LTV Verification- Returns:
- same instance of
PdfPadesSigner
-
setExternalDigest
SetIExternalDigestto be used for main signing operation.If none is set,
BouncyCastleDigestinstance will be used instead.- Parameters:
externalDigest-IExternalDigestto be used for main signing operation.- Returns:
- same instance of
PdfPadesSigner
-
setIssuingCertificateRetriever
public PdfPadesSigner setIssuingCertificateRetriever(IIssuingCertificateRetriever issuingCertificateRetriever) SetIIssuingCertificateRetrieverto be used before main signing operation.If none is set,
IssuingCertificateRetrieverinstance will be used instead.- Parameters:
issuingCertificateRetriever-IIssuingCertificateRetrieverinstance to be used for getting missing certificates in chain or CRL response issuer certificates.- Returns:
- same instance of
PdfPadesSigner.
-
setTrustedCertificates
Set certificate list to be used by theIIssuingCertificateRetrieverto retrieve missing certificates.- Parameters:
certificateList- certificate list for getting missing certificates in chain or CRL response issuer certificates.- Returns:
- same instance of
PdfPadesSigner.
-
performTimestamping
void performTimestamping(PdfDocument document, OutputStream outputStream, ITSAClient tsaClient) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
createPdfSigner
- Throws:
IOException
-
performLtvVerification
void performLtvVerification(PdfDocument pdfDocument, List<String> signatureNames, LtvVerification.RevocationDataNecessity revocationDataNecessity) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
deleteTempFiles
void deleteTempFiles() -
createOutputStream
- Throws:
IOException
-
createInputStream
- Throws:
IOException
-
createRevocationClients
-
performSignDetached
private void performSignDetached(SignerProperties signerProperties, boolean isFinal, IExternalSignature externalSignature, Certificate[] chain, ITSAClient tsaClient) throws GeneralSecurityException, IOException - Throws:
GeneralSecurityExceptionIOException
-
getNextTempFile
-
getDigestAlgorithm
-