Why trust list of keychain not work?

I have two applications to operate the same keychain item.

App A save a key in keychain item and App B get the key from that keychain item.


I know there are some solutions:

  1. "set trust list", but it doesn't work.
  2. "allows all applications to access the item", but I don't know how to do with objc.
  3. "keychain share", but my developer account is temporarily unavailable.


First,

I want to know why trust list of keychain not work?

When App B want to get the key, it need to input login password, but it doesn't need when App A to get the key.

There are some following codes:

    // save app
    SecTrustedApplicationRef saveRef;
    SecTrustedApplicationCreateFromPath([@"/Users/mr.zhang/Desktop/SaveKeychainInfo.app" cStringUsingEncoding:NSUTF8StringEncoding]
                                        , &saveRef);
    // get app
    SecTrustedApplicationRef getRef;
    SecTrustedApplicationCreateFromPath([@"/Users/mr.zhang/Desktop/GetKeychainInfo.app" cStringUsingEncoding:NSUTF8StringEncoding]
                                        , &getRef);
 
    SecAccessRef accessRef;
    NSArray *trustList = @[(__bridge id)saveRef, (__bridge id)getRef];
    SecAccessCreate((__bridge CFStringRef)@"access", (__bridge CFArrayRef)trustList, &accessRef);
 
    NSDictionary *keychainQuery = @{
                                    (__bridge NSString *)kSecClass : (__bridge NSString *)kSecClassGenericPassword,
                                    (__bridge NSString *)kSecAttrService : service,
                                    (__bridge NSString *)kSecAttrAccount : service,
                                    (__bridge NSString *)kSecAttrAccess : (__bridge NSString *)accessRef,
                                   };


Second,

I want to know how to "allows all applications to access the item" with code?

I have no idea about it.


Thanks

Replies

I use the following codes can "allows all applications to access the item":

SecAccessRef accessRef;
NSArray *trustList = [NSArray arrayWithObjects:(__bridge id)saveRef, (__bridge id)getRef, nil];
SecAccessCreate((__bridge CFStringRef)@"access", (__bridge CFArrayRef)trustList, &accessRef);
SecACLRef aclRef;
SecACLCreateWithSimpleContents(accessRef, NULL, (__bridge CFStringRef)@"access", 0, &aclRef);


But,

App A create a key and could get it, App B could not get it.

Why?

What have I missed?

It seems that you’ve created multiple threads all clustered around the same high-level question. I’ve responded on one of your other threads and I suggest we focus our efforts there.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Right, and I want to delete redundant issues, but I didn't find a way~