CLI: Trouble to verfiy signed pdfs with pfx certificate store #77
-
Hej @MatthiasValvekens, first: Thank so much for that creating this great project. I'm continue with Python because of pyHanko! After verify successful other pdfs by python and cli i started today to sign the first pdf myself. Here is what i'm doing with pyHanko-0.12.0: Download root and subs and create pkcs12 certificate store gundlac@batch-ost:~/mytest2$ curl -o RapidSSL_TLS_DV_RSA_Mixed_SHA256_2020_CA-1.crt.pem https://cacerts.digicert.com/RapidSSLTLSDVRSAMixedSHA2562020CA-1.crt.pem
gundlac@batch-ost:~/mytest2$ curl -o DigiCertGlobalRootCA.crt.pem https://cacerts.digicert.com/DigiCertGlobalRootCA.crt.pem
gundlac@batch-ost:~/mytest2$ cat star.domain.crt RapidSSL_TLS_DV_RSA_Mixed_SHA256_2020_CA-1.crt.pem DigiCertGlobalRootCA.crt.pem > new_cert.pem
gundlac@batch-ost:~/mytest2$ openssl pkcs12 -export -in new_cert.pem -inkey private_encrypted_key -out wc21.domain.p12
Enter Export Password:
Verifying - Enter Export Password: Check that all certificates in the chain of trust and supplied KeyUsages gundlac@batch-ost:~/mytest2$ keytool -J-Duser.language=en -list -v -storetype pkcs12 -keystore wc.domain.p12
Enter keystore password:
Keystore type: PKCS12
Keystore provider: SunJSSE
Your keystore contains 1 entry
Alias name: jetty
Creation date: Feb 14, 2022
Entry type: PrivateKeyEntry
Certificate chain length: 3
...
Certificate[1]:
Owner: CN=*.hanse-merkur.de
Issuer: CN=RapidSSL TLS DV RSA Mixed SHA256 2020 CA-1, O=DigiCert Inc, C=US
Serial number: 1cfdb574c3e0a43e8d6d764ccb7b81a
Valid from: Thu Jan 28 01:00:00 CET 2021 until: Tue Mar 01 00:59:59 CET 2022
...
#3: ObjectId: 2.5.29.15 Criticality=true
KeyUsage [
DigitalSignature
Key_CertSign
Crl_Sign
]
...
Certificate[2]:
Owner: CN=RapidSSL TLS DV RSA Mixed SHA256 2020 CA-1, O=DigiCert Inc, C=US
Issuer: CN=DigiCert Global Root CA, OU=www.digicert.com, O=DigiCert Inc, C=US
Serial number: 7983603ade39908219ca00c27bc8a6c
Valid from: Thu Jul 16 14:25:27 CEST 2020 until: Thu Jun 01 01:59:59 CEST 2023
...
#7: ObjectId: 2.5.29.15 Criticality=true
KeyUsage [
DigitalSignature
Key_CertSign
Crl_Sign
]
...
Certificate[3]:
Owner: CN=DigiCert Global Root CA, OU=www.digicert.com, O=DigiCert Inc, C=US
Issuer: CN=DigiCert Global Root CA, OU=www.digicert.com, O=DigiCert Inc, C=US
Serial number: 83be056904246b1a1756ac95991c74a
Valid from: Fri Nov 10 01:00:00 CET 2006 until: Mon Nov 10 01:00:00 CET 2031
...
#8: ObjectId: 2.5.29.15 Criticality=true
KeyUsage [
DigitalSignature
Key_Encipherment
]
... creating configuration for testing purposes to ignore missing non repudiation key extension because i cannot recreate the certifiate shortly gundlac@batch-ost:~/mytest2$ vi pyhanko.yml
validation-contexts:
setup-a:
trust: star.domain.crt
trust-replace: true
other-certs: anchor.pem
signer-key-usage: ["digital_signature"] sign pdf seems ok gundlac@batch-ost:~/mytest2$ pyhanko --verbose sign addsig --field Sig1 pkcs12 input.pdf output-pyhankoo.pdf wc.domain.p12
2022-02-14 17:29:29,740 - root - DEBUG - Running with --verbose
2022-02-14 17:29:29,740 - root - DEBUG - There was no configuration to parse.
PKCS#12 passphrase:
2022-02-14 17:29:38,698 - asyncio - DEBUG - Using selector: EpollSelector anyhow validation failed unfortunately because of non repudiation and failed Chain of trust validation gundlac@batch-ost:~/mytest2$ pyhanko sign validate --pretty-print output-pyhankoo.pdf
2022-02-14 17:30:05,397 - pyhanko.sign.validation.status - WARNING - The active key usage policy requires at least one of the key usage extensions non repudiation to be present.
2022-02-14 17:30:05,397 - pyhanko.sign.validation.status - WARNING - Chain of trust validation for Common Name: *.domain failed.
=============
Field 1: Sig1
=============
Signer info
-----------
Certificate subject: "Common Name: *.domain"
Certificate SHA1 fingerprint: 4e2b630023cb46c780f7383b8eed3acdcbe6d226
Certificate SHA256 fingerprint: 4f61b67b01ad745fb395b14a447692c1300bd26446800cd1637dc0ab9cb16e49
Trust anchor: "No path to trust anchor found."
The signer's certificate is untrusted.
Integrity
---------
The signature is cryptographically sound.
The digest algorithm used was 'sha256'.
The signature mechanism used was 'sha256_rsa'.
Signing time
------------
Signing time as reported by signer: 2022-02-14T16:29:38+00:00
Modifications
-------------
The signature covers the entire file.
Bottom line
-----------
The signature is judged INVALID.
Error: Validation failed checking that root certifiate will be trusted gundlac@batch-ost:~/mytest2$ ls -altr /etc/ssl/certs/ | grep -i DigiCert_Global_Root_CA
lrwxrwxrwx 1 root root 62 Dez 22 16:55 DigiCert_Global_Root_CA.pem -> /usr/share/ca-certificates/mozilla/DigiCert_Global_Root_CA.crt
lrwxrwxrwx 1 root root 27 Dez 22 16:55 3513523f.0 -> DigiCert_Global_Root_CA.pem create pem file with sub and root certifiate to explicit embed them gundlac@batch-ost:~/mytest2$ cat RapidSSL_TLS_DV_RSA_Mixed_SHA256_2020_CA-1.crt.pem DigiCertGlobalRootCA.crt.pem > anchor.pem resigning pdf seems good gundlac@batch-ost:~/mytest2$ pyhanko --verbose sign addsig --field Sig1 pkcs12 --chain anchor.pem input.pdf output-pyhankoo.pdf wc.domain.p12
2022-02-14 17:37:44,620 - root - DEBUG - Running with --verbose
2022-02-14 17:37:44,620 - root - DEBUG - There was no configuration to parse.
PKCS#12 passphrase:
2022-02-14 17:37:49.483 - asyncio - DEBUG - Using selector: EpollSelector validation faileds again gundlac@batch-ost:~/mytest2$ pyhanko --verbose sign validate --pretty-print output-pyhankoo.pdf
2022-02-14 17:48:13,720 - root - DEBUG - Running with --verbose
2022-02-14 17:48:13,720 - root - DEBUG - There was no configuration to parse.
2022-02-14 17:48:13,845 - asyncio - DEBUG - Using selector: EpollSelector
2022-02-14 17:48:13,870 - pyhanko.sign.validation.status - WARNING - The active key usage policy requires at least one of the key usage extensions non repudiation to be present.
2022-02-14 17:48:13,870 - pyhanko.sign.validation.status - WARNING - Chain of trust validation for Common Name: *.domain failed.
=============
Field 1: Sig1
=============
Signer info
-----------
Certificate subject: "Common Name: *.domain"
Certificate SHA1 fingerprint: 4e2b630023cb46c780f7383b8eed3acdcbe6d226
Certificate SHA256 fingerprint: 4f61b67b01ad745fb395b14a447692c1300bd26446800cd1637dc0ab9cb16e49
Trust anchor: "No path to trust anchor found."
The signer's certificate is untrusted.
Integrity
---------
The signature is cryptographically sound.
The digest algorithm used was 'sha256'.
The signature mechanism used was 'sha256_rsa'.
Signing time
------------
Signing time as reported by signer: 2022-02-14T16:29:38+00:00
Modifications
-------------
The signature covers the entire file.
Bottom line
-----------
The signature is judged INVALID.
Error: Validation failed The pkcs12 certificate store with the certifiate and the chain of trust accepted by google chrome and other browsers as valid. Best Regards, Thomas |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Hi Thomas, Thanks for checking in, and for the detailed report! Reading your description, three things come to mind:
TL;DR: Passing Hope that helps. |
Beta Was this translation helpful? Give feedback.
-
Hej @MatthiasValvekens, thank you very much. That was the problem. Now it works like a charm: pyhanko --verbose sign addsig --field Sig1 pkcs12 input.pdf output-pyhankoo.pdf wc.domain.p12
pyhanko --config \
<(echo "validation-contexts:";
echo " setup-a:";
echo " signer-key-usage: ["digital_signature"]";
) \
--verbose sign validate --validation-context setup-a --pretty-print output-pyhankoo.pdf You right. The certificate is not common for document signing. I just had nothing other ca signed certificate and was not sure what kind of certificate i need for request. I had wrote a little script in python with pyhanko to validate signed pdfs. Now i need to test that script still working after system upgrades. For that i need an other script which creates signed test pdfs - to test the first script automatically. For that i will request a common certifiate for document signing tomorrow: openssl req -newkey rsa:4096 -sha256 -keyform PEM -keyout key.pem -out cert-request.csr \
-subj '/C=DE/ST=State/L=City/O=Organisation/OU=Group/CN=pyhanko_Signaturtest/emailAddress=mail@address' \
-addext "keyUsage = critical,nonRepudiation,digitalSignature" \
-addext "extendedKeyUsage = critical,codeSigning"
openssl req -text -in cert-request.csr Thank you so much from Hamburg and have a good night. |
Beta Was this translation helpful? Give feedback.
-
Thanks @MatthiasValvekens. Yesterday, while i'm searching for my problem i just saw it when passing by the documention. but unfortunately i've got a new Problem. Because of interprocess communication and our workflow design i have to import the trusted certificate from the enviroment. In Reference to the Documentation
i tried the following and failed:
Same way works in Seems ValidationContext expect an object with the attribut issuer_serial. From the code that should be .authority.TrustAnchor or, as documented, asn1crypto.x509.Certificate. I cannot figure out how i can create an .authority.TrustAnchor Object from a byte encoded PEM String. Do you have a hint? Best Regards, Thomas |
Beta Was this translation helpful? Give feedback.
-
Hej @MatthiasValvekens , works perfect. Thank you for making that clear! I've got another Problem. But i will open a new thread for that. Best Regards, Thomas |
Beta Was this translation helpful? Give feedback.
Hi Thomas,
Thanks for checking in, and for the detailed report! Reading your description, three things come to mind:
nonRepudiation
key usage bit set. In other words, you need to ensure that your custom validation context is also used when validating the signature (assuming you didn't set it as the default). In your case, that'd mean passing--validation-context setup-a
topyhanko sign validate
.\oscrypto
) may or may not agree with your browser's or favourite PDF viewer's trust store. How that's best addressed d…