I am evaluating the capability of openssl for generating PDF signatures. I see some differences between the PKCS7 signature fields generated by openssl and other programs.

How can I specify exactly which signedAttr fields would be included in the signature ?

For example, here is three-way comparison via meld:

$ meld <(openssl cms -inform DER -cmsout -print -in minimal_signed_pdfbox.pkcs7) \
       <(openssl cms -inform DER -cmsout -print -in minimal_signed_adobe.pkcs7)  \
       <(openssl cms -inform DER -cmsout -print -in minimal.pkcs7)

enter image description here

Left side: minimal_signed_pdfbox.pkcs7 generated by pdfbox (it uses Bouncy Castle) this way:

java -jar pdfbox-sign.jar JohnSmith.pem <PASSWORD> minimal.pdf
  • extract the PKCS7 to minimal_signed_pdfbox.pkcs7

Center: PKCS7 generated by Adobe Reader DC (it uses Adobe PubSec) this way:

  • Create a digital ID from the file JohnSmith.pfx

  • Sign the document with that digital ID

  • Save the result as in minimal_signed_adobe.pdf

  • extract the PKCS7 to minimal_signed_adobe.pkcs7

Right: PKCS7 generated by OpenSSL this via command line:

openssl cms -sign -signer JohnSmith.pem -binary -in minimal.pdf -outform der -out minimal.pkcs7

In the first two cases the pkcs7 was extracted from the pdf using the peepdf tool.

The minimal.pdf file being signed is the one described in the standard ISO-32000 in Annex H.2: Minimal PDF File.

The rest of the files used and the certificates are zipped here: so.zip.

The signature and messageDigest fields are different because:

  1. Adobe linearizes the file before starting (changing also the PDF version)

  2. The signed PKCS7 attributes (signedAttrs) included in every case is different (and they are included in the calculation)

  3. In the real scenario, the PDF need extra objects to include the signature, that are not present in this case, for simplification.

Signing a PDF is not only to generate the signature, it is also to embed it into the file. But now I am focused on the signature format (2)

Once the smime capabilities are excluded:

openssl cms -nosmimecap -sign -signer JohnSmith.pem -binary -in minimal.pdf -outform der -out minimal_nosmimecap.pkcs7

The differences are more clear:

enter image description here

The remaining differences are:

  1. Adobe doesn't include the signingTime (1.2.840.113549.1.9.5)

  2. pdfbox specify the extra signed attribute 1.2.840.113549.1.9.52 not recognized by (openssl asn1parse) in order to specify the sha256 encryption instead of specifying the signatureAlgorithm/algorithm as sha256WithRSAEncryption (1.2.840.113549.1.1.11)

How can I manage those signed attributes ? Via command line I have only this related parameter:

-noattr        don't include any signed attributes

the parameter -nosmimecap doesn't appear via:

openssl cms --help

but it works, are there other hidden parameters to control that?

I'm using:

$ openssl version
OpenSSL 1.0.2g  1 Mar 2016

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.