Xamarin iOS add value to KeyChain which can be accessed by all apps on device

给你一囗甜甜゛ 提交于 2021-02-17 01:57:07

问题


I've created a new question for this since this is more linked to Xamarin. I was looking for a way to uniquely identify a device in iOS when I stumbled upon this question in StackOverflow. It took me a while to figure out how to add anything into Keychain and them I stumbled upon this question.

After all the stumbling, I came up with this piece of code for generating the unique token.

var s = new SecRecord(SecKind.GenericPassword)
            {
                AccessGroup = "kSecAttrAccessGroupToken",
                ValueData = NSData.FromString(value),
                Generic = NSData.FromString(key)
            };
            SecKeyChain.Add(s);

Now the problem is that even though I'm adding this entry to keychain I am unable to find it. I'm also interested to know if I am using the kSecAttrAccessGroupToken correctly.

My Enlistments.plist file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>keychain-access-groups</key>
    <array>
        <string>my app id</string>
        <string>kSecAttrAccessGroupToken</string>
    </array>
</dict>
</plist>

回答1:


kSecAttrAccessGroupToken is writable only by CryptoTokenKit smart card drivers. Apps can query the keychain using that attribute in order to find items stored on a particular smart card. This attribute is not for any other use.

There was a bug in 10.3.x beta that would allow any app to also write to it, but that has been patched.

Re: https://forums.developer.apple.com/thread/72271



来源:https://stackoverflow.com/questions/46396533/xamarin-ios-add-value-to-keychain-which-can-be-accessed-by-all-apps-on-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!