无法识别iOS OSStatus代码

前端之家收集整理的这篇文章主要介绍了无法识别iOS OSStatus代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在iOS应用程序中有一个非常奇怪的行为.
我从iOS 6切换到iOS 7.在iOS 6中,一切都很完美.
  1. - (NSMutableDictionary *)newSearchDictionary:(NSString *)identifier {
  2. NSMutableDictionary *searchDictionary = [[NSMutableDictionary alloc] init];
  3.  
  4. [searchDictionary setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass];
  5.  
  6. NSData *encodedIdentifier = [identifier dataUsingEncoding:NSUTF8StringEncoding];
  7. [searchDictionary setObject:encodedIdentifier forKey:(__bridge id)kSecAttrGeneric];
  8. [searchDictionary setObject:encodedIdentifier forKey:(__bridge id)kSecAttrAccount];
  9. [searchDictionary setObject:serviceName forKey:(__bridge id)kSecAttrService];
  10.  
  11. return searchDictionary;
  12. }
  13.  
  14. - (NSData *)searchKeychainCopyMatching:(NSString *)identifier {
  15. NSMutableDictionary *searchDictionary = [self newSearchDictionary:identifier];
  16.  
  17. [searchDictionary setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit];
  18. [searchDictionary setObject:(id)kcfBooleanTrue forKey:(__bridge id)kSecReturnData];
  19.  
  20. CFDataRef dataRef;
  21. OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary,(CFTypeRef *)&dataRef);
  22.  
  23. if (status != errSecSuccess) {
  24. #ifdef DEBUG
  25. NSLog(@"%s - No OSStatus errSecSuccess. Caused by SecItemCopyMatching",__PRETTY_FUNCTION__);
  26. #endif
  27. return nil;
  28. }
  29. NSData *result = (__bridge_transfer NSData *)dataRef;
  30. return result;
  31. }

当应用程序启动时 – (NSData *)searchKeychainCopyMatching:(NSString *)标识符函数从keychain加载值.一切都运行良好一段时间.但在大约15次成功的价值请求后,我收到了一个错误.

OSStatus代码-34018

SecItemCopyMatching函数返回该错误代码.文件

@result一个结果代码.请参阅“安全错误代码”(SecBase.h).

但是在SecBase.h中查看只指定了这些OSStatus代码.

  1. enum
  2. {
  3. errSecSuccess = 0,/* No error. */
  4. errSecUnimplemented = -4,/* Function or operation not implemented. */
  5. errSecIO = -36,/*I/O error (bummers)*/
  6. errSecOpWr = -49,/*file already open with with write permission*/
  7. errSecParam = -50,/* One or more parameters passed to a function where not valid. */
  8. errSecAllocate = -108,/* Failed to allocate memory. */
  9. errSecUserCanceled = -128,/* User canceled the operation. */
  10. errSecBadReq = -909,/* Bad parameter or invalid state for operation. */
  11. errSecInternalComponent = -2070,errSecNotAvailable = -25291,/* No keychain is available. You may need to restart your computer. */
  12. errSecDuplicateItem = -25299,/* The specified item already exists in the keychain. */
  13. errSecItemNotFound = -25300,/* The specified item could not be found in the keychain. */
  14. errSecInteractionNotAllowed = -25308,/* User interaction is not allowed. */
  15. errSecDecode = -26275,/* Unable to decode the provided data. */
  16. errSecAuthFailed = -25293,/* The user name or passphrase you entered is not correct. */
  17. };

已经检查过的值不会被覆盖.

最后但并非最不重要的搜索词典:

编辑 – 新信息

我整天都在调试,我发现了一些消息.我正在下载包含可执行Bundle的Zip文件.这是一个内部应用程序,因此不必担心审查指南中的第2.7和2.8点.成功加载捆绑包后,将显示权利错误.

  1. NSBundle *bundle = nil;
  2. NSError *error = nil;
  3. bundle = [[NSBundle alloc] initWithPath:bundlePath];
  4. if (!bundle) {
  5. return nil;
  6. }
  7.  
  8. // Here i can access the keychain as usually
  9. [bundle loadAndReturnError:&error];
  10. // Well here it suddenly doesn't work anymore
  11. // error is also nil

那么内部的包代码不使用钥匙串.可能这是某种安全逻辑?有什么线索吗?

解决方法

错误表示您的应用的权利存在问题.找到 this:原因通常是应用程序权利中的应用程序标识符前缀与配置文件中的应用程序标识符前缀不匹配.

要进行验证,请使用codesign工具查看应用的权利:

  1. codesign -d --entitlements - MyApp.app/

然后,将应用程序标识符前缀与配置文件中的应用程序标识符前缀进行比较:

  1. cat MyApp.app/embedded.mobileprovision

猜你在找的iOS相关文章