New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Could not save account to KeyChain -- iOS 10 #128

Closed
jimnorth55 opened this Issue Sep 15, 2016 · 20 comments

Comments

Projects
None yet
@jimnorth55
Copy link

jimnorth55 commented Sep 15, 2016

Environment:

  • Visual Studio 2015
  • Xamarin (VS) 4.2.680
  • Xamarin.Auth 1.2.3.1
  • Xamarin Studio (Mac) 6.1.5441
  • Xamarin.iOS 10.0.0.6
  • XCode 8.0 (8A218a

After update to XCode 8 (iOS 10), application throws the following exception on call to AccountStore.Save.

System.Exception: Could not save account to KeyChain: -34018

@aweFalafel

This comment has been minimized.

Copy link

aweFalafel commented Sep 16, 2016

I to am having this issue. Here's a bit more detail:

System.ArgumentNullException: Value cannot be null.
Parameter name: data
  at Foundation.NSString.FromData (Foundation.NSData data, Foundation.NSStringEncoding encoding) [0x00026] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/src/Foundation/NSString2.cs:94 
  at Xamarin.Auth.KeyChainAccountStore.GetAccountFromRecord (Security.SecRecord r) [0x00006] in <402cf9b3716845b3bdddef581cb33a3e>:0 
  at System.Linq.Enumerable+WhereSelectArrayIterator`2[TSource,TResult].MoveNext () [0x0004d] in <45ddf04144214dd89fc1e7215a8a94aa>:0 
  at System.Collections.Generic.List`1[T]..ctor (System.Collections.Generic.IEnumerable`1[T] collection) [0x0008b] in <cc958e60dbab45a48329f27123804526>:0 
  at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00011] in <45ddf04144214dd89fc1e7215a8a94aa>:0 
  at Xamarin.Auth.KeyChainAccountStore.FindAccountsForService (System.String serviceId) [0x00034] in <402cf9b3716845b3bdddef58
1cb33a3e>:0
@aweFalafel

This comment has been minimized.

Copy link

aweFalafel commented Sep 16, 2016

I've reverted to 1.3.0 from Nuget and all seems to be working properly.

@jimnorth55

This comment has been minimized.

Copy link
Author

jimnorth55 commented Sep 16, 2016

Pardon, but it was not clear... 1.3.0 of which Nuget package?

@aweFalafel

This comment has been minimized.

Copy link

aweFalafel commented Sep 16, 2016

@jimnorth55

This comment has been minimized.

Copy link
Author

jimnorth55 commented Sep 16, 2016

Interesting that this repository shows the latest release as 1.2.2 dated back in 2013. I had installed as a Component from the Xamarin site a couple of months ago and was running 1.2.3.1. Is this not the repository for the Xamarin.Auth package? It seems not.

At any rate, I removed the Component and installed from Nuget, first the latest 1.3.1.1 and got the Exception as expected. Reverted to 1.3.0 as suggested. Still fails with the -34018 code.

@mstrong64

This comment has been minimized.

Copy link

mstrong64 commented Sep 20, 2016

I did all the updates and the problem still occurred, but only on the simulator. The device works fines which is strange. However, I have managed to fix this on the simulator by adding Entitlements.plist to the iOS project (File -> New file -> iOS -> Entitlements.plist). When you edit that file you will be able to select "Enable Keychain Access Groups". You will also need to add the entitlements.plist to the custom entitlements entry in the project options. (Project Options -> iOS Bundle Signing, then select Configuration: Debug / Platform: iPhoneSimulator and enter "Entitlements.plist" into the Custom Entitlements field.)

@beeradmoore

This comment has been minimized.

Copy link

beeradmoore commented Sep 22, 2016

@mstrong64 , your answer fixed it for me. Our debug builds on our new Xamarin.Forms app was missing the Entitlements.plist

EDIT:
@jimnorth55 , I think the code updates are committed in their bait and switch branch, not in the master branch.
https://github.com/xamarin/Xamarin.Auth/tree/portable-bait-and-switch

@zengable

This comment has been minimized.

Copy link

zengable commented Oct 13, 2016

This helped me out as well, thanks!

@moljac

This comment has been minimized.

Copy link
Member

moljac commented Oct 13, 2016

@jimnorth55 The Component store version does not match, because samples became more complex and packaging is not trivial. We are working on that.
Current version is on nuget
http://www.nuget.org/packages/Xamarin.Auth/1.3.1.1

The reason that it has not been merged to master is simple - a lot changed (Windows platforms mostly) and we need more time for testing.

@mstrong Seems that there is a bug in iOS10 simulator.

From hockeyapp team:

https://www.hockeyapp.net/blog/2016/09/13/hockeysdk-ios-4-1-1-macos-tvos-4-1-0.html
https://support.hockeyapp.net/discussions/problems/63710-the-authentication-token-could-not-be-stored-due-to-a-keychain-error

Seems like firebase is hit by the same problem:
https://firebase.googleblog.com/2016/08/ios-10-xcode-8-and-swift-3.html
http://stackoverflow.com/questions/38456471/secitemadd-always-returns-error-34018-in-xcode-8-in-ios-10-simulator

@LuigiMaestrelli

This comment has been minimized.

Copy link

LuigiMaestrelli commented Oct 29, 2016

Any news about this issue?
I'm facing the same problem.
I'm testing on iOS 10.1.
Testing on 9.3 works

@aimore

This comment has been minimized.

Copy link

aimore commented Nov 2, 2016

@mstrong64 I did this, now it creates a new keychain, but still one issue to delete the keychain after logout... and to retrieve stored accounts does not work properly.
PS: just on iOS 10.0

@sinhan23

This comment has been minimized.

Copy link

sinhan23 commented Feb 3, 2017

i got this issue when build project after add entitlements.
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets: Error: No installed provisioning profiles match the installed iOS signing identities.

Isn;t iphone simulator in debug mode does not need any provision installed? why it shows this error when build project?

@joseprl89

This comment has been minimized.

Copy link

joseprl89 commented Feb 13, 2017

Just an addendum, I believe this is a change in iOS10 that to use the Keychain it requires to define it in Entitlements.plist.

Make sure that all your configurations are set up to use entitlements.plist, not only Debug | iPhone as mentioned above, but also Debug | iPhone Simulator and Release | iPhone, Release | iPhone Simulator.

We had to track what was going on when building a Release in an iphone simulator and eventually realised the entitlements wasn't there.

@shribits

This comment has been minimized.

Copy link

shribits commented Feb 16, 2017

"Enable key chain access group" in entitlements for Release | iPhone, Release | iPhone Simulator is throwing this error:
"Your code signing/provisioning profiles are not correctly configured. Probably you have an entitlement not supported by your current provisioning profile, or your device is not part of the current provisioning profile. Please check the iOS Device Log for details (error: 0xe8008016)."

@14skywalker

This comment has been minimized.

Copy link

14skywalker commented Feb 21, 2017

Yes @shribits, all solutions to this type of error suggest to remove the Entitlements.plist. Mine is No installed provisioning profiles match the installed iOS signing identities.

Seems like a #catch22 to me. Anyone?

@shribits

This comment has been minimized.

Copy link

shribits commented Feb 22, 2017

Hi @14skywalker,
I have fixed mine. It's working fine now.
Had to update the Xamarin.Auth to the lastest version .
Also had few other issues with xlabs, pre-release version work fine.

@gustblima

This comment has been minimized.

Copy link

gustblima commented Mar 9, 2017

I can't see where do i Enable Keychan Access Group

@prankard

This comment has been minimized.

Copy link

prankard commented Mar 28, 2017

I had issues with not installing on my device with Entitlements.plist.
It's because when I added 'Enable Keychain' in the Entitlements.plist. By default, it adds your app name 'com.company.appname' to keychain groups aswell. It enables saving to the keychain and allowing other apps to access the data via a key.
But that requires more permissions in the 'App Id' section on Apple's certificate side.
So removing that fixed my issue. Hope this helps other people.

@tobber72

This comment has been minimized.

Copy link

tobber72 commented Apr 11, 2017

I found a solution (which works for me :-)) on this page: http://stackoverflow.com/a/40249263/2366321

Do not add Entitlements.plist to your Debug iPhoneSimulator configuration, instead: Add an Environment Variable to your Debug iPhoneSimulator configuration named ENTITLEMENTS_REQUIRED and set the value to YES. This will cause Xcode to automatically insert an application-identifier entitlement when building.

@moljac

This comment has been minimized.

Copy link
Member

moljac commented May 27, 2017

Closing.

References (duplicates):

  • 139 Could not save account to KeyChain: -34018
    #139
  • 133 System.Exception: Could not save account to KeyChain: -34018
    on iOS Simulator 7 OS 10.1
    #133
  • 128 Error: Could not save account to KeyChain -- iOS 10
    #128

Analysis

This problem is not Xamarin related: seems like this is bug in iOS 10 simulator and XCode (8.x).

https://forums.developer.apple.com/thread/4743?tstart=0
https://forums.developer.apple.com/thread/51071
https://stackoverflow.com/questions/27752444/ios-keychain-writing-value-results-in-error-code-34018
https://stackoverflow.com/questions/22082996/testing-the-keychain-osstatus-error-34018
https://stackoverflow.com/questions/38456471/secitemadd-always-returns-error-34018-in-xcode-8-in-ios-10-simulator
https://stackoverflow.com/questions/29740952/osstatus-error-code-34018

[Re]Solution / Workaround

If not present create empty Entitlements.plist

<?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>
</dict>
</plist>

Entitlements.plist must be added to iOS Bundle Signing options for the iPhoneSimulator|Debug
platform.

iOS App Options/Properties +/ Build / iOS Bundle Signing +/ Custom Entitlements : Entitlements.plist

This will result in following code in *.csproj file:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\iPhone\Debug</OutputPath>
    <DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <ConsolePause>false</ConsolePause>
    <MtouchArch>ARMv7, ARM64</MtouchArch>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
    <MtouchFloat32>true</MtouchFloat32>
    <CodesignKey>iPhone Developer</CodesignKey>
    <DeviceSpecificBuild>true</DeviceSpecificBuild>
    <MtouchDebug>true</MtouchDebug>
    <MtouchProfiling>true</MtouchProfiling>
    <IpaPackageName>
    </IpaPackageName>
  </PropertyGroup>

while default *.csproj file looks like this

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
    <DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <CodesignKey>iPhone Developer</CodesignKey>
    <DeviceSpecificBuild>true</DeviceSpecificBuild>
    <MtouchDebug>true</MtouchDebug>
    <MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
    <MtouchFastDev>true</MtouchFastDev>
    <IOSDebuggerPort>50317</IOSDebuggerPort>
    <MtouchLink>None</MtouchLink>
    <MtouchArch>i386, x86_64</MtouchArch>
    <MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
  </PropertyGroup>

NOTE: difference is in this file:

    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>

@moljac moljac closed this May 27, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment