7

I'm trying to import .p12 certificate into the keychain on my Mac via bash script. So far, I've been trying:

  1. sudo security import command.

It returns that import was successful but, in fact, it never gets imported into any keychain.

  1. sudo security add-certificates -k /Library/Keychains/System.keychain certificate.p12

it throws the following error:

Password: SecCertificateCreateFromData: Unknown format in import.

The only thing that worked for me was the .cer format via this command: sudo security add-certificates -k /Library/Keychains/System.keychain certificate.cer. It does import the certificate into the keychain and I can see it in the keychain access.

But I only have .p12 certificates. Could anyone help me with that one, please?

1
  • Can .p12 certs be imported via the GUI Keychain Access app? If not, I agree with Robert Longson’s answer that converting with OpenSSL first is the solution. Commented Sep 18, 2022 at 12:21

2 Answers 2

5

You can convert a .p12 file to .cer via the openssl pkcs12 command

openssl pkcs12 -in certificate.p12 -clcerts -nokeys -out certificate.cer

Then import the .cer since you know how to do that.

2

Password: SecCertificateCreateFromData: Unknown format in import

SecCertificateCreateFromData is actually deprecated https://developer.apple.com/documentation/security/1396025-seccertificatecreatefromdata. Not sure why security tool would still use it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .