SecIdentityCreateWithCertificate return errSecItemNotFound

I created public/private key with SecKeyCreateRandomKey.

I then use openssl to create csr and a client certificate using the private key. The private key and certificate exist together in the keychain.

I then query for the certificate with SecItemCopyMatching and use that certificate to create the identity:

SecIdentityCreateWithCertificate(
                             nullptr,  
                             client_cert, 
                             &identity) 

I get error result of errSecItemNotFound.

Any idea what is wrong here ?

I'm running on macOS version 11.6

Thanks, Tal

Accepted Answer

The private key and certificate exist together in the keychain.

If you find the certificate in Keychain Access, does it show paired up with the private key?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Answers

The private key and certificate exist together in the keychain.

If you find the certificate in Keychain Access, does it show paired up with the private key?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I found out I got a different certificate from what I expected. Once I got the right certificate it worked fine.

Thanks, Tal