iOS SFHFKeychainUtils失败*有时*错误-25308 errSecInteractionNotAllowed [英] iOS SFHFKeychainUtils failing *sometimes* with error -25308 errSecInteractionNotAllowed

查看:888
本文介绍了iOS SFHFKeychainUtils失败*有时*错误-25308 errSecInteractionNotAllowed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码从钥匙串中取回给定用户名NSString的密码:

I have this code getting back a password from the keychain for a given username NSString:

NSError *error = nil;
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];
NSString *pw = [SFHFKeychainUtils getPasswordForUsername:username andServiceName:appName error:&error];
if(error != nil)
    // log the error    

大多数大多数用户的时间一切正常 - 但对于某些特定用户来说,这个调用似乎失败了(并继续失败),它返回以下错误:

Most of the time for most users this all works fine - but for some specific users this call seems to fail (and carry on failing) where it returns the following error:

The operation couldn’t be completed. (SFHFKeychainUtilsErrorDomain error -25308.)

这显然是errSecInteractionNotAllowed - 从我读过的内容我想想这意味着要访问钥匙串需要某种用户交互。

This is apparently errSecInteractionNotAllowed - which from what I've read I think this means some kind of user interaction is required for the keychain to be accessed.

有没有人知道为什么这个电话可能会失败?仅限某些特定用户?这个钥匙串条目特定于我的应用程序 - 那么为什么要访问它需要任何用户交互?

Does anyone have any idea why this call may be failing for some specific users only? This keychain entry is specific to my app - so why would any user interaction be required to access it?

任何指针都非常赞赏......

Any pointers much appreciated...

推荐答案

好的,所以我最终解决了这个问题。

OK so I worked this out finally.

最终我找到了有用户问题在他们的手机上设置了锁码。如果手机被锁定,钥匙串系统会返回-25308错误。

Eventually I worked out the users who were having problems had set a lock code on their phone. If the phone was locked the keychain system was returning this -25308 error.

如果您只需要在应用程序在forground中处于活动状态时访问钥匙串,您将永远不会看到这个问题 - 但如果您需要在手机锁定或应用程序处于后台时进行处理,那么您会看到它。

If you only ever need to access the keychain when the app is active in the forground you would never see this issue - but if you need to carry on processing when the phone is locked or if the app is in background then you would see it.

在其他地方我读过kechain系统的默认访问属性是kSecAttrAccessibleAlways - 但我认为这已经过时了。似乎钥匙串系统的默认访问属性是这样的,当手机被密码锁定时,这些项目就不可用了。

Elsewhere I'd read that the default access attribute for the kechain system is kSecAttrAccessibleAlways - but I think that is out of date. It seems the default access attribute for the keychain system is such that when the phone is locked with a pin code then the items are unavailable.

修复此问题的方法是更改SFHFKeychainUtils代码在它管理的钥匙串项目上设置一个特定的kSecAttrAccessible属性(原始代码没有这样做 - 可能是因为它早于这些属性)。

The fix for this is to change the SFHFKeychainUtils code to set a specific kSecAttrAccessible attribute on the keychain items it manages (which the original code did not do - presumably as it pre-dated these attributes).

这个wordpress 更新版本 SFHFKeychainUtils代码中包含修复程序 - 搜索kSecAttrAccessible以查看它们添加了可访问属性代码的位置。

This wordpress updated version of the SFHFKeychainUtils code has the fixes in it - search for kSecAttrAccessible to see where they have added the accessible attribute code.

希望这可以帮助其他任何人遇到此...

Hope this helps anyone else running into this...

这篇关于iOS SFHFKeychainUtils失败*有时*错误-25308 errSecInteractionNotAllowed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