1
0
Fork 0
mirror of https://github.com/Corewala/Buran synced 2025-01-02 21:24:19 +00:00

Removed unnecessary values in BiometricManager

This commit is contained in:
Corewala 2022-05-17 13:25:49 -04:00
parent 93191e67c4
commit 55db823420

View file

@ -1,5 +1,6 @@
package corewala.buran.io.keymanager package corewala.buran.io.keymanager
import android.app.Activity
import android.content.Context import android.content.Context
import android.os.Build import android.os.Build
import android.security.keystore.KeyGenParameterSpec import android.security.keystore.KeyGenParameterSpec
@ -8,6 +9,7 @@ import androidx.annotation.RequiresApi
import androidx.biometric.BiometricPrompt import androidx.biometric.BiometricPrompt
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import corewala.buran.Buran import corewala.buran.Buran
import corewala.buran.R import corewala.buran.R
import java.nio.charset.Charset import java.nio.charset.Charset
@ -25,10 +27,6 @@ class BuranBiometricManager {
private lateinit var biometricPrompt: BiometricPrompt private lateinit var biometricPrompt: BiometricPrompt
private lateinit var promptInfo: BiometricPrompt.PromptInfo private lateinit var promptInfo: BiometricPrompt.PromptInfo
private val ENCRYPTION_BLOCK_MODE = KeyProperties.BLOCK_MODE_GCM
private val ENCRYPTION_PADDING = KeyProperties.ENCRYPTION_PADDING_NONE
private val ENCRYPTION_ALGORITHM = KeyProperties.KEY_ALGORITHM_AES
fun createBiometricPrompt(context: Context, fragment: Fragment, callback: BiometricPrompt.AuthenticationCallback){ fun createBiometricPrompt(context: Context, fragment: Fragment, callback: BiometricPrompt.AuthenticationCallback){
val executor = ContextCompat.getMainExecutor(context) val executor = ContextCompat.getMainExecutor(context)
biometricPrompt = BiometricPrompt(fragment, executor, callback) biometricPrompt = BiometricPrompt(fragment, executor, callback)
@ -76,7 +74,7 @@ class BuranBiometricManager {
} }
private fun getCipher(): Cipher { private fun getCipher(): Cipher {
val transformation = "$ENCRYPTION_ALGORITHM/$ENCRYPTION_BLOCK_MODE/$ENCRYPTION_PADDING" val transformation = "${KeyProperties.KEY_ALGORITHM_AES}/${KeyProperties.BLOCK_MODE_GCM}/${KeyProperties.ENCRYPTION_PADDING_NONE}"
return Cipher.getInstance(transformation) return Cipher.getInstance(transformation)
} }
@ -90,8 +88,8 @@ class BuranBiometricManager {
keyName, keyName,
KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT
).apply { ).apply {
setBlockModes(ENCRYPTION_BLOCK_MODE) setBlockModes(KeyProperties.BLOCK_MODE_GCM)
setEncryptionPaddings(ENCRYPTION_PADDING) setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
setKeySize(256) setKeySize(256)
setUserAuthenticationRequired(true) setUserAuthenticationRequired(true)
}.build() }.build()