Class PadesTwoPhaseSigningHelper

    • Field Detail

      • temporaryDirectoryPath

        private java.lang.String temporaryDirectoryPath
      • timestampSignatureName

        private java.lang.String timestampSignatureName
      • stampingPropertiesWithMetaInfo

        private StampingProperties stampingPropertiesWithMetaInfo
      • estimatedSize

        private int estimatedSize
    • Method Detail

      • setOcspClient

        public PadesTwoPhaseSigningHelper setOcspClient​(IOcspClient ocspClient)
        Set IOcspClient to 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 - IOcspClient instance to be used for LTV Verification
        Returns:
        same instance of PadesTwoPhaseSigningHelper
      • setTrustedCertificates

        public PadesTwoPhaseSigningHelper setTrustedCertificates​(java.util.List<java.security.cert.Certificate> certificateList)
        Set certificate list to be used by the IIssuingCertificateRetriever to retrieve missing certificates.
        Parameters:
        certificateList - certificate list for getting missing certificates in chain or CRL response issuer certificates.
        Returns:
        same instance of PadesTwoPhaseSigningHelper.
      • setCrlClient

        public PadesTwoPhaseSigningHelper setCrlClient​(ICrlClient crlClient)
        Set ICrlClient to 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 - ICrlClient instance to be used for LTV Verification
        Returns:
        same instance of PadesTwoPhaseSigningHelper
      • setEstimatedSize

        public PadesTwoPhaseSigningHelper setEstimatedSize​(int estimatedSize)
        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 PadesTwoPhaseSigningHelper
      • setTemporaryDirectoryPath

        public PadesTwoPhaseSigningHelper setTemporaryDirectoryPath​(java.lang.String temporaryDirectoryPath)
        Set temporary directory to be used for temporary files creation.

        If none is set, temporary documents will be created in memory.

        Parameters:
        temporaryDirectoryPath - String representing relative or absolute path to the directory
        Returns:
        same instance of PadesTwoPhaseSigningHelper
      • createCMSContainerWithoutSignature

        public CMSContainer createCMSContainerWithoutSignature​(java.security.cert.Certificate[] certificates,
                                                               java.lang.String digestAlgorithm,
                                                               PdfReader inputDocument,
                                                               java.io.OutputStream outputStream,
                                                               SignerProperties signerProperties)
                                                        throws java.io.IOException,
                                                               java.security.GeneralSecurityException
        Creates CMS container compliant with PAdES level. Prepares document and placeholder for the future signature without actual signing process.
        Parameters:
        certificates - certificates to be added to the CMS container
        digestAlgorithm - the algorithm to generate the digest with
        inputDocument - reader PdfReader instance to read original PDF file
        outputStream - OutputStream output stream to write the resulting PDF file into
        signerProperties - properties to be used in the signing operations
        Returns:
        prepared CMS container without signature.
        Throws:
        java.io.IOException - if an I/O error occurs.
        java.security.GeneralSecurityException - if some problem with signature or security occur.
      • signCMSContainerWithBaselineBProfile

        public void signCMSContainerWithBaselineBProfile​(IExternalSignature externalSignature,
                                                         PdfReader inputDocument,
                                                         java.io.OutputStream outputStream,
                                                         java.lang.String signatureFieldName,
                                                         CMSContainer cmsContainer)
                                                  throws java.lang.Exception
        Follow-up step that signs prepared document with PAdES Baseline-B profile.
        Parameters:
        externalSignature - external signature to do the actual signing
        inputDocument - reader PdfReader instance to read prepared document
        outputStream - the output PDF
        signatureFieldName - the field to sign
        cmsContainer - the finalized CMS container (e.g. created in the first step)
        Throws:
        java.lang.Exception - if some exception occur.
      • signCMSContainerWithBaselineTProfile

        public void signCMSContainerWithBaselineTProfile​(IExternalSignature externalSignature,
                                                         PdfReader inputDocument,
                                                         java.io.OutputStream outputStream,
                                                         java.lang.String signatureFieldName,
                                                         CMSContainer cmsContainer)
                                                  throws java.lang.Exception
        Follow-up step that signs prepared document with PAdES Baseline-T profile.
        Parameters:
        externalSignature - external signature to do the actual signing
        inputDocument - reader PdfReader instance to read prepared document
        outputStream - the output PDF
        signatureFieldName - the field to sign
        cmsContainer - the finalized CMS container (e.g. created in the first step)
        Throws:
        java.lang.Exception - if some exception occur.
      • signCMSContainerWithBaselineLTProfile

        public void signCMSContainerWithBaselineLTProfile​(IExternalSignature externalSignature,
                                                          PdfReader inputDocument,
                                                          java.io.OutputStream outputStream,
                                                          java.lang.String signatureFieldName,
                                                          CMSContainer cmsContainer)
                                                   throws java.lang.Exception
        Follow-up step that signs prepared document with PAdES Baseline-LT profile.
        Parameters:
        externalSignature - external signature to do the actual signing
        inputDocument - reader PdfReader instance to read prepared document
        outputStream - the output PDF
        signatureFieldName - the field to sign
        cmsContainer - the finalized CMS container (e.g. created in the first step)
        Throws:
        java.lang.Exception - if some exception occur.
      • signCMSContainerWithBaselineLTAProfile

        public void signCMSContainerWithBaselineLTAProfile​(IExternalSignature externalSignature,
                                                           PdfReader inputDocument,
                                                           java.io.OutputStream outputStream,
                                                           java.lang.String signatureFieldName,
                                                           CMSContainer cmsContainer)
                                                    throws java.lang.Exception
        Follow-up step that signs prepared document with PAdES Baseline-LTA profile.
        Parameters:
        externalSignature - external signature to do the actual signing
        inputDocument - reader PdfReader instance to read prepared document
        outputStream - the output PDF
        signatureFieldName - the field to sign
        cmsContainer - the finalized CMS container (e.g. created in the first step)
        Throws:
        java.lang.Exception - if some exception occur.
      • setSignatureAlgorithmAndSignature

        private byte[] setSignatureAlgorithmAndSignature​(IExternalSignature externalSignature,
                                                         CMSContainer cmsContainer)
                                                  throws java.io.IOException,
                                                         java.security.GeneralSecurityException
        Throws:
        java.io.IOException
        java.security.GeneralSecurityException
      • createPadesSigner

        private PdfPadesSigner createPadesSigner​(PdfReader inputDocument,
                                                 java.io.OutputStream outputStream)