openssl: OSSL_STORE does not support loading certs from unusual PKCS#12 encoding and does not give any clue about this
For some reason, OSSL_STORE cannot load certs from PKCS#12 if encrypted using ~TripleDES-CBC~ pbeWithSHA1And3-KeyTripleDES-CBC, e.g.:
$ openssl x509 -in test-TripleDES-CBC.p12 -passin pass:12345
Could not find certificate from test-TripleDES-CBC.p12
This holds even when the legacy provider is used:
$ openssl x509 -in test-TripleDES-CBC.p12 -passin pass:12345 -provider legacy -provider default
Could not find certificate from test-TripleDES-CBC.p12
Moreover, OSSL_STORE does not provide any error queue entry on this failure, so users can have a hard time finding out that it is due to TripleDES-CBC not being supported.
The pkcs12 app, which reads the structure more directly, works fine here,
even without the -legacy option:
$ openssl pkcs12 -info -in test-TripleDES-CBC.p12 -passin pass:12345 -nodes
MAC: sha1, Iteration 102400
MAC length: 20, salt length: 20
PKCS7 Data
Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 51200
Bag Attributes
localKeyID: C9 3A 5C 8F DA 32 A8 A5 18 73 31 FD 36 07 B1 F0 D0 71 8B 8D
friendlyName: Docker_Playground_TLS
Key Attributes: <No Attributes>
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgf9kaFByqRUyzn+P0
rYZzb9YfAmZjsDVExPl/aXhSU5KhRANCAARXGKeXCT//bKq1OcRrCbX49Y8pPIi+
dvT9TuTalc2zW22+ZsR34Q2HSCYME6T7upi1g/Xix/VYydGZX/urmaY0
-----END PRIVATE KEY-----
PKCS7 Encrypted data: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 51200
Certificate bag
Bag Attributes
localKeyID: C9 3A 5C 8F DA 32 A8 A5 18 73 31 FD 36 07 B1 F0 D0 71 8B 8D
friendlyName: Docker_Playground_TLS
subject=CN=Docker_Playground_TLS
issuer=CN=TLS_ISSUING_CA
-----BEGIN CERTIFICATE-----
MIIBsDCCAVagAwIBAgIUFnCqv+gqsItFwtJVnwe6xXpYwb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NVHQ8BAf8EBAMCAYYwCgYIKoZIzj0EAwIDSAAwRQIh
AJgGpUH4Ra6UrCGht9/lbnAAlZB+N9XhAljfaOiWveLpAiBPeufi17WrQQ1bE/qh
9EGpEmZrCs6urn5Ev/voAIa7nQ==
-----END CERTIFICATE-----
Certificate bag
Bag Attributes
friendlyName: TLS_ISSUING_CA
subject=CN=TLS_ISSUING_CA
issuer=CN=TLS_ROOTCA
-----BEGIN CERTIFICATE-----
MIIBkjCCATmgAwIBAgIUDcfEgIEVzvy7TkvJk+ttQOCYfI4wCgYIKoZIzj0EAwIw
FTETMBEGA1UEAwwKVExTX1JPT1RDQTAeFw0yMzAzMjAyMzU1MDdaFw0zMzAzMTcy
MzU1MDZaMBkxFzAVBgNVBAMMDlRMU19JU1NVSU5HX0NBMFkwEwYHKoZIzj0CAQYI
KoZIzj0DAQcDQgAEdHKVuCRMGL8GGjeQZFZNuz6e5u5YKvIDpBn29J8dF77a35DO
dt/Kv//3P/HUuJF3BZQRDbsZYRO6bM6y8mR71KNjMGEwDwYDVR0TAQH/BAUwAwEB
/zAfBgNVHSMEGDAWgBSZxLQnbuGkMjqefp4ny8BISHXXPzAdBgNVHQ4EFgQUxega
12Tq5zISWH1eq4w+8qXawwUwDgYDVR0PAQH/BAQDAgGGMAoGCCqGSM49BAMCA0cA
MEQCIAjaBQoZoz0s6JAVn9P004OxCosDZ9D8R0YNdd1tfD/nAiBMgXc+C9jtm8nH
I7rwpzaxK5fbOomZDVNebCe/sBn/kg==
-----END CERTIFICATE-----
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 34 (34 by maintainers)
It was created by EJBCA .
Another benefit of this issue was that I came across a mem leak when using
load_key_certs_crls()fromapps/lib/apps.cto load both a pkey and certs from that weird PKCS#12 file. After the pkey was parsed successfully but getting the certs did not work, such that the overall function failed, the caller did not free the pkey, which was still allocated. This motivated #28005, which makes sure that on error return,load_key_certs_crls()frees all credentials loaded so far.After a little bit of thinking, I understand how the situation happened.
Since test-AES-256-CBC.p12 is DER encoded, the loader read an exact number of bytes, which makes the file “cursor” stop at the end of file, but didn’t attempt to read beyond it, so the eof bit was not flagged while going through the OSSL_STORE cached info.
However, since test-TripleDES-CBC.p12 is BER encoded, the loader keeps reading to see if there’s more to read, actually hits the end of file, which flags the eof bit, thereby uncovering this bug.
Something to note is that the ending EOC in test-TripleDES-CBC.p12 suggests BER encoding rather than DER encoding. Actually, now that I look more closely at it, I find all sorts of traces:
Our
d2iroutines aren’t absolutely strict about DER… partly for CMS purposes if I’m not mistaken? But perhaps it should be for PKCS#12.Even better that there is not really an issue with
pbeWithSHA1And3-KeyTripleDES-CBCbut that the unconventional PKCS#12 encoding used by the example file given indicated a general PKCS#12-related OSSL_STORE bug that now gets fixed.The default provider has DES-EDE3-CBC, so it’s surprising that this algo should be a reason for failure. However, it could be that we missed something with the PBEs, like
pbeWithSHA1And3-KeyTripleDES-CBC.I think OSSL_STORE was hardly ever used by anyone with PKCS12 files in 1.1.1. We started using the OSSL_STORE in apps (except of storeutl) only in 3.x.