keychain-swift icon indicating copy to clipboard operation
keychain-swift copied to clipboard

Creating "synchronizable" entries on OS X fails

Open orchetect opened this issue 9 years ago • 8 comments

Not sure what is amiss here. I'm on OS X 10.11.5, Xcode 8 beta 2, Swift 3.

This works fine: keychain.set("Value", forKey: "KeyName") // returns true keychain.get("KeyName") // returns "Value"

But this fails to create new entries in the keychain (assuming key does not yet exist): keychain.synchronizable = true if keychain.set("Value", forKey: "KeyName") { print("success") } else { print("failed") }

The .set function returns false and the key fails to be created.

orchetect avatar Jul 18 '16 05:07 orchetect

Hi @orchetect, thank you for reporting. I have never actually tested the synchronization in OS X, only in iOS. If you still have the code nearby, what error code does the set method return?

keychain.set("Value", forKey: "KeyName")
print(keychain.lastResultCode)

evgenyneu avatar Jul 19 '16 10:07 evgenyneu

I tested keychain synchronization on macOS and could not make it work. Function SecItemAdd returns -34018 result code on macOS when kSecAttrSynchronizable is true.

Added a macOS demo app to the project as well.

keychain_demo_mac_os

evgenyneu avatar Jul 20 '16 09:07 evgenyneu

I have the same issue.

grosch avatar Aug 05 '16 05:08 grosch

Is this a KeyChain bug? Will this problem also occur if I use the KeyChain API from Apple directly without using this library?

funkenstrahlen avatar Feb 23 '17 07:02 funkenstrahlen

Good question. I have no idea. Based on my tests, the iCloud synchronization in this library works on iOS but not on macOS.

Here is another question that I want to know the answer to. Does macOS support iCloud keychain synchronization at all? If it does then we aren't using it correctly in this library.

evgenyneu avatar Feb 23 '17 08:02 evgenyneu

macOS does support it.

Apple's docs for macOS Sierra state:

Developer ID-signed apps can now take advantage of CloudKit, iCloud Keychain, ...

I'm building apps with a free Apple Dev account. Do you suppose that's why it's not working? Maybe it requires a paid Developer account with proper certificate signing.

orchetect avatar Apr 11 '17 07:04 orchetect

Have there been any updates on this?

fishcharlie avatar Nov 19 '18 18:11 fishcharlie

This issue seems to be fixed when adding "Keychain Sharing" to the macOS App Target Capabillities (it's off by default). After this Xcode will need to generate a provision profile with this capability and the error will disappear.

joaocolaco avatar Jan 26 '19 22:01 joaocolaco