🔐 PKCS #12¶
PKCS 12 (also known as PFX) is a binary format for storing a certificate together with its private key in a single, password-protected file (usually .p12 or .pfx).
See also
Check out the «PKCS 12» Wikipedia article for more information about it.
PKCS #12 incompatibility¶
Warning
⚠️ 🐰 WARNING, RABBIT HOLE AHEAD 🐰 ⚠️
During the engineering of the CA & CertBob, we had some issues with PKCS 12 certificates and the macOS keychain.
This happened especially when we used the step certificate p12 command.
There’s some talk in the interwebs regarding incompatibility (e.g. pyca cryptography issue), because the SSL library of macOS wasn’t compatible with OpenSSL 3.x in the beginning. Thus, some suggest using the -legacy flag when exporting PKCS 12 certificates, or explicitly setting setting the algorithms.
In the end, we could always import certificates exported with openssl pkcs12 -export…, but never with step certificate p12….
We checked the certificates, and could find a minor difference, which “broke” the macOS keychain support:
openssl pkcs12 -in working-openssl.p12 -info -noout
# MAC: sha256, Iteration 2048
# MAC length: 32, salt length: 8
# PKCS7 Encrypted data: PBES2, PBKDF2, AES-256-CBC, Iteration 2048, PRF hmacWithSHA256
# Certificate bag
# Certificate bag
# PKCS7 Data
# Shrouded Keybag: PBES2, PBKDF2, AES-256-CBC, Iteration 2048, PRF hmacWithSHA256
openssl pkcs12 -in broken-step.p12 -info -noout
# MAC: sha256, Iteration 2048
# MAC length: 32, salt length: 16
# PKCS7 Encrypted data: PBES2, PBKDF2, AES-256-CBC, Iteration 2048, PRF hmacWithSHA256
# Certificate bag
# Certificate bag
# PKCS7 Data
# Shrouded Keybag: PBES2, PBKDF2, AES-256-CBC, Iteration 2048, PRF hmacWithSHA256
Important
As you can see, the only difference is the salt length. macOS seems to have an issue with either the salt length of 16 characters – or the salt has some characters which macOS didn’t like.