Class PDFBoxSignatureUtils

java.lang.Object
se.idsec.signservice.security.sign.pdf.utils.PDFBoxSignatureUtils

public class PDFBoxSignatureUtils extends Object
Static utilities for signed PDF documents.
Author:
Martin Lindström (martin@idsec.se), Stefan Santesson (stefan@idsec.se)
  • Constructor Details

    • PDFBoxSignatureUtils

      public PDFBoxSignatureUtils()
  • Method Details

    • getCmsSignedAttributes

      public static byte[] getCmsSignedAttributes(org.bouncycastle.cms.CMSSignedData signedData) throws org.bouncycastle.cms.CMSException
      This method extracts signed attribute data from a CMS signature
      Parameters:
      signedData - CMSSignedData object holding signature data
      Returns:
      The signed attributes of a PDF signature
      Throws:
      org.bouncycastle.cms.CMSException - If the provided input has no signed attribute data
    • getCmsSignedAttributes

      public static byte[] getCmsSignedAttributes(byte[] contentInfoBytes) throws org.bouncycastle.cms.CMSException
      This method extracts signed attribute data from a CMS signature.
      Parameters:
      contentInfoBytes - the CMS Content info bytes holding CMS SignedData content
      Returns:
      The signed attributes of a PDF signature
      Throws:
      org.bouncycastle.cms.CMSException - If the provided input has no signed attribute data
    • updatePdfPKCS7

      public static byte[] updatePdfPKCS7(byte[] cmsSignedData, byte[] newTbsBytes, byte[] newSigValue, List<X509Certificate> chain) throws org.bouncycastle.cms.CMSException
      A method that updates the PDF SignedData object (Actually a CMS ContentInfo) with a new signature, certificates and SignedAttributes obtained from an external signing service.
      Parameters:
      cmsSignedData - Input CMS SignedData
      newTbsBytes - The new signed attributes bytes signed by the new signature
      newSigValue - The new signature value
      chain - The new certificate chain
      Returns:
      The bytes of an updated PDF signature (Encoded Content info)
      Throws:
      org.bouncycastle.cms.CMSException - for errors
    • setSubjectNameAndLocality

      public static void setSubjectNameAndLocality(org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature signature, Certificate sigCert) throws IOException
      Sets the signer name and location from the signer certificate subject DN.
      Parameters:
      signature - the signature object to be updated
      sigCert - the certificate being source of data
      Throws:
      IOException - for errors getting the subject attributes from the certificate
    • getSubjectAttributes

      public static Map<SubjectDnAttribute,String> getSubjectAttributes(Certificate cert) throws IOException
      Gets a map of recognized subject DN attributes.
      Parameters:
      cert - X.509 certificate
      Returns:
      subject DN attribute map
      Throws:
      IOException - for errors getting the subject attributes from the certificate
    • getSubjectAttributes

      public static Map<SubjectDnAttribute,String> getSubjectAttributes(org.bouncycastle.asn1.ASN1Sequence subjectDn)
      Gets a map of recognized subject DN attributes.
      Parameters:
      subjectDn - subject DN
      Returns:
      subject DN attribute map
    • getRSAPkcs1DigestInfo

      public static byte[] getRSAPkcs1DigestInfo(org.bouncycastle.asn1.x509.AlgorithmIdentifier digestAlgo, byte[] hashValue) throws IOException
      Gets the RSA PKCS#10 digest info.
      Parameters:
      digestAlgo - digest algorithm
      hashValue - the hash value
      Returns:
      the digest info
      Throws:
      IOException - for errors
    • getPadesSignerInfoGenerator

      public static org.bouncycastle.cms.DefaultSignedAttributeTableGenerator getPadesSignerInfoGenerator(Certificate signerCert, org.bouncycastle.asn1.ASN1ObjectIdentifier digestAlgo, boolean includeIssuerSerial) throws CertificateException, NoSuchAlgorithmException
      Throws:
      CertificateException
      NoSuchAlgorithmException
    • getSignedCertAttr

      public static org.bouncycastle.asn1.ASN1EncodableVector getSignedCertAttr(org.bouncycastle.asn1.ASN1ObjectIdentifier digestAlgo, X509Certificate certificate, boolean includeIssuerSerial) throws NoSuchAlgorithmException, CertificateException
      Throws:
      NoSuchAlgorithmException
      CertificateException
    • removeSignedAttr

      public static byte[] removeSignedAttr(byte[] signedAttrBytes, org.bouncycastle.asn1.ASN1ObjectIdentifier[] attrOid) throws IOException
      Throws:
      IOException
    • getSignedCertRefAttribute

      public static PDFBoxSignatureUtils.SignedCertRef getSignedCertRefAttribute(byte[] signedAttrBytes) throws IOException
      Throws:
      IOException