Essentials icon indicating copy to clipboard operation
Essentials copied to clipboard

SecureStorage: Keystore Operation Failed on Pixel 3 w/ Android 10

Open kspearrin opened this issue 7 years ago • 2 comments

Description

We just switched from our custom Android Keystore implementation to using Xamarin.Essentials.SecureStorage. It seems to work fine in all of our testing. We are now running our app in public beta and are seeing crash logs in HockeyApp from a few Pixel 3 users on Android 10 regarding Keystore Operation Failed.

Steps to Reproduce

  1. Use an affected device (so far only observed with some Pixel 3 users on Android 10).
  2. Call await Xamarin.Essentials.SecureStorage.SetAsync("key", "value");

Expected Behavior

No crash.

Actual Behavior

Crashing with

Package: com.x8bit.bitwarden
Version Code: 1801
Version Name: 2.0.0
Android: 10
Android Build: QPP3.190404.015
Manufacturer: Google
Model: Pixel 3
Thread: Thread-2-88
CrashReporter Key: 46392bb4-54e2-4076-b9c9-5b0ee78941ea
Start Date: 2019-06-04T20:29:23.395Z
Date: 2019-06-04T20:29:24.025Z
Format: Xamarin

Xamarin caused by: android.runtime.JavaProxyThrowable: System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> Java.Lang.RuntimeException: Keystore operation failed ---> Java.Lang.Exception: -1
   --- End of inner exception stack trace ---
  at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <5086522f0a76456eb7469cf646ada571>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0001f] in <5086522f0a76456eb7469cf646ada571>:0 
  at Javax.Crypto.KeyGenerator.GenerateKey () [0x0000a] in <1f2beb72521645e9b6bfd823ec06d134>:0 
  at Xamarin.Essentials.AndroidKeyStore.GetSymmetricKey () [0x00083] in <2175d7bc7f5f4196bea27f5e5268354c>:0 
  at Xamarin.Essentials.AndroidKeyStore.GetKey () [0x0002d] in <2175d7bc7f5f4196bea27f5e5268354c>:0 
  at Xamarin.Essentials.AndroidKeyStore.Encrypt (System.String data) [0x00000] in <2175d7bc7f5f4196bea27f5e5268354c>:0 
  at Xamarin.Essentials.SecureStorage.PlatformSetAsync (System.String key, System.String data) [0x00029] in <2175d7bc7f5f4196bea27f5e5268354c>:0 
  at Xamarin.Essentials.SecureStorage.SetAsync (System.String key, System.String value) [0x00021] in <2175d7bc7f5f4196bea27f5e5268354c>:0 
  at Bit.App.Services.SecureStorageService+<SaveAsync>d__3`1[T].MoveNext () [0x000c0] in <06079d40107140c39772e643eb9784f1>:0 
--- End of stack trace from previous location where exception was thrown ---
  at Bit.App.Migration.MigrationHelpers+<PerformMigrationAsync>d__2.MoveNext () [0x00e4c] in <06079d40107140c39772e643eb9784f1>:0 
   --- End of inner exception stack trace ---
---> (Inner Exception #0) Java.Lang.RuntimeException: Keystore operation failed ---> Java.Lang.Exception: -1
   --- End of inner exception stack trace ---
  at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <5086522f0a76456eb7469cf646ada571>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0001f] in <5086522f0a76456eb7469cf646ada571>:0 
  at Javax.Crypto.KeyGenerator.GenerateKey () [0x0000a] in <1f2beb72521645e9b6bfd823ec06d134>:0 
  at Xamarin.Essentials.AndroidKeyStore.GetSymmetricKey () [0x00083] in <2175d7bc7f5f4196bea27f5e5268354c>:0 
  at Xamarin.Essentials.AndroidKeyStore.GetKey () [0x0002d] in <2175d7bc7f5f4196bea27f5e5268354c>:0 
  at Xamarin.Essentials.AndroidKeyStore.Encrypt (System.String data) [0x00000] in <2175d7bc7f5f4196bea27f5e5268354c>:0 
  at Xamarin.Essentials.SecureStorage.PlatformSetAsync (System.String key, System.String data) [0x00029] in <2175d7bc7f5f4196bea27f5e5268354c>:0 
  at Xamarin.Essentials.SecureStorage.SetAsync (System.String key, System.String value) [0x00021] in <2175d7bc7f5f4196bea27f5e5268354c>:0 
  at Bit.App.Services.SecureStorageService+<SaveAsync>d__3`1[T].MoveNext () [0x000c0] in <06079d40107140c39772e643eb9784f1>:0 
