不恢复 iOS 钥匙串中插入的密码问题

发布于 2024-12-06 07:50:34 字数 1090 浏览 1 评论 0原文

我正在为 iPad2 开发一个应用程序,需要在钥匙串中写入一些项目,但我不希望它在我插入的每台计算机中进行复制,从而对设备进行备份/恢复。我使用 kSecAttrAccessible 键来选择我想要的可访问性类型,并使用 kSecAttrAccessibleWhenUnlockedThisDeviceOnly 值来确保如果我对设备中的所有内容进行备份,则钥匙串不会出现在该备份中。

所以我以这种方式进行:我重置钥匙串,在钥匙串中插入一个项目并转储钥匙串的所有内容,所以我看到该项目在那里。然后我对 iPad 进行备份。我重置了钥匙串并恢复了备份,因此只要恢复过程不处理钥匙串,钥匙串中就不应该有任何钥匙。下次运行该应用程序时,我会转储钥匙串的内容,并且密钥就在那里,因此它无法正常工作。我正在使用 iphone-lib (http://code.google.com/p/iphone-lib/) 转储和重置 iPad 中的凭据。我的SDK版本是4.3。

我用来在钥匙串中插入项目的代码如下:

NSMutableDictionary *dic = [NSMutableDictionary dictionary];
NSData* identifier = [@"mypassword" dataUsingEncoding: NSASCIIStringEncoding];
[dic setObject:(id)kSecAttrAccessibleWhenUnlockedThisDeviceOnly forKey:(id)kSecAttrAccessible];
[dic setObject:identifier forKey:(id)kSecAttrGeneric];
[dic setObject:@"myaccount" forKey:(id)kSecAttrAccount];
[dic setObject:@"myservice" forKey:(id)kSecAttrService];
[dic setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
[dic setObject:identifier forKey:(id)kSecValueData];
OSStatus error = SecItemAdd((CFDictionaryRef)dic, NULL);

谢谢!

I'm developing an application for an iPad2 that needs to write some items in Keychain but I don't want it replicates in every computer I plug, doing a backup/restore of the device. I'm using kSecAttrAccessible key to select the kind of accesibility I want with kSecAttrAccessibleWhenUnlockedThisDeviceOnly value to be sure that if I do a backup of all things that are in the device, the Keychain is not going to be present in that backup.

So I proceed in this way: I reset the Keychain, insert a item in Keychain and dump all the content of Keychain, so I see that the item is there. Then I do a backup of the iPad. I reset the Keychain and restore the backup so no key should be in the Keychain as long as the restore procedure doesn't deal with the Keychain. Next time I run the application, I dump the contents of the Keychain and the key is there, so it's not working as it should. I'm using iphone-lib (http://code.google.com/p/iphone-lib/) to dump and reset credentials in my iPad. My SDK version is 4.3.

The code I use to insert the item in the Keychain is the following:

NSMutableDictionary *dic = [NSMutableDictionary dictionary];
NSData* identifier = [@"mypassword" dataUsingEncoding: NSASCIIStringEncoding];
[dic setObject:(id)kSecAttrAccessibleWhenUnlockedThisDeviceOnly forKey:(id)kSecAttrAccessible];
[dic setObject:identifier forKey:(id)kSecAttrGeneric];
[dic setObject:@"myaccount" forKey:(id)kSecAttrAccount];
[dic setObject:@"myservice" forKey:(id)kSecAttrService];
[dic setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
[dic setObject:identifier forKey:(id)kSecValueData];
OSStatus error = SecItemAdd((CFDictionaryRef)dic, NULL);

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满身野味 2024-12-13 07:50:34

Apple 有两个很酷的示例(带有工作示例代码),帮助我了解钥匙串服务在 iOS 上的工作原理。我建议您查看它们,并希望它们能帮助您解决您的问题:

  1. 通用钥匙串此示例演示如何添加、查询、删除和更新泛型类类型。还演示了共享钥匙串项目的使用。所有类都表现出非常相似的行为,因此包含的示例将扩展到钥匙串项目的其他类:Internet 密码、证书、密钥和身份。
  2. AdvancedURLConnections此示例演示了使用 NSURLConnection 的各种高级网络技术。具体来说,它演示了如何响应身份验证质询、如何修改默认服务器信任评估(例如,支持具有自签名证书的服务器)以及如何提供客户端身份。

There two cool examples (with working sample code) from Apple, that helped me to understand how keychain service works on iOS. I suggest you to look at them, and hope they will help you to resolve your issue:

  1. Generic Keychain : This sample shows how to add, query for, remove, and update a keychain item of generic class type. Also demonstrates the use of shared keychain items. All classes exhibit very similar behavior so the included examples will scale to the other classes of Keychain Item: Internet Password, Certificate, Key, and Identity.
  2. AdvancedURLConnections : This sample demonstrates various advanced networking techniques with NSURLConnection. Specifically, it demonstrates how to respond to authentication challenges, how to modify the default server trust evaluation (for example, to support a server with a self-signed certificate), and how to provide client identities.
信仰 2024-12-13 07:50:34

kSecAttrAccessibleWhenUnlockedThisDeviceOnly 可能是原因。

你可以尝试别的吗?

例如。 kSecAttrAccessibleWhenUnlocked

kSecAttrAccessibleWhenUnlockedThisDeviceOnly maybe the reason.
Can you try something else?

eg. kSecAttrAccessibleWhenUnlocked

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文