oblador / react-native-keychain

:key: Keychain Access for React Native
MIT License
3.22k stars 518 forks source link

credentials wiping on app uninstall is not consistent between platforms #135

Open anshul-kai opened 6 years ago

anshul-kai commented 6 years ago

Seems like my credentials are being wiped out on Android upon app uninstall on Android 6, 7 & 8. Am I missing something here? I was under the impression that keychain data is retained even after an uninstall. Seems to work this way on iOS. Any suggestions would be appreciated.

enahum commented 6 years ago

In my case I would expect the data being wiped out but not happening on iOS which is what I wanted to report

MacKentoch commented 6 years ago
<application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="true"
anshul-kai commented 6 years ago

allowBackup is already set to true for my app. Looks like I was operating with the misunderstanding that the keychain would be persisted and available even after an app uninstall.

With a combination of AsyncStorage and some simple encryption algorithm, one can easily achieve this functionality on both platforms. Would it be possible to shed some light on the use cases where this library comes in handy on an Android device given that the data isn't persisted?

leethree commented 5 years ago

This behaviour breaks the feature parity between iOS and Android. People would expect that the library works the same way on both platforms. So I think it should be fixed in this library (i.e. wipe out credentials on both iOS and Android) or at least documented.

Related issue: #87

hellogerard commented 5 years ago

I have been looking into this as well. It does not look like we can get persistent "keychain" data on Android after an app uninstall. The encrypted data itself is stored in SharedPreferences which is by default deleted on app uninstall. In theory, this could get backed up/restored using Android's Auto Backup feature (though I could not get even this to work). However, the keystore entries also get deleted on app uninstall, so even if we had the data, we could not decrypt them without the keys. I think I've got that right.

With a combination of AsyncStorage and some simple encryption algorithm, one can easily achieve this functionality on both platforms.

I'm not a security expert, but I'd like to try to answer this for my own edification because I've been asking myself similar questions lately.

You could totally do this in React Native, however, what I have come to understand is that doing it this way is in practice inherently insecure. AsyncStorage is not a secure storage container, meaning someone with access to your phone or a malicious app could read the data. But who cares about that because it is encrypted, right? Then, the question is where to put your keys? You can't put them anywhere in your source code because apps can get statically analyzed and reverse engineered. You could put them in your database, but then it exposes your keys to the internet in general, not to mention all of your developers who might like to snoop on users.

Things like Android Keystore exist to prevent all of the above and ensure that no one could possibly read secure data except for the person who created it. The benefit is admittedly non-obvious for the trouble, but that's how I've been thinking of this.

sujayjaju commented 5 years ago

Other similar libraries provide an option to clear or keep on uninstall. https://www.npmjs.com/package/react-native-secure-key-store

Clearing data should be the default in my opinion.

Bardiamist commented 5 years ago

@sujayjaju seems setResetOnAppUninstallTo implemented in react-native-secure-key-store only for iOS. I not found this method here.

I would to have something like setResetOnAppUninstallTo in react-native-keychain.

kaloudis commented 4 years ago

I too would like an option to wipe data on uninstall on iOS

AndreyPatseiko commented 4 years ago

Any updates?? Me need this feature too!

TheWirv commented 4 years ago

+1 does nobody else care about this? I understand that this is not the most qualified comment, but it's weird that not even a discussion arises and there's no input whatsoever from the maintainers... :/

dhanazam commented 4 years ago

Any updates ? ?

andylim0221 commented 4 years ago

Other similar libraries provide an option to clear or keep on uninstall. https://www.npmjs.com/package/react-native-secure-key-store

Clearing data should be the default in my opinion.

can we apply the method from the library above on this keychain library?

Sakshisrivastava413 commented 3 years ago

any update on this issue?

mountain-hiker commented 2 years ago

You can use the Settings API which is a wrapper for NSUserDefaults on iOS (gets cleared on delete) https://reactnative.dev/docs/settings

One solutions might look like this in your App.tsx:

useEffect(() => {      
    if(!Settings.get('hasOpened')){
        await Keychain.resetGenericPassword({service: KEY_HERE})
        //TODO: Update Login state here
        Settings.set({hasOpened: true})
    }
},[])

Inspired from this: https://stackoverflow.com/questions/4747404/delete-keychain-items-when-an-app-is-uninstalled

*This doesn't wipe data on uninstall but it does on reinstall, which is effectively what I needed. Just in case it's helpful for others.

bachbonglong commented 2 years ago

How to keep data keychain Android when swipe or reinstall App . I try setInternetCredentials but not work

timothyerwin commented 1 year ago

wow...no one can answer how to persist data on android in like 5 years?

vinithreddy3 commented 1 year ago

https://github.com/oblador/react-native-keychain/issues/135#issuecomment-534081526

But it actually doesn't delete on uninstall rather let's say it deletes keychain when the app is reinstalled back later based on the config provided https://github.com/pradeep1991singh/react-native-secure-key-store/issues/55#issuecomment-522554547

bdtren commented 9 months ago

I'm not really like expo, but expo-secure-store actually support saved data when App is uninstall for both Android and iOS (It not use keychain in iOS though). So there should be a way...

Akhil-PITS commented 6 months ago

@kaloudis , any update on this?

thanks