react-native-keychain icon indicating copy to clipboard operation
react-native-keychain copied to clipboard

[Android] Error: accessControl when `rules` are set to `Keychain.SECURITY_RULES.NONE`

Open dkoprowski opened this issue 3 years ago • 1 comments

Hi, I configured package and on iOS everything works well. On Android though (for now I tested only on emulator) it crashes on getGenericPassword.

export const getSecureValue = async key => {
  const keyStr = JSON.stringify(key)
  const result = await Keychain.getGenericPassword({
    service: keyStr,
    accessible: Keychain.ACCESSIBLE.ALWAYS_THIS_DEVICE_ONLY,
    rules: Keychain.SECURITY_RULES.NONE,
  })
  if (result) {
    const value = JSON.parse(result.password)
    return value
  }
  return null
}

I have such a function and all I want from this package to store tokens in a secure container. This is why i set up rules to none and accessible on iOS to Always.

Android crashes when and I don't even have a proper error message. Just:

 Error: accessControl

Stack:

    "react-native-keychain": "^7.0.0",
    "react-native": "0.61.5",

Gradle:

        buildToolsVersion = "29.0.3"
        minSdkVersion = 21
        compileSdkVersion = 29
        targetSdkVersion = 29

Screenshot

image

dkoprowski avatar Jul 21 '21 14:07 dkoprowski

The issue is with this line:

    rules: Keychain.SECURITY_RULES.NONE,

As when I comment it out it works. But... I don't want the default mechanism. I want no security rules in that app. Is there any workaround?

dkoprowski avatar Jul 22 '21 07:07 dkoprowski