Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Allow PIN fallback on Android unlock flow (#846)
Leendert de Borst890025cd4967
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.ktindex d9a77d61f..019291568 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultStore.kt@@ -313,6 +313,11 @@ class VaultStore(fun setAuthMethods(authMethods: String) {storageProvider.setAuthMethods(authMethods)++ // If the new auth methods no longer include biometrics, clear the biometric key.+ if (!authMethods.contains(BIOMETRICS_AUTH_METHOD)) {+ keystoreProvider.clearKeys()+ }}fun getAuthMethods(): String {diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/AndroidKeystoreProvider.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/AndroidKeystoreProvider.ktindex 3a08722e5..7c0e540d5 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/AndroidKeystoreProvider.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/keystoreprovider/AndroidKeystoreProvider.kt@@ -37,8 +37,11 @@ class AndroidKeystoreProvider(private val SHARED_PREFS_NAME = "net.aliasvault.keystore"override fun isBiometricAvailable(): Boolean {- return biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG) ==- BiometricManager.BIOMETRIC_SUCCESS+ return biometricManager.canAuthenticate(+ BiometricManager.Authenticators.BIOMETRIC_WEAK or+ BiometricManager.Authenticators.BIOMETRIC_STRONG or+ BiometricManager.Authenticators.DEVICE_CREDENTIAL+ ) == BiometricManager.BIOMETRIC_SUCCESS}override fun storeKey(key: String, callback: KeystoreOperationCallback) {@@ -66,7 +69,7 @@ class AndroidKeystoreProvider().setBlockModes(KeyProperties.BLOCK_MODE_GCM).setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)- .setUserAuthenticationRequired(true)+ .setUserAuthenticationRequired(false).build()keyGenerator.init(keySpec)@@ -79,16 +82,26 @@ class AndroidKeystoreProvider(// Create BiometricPromptval promptInfo = BiometricPrompt.PromptInfo.Builder().setTitle("Store Encryption Key")- .setSubtitle("Authenticate to securely store your encryption key in the Android Keystore. This enables biometric access to your vault.")- .setNegativeButtonText("Cancel")+ .setSubtitle("Authenticate to securely store your encryption key in the Android Keystore. This enables secure access to your vault.")+ .setAllowedAuthenticators(+ BiometricManager.Authenticators.BIOMETRIC_STRONG or+ BiometricManager.Authenticators.DEVICE_CREDENTIAL+ ).build()val biometricPrompt = BiometricPrompt(currentActivity, executor,object : BiometricPrompt.AuthenticationCallback() {override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {try {- // Get the cipher from the result- val cipher = result.cryptoObject?.cipher ?: throw Exception("Cipher is null")+ // Initialize cipher for encryption+ val cipher = Cipher.getInstance(+ "${KeyProperties.KEY_ALGORITHM_AES}/" ++ "${KeyProperties.BLOCK_MODE_GCM}/" ++ KeyProperties.ENCRYPTION_PADDING_NONE+ )++ // Initialize cipher with the secret key+ cipher.init(Cipher.ENCRYPT_MODE, secretKey)// Encrypt the keyval encryptedKey = cipher.doFinal(key.toByteArray())@@ -109,13 +122,13 @@ class AndroidKeystoreProvider(callback.onSuccess("Key stored successfully")} catch (e: Exception) {Log.e(TAG, "Error storing encryption key", e)- callback.onError(e)+ callback.onError(Exception("Failed to store encryption key: ${e.message}"))}}override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {- Log.e(TAG, "Authentication error: $errString")- callback.onError(Exception("Authentication error: $errString"))+ Log.e(TAG, "Authentication error: $errorCode - $errString")+ callback.onError(Exception("Authentication error: $errString (code: $errorCode)"))}override fun onAuthenticationFailed() {@@ -123,20 +136,12 @@ class AndroidKeystoreProvider(}})- // Initialize cipher for encryption- val cipher = Cipher.getInstance(- "${KeyProperties.KEY_ALGORITHM_AES}/" +- "${KeyProperties.BLOCK_MODE_GCM}/" +- KeyProperties.ENCRYPTION_PADDING_NONE- )- cipher.init(Cipher.ENCRYPT_MODE, secretKey)-- // Show biometric prompt- biometricPrompt.authenticate(promptInfo, BiometricPrompt.CryptoObject(cipher))+ // Show biometric prompt without crypto object for device credentials+ biometricPrompt.authenticate(promptInfo)} catch (e: Exception) {Log.e(TAG, "Error in biometric key storage", e)- callback.onError(e)+ callback.onError(Exception("Failed to initialize key storage: ${e.message}"))}}}@@ -177,7 +182,10 @@ class AndroidKeystoreProvider(val promptInfo = BiometricPrompt.PromptInfo.Builder().setTitle("Unlock Vault").setSubtitle("Authenticate to access your vault")- .setNegativeButtonText("Cancel")+ .setAllowedAuthenticators(+ BiometricManager.Authenticators.BIOMETRIC_STRONG or+ BiometricManager.Authenticators.DEVICE_CREDENTIAL+ ).build()val biometricPrompt = BiometricPrompt(currentActivity, executor,diff --git a/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx b/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsxindex 3703bb1ea..e37d0b43c 100644--- a/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx+++ b/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx@@ -33,16 +33,8 @@ export default function VaultUnlockSettingsScreen() : React.ReactNode {// Check if any biometrics are enrolledconst enrolled = await LocalAuthentication.isEnrolledAsync();- // Check for strong authentication support- const hasStrongAuth = await LocalAuthentication.authenticateAsync({- promptMessage: 'Checking biometric capabilities',- disableDeviceFallback: true,- cancelLabel: 'Cancel',- fallbackLabel: 'Use password',- }).then(result => result.success);-// Set biometric availability based on all checks- const isBiometricAvailable = compatible && enrolled && hasStrongAuth;+ const isBiometricAvailable = compatible && enrolled;setHasBiometrics(isBiometricAvailable);// Get appropriate display namediff --git a/apps/mobile-app/context/AuthContext.tsx b/apps/mobile-app/context/AuthContext.tsxindex b09862a1b..1d4e49726 100644--- a/apps/mobile-app/context/AuthContext.tsx+++ b/apps/mobile-app/context/AuthContext.tsx@@ -171,11 +171,11 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children// Ensure password is always includedconst methodsToSave = methods.includes('password') ? methods : [...methods, 'password'];- // Update iOS credentials manager+ // Update native credentials managertry {await NativeVaultManager.setAuthMethods(methodsToSave);} catch (error) {- console.error('Failed to update iOS auth methods:', error);+ console.error('Failed to update native auth methods:', error);}}, []);@@ -184,10 +184,16 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children*/const getBiometricDisplayName = useCallback(async (): Promise<string> => {try {- const hasFaceID = await LocalAuthentication.hasHardwareAsync();+ const hasBiometrics = await LocalAuthentication.hasHardwareAsync();const enrolled = await LocalAuthentication.isEnrolledAsync();- if (!hasFaceID || !enrolled) {+ // For Android, we use the term "Biometrics" for facial recognition and fingerprint.+ if (Platform.OS === 'android') {+ return 'Biometrics';+ }++ // For iOS, we check if the device has explicit Face ID or Touch ID support.+ if (!hasBiometrics || !enrolled) {return 'Face ID / Touch ID';}