[英]Is it possible to use Touch-ID Authentication AND Keychain sharing in an iOS app?
我已經成功地分別使用鑰匙串和鑰匙串共享(在多個設備之間同步鑰匙串項)來實現TouchID。 當我嘗試同時執行它們時,我收到錯誤“-50”,這是無效參數。 從下面的代碼中,刪除kSecAttrAccessControl或kSecAttrSynchronizable按預期工作。
根據我的經驗(閱讀 - 幾天的挫折)到目前為止,並基於一些鑰匙串API簡化工具(如UICKeychainStore)的功能 ,似乎如果我使用Touch ID身份驗證,鑰匙串共享將無法工作,反之亦然。 我正在尋找可以說明但無法找到它的Apple文檔。
我已經瀏覽了Apple的SecItem.h頁面,我找到了一個有用的信息,其中包含有關kSecAttrAccessible和kSecAttrSynchronizable的信息 :“如果在OS X或iOS上都指定了這兩個屬性,則kSecAttrAccessible密鑰的值可能只是其名稱之一不會以“ThisDeviceOnly”結尾,因為那些不能同步到另一台設備。“但是,我沒有使用”ThisDeviceOnly“(我目前正在使用kSecAttrAccessibleAlways進行測試)
您能否指出Apple是否以及在何處記錄此限制? 這將有助於我記錄它的記錄,並繼續前進。 謝謝。
- (void)addKeychainItemWithIdentifier:(NSString *)identifier andData:(NSData *)data {
CFErrorRef error = NULL;
SecAccessControlRef sacObject;
sacObject = SecAccessControlCreateWithFlags(kCFAllocatorDefault,
kSecAttrAccessibleAlways,
kSecAccessControlUserPresence, &error);
if(sacObject == NULL || error != NULL)
{
NSString *msg0 = [NSString stringWithFormat:NSLocalizedString(@"SEC_ITEM_ADD_CAN_CREATE_OBJECT", nil), error];
[self printResultWithMessage:msg0];
return;
}
NSDictionary *attributes = @{
(__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword,
(__bridge id)kSecValueData: data,
(__bridge id)kSecAttrAccessible:(__bridge id)kSecAttrAccessibleAlways,
(__bridge id)kSecAttrService: identifier,
(__bridge id)kSecAttrSynchronizable:(__bridge id)kCFBooleanTrue,
(__bridge id)kSecAttrAccessControl: (__bridge_transfer id)sacObject
};
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
OSStatus status = SecItemAdd((__bridge CFDictionaryRef)attributes, nil);
NSError *statuserror = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil];
[self printResultWithMessage:[self keychainErrorToString:status]];
});
}
我想我可能已經找到了答案
在WWDC 2014視頻711中,在31:48提到以下內容
ACL受保護的項目 - 無同步,無備份
因此,Touch ID身份驗證不能用於設備之間的Keychain Sharing,因為這些項目是“僅設備”
這個示例項目可能會有所幫助,標題是KeychainTouchID:使用Touch ID和Keychain以及LocalAuthentication :
https://developer.apple.com/library/ios/samplecode/KeychainTouchID/Introduction/Intro.html
這可能僅限於本地,不分享。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.