-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AEADBadTagException AndroidX Jetpack Security startup crash #23
Comments
Fortunately, I've managed to reproduce the issue. The issue is related to backup. Ideally it should be solved gracefully handled from within the app, without the need to Here's a reproducer project (tested against Android 13)
I believe a quick solution is to disallow backups; however, IMO, it's not feasible to ask every app that uses Tink/Jetpack security to disallow backups and make the user lose a useful feature such as backups.
|
Thanks for the detailed report. Others have had the same issue before, that's why a warning was added to not back up these files: There is nothing else we can do, unfortunately. The keys stored in keystore are not backed up. So if you restore the backup, you don't have the key anymore, and therefore you can't decrypt anymore. Also, note that Android will encrypt the data by default, see https://source.android.com/docs/security/features/encryption/file-based. |
Thanks @juergw for the response. Does that mean a solution would be, to handle this without declaring backup rules, during
If this was the case, Do you think storing the keysets into plain text format rather than on Android's KeyStore would be more reliable during backup/restore? (Not sure about the Security implications of this though) |
I'd also like to add that it turned out that even with |
It would be enough to delete the shared preferences, there is no need to delete the (newly created) key in keystore. |
I'm experiencing this issue (repeatable) on a single device but not others: Pixel 7 running Android 14 (up to date with latest official updates). I'm using the same versions of jetpack as mentioned. I have tried: disabling backups via the manifest and I have tried excluding the encrypted files. Neither work, it does not appear to be the cause of the problem. I have also factory reset the device and the error still occurs. in my case, a clean install of the app on that device, launches and works. if I kill the app and restart (all future restarts) fail with the error from this report. In my case, deleting the prefs is not a working solution. I have also discovered that once EncryptedSharedPreferences.create shows the error so does EncryptedFile.Builder. |
As a follow-up, I was finally able to get the app to no longer have this failure. I used Device Explorer in Android Studio to manually delete the offending shared prefs file and let the app recreate it. |
This solution that targets the scenario when the encrypted file is backed up and system restored it, but lost the key used for encryption (e.g. app was uninstalled and installed again). Here is the gist if someone still needed it: Tested with "androidx.security:security-crypto:1.1.0-alpha06". In addition, it is good to explicitly set which files should be backed up, with:
|
I think the main problem here is that both jetpack and Tink tried to give a too simple API to the user. That API works fine in most cases, but when something goes wrong, it is much more difficult for the user of the API to figure out what is happening. So we have decided to provide a more low-level API that forces the user to write more code themselves. But it makes it easier to understand what is going on, so I think it will be easier to maintain. Here is the new API: and here is how a user might use this API in their API: |
Thank you for this, when will this be released? |
Help us help you
We're using Tink via AndroidX Jetpack Security
v1.1.0-alpha06
and using the non-deprecatedEncryptedSharedPreferences.create
method that avoids the race condition when creating a globalMasterKey
.The crash happens on: Device - Pixel 7 pro, OS - Android 14
Describe the bug:
The crash isn't consistently reproducible we have crash reports from different devices and across different Android SDK versions.
But according to this stack trace, it's happening on startup during
Application.onCreate
.What was the expected behavior?
No crashes.
How can we reproduce the bug?
We're creating an EncryptedSharedPreference instance using the below snippet.
Do you have any debugging information?
I've posted a reproducer below.
What version of Tink are you using?
Jetpack Security is using Tink v 1.8.0 behind the scenes.
Can you tell us more about your development environment?
N/A
Is there anything else you'd like to add?
I've read this comment, and mentioned
I'm not sure, though, how this can be caused? We're creating
EncryptedSharedPreferences
instances, but we never touch the MasterKey used to encrypt the data there.The text was updated successfully, but these errors were encountered: