Skip to content
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

Fix corrupt encrypted files caused by unwanted backup and restore #313

Merged
merged 6 commits into from
Sep 17, 2024

Conversation

rajdeepnanua-okta
Copy link
Contributor

This PR adds recovery mechanisms for handling unexpected backup and restore with SDK storage files. Since SDK files in storage are encrypted using device keystore, they shouldn't be copied over to other devices, or even across app installations.

In addition to the recovery mechanisms, this PR also adds rules to exclude SDK files from automatic backup. I tested backup and restore using this to ensure sdk files aren't getting backed up: https://developer.android.com/identity/data/testingbackup

Comment on lines +22 to +34
object TokenDbRecoveryUtil {
fun setupDatabaseRecovery() {
val context = ApplicationContextHolder.appContext
val defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler { thread, exception ->
if (exception is SQLiteException) {
context.deleteDatabase(TokenDatabase.DB_NAME)
} else {
defaultUncaughtExceptionHandler?.uncaughtException(thread, exception)
}
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to add this just in case things don't get fixed with the other fixes. This code should fix the token database if it ends up in an unrecoverable state, even if the encryption token is unchanged.

@rajdeepnanua-okta rajdeepnanua-okta merged commit 582499d into master Sep 17, 2024
5 of 6 checks passed
@rajdeepnanua-okta rajdeepnanua-okta deleted the backup_corruption_fix branch September 17, 2024 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants