简体   繁体   English

区分Mac OS X钥匙串中的会话和系统项

[英]Distinguish session and system items in Mac OS X keychain

How can I query the Mac OS X keychain to retrieve only session items ? 如何查询Mac OS X钥匙串以仅检索会话项?

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 会话项和系统项具有完全相同的键属性: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 ! 谢谢您的帮助 !

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): 您可以像这样查询会话密码(如果您需要所有密码, kSecMatchLimitAll替换为kSecMatchLimitOne 。在这种情况下, attributes将具有CFArrayRef类型):

 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; } 

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM