Hey, guys!
I am using C++ to write some MacOS code.
It actually works and I can see the entry in the keychain.
2. I call the SecItemCopyMatching to get the entry. You can find the code snipped below.
Here is the implementation of CreateSearchQuery
I have confirmed that ServiceRef, TypeRef and AccountRef have the same values as when SecItemAdd was called. Also It do returns non-empty Query
I think it worth to notice, that SecItemDelete successfully deletes the entry with the same Query.
MacOS version = 10.15.6
I am using C++ to write some MacOS code.
I have added the data to the keychain with the SecItemAdd Here is the code snipped.
Code Block CFStringRef DictKeys[] = {kSecClass, kSecAttrService, kSecAttrType, kSecAttrAccount, kSecValueData, kSecAttrDescription}; CFTypeRef DictValues[] = {kSecClassGenericPassword, ServiceRef, TypeRef, AccountRef, ValueRef, DescriptionRef}; /* Create a dictionary object that holds key-value parameters to store with the new credentials entry. */ CFDictionaryRef KeychainRef = CFDictionaryCreate(kCFAllocatorDefault, (const void **)DictKeys, (const void **)DictValues, 6, nullptr, nullptr); if (KeychainRef != nullptr) { /* Create a new credentials entry in the default keychain of the currently logged in local user. */ const OSStatus Status = SecItemAdd(KeychainRef, nullptr); Result = OSStatusToResult(Status); }
It actually works and I can see the entry in the keychain.
2. I call the SecItemCopyMatching to get the entry. You can find the code snipped below.
Code Block CFMutableDictionaryRef Query = CreateSearchQuery(ServiceRef, TypeRef, AccountRef); if (Query != nullptr) { CFDataRef DataRef = nullptr; const OSStatus Status = SecItemCopyMatching(Query, (CFTypeRef *)DataRef); /* Here Status = errSecSuccess but DataRef = nullptr */ if (Status == errSecSuccess && DataRef != nullptr) { /* Some code here ... */ }
Here is the implementation of CreateSearchQuery
Code Block CFMutableDictionaryRef CreateSearchQuery(CFStringRef ServiceRef, CFNumberRef TypeRef, CFStringRef AccountRef) { CFMutableDictionaryRef Query = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, nullptr, nullptr); if (Query) { CFDictionaryAddValue(Query, kSecClass, kSecClassGenericPassword); CFDictionaryAddValue(Query, kSecMatchLimit, kSecMatchLimitOne); CFDictionaryAddValue(Query, kSecUseAuthenticationUI, kSecUseAuthenticationUISkip); CFDictionaryAddValue(Query, kSecReturnData, kCFBooleanTrue); CFDictionaryAddValue(Query, kSecAttrService, ServiceRef); CFDictionaryAddValue(Query, kSecAttrType, TypeRef); CFDictionaryAddValue(Query, kSecAttrAccount, AccountRef); } return Query; }
I have confirmed that ServiceRef, TypeRef and AccountRef have the same values as when SecItemAdd was called. Also It do returns non-empty Query
I think it worth to notice, that SecItemDelete successfully deletes the entry with the same Query.
MacOS version = 10.15.6