And then I ran xxd -p myfile.p12
and the result is in hex.txt
Thanks. That’s exactly what I needed.
I converted your hex dump back to binary and put it in a file called test.p12
. I tried importing this into Keychain Access on the Mac. That also failed. So something about this PKCS#12 data is not making Apple systems happy.
Unfortunately I’m not a PKCS#12 guru so I can’t point you to the exact problem. However, I do have some info to share.
I used openssl
to convert the file to PEM and back again:
| % openssl pkcs12 -in test.p12 -out test.pem |
| … |
| % openssl pkcs12 -export -in test.pem -out test-openssl.p12 |
| … |
The Mac can import this test-openssl.p12
file. I then dump the two files:
| % openssl pkcs12 -info -in test-openssl.p12 |
| Enter Import Password: |
| MAC Iteration 2048 |
| MAC verified OK |
| PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048 |
| Certificate bag |
| Bag Attributes |
| localKeyID: B1 52 93 3A FC DD B0 30 44 C8 A8 D4 CC 1E A7 4A 25 40 1B F8 |
| subject=/CN=cast_nearby_client_auth |
| issuer=/CN=cast_nearby_client_auth |
| -----BEGIN CERTIFICATE----- |
| MIIC/jCCAeagAwIBAgIIaFS1HFLdQrUwDQYJKoZIhvcNAQELBQAwIjEgMB4GA1UE |
| … |
| 3BFewf6vISPnxGMb6ZHUrQJRv96Mtptx5lWdoTOcHC0J5Wgd0NedO3lYKBBixy32 |
| U3U= |
| -----END CERTIFICATE----- |
| PKCS7 Data |
| Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 2048 |
| Bag Attributes |
| localKeyID: B1 52 93 3A FC DD B0 30 44 C8 A8 D4 CC 1E A7 4A 25 40 1B F8 |
| Key Attributes: <No Attributes> |
| Enter PEM pass phrase: |
| Verifying - Enter PEM pass phrase: |
| -----BEGIN ENCRYPTED PRIVATE KEY----- |
| MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIG6ZeBMFUmG0CAggA |
| … |
| QFIdCtz/tfQhgNfIZiLJBAEf/NHD7Tb1I6NuCujT4xH3yHHBO40Ldreu5xFekY3A |
| Sb8= |
| -----END ENCRYPTED PRIVATE KEY----- |
| % |
| % |
| % openssl pkcs12 -info -in test.p12 |
| Enter Import Password: |
| MAC Iteration 100000 |
| MAC verified OK |
| PKCS7 Data |
| Shrouded Keybag: Bag Attributes |
| friendlyName: cast_nearby_client_auth |
| localKeyID: 54 69 6D 65 20 31 36 34 30 30 33 31 38 32 34 32 31 32 |
| Key Attributes: <No Attributes> |
| Enter PEM pass phrase: |
| Verifying - Enter PEM pass phrase: |
| -----BEGIN ENCRYPTED PRIVATE KEY----- |
| MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIjQ3PJLW2KYwCAggA |
| … |
| QWCGyY3tmwNBBfzZUIhG/uDXgfPo4v4pyPPGGmig1A8rXyQdgW7v9JHsmtReiai6 |
| NQE= |
| -----END ENCRYPTED PRIVATE KEY----- |
| PKCS7 Encrypted data: Certificate bag |
| Bag Attributes |
| friendlyName: cast_nearby_client_auth |
| localKeyID: 54 69 6D 65 20 31 36 34 30 30 33 31 38 32 34 32 31 32 |
| subject=/CN=cast_nearby_client_auth |
| issuer=/CN=cast_nearby_client_auth |
| -----BEGIN CERTIFICATE----- |
| MIIC/jCCAeagAwIBAgIIaFS1HFLdQrUwDQYJKoZIhvcNAQELBQAwIjEgMB4GA1UE |
| … |
| 3BFewf6vISPnxGMb6ZHUrQJRv96Mtptx5lWdoTOcHC0J5Wgd0NedO3lYKBBixy32 |
| U3U= |
| -----END CERTIFICATE----- |
These two files have significant structural differences. Specifically, contrast this in the working case (test-openssl.p12
):
| PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048 |
| Certificate bag |
| … |
| PKCS7 Data |
| Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 2048 |
with this in the failing case (test.p12
):
| PKCS7 Data |
| Shrouded Keybag: Bag Attributes |
| … |
| PKCS7 Encrypted data: Certificate bag |
The two PKCS#7 blobs are in different order, but that’s OK. But they also have completely different format, which is clearly not OK. Note that the first, working case has the encryption algorithms I’d expect to see in a PKCS#12.
So, I’m not entirely sure what’s going on here but I’m quite sure that you need to look at the code that generated the test.p12
file you posted, because it’s generating a file that’s quite strangely formatted.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"