react-native-keychain: android.security.keystore.AndroidKeyStoreUnauthenticatedAESCipherPadding.finalize() timed out after 10 seconds

Hey, first of all great library! Managed to get it working with ease!

We have noticed the following issue on some old Android version 7 devices the last few weeks:

Fatal Exception: java.util.concurrent.TimeoutException: android.security.keystore.AndroidKeyStoreUnauthenticatedAESCipherSpi$CBC$PKCS7Padding.finalize() timed out after 10 seconds
       at android.os.BinderProxy.transactNative(Binder.java)
       at android.os.BinderProxy.transact(Binder.java:615)
       at android.security.IKeystoreService$Stub$Proxy.abort(IKeystoreService.java:1341)
       at android.security.KeyStore.abort(KeyStore.java:519)
       at android.security.keystore.AndroidKeyStoreCipherSpiBase.finalize(AndroidKeyStoreCipherSpiBase.java:744)
       at android.security.keystore.AndroidKeyStoreUnauthenticatedAESCipherSpi$CBC$PKCS7Padding.finalize(AndroidKeyStoreUnauthenticatedAESCipherSpi.java)
       at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:222)
       at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:209)
       at java.lang.Thread.run(Thread.java:761)

Here are the devices details from Crashlytics:

Screenshot 2020-06-24 at 10 51 16 Screenshot 2020-06-24 at 10 50 52

Anyone else experiencing this issue?

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 10
  • Comments: 17

Most upvoted comments

I solve this problem with a workaround. It happens when the app tries to call the function getGenericPassword() when the app state is background

You guys can use this hook:

import { useState, useEffect } from 'react';
import { AppState } from 'react-native';
export default function useAppState(settings) {
  const { onChange, onForeground, onBackground } = settings || {};
  const [appState, setAppState] = useState(AppState.currentState);
  useEffect(() => {
    function handleAppStateChange(nextAppState) {
      if (
        nextAppState === 'active' &&
        appState !== 'active' &&
        isValidFunction(onForeground)
      )
        onForeground();
      else if (
        appState === 'active' &&
        nextAppState.match(/inactive|background/) &&
        isValidFunction(onBackground)
      )
        onBackground();
      setAppState(nextAppState);
      if (isValidFunction(onChange)) onChange(nextAppState);
    }
    const appStateListener = AppState.addEventListener(
      'change',
      handleAppStateChange,
    );
    return () => appStateListener?.remove();
  }, [onChange, onForeground, onBackground, appState]);
  // settings validation
  function isValidFunction(func) {
    return func && typeof func === 'function';
  }
  return { appState };
}

And after that:

const { appState } = useAppState();

if (appState === 'active') {
  getGenericPassword({ ...options });
}

Same issue. This is affecting a lot of our users in production. FYI, the affected users had android version 7.1.2 and below and the most affected android version was 7.0

java.util.concurrent.TimeoutException: android.security.keystore.AndroidKeyStoreUnauthenticatedAESCipherSpi$CBC$PKCS7Padding.finalize() timed out after 10 seconds

same here: react-native-keychain: 7.0.0 Android version: 10 Models: Galaxy A50 (SM-A505F)