Post

Replies

Boosts

Views

Activity

How to add new SecTrustedApplicationRef to the ACL of a login keychain?
Let's say I have a login keychain with ACL that contains trusted application list. Now I want to add a new SecTrustedApplicationRef to this existing list, and hence update the ACL of this object. Here's the steps I took, but doesn't seem to be working retrieve keychain item reference of kSecClassGenericPassword object OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)queryDictionary,(CFTypeRef *)&attributeDictionary); Then get existing access ref  SecKeychainItemRef itemRef = (SecKeychainItemRef) CFBridgingRetain([bridgedDict objectForKey:(__bridge id)kSecValueRef]);       SecAccessRef accessRef = NULL;       status = SecKeychainItemCopyAccess(itemRef,&accessRef); Update this existing Access Ref by appending a new ACL that contains new trusted apps info      status = SecACLCreateWithSimpleContents(accessRef, (__bridge CFArrayRef)microsoftTrustedApps, (__bridge CFStringRef)tenantIdentifier, kSecKeychainPromptRequirePassphase, &newAcl); Finally, update access ref using SecItemUpdate      NSMutableDictionary *origQuery = [NSMutableDictionary new];     [origQuery setObject:tenantIdentifier forKey:(__bridge id)kSecAttrService];     [origQuery setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass];     NSMutableDictionary *updateQuery = [NSMutableDictionary new];     [updateQuery setObject:(__bridge id)accessRef forKey:(__bridge id)kSecAttrAccess];     status = SecItemUpdate((CFDictionaryRef)origQuery, (CFDictionaryRef)updateQuery); It does return errSecSuccess, and I get prompted for passphrase during SecItemUpdate, but the resultant login keychain object in keychain access still doesn't show the new app under "always allow access by these applications" under "Access Control" tab. Any help would be appreciated. Thanks!
3
0
713
Oct ’21
On MacOS, using Xcode13, does SecItemAdd automatically create ACL on login keychain?
In older MacOS versions, below API would create access ref object of the app running the code and store it into SectrustedApplicationRef mySelf object. SecTrustedApplicationRef mySelf = NULL; SecTrustedApplicationCreateFromPath(NULL, &mySelf); Then I can store mySelf in an array - allTrustedApps, and create SecAccessRef object    SecAccessRef accessRef = NULL;   status = SecAccessCreate((CFStringRef)accessLabel, (__bridge CFArrayRef)allTrustedApps, &accessRef); Finally, I would then add this access ref object into kSecAttrAccess field of the query dictionary before feeding it into SecItemAdd. However, on MacOS 10.15+ SecTrustedApplicationCreateFromPath is deprecated. As I was playing around with ACL, and when I tried to add a kSecClassGenericPassword object into login keychain using SecItemAdd, without 'KSecAttrAccess' in the write query dictionary. (nothing but kSecAttrAccount and kSecAttrService) - I've noticed that the final object in the login keychain still has ACL containing the hosting app that ran the keychain add op. Is this by design? Thanks, Peter
1
0
579
Sep ’21
How to add new SecTrustedApplicationRef to the ACL of a login keychain?
Let's say I have a login keychain with ACL that contains trusted application list. Now I want to add a new SecTrustedApplicationRef to this existing list, and hence update the ACL of this object. Here's the steps I took, but doesn't seem to be working retrieve keychain item reference of kSecClassGenericPassword object OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)queryDictionary,(CFTypeRef *)&attributeDictionary); Then get existing access ref  SecKeychainItemRef itemRef = (SecKeychainItemRef) CFBridgingRetain([bridgedDict objectForKey:(__bridge id)kSecValueRef]);       SecAccessRef accessRef = NULL;       status = SecKeychainItemCopyAccess(itemRef,&accessRef); Update this existing Access Ref by appending a new ACL that contains new trusted apps info      status = SecACLCreateWithSimpleContents(accessRef, (__bridge CFArrayRef)microsoftTrustedApps, (__bridge CFStringRef)tenantIdentifier, kSecKeychainPromptRequirePassphase, &newAcl); Finally, update access ref using SecItemUpdate      NSMutableDictionary *origQuery = [NSMutableDictionary new];     [origQuery setObject:tenantIdentifier forKey:(__bridge id)kSecAttrService];     [origQuery setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass];     NSMutableDictionary *updateQuery = [NSMutableDictionary new];     [updateQuery setObject:(__bridge id)accessRef forKey:(__bridge id)kSecAttrAccess];     status = SecItemUpdate((CFDictionaryRef)origQuery, (CFDictionaryRef)updateQuery); It does return errSecSuccess, and I get prompted for passphrase during SecItemUpdate, but the resultant login keychain object in keychain access still doesn't show the new app under "always allow access by these applications" under "Access Control" tab. Any help would be appreciated. Thanks!
Replies
3
Boosts
0
Views
713
Activity
Oct ’21
On MacOS, using Xcode13, does SecItemAdd automatically create ACL on login keychain?
In older MacOS versions, below API would create access ref object of the app running the code and store it into SectrustedApplicationRef mySelf object. SecTrustedApplicationRef mySelf = NULL; SecTrustedApplicationCreateFromPath(NULL, &mySelf); Then I can store mySelf in an array - allTrustedApps, and create SecAccessRef object    SecAccessRef accessRef = NULL;   status = SecAccessCreate((CFStringRef)accessLabel, (__bridge CFArrayRef)allTrustedApps, &accessRef); Finally, I would then add this access ref object into kSecAttrAccess field of the query dictionary before feeding it into SecItemAdd. However, on MacOS 10.15+ SecTrustedApplicationCreateFromPath is deprecated. As I was playing around with ACL, and when I tried to add a kSecClassGenericPassword object into login keychain using SecItemAdd, without 'KSecAttrAccess' in the write query dictionary. (nothing but kSecAttrAccount and kSecAttrService) - I've noticed that the final object in the login keychain still has ACL containing the hosting app that ran the keychain add op. Is this by design? Thanks, Peter
Replies
1
Boosts
0
Views
579
Activity
Sep ’21
How to I get MacOS Build Number programmatically?
On MacOS, let's say I am using Big Sur Version 11.6 (20G165) Is there any API on Xcode that would allow me to retrieve the build number programmatically, (in this case 20G165)? For version, I can use [[NSProcessInfo processInfo] operatingSystemVersion], but can't seem to be able to find the API for the build number. Thanks!
Replies
2
Boosts
0
Views
2.1k
Activity
Sep ’21