Hi,
I'm adding certificate to keychain as describe Here
I add the certificate to keychain successfully but when I try to fetch it, it always return error item not found (25300)
I'm running on macOS Big Sur (ver 11.6)
Below is the code. What am I missing ?
Thanks,
Tal
// code that insert the certificate
NSDictionary* addquery = @{
(id)kSecValueRef: (__bridge id)cert,
(id)kSecClass: (id)kSecClassCertificate,
(id)kSecAttrLabel: @"ClientCert"};
OSStatus status = SecItemAdd((__bridge CFDictionaryRef)addquery, nullptr);
// code that fetch the certificate
NSDictionary *queryDict = @{
(id) kSecClass : (id) kSecClassCertificate,
(id) kSecAttrLabel : @"ClientCert",
(id) kSecReturnRef : @YES};
auto sanityCheck = SecItemCopyMatching((__bridge CFDictionaryRef) queryDict, (CFTypeRef *) &m_client_cert);
Is there a way for me to look at the certificate and keys (not from code)?
No.
I was actually quite surprised by this. You can view the data protection keychain in Keychain Access by selecting iCloud Keychain (or, if iCloud Keychain is disabled, Local Items) in the list on the left. However, this seems to only show password items, not keys and certificates.
Also, you wrote … is that means I cannot use a service or background process with that code ?
That depends on what you mean by “service or background process”. A launchd daemon, which runs in a global context, independent of any user login session, cannot use the data protection keychain. The same applies for system extensions, which are more-or-less daemons on the covers. Most other code runs in a specific user context and thus can use the data protection keychain. That list includes:
-
Apps
-
App extensions
-
XPC Services
-
launchdagents -
Service Management login items
Technote 2083 Daemons and Agents goes it to gory details about execution contexts on macOS (it’s no longer 100% accurate but it’s still a good reference for most tasks).
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"