5

我正在尝试从具有相同标识符(相同配置文件)的另一个应用程序访问应用程序设置的钥匙串数据。我使用这个链接来实现这一点。

钥匙串数据的保存正常进行,我得到以下语句的 errSecSuccess (在模拟器和设备中)

OSStatus status = SecItemAdd((CFDictionaryRef)dictionary, NULL);

到目前为止一切都很好,但是当我试图取回我的应用程序 A 保存在另一个应用程序 B 中的凭据时,它在模拟器和设备中的工作方式不同。

在 iOS 模拟器 6.1 中,以下语句的状态为“0”。

 OSStatus status = SecItemCopyMatching((CFDictionaryRef)searchDictionary, &foundDict);

在任何 iOS 设备中,我的状态都是“-25300”。

我知道这些是安全框架中的错误代码:

//errSecSuccess                = 0,       /* No error. */
//errSecUnimplemented          = -4,      /* Function or operation not implemented. */
//errSecParam                  = -50,     /* One or more parameters passed to a function where not valid. */
//errSecAllocate               = -108,    /* Failed to allocate memory. */
//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. */

我明白了,找不到该项目,但为什么在设备和模拟器中有所不同。

4

1 回答 1

3

据我所知,您在应用程序中处理的钥匙串组默认情况下不会在系统上的其他应用程序之间共享。如果是这种情况,则意味着如果您设法找到另一个应用程序的组,您可以窃取他们的私有钥匙串项目,从而使钥匙串提供的安全性无效。

因此,有一个称为 Keychain Access Groups 的概念,它允许公开定义您希望在您的应用程序之间共享的 keychain 组。该文档指出:

启用钥匙串共享允许您的应用与您团队开发的其他应用共享钥匙串中的密码

因此请注意,您只能与来自同一开发人员的其他应用程序(即您的其他应用程序)共享钥匙串项。

于 2014-11-16T15:42:15.240 回答