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);
UPDATE I replaced kSecAttrLabel with kSecAttrApplicationTag and it start working. No idea why it does not work as stated in the documentation.
UPDATE2 The replacement of kSecAttrLabel with kSecAttrApplicationTag actually did not work. The query disregard it and I notice I end up with a different certificate.
So, I still need to figure out why kSecAttrLabel is not working on macOS.