How can I query the Mac OS X keychain to retrieve only session items ?

When I try to get all items like this :

[SSKeychain accountsForService:nil];

A session item and a system item have exactly the same attributes for the keys : acct, cdat, class, crtr, labl, mdat, svce

How can y query the keychain to get only session items or distinguish them ?

Thank you for your help !

有帮助吗?

解决方案 2

I have found by opening the user keychain :

NSArray *path = [NSHomeDirectory() pathComponents];
NSString *keychainPath = [NSString stringWithFormat:@"%@%@/%@%@",path[0],path[1],path[2],@"/Library/Keychains/login.keychain"];
SecKeychainRef ref = NULL;
SecKeychainOpen([keychainPath UTF8String],&ref);

其他提示

You can query the session password like this (replace kSecMatchLimitOne with kSecMatchLimitAll if you need all passwords. The attributes will have CFArrayRef type in this case):

NSDictionary* passwordQuery = @{
    (__bridge id)kSecAttrService : sessionServiceName,
    (__bridge id)kSecClass : (__bridge id)kSecClassGenericPassword,
    (__bridge id)kSecReturnAttributes: (__bridge id)kCFBooleanTrue,
    (__bridge id)kSecReturnData: (__bridge id)kCFBooleanTrue,
    (__bridge id)kSecMatchLimit : (__bridge id)kSecMatchLimitOne
};

CFTypeRef attributes = nil;
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)passwordQuery, &attributes);
if (status != 0){
    return nil;
 }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top