Bug 41516 - SecKeychain.Update always error with Param as SecStatusCode
Summary: SecKeychain.Update always error with Param as SecStatusCode
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.6 (iOS 9.3)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Alex Soto [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2016-06-05 14:44 UTC by Steven M
Modified: 2016-06-08 15:10 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Steven M 2016-06-05 14:44:19 UTC
SecKeyChain.Update seems to fail all the time. 

Include test application at https://github.com/smoy/Xamarin.iOS.KeyChainTest

I found a related ticket but it has been out of date for a long time: https://bugzilla.xamarin.com/show_bug.cgi?id=27311
Comment 1 Alex Soto [MSFT] 2016-06-07 05:20:51 UTC
I can reproduce the behaviour using the provided test case, still, I am not sure this is our bug, have you tried to reproduce this code in ObjC? Most of the time param means that something was wrong with the provided info in the dictionary. Will dig a little more with your sample code
Comment 2 Alex Soto [MSFT] 2016-06-08 06:51:27 UTC
After a little of head scratching and some blog posts about the subject (Because this api is really not well documented) I found the issue.

I was on the right track (no bug on Xamarin.iOS) the dictionary (SecRecord) you are sending in you sample is (just a little) wrong, you are supposed to send only the properties you are supposed to update. So in your sample you have the following code to create the new SecRecord with the info you want to update:

>      // try updating
>      SecRecord newSecret = new SecRecord(SecKind.GenericPassword)
>      {
>          Generic = TestNewSecret
>      };

This will generate a dictionary with two values, one being Generic and a second one containing the SecKind. This is why update is complaining because it does not like you sending the SecKind info. By removing that from the ctor you get a dictionary (SecRecord) only with the info you want to update and now update works.

>      // try updating
>      SecRecord newSecret = new SecRecord {
>          Generic = TestNewSecret
>      };

This blog post[1] while a little old I found it to be really nice in this subject, hope it helps.

[1]: http://useyourloaf.com/blog/simple-iphone-keychain-access/
Comment 3 Steven M 2016-06-08 15:10:46 UTC
Thank you so much, the prescribed change you suggested nailed it. Thank you for your assistance.