As I understand pkcs12 defines a container structure that can hold both a certificate and one or more private keys.
openssl pkcs12 -export -inkey test-key.pem -out test.p12 -name 'Test name' -in test.crt Enter pass phrase for test-key.pem: KEYPW Enter Export Password: EXPPW Verifying - Enter Export Password: EXPPW
Read the p12 file:
openssl pkcs12 -info -in test.p12 Enter Import Password: EXPPW <outputs certificate, followed by> PKCS7 Data Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 2048 Bag Attributes friendlyName: Test name localKeyID: 92 C7 F8 7A 23 F4 03 21 0A 3B D6 CE 29 C6 45 C8 1E E0 D2 DD Key Attributes: <No Attributes> Enter PEM pass phrase: KEYPW Verifying - Enter PEM pass phrase: KEYPW -----BEGIN ENCRYPTED PRIVATE KEY----- ... -----END ENCRYPTED PRIVATE KEY-----
For the PEM pass phrase I use the one when the private key was created. But why does the output show encrypted private key instead of private key? That's why I entered the pass phrase isn't it?
What makes it even more confusing: passing option
-nodes to the openssl command doesn't ask the pass phrase anymore (as expected) but still shows the private key, this time not encrypted anymore. I would expect the opposite: without pass phrase show the encrypted private key, with pass phrase show the unencrypted private key. After all, I can only use the private key when it is not encrypted.
EDIT: hopefully it's easier if I ask smaller questions. Given the created test.p12 as shown above:
- Is it correct that EXPPW is the p12 container password and KEYPW is the pass phrase to protect the private key?
- Is it possible to get the unencrypted private key with only EXPPW? In other words, is KEYPW not used inside the p12 container?
- If the private key is stored encrypted inside the p12 using EXPPW, why does
openssl pkcs12 -info -in test.p12not accept a new pass phrase for outputting the new encrypted private key? If you don't use the original KEYPW it fails with Error outputting keys and certificates.
- Is it possible to protect the whole p12 container with password X and the private key with password Y? So that if you know X, you can still get the public certificate yet you can't get the private key?