--- End of stack trace from previous location where exception was thrown ---
  at Bit.App.Migration.MigrationHelpers+<PerformMigrationAsync>d__2.MoveNext () [0x00e4c] in <06079d40107140c39772e643eb9784f1>:0 <---

Basic Information

  • Version with issue: 1.1.0
  • Last known good version: Unknown
  • IDE: VS 2017
  • Platform Target Frameworks:
    • Android: 9
  • Android Support Library Version: 28.0.01
  • Affected Devices: Only seeing Pixel 3 so far

Reproduction Link

Our app is open source.

https://github.com/bitwarden/mobile/blob/master/src/App/Services/SecureStorageService.cs#L30

kspearrin avatar Jun 05 '19 01:06 kspearrin

Got similar issue on HUAWEI GRA-L09 + Android 6

Java.Lang.RuntimeException: Failed to communicate with keystore service at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <98abe4eae39f4b3798c1307368f1f98b>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0001f] in <98abe4eae39f4b3798c1307368f1f98b>:0 at Javax.Crypto.Cipher.DoFinal (System.Byte[] input) [0x00029] in <3f4ab1e7106941b9bee3fdc782133a36>:0 at Xamarin.Essentials.AndroidKeyStore.Encrypt (System.String data) [0x00062] in :0 at Xamarin.Essentials.SecureStorage.PlatformSetAsync (System.String key, System.String data) [0x00029] in :0 at Xamarin.Essentials.SecureStorage.SetAsync (System.String key, System.String value) [0x00021] in :0 at IFBaltics.MobileApplication.Core.Features.Platform.XamarinEssentialsService.SecureStorageSetAsync (System.String key, System.String value) [0x0000a] in <02566a287d5746479cc8243d085506c8>:0 at IFBaltics.MobileApplication.Core.Features.Platform.SecureStorageCacheService.AddAsync[T] (System.String key, T data) [0x000ff] in <02566a287d5746479cc8243d085506c8>:0 at IFBaltics.MobileApplication.Core.Features.MyFeature.MyModel.Load (System.Boolean useCachedData) [0x00198] in <02566a287d5746479cc8243d085506c8>:0 at IFBaltics.MobileApplication.Core.Features.MyFeature.MyModel.Load (System.Boolean useCachedData) [0x003af] in <02566a287d5746479cc8243d085506c8>:0 at MyApplication.Core.Features.MyFeature.MyViewModel.Load (System.Boolean useCachedData) [0x00092] in <02566a287d5746479cc8243d085506c8>:0 --- End of managed Java.Lang.RuntimeException stack trace --- android.security.keystore.KeyStoreConnectException: Failed to communicate with keystore service at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.update(KeyStoreCryptoOperationChunkedStreamer.java:130) at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:217) at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:473) at javax.crypto.Cipher.doFinal(Cipher.java:1505) at mono.java.lang.RunnableImplementor.n_run(Native Method) at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30) at android.os.Handler.handleCallback(Handler.java:743) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:150) at android.app.ActivityThread.main(ActivityThread.java:5546) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:682)

Lubans avatar Mar 04 '20 14:03 Lubans

@kspearrin is this still an issue, with the latest version of Essentials?

davehump avatar May 28 '20 20:05 davehump