[英]Unable to identify iOS OSStatus Code
我在iOS應用程序中有一個非常奇怪的行為。 我從iOS 6切換到iOS7。在iOS 6中,一切正常。
- (NSMutableDictionary *)newSearchDictionary:(NSString *)identifier {
NSMutableDictionary *searchDictionary = [[NSMutableDictionary alloc] init];
[searchDictionary setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass];
NSData *encodedIdentifier = [identifier dataUsingEncoding:NSUTF8StringEncoding];
[searchDictionary setObject:encodedIdentifier forKey:(__bridge id)kSecAttrGeneric];
[searchDictionary setObject:encodedIdentifier forKey:(__bridge id)kSecAttrAccount];
[searchDictionary setObject:serviceName forKey:(__bridge id)kSecAttrService];
return searchDictionary;
}
- (NSData *)searchKeychainCopyMatching:(NSString *)identifier {
NSMutableDictionary *searchDictionary = [self newSearchDictionary:identifier];
[searchDictionary setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit];
[searchDictionary setObject:(id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData];
CFDataRef dataRef;
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary,
(CFTypeRef *)&dataRef);
if (status != errSecSuccess) {
#ifdef DEBUG
NSLog(@"%s - No OSStatus errSecSuccess. Caused by SecItemCopyMatching", __PRETTY_FUNCTION__);
#endif
return nil;
}
NSData *result = (__bridge_transfer NSData *)dataRef;
return result;
}
當應用程序啟動時, -(NSData *)searchKeychainCopyMatching:(NSString *)identifier函數從鑰匙串加載值。 一切正常一段時間。 但是在大約15個成功的值請求之后,我得到了一個錯誤。
OSStatus代碼-34018
SecItemCopyMatching函數返回該錯誤代碼。 該文件說
@result結果代碼。 請參閱“安全錯誤代碼”(SecBase.h)。
但是在SecBase.h中,僅指定了這些OSStatus代碼。
enum
{
errSecSuccess = 0, /* No error. */
errSecUnimplemented = -4, /* Function or operation not implemented. */
errSecIO = -36, /*I/O error (bummers)*/
errSecOpWr = -49, /*file already open with with write permission*/
errSecParam = -50, /* One or more parameters passed to a function where not valid. */
errSecAllocate = -108, /* Failed to allocate memory. */
errSecUserCanceled = -128, /* User canceled the operation. */
errSecBadReq = -909, /* Bad parameter or invalid state for operation. */
errSecInternalComponent = -2070,
errSecNotAvailable = -25291, /* No keychain is available. You may need to restart your computer. */
errSecDuplicateItem = -25299, /* The specified item already exists in the keychain. */
errSecItemNotFound = -25300, /* The specified item could not be found in the keychain. */
errSecInteractionNotAllowed = -25308, /* User interaction is not allowed. */
errSecDecode = -26275, /* Unable to decode the provided data. */
errSecAuthFailed = -25293, /* The user name or passphrase you entered is not correct. */
};
值不會被覆蓋,已經檢查。
最后但並非最不重要的搜索字典:
編輯-新信息
我整天都在調試,發現了一些消息。 我正在下載一個包含可執行包的Zip文件。 這是一個內部應用程序,因此無需擔心審核指南中的第2.7和2.8點。 成功加載捆綁軟件后,將顯示權利錯誤。
NSBundle *bundle = nil;
NSError *error = nil;
bundle = [[NSBundle alloc] initWithPath:bundlePath];
if (!bundle) {
return nil;
}
// Here i can access the keychain as usually
[bundle loadAndReturnError:&error];
// Well here it suddenly doesn't work anymore
// error is also nil
好吧,里面的捆綁代碼不使用鑰匙串。 可能這是某種安全邏輯嗎? 有什么線索嗎?
此錯誤表示您的應用的權利存在問題。 發現這一點 :原因通常是應用授權中的應用標識符前綴與供應配置文件中的應用標識符前綴不匹配。
要進行驗證,請使用代碼簽名工具查看您的應用的權利:
codesign -d --entitlements - MyApp.app/
然后,將“ App Identifier Prefix”(應用程序標識符前綴)與供應配置文件中的前綴進行比較:
cat MyApp.app/embedded.mobileprovision
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.