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)
java -jar pdfbox-sign.jar JohnSmith.pem <PASSWORD> minimal.pdf
- extract the PKCS7 to minimal_signed_pdfbox.pkcs7
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:
Adobe linearizes the file before starting (changing also the PDF version)
The signed PKCS7 attributes (signedAttrs) included in every case is different (and they are included in the calculation)
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:
The remaining differences are:
Adobe doesn't include the signingTime (1.2.840.1135126.96.36.199)
pdfbox specify the extra signed attribute 1.2.840.1135188.8.131.52 not recognized by (openssl asn1parse) in order to specify the sha256 encryption instead of specifying the signatureAlgorithm/algorithm as sha256WithRSAEncryption (1.2.840.1135184.108.40.206)
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?
$ openssl version OpenSSL 1.0.2g 1 Mar 2016