Prevent crash while validating biometric key.

This commit is contained in:
Jorge Martín 2022-08-08 12:22:05 +02:00
parent 6e1e31bac1
commit 2f4725cfe9
2 changed files with 4 additions and 9 deletions

1
changelog.d/6768.bugfix Normal file
View File

@ -0,0 +1 @@
Fix crash when biometric key is used when coming back to foreground and KeyStore reports that the device is still locked.

View File

@ -20,13 +20,13 @@ import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import android.security.keystore.KeyPermanentlyInvalidatedException
import android.security.keystore.UserNotAuthenticatedException
import android.util.Base64
import androidx.annotation.VisibleForTesting
import androidx.biometric.BiometricPrompt
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.securestorage.SecretStoringUtils
import org.matrix.android.sdk.api.util.BuildVersionSdkIntProvider
import java.security.Key
@ -113,14 +113,8 @@ class KeyStoreCrypto @AssistedInject constructor(
fun hasValidKey(): Boolean {
val keyExists = hasKey()
return if (buildVersionSdkIntProvider.get() >= Build.VERSION_CODES.M && keyExists) {
try {
ensureKey()
true
} catch (e: KeyPermanentlyInvalidatedException) {
false
} catch (e: UserNotAuthenticatedException) {
false
}
val initializedKey = tryOrNull("Error validating lockscreen system key.") { ensureKey() }
initializedKey != null
} else {
keyExists
}