Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Crash with Xamarin.Auth 1.6.0.2 opening the default AccountStore

XavierPerseguersXavierPerseguers CHMember ✭✭✭

Hello,

Looks like since I upgraded Xamarin.Auth my application is now crashing at startup with a Java.IO.IOException "KeyStore integrity check failed.".

I found that the method signature to fetch an existing AccountStore changed a bit and one is now supposed to provide a custom password:

var password = "1234567890ABCDEF...";
var account = AccountStore.Create(LocalContext, password).FindAccountsForService("My Application").FirstOrDefault();

before it was:

var account = AccountStore.Create(LocalContext).FindAccountsForService("My Application").FirstOrDefault();

However, I get the aforementioned exception and it crashes my app at startup (since I try to read some settings).

I found this code to migrate old content to a new AccountStore: https://github.com/xamarin/Xamarin.Auth/pull/56/commits/f0aad93c37cb5bbcdeb56e59ecf7f9cb9ffbf48c

However it does not help.

My questions:

  1. How can I just throw every associated AccountStore without getting the exception? I'm fine not "migrating" but cannot open the old AccountStore even if I provide the password supposed to be the old default one as in the pull request.
  2. Is there anything else I should know?
  3. That's cool not to have a default hardcoded password but if my app now hardcode its own password, I'm really not sure this is "better" since this may be most probably easily bet read by opening the binary. So what would be the best way to choose some password to use for storing secret settings for my app?

Thanks.

Best Answers

  • XavierPerseguersXavierPerseguers CHMember ✭✭✭
    Accepted Answer

    @NicholasFritsche AccountStore.Create (context, password) does not take a char[] but a string as argument, so this does not work.

    @GarrettWelshons Indeed! Looks like this prevent the crash:

    Account account = null;
    try {
        account = AccountStore.Create(LocalContext, "System.Char[]").FindAccountsForService("My APP").FirstOrDefault();
    } catch (Java.IO.IOException ex) {
        // This part is not invoked anymore once I use the suggested password.
    }
    

    Successfully tested on a Samsung S7 Edge (LineageOS 14.1 with Android 7.1.2) and a Huawei (Android 5.1).

    Thanks a bunch!

Answers

  • NicholasFritscheNicholasFritsche USMember ✭✭

    Make sure your default password variable is
    static readonly char[] DefaultPassword = "3295043EA18CA264B2C40E0B72051DEF2D07AD2B4593F43DDDE1515A7EC32617".ToCharArray();
    and NOT this
    static readonly string DefaultPassword = "3295043EA18CA264B2C40E0B72051DEF2D07AD2B4593F43DDDE1515A7EC32617";

  • XavierPerseguersXavierPerseguers CHMember ✭✭✭
    Accepted Answer

    @NicholasFritsche AccountStore.Create (context, password) does not take a char[] but a string as argument, so this does not work.

    @GarrettWelshons Indeed! Looks like this prevent the crash:

    Account account = null;
    try {
        account = AccountStore.Create(LocalContext, "System.Char[]").FindAccountsForService("My APP").FirstOrDefault();
    } catch (Java.IO.IOException ex) {
        // This part is not invoked anymore once I use the suggested password.
    }
    

    Successfully tested on a Samsung S7 Edge (LineageOS 14.1 with Android 7.1.2) and a Huawei (Android 5.1).

    Thanks a bunch!

  • PhilippGayko.9736PhilippGayko.9736 CHMember ✭✭

    Accepted suggestion doesn't work in my case.

Sign In or Register to comment.