-
Notifications
You must be signed in to change notification settings - Fork 27
Description
Help us help you
We're using Tink via AndroidX Jetpack Security v1.1.0-alpha06 and using the non-deprecated EncryptedSharedPreferences.create method that avoids the race condition when creating a global MasterKey.
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.
class SharedPreferencesDataSource(
context: Context,
filename: String
) {
companion object {
fun getEncryptedSharedPreferences(context: Context, filename: String) =
EncryptedSharedPreferences.create(
context,
"${filename}_secure",
getOrCreateKey(context),
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
private fun getOrCreateKey(context: Context) =
MasterKey.Builder(context, MasterKey.DEFAULT_MASTER_KEY_ALIAS)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build()
}
}
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
a) the encrypted keyset has been modified.
b) the current master key in keystore is not the same as the master key that was used to encrypt the keyset.
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.