Some devices (in this case, XT1030) are experiencing a "java.security.InvalidKeyException: Unsupported key size: 24 bytes (must be 16 or 32)" exception.
I observe the following crash in HockeyApp for this particular user's device:
Package: com.x8bit.bitwarden
Version Code: 1914
Version Name: 2.0.3
Android: 4.4.4
Android Build: SU6-7.7
Manufacturer: motorola
Model: XT1030
Thread: main-1
CrashReporter Key: e2083c5e-900a-40a3-82b7-1ea05e651e50
Start Date: 2019-06-14T15:15:59.597Z
Date: 2019-06-14T15:16:20.752Z
Format: Xamarin
java.security.InvalidKeyException: Unsupported key size: 24 bytes (must be 16 or 32)
at com.google.android.gms.org.conscrypt.OpenSSLCipher$EVP_AEAD$AES.checkSupportedKeySize(:com.google.android.gms@[email protected] (000306-248795830))
at com.google.android.gms.org.conscrypt.OpenSSLCipher.checkAndSetEncodedKey(:com.google.android.gms@[email protected] (000306-248795830):5)
at com.google.android.gms.org.conscrypt.OpenSSLCipher.engineInit(:com.google.android.gms@[email protected] (000306-248795830):6)
at javax.crypto.Cipher.init(Cipher.java:616)
at javax.crypto.Cipher.init(Cipher.java:566)
at md51558244f76c53b6aeda52c8a337f2c37.EntryRendererBase_1.n_onEditorAction(Native Method)
at md51558244f76c53b6aeda52c8a337f2c37.EntryRendererBase_1.onEditorAction(EntryRendererBase_1.java:75)
at android.widget.TextView.onEditorAction(TextView.java:4267)
at com.android.internal.widget.EditableInputConnection.performEditorAction(EditableInputConnection.java:138)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:297)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:77)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Xamarin caused by: Java.Security.InvalidKeyException: Unsupported key size: 24 bytes (must be 16 or 32)
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <bb10d1c5101a4136bc73106419f3d3a4>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0001f] in <bb10d1c5101a4136bc73106419f3d3a4>:0
at Javax.Crypto.Cipher.Init (Javax.Crypto.CipherMode opmode, Java.Security.IKey key, Java.Security.Spec.IAlgorithmParameterSpec params) [0x00073] in <689af8d6ecac4f2abdfef44ab1b64b80>:0
at Xamarin.Essentials.AndroidKeyStore.Decrypt (System.Byte[] data) [0x0003c] in <eb00b8e256f541fe87550c11f03a0586>:0
at Xamarin.Essentials.SecureStorage.PlatformGetAsync (System.String key) [0x0004f] in <eb00b8e256f541fe87550c11f03a0586>:0
at Xamarin.Essentials.SecureStorage.GetAsync (System.String key) [0x00013] in <eb00b8e256f541fe87550c11f03a0586>:0
at Bit.App.Services.SecureStorageService+<GetAsync>d__2`1[T].MoveNext () [0x00022] in <ff536f2a7c004fa685a56fc511fb3062>:0
--- End of stack trace from previous location where exception was thrown ---
at Bit.App.Pages.LockPageViewModel+<SubmitAsync>d__59.MoveNext () [0x0073b] in <ff536f2a7c004fa685a56fc511fb3062>:0
--- End of stack trace from previous location where exception was thrown ---
at Bit.App.Pages.LockPageViewModel+<<-ctor>b__19_0>d.MoveNext () [0x00062] in <ff536f2a7c004fa685a56fc511fb3062>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <ef60f641e9504f5b961449d4935c6505>:0
at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <689af8d6ecac4f2abdfef44ab1b64b80>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <689af8d6ecac4f2abdfef44ab1b64b80>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <689af8d6ecac4f2abdfef44ab1b64b80>:0
at (wrapper dynamic-method) System.Object.44(intptr,intptr)
--- End of managed Java.Security.InvalidKeyException stack trace ---
java.security.InvalidKeyException: Unsupported key size: 24 bytes (must be 16 or 32)
at com.google.android.gms.org.conscrypt.OpenSSLCipher$EVP_AEAD$AES.checkSupportedKeySize(:com.google.android.gms@[email protected] (000306-248795830))
at com.google.android.gms.org.conscrypt.OpenSSLCipher.checkAndSetEncodedKey(:com.google.android.gms@[email protected] (000306-248795830):5)
at com.google.android.gms.org.conscrypt.OpenSSLCipher.engineInit(:com.google.android.gms@[email protected] (000306-248795830):6)
at javax.crypto.Cipher.init(Cipher.java:616)
at javax.crypto.Cipher.init(Cipher.java:566)
at md51558244f76c53b6aeda52c8a337f2c37.EntryRendererBase_1.n_onEditorAction(Native Method)
at md51558244f76c53b6aeda52c8a337f2c37.EntryRendererBase_1.onEditorAction(EntryRendererBase_1.java:75)
at android.widget.TextView.onEditorAction(TextView.java:4267)
at com.android.internal.widget.EditableInputConnection.performEditorAction(EditableInputConnection.java:138)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:297)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:77)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
SecureStorage.GetAsync("some-id");No crash.
Crash.
Also observe this same crash on an Acer A1-840FHD, Android 4.4.2:
Package: com.x8bit.bitwarden
Version Code: 1921
Version Name: 2.0.4
Android: 4.4.2
Android Build: Acer_AV0K1_A1-840FHD_1.057.00_WW_GEN1
Manufacturer: Acer
Model: A1-840FHD
Thread: main-1
CrashReporter Key: 731f29a4-8012-4658-bd18-81f57ceed57e
Start Date: 2019-06-14T20:28:39.457Z
Date: 2019-06-14T20:28:52.959Z
Format: Xamarin
java.security.InvalidKeyException: Unsupported key size: 24 bytes (must be 16 or 32)
at com.google.android.gms.org.conscrypt.OpenSSLCipher$EVP_AEAD$AES.checkSupportedKeySize(:com.google.android.gms@[email protected] (000700-248795830))
at com.google.android.gms.org.conscrypt.OpenSSLCipher.checkAndSetEncodedKey(:com.google.android.gms@[email protected] (000700-248795830):5)
at com.google.android.gms.org.conscrypt.OpenSSLCipher.engineInit(:com.google.android.gms@[email protected] (000700-248795830):6)
at javax.crypto.Cipher.init(Cipher.java:616)
at javax.crypto.Cipher.init(Cipher.java:566)
at md51558244f76c53b6aeda52c8a337f2c37.FormsAppCompatActivity.n_onStop(Native Method)
at md51558244f76c53b6aeda52c8a337f2c37.FormsAppCompatActivity.onStop(FormsAppCompatActivity.java:128)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1212)
at android.app.Activity.performStop(Activity.java:5376)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3225)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3274)
at android.app.ActivityThread.access$1100(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1263)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5061)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Xamarin caused by: Java.Security.InvalidKeyException: Unsupported key size: 24 bytes (must be 16 or 32)
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <12dc807e03ff46768a450b5c5868a5d5>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0001f] in <12dc807e03ff46768a450b5c5868a5d5>:0
at Javax.Crypto.Cipher.Init (Javax.Crypto.CipherMode opmode, Java.Security.IKey key, Java.Security.Spec.IAlgorithmParameterSpec params) [0x00073] in <85cd7d174bef4530b182744f2d6275a0>:0
at Xamarin.Essentials.AndroidKeyStore.Decrypt (System.Byte[] data) [0x0003c] in <77747ac216f44ed3b328ad34daa15d61>:0
at Xamarin.Essentials.SecureStorage.PlatformGetAsync (System.String key) [0x0004f] in <77747ac216f44ed3b328ad34daa15d61>:0
at Xamarin.Essentials.SecureStorage.GetAsync (System.String key) [0x00013] in <77747ac216f44ed3b328ad34daa15d61>:0
at Bit.App.Services.SecureStorageService+<GetAsync>d__2`1[T].MoveNext () [0x00022] in <f88e126b3c30440f8c0b56653255f39b>:0
--- End of stack trace from previous location where exception was thrown ---
at Bit.Core.Services.CryptoService+<GetKeyAsync>d__23.MoveNext () [0x00083] in <d6178d6defea4fd79211eae9c784f705>:0
--- End of stack trace from previous location where exception was thrown ---
at Bit.Core.Services.CryptoService+<HasKeyAsync>d__31.MoveNext () [0x00062] in <d6178d6defea4fd79211eae9c784f705>:0
--- End of stack trace from previous location where exception was thrown ---
at Bit.Core.Services.LockService+<IsLockedAsync>d__19.MoveNext () [0x00074] in <d6178d6defea4fd79211eae9c784f705>:0
--- End of stack trace from previous location where exception was thrown ---
at Bit.App.App+<HandleLockingAsync>d__28.MoveNext () [0x0007d] in <f88e126b3c30440f8c0b56653255f39b>:0
--- End of stack trace from previous location where exception was thrown ---
at Bit.App.App+<OnSleep>d__23.MoveNext () [0x000ea] in <f88e126b3c30440f8c0b56653255f39b>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <0c5901ef3ffa42028431ecee34b7b370>:0
at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <85cd7d174bef4530b182744f2d6275a0>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <85cd7d174bef4530b182744f2d6275a0>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <85cd7d174bef4530b182744f2d6275a0>:0
at (wrapper dynamic-method) System.Object.27(intptr,intptr)
--- End of managed Java.Security.InvalidKeyException stack trace ---
java.security.InvalidKeyException: Unsupported key size: 24 bytes (must be 16 or 32)
at com.google.android.gms.org.conscrypt.OpenSSLCipher$EVP_AEAD$AES.checkSupportedKeySize(:com.google.android.gms@[email protected] (000700-248795830))
at com.google.android.gms.org.conscrypt.OpenSSLCipher.checkAndSetEncodedKey(:com.google.android.gms@[email protected] (000700-248795830):5)
at com.google.android.gms.org.conscrypt.OpenSSLCipher.engineInit(:com.google.android.gms@[email protected] (000700-248795830):6)
at javax.crypto.Cipher.init(Cipher.java:616)
at javax.crypto.Cipher.init(Cipher.java:566)
at md51558244f76c53b6aeda52c8a337f2c37.FormsAppCompatActivity.n_onStop(Native Method)
at md51558244f76c53b6aeda52c8a337f2c37.FormsAppCompatActivity.onStop(FormsAppCompatActivity.java:128)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1212)
at android.app.Activity.performStop(Activity.java:5376)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3225)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3274)
at android.app.ActivityThread.access$1100(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1263)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5061)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Crash was also logged for Samsung GT-I9300 , Android 4.4.4. Definitely seems to be an Android 4,4 issue.
@kspearrin can you provide a small code sample or project that demonstrates this so we can replicate
Thanks advance
Code sample was provided in my initial report. Simply call SecureStorage.GetAsync("some-id").
I am pretty sure we take the first 16 bytes... odd..
Did you do a SetAsync first? or just trying to read it?
I am not sure if set was called before get. These are crash reports coming from the wild (prod) on certain 4.4 devices, so I have not been able to reproduce them locally.
Something to do is to try/catch your GetAsync (recommended practice) and report that exception if caught to get details. You could even try to check if it exists and report that back.
Any update on this issue ?
I've the same issue but with Api 21 Android 5.0:
[0:] Java.Security.InvalidKeyException: Unsupported key size: 24 bytes (must be 16 or 32)
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <42748fcc36b74733af2d9940a8f3cc8e>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0001f] in <42748fcc36b74733af2d9940a8f3cc8e>:0
at Javax.Crypto.Cipher.Init (Javax.Crypto.CipherMode opmode, Java.Security.IKey key, Java.Security.Spec.IAlgorithmParameterSpec params) [0x00069] in /Users/builder/azdo/_work/287/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-28/mcw/Javax.Crypto.Cipher.cs:508
at Xamarin.Essentials.AndroidKeyStore.Encrypt (System.String data) [0x00025] in d:\a\1\s\Xamarin.Essentials\SecureStorage\SecureStorage.android.cs:335
at Xamarin.Essentials.SecureStorage.PlatformSetAsync (System.String key, System.String data) [0x00029] in d:\a\1\s\Xamarin.Essentials\SecureStorage\SecureStorage.android.cs:85
at Xamarin.Essentials.SecureStorage.SetAsync (System.String key, System.String value) [0x00021] in d:\a\1\s\Xamarin.Essentials\SecureStorage\SecureStorage.shared.cs:27