stripe / stripe-terminal-android

Stripe Terminal Android SDK
https://stripe.dev/stripe-terminal-android/
Other
94 stars 46 forks source link

error keystore on initTerminal (java.security.ProviderException: Failed to generate key pair) #486

Open spnuac opened 2 months ago

spnuac commented 2 months ago

hello My program works correctly on most devices and there is no problem, but we recently received a POS (KIOSK) register from China, which then crashes during initTerminal and adb gives the following error. Please guide...

Summary

08-30 08:24:40.161 415 19376 E keymaster_worker: HIDL call failed with Status(EX_TRANSACTION_FAILED): 'DEAD_OBJECT: ' @ system/security/keystore/keymaster_worker.cpp:795:auto keystore::KeymasterWorker::generateKey(LockedKeyBlobEntry, hidl_vec, hidl_vec, int, keystore::KeymasterWorker::generateKey_cb)::(anonymous class)::operator()() 08-30 08:24:40.162 17419 17518 E KeyStore: generateKeyInternal failed on response -1000 08-30 08:24:40.167 17419 17518 E StripeTerminal: class=Terminal 08-30 08:24:40.167 17419 17518 E StripeTerminal: java.security.ProviderException: Failed to generate key pair 08-30 08:24:40.167 17419 17518 E StripeTerminal: at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeystoreKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:515) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:471) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:727) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at java.security.KeyPairGenerator.genKeyPair(KeyPairGenerator.java:497) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at com.stripe.cots.common.compatibility.PreFlightChecks.initialize(PreFlightChecks.kt:70) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at com.stripe.cots.common.CotsClient.initializeKeys(CotsClient.kt:124) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at com.stripe.stripeterminal.internal.common.adapter.CotsAdapter.initKeystore(CotsAdapter.kt:178) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at com.stripe.stripeterminal.Terminal$Companion.initTerminal(Terminal.kt:1047) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at com.stripe.stripeterminal.Terminal$Companion.initTerminal(Terminal.kt:975) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at com.stripe.stripeterminal.Terminal.initTerminal(Unknown Source:2) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at io.event1.capacitorstripeterminal.StripeTerminal._initialize(StripeTerminal.java:176) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at io.event1.capacitorstripeterminal.StripeTerminal.initialize(StripeTerminal.java:143) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at java.lang.reflect.Method.invoke(Native Method) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:780) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at android.os.Handler.handleCallback(Handler.java:938) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at android.os.Handler.dispatchMessage(Handler.java:99) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at android.os.Looper.loop(Looper.java:223) 08-30 08:24:40.167 17419 17518 E StripeTerminal: at android.os.HandlerThread.run(HandlerThread.java:67) 08-30 08:24:40.167 17419 17518 E StripeTerminal: Caused by: android.security.KeyStoreException: Unknown error 08-30 08:24:40.167 17419 17518 E StripeTerminal: at android.security.KeyStore.getKeyStoreException(KeyStore.java:1301) 08-30 08:24:40.167 17419 17518 E StripeTerminal: ... 21 more 08-30 08:24:40.190 17419 17518 E AndroidRuntime: FATAL EXCEPTION: CapacitorPlugins 08-30 08:24:40.190 17419 17518 E AndroidRuntime: Process: com.kiosk.grub24, PID: 17419 08-30 08:24:40.190 17419 17518 E AndroidRuntime: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:789) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:938) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at android.os.Looper.loop(Looper.java:223) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at android.os.HandlerThread.run(HandlerThread.java:67) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:780) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: ... 6 more 08-30 08:24:40.190 17419 17518 E AndroidRuntime: Caused by: java.security.ProviderException: Failed to generate key pair 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeystoreKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:515) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:471) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:727) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at java.security.KeyPairGenerator.genKeyPair(KeyPairGenerator.java:497) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at com.stripe.cots.common.compatibility.PreFlightChecks.initialize(PreFlightChecks.kt:70) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at com.stripe.cots.common.CotsClient.initializeKeys(CotsClient.kt:124) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at com.stripe.stripeterminal.internal.common.adapter.CotsAdapter.initKeystore(CotsAdapter.kt:178) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at com.stripe.stripeterminal.Terminal$Companion.initTerminal(Terminal.kt:1047) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at com.stripe.stripeterminal.Terminal$Companion.initTerminal(Terminal.kt:975) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at com.stripe.stripeterminal.Terminal.initTerminal(Unknown Source:2) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at io.event1.capacitorstripeterminal.StripeTerminal._initialize(StripeTerminal.java:176) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at io.event1.capacitorstripeterminal.StripeTerminal.initialize(StripeTerminal.java:143) 08-30 08:24:40.190 17419 17518 E AndroidRuntime: ... 9 more 08-30 08:24:40.190 17419 17518 E AndroidRuntime: Caused by: android.security.KeyStoreException: Unknown error 08-30 08:24:40.190 17419 17518 E AndroidRuntime: at android.security.KeyStore.getKeyStoreException(KeyStore.java:1301)

Android version

11

Impacted devices (Android devices or readers)

SDK version

3.8.1

Other information

ebarrenechea-stripe commented 2 months ago

@spnuac would you be able to provide details about this device (make, model, etc)? Do you have access to another one of those devices that you could try running your app on? We're trying to rule out an issue with this individual device vs an issue for all devices of this particular model.

The error code -1000 from the logs doesn't map to anything useful, unfortunately. One possible issue would be a corrupt keystore. If this is the case then a factory reset should fix the problem.

harryd31 commented 1 month ago

@ebarrenechea-stripe Currently experiencing the same issue, seems like it comes from google play services not being on the device. Is there a way around that?

ebarrenechea-stripe commented 1 month ago

@harryd31 the issue is probably tied to tap to pay as it requires google play services to work properly. We'll look into better handling this error so it doesn't result in a crash when initializing the library. In the mean time, the best approach would be not to include the localmobile artifact in your apk when you need it to run on devices without google play services.