Hi there, I'm currently working on a compatibility feature for Apple that allows the user to manage their keys and certificates from within our internal API. For this I need to retrieve all the items contained within keychains.
I am looking at the documentation for SecItem API but so far I have not really found an obvious way to link these items together. My best guess so far is to perform two queries, grabbing all SecKey
s from the keychains, pairing them up with public keys through SecKeyCopyPublicKey
, then downloading all CertItem
s and pairing them with public keys with SecCertificateCopyKey
, and then join the two using public keys.
This sounds however somewhat involved and I was wondering if there was a better way of going about the process?
What platform are you targeting?
This matters because the keychain story is radically different on macOS than on our other platforms. See TN3137 On Mac keychain APIs and implementations.
the user to manage their keys and certificates from within our internal API.
By “user” do you mean a developer that calls your API?
It sounds like you’re trying to work with digital identities, that is, the combination of a certificate and the private key that matches the public key within that certificate. Is that right?
If so, the SecItem API has a specific class for that, kSecClassIdentity
. This works in terms of SecIdentity
objects.
Digital identities aren’t stored as such, by instead synthesised by combining key and certificate items. I talk about this in the Digital Identities Aren’t Real section of SecItem: Pitfalls and Best Practices.
Oh, and speaking of that you’ll probably want to real it and its platonic life partner, SecItem: Fundamentals.
If you have follow-up questions, feel free to post them here.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"