android / android/security-samples
When upgrading AGP from version 7.2.2 to 7.3.1, the implementation I had for detecting if there was a change in the biometric (e.g. adding a new fingerprint) does not work.
- Lingua principale
- Kotlin
- Stelle
- 1k
- Fork
- 450
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
When upgrading AGP from version 7.2.2 to 7.3.1, the implementation I had for detecting if there was a change in the biometric (e.g. adding a new fingerprint) does not work. In AGP 7.2.2, it detects the change and throws a KeyPermanentlyInvalidatedException when cipher.apply { init(Cipher.ENCRYPT_MODE, secretKey) }
``` val cipher = Cipher.getInstance("$KEY_ALGORITHM_AES/$BLOCK_MODE_CBC/$ENCRYPTION_PADDING_PKCS7")
val secretKey = getSecretKey()
return try {
cipher.apply { init(Cipher.ENCRYPT_MODE, secretKey) }
} catch (error: KeyPermanentlyInvalidatedException) {
// do something
}
private fun getSecretKey(): SecretKey {
val keyStore = KeyStore.getInstance(KEY_ANDROID_STORE).apply {
load(null)
}
if (!isKeyExists(keyStore)) {
createSecretKey()
}
return keyStore.getKey(KEY_NAME, null) as SecretKey
}
private fun createSecretKey() {
generateSecretKey(
KeyGenParameterSpec.Builder(KEY_NAME, PURPOSE_ENCRYPT or PURPOSE_DECRYPT)
.setBlockModes(BLOCK_MODE_CBC)
.setEncryptionPaddings(ENCRYPTION_PADDING_PKCS7)
.setUserAuthenticationRequired(true)
.setInvalidatedByBiometricEnrollment(true)
.build()
)
}
private fun generateSecretKey(keyGenParameterSpec: KeyGenParameterSpec): SecretKey? {
val keyGenerator = KeyGenerator.getInstance(KEY_ALGORITHM_AES, KEY_ANDROID_STORE)
keyGenerator.init(keyGenParameterSpec)
return keyGenerator.generateKey()
}
private fun isKeyExists(keyStore: KeyStore): Boolean {
val aliases = keyStore.aliases()
while (aliases.hasMoreElements()) {
return KEY_NAME == aliases.nextElement()
}
return false
}
// `....`
biometric info config
setAllowedAuthenticators(BIOMETRIC_STRONG)
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia con lo snippet Kotlin nell’issue, in particolare con la creazione delle chiavi KeyStore, l’inizializzazione di Cipher e la configurazione di BIOMETRIC_STRONG. Riproduci il comportamento con AGP 7.2.2 e 7.3.1, quindi confronta se le modifiche alla registrazione biometrica producono ancora l’eccezione documentata; il lavoro è completato quando sono disponibili una spiegazione confermata e una correzione verificata oppure una limitazione documentata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- android, kotlin
- Ambito
- authentication, mobile, security
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 35/100