Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add Android explicit level 3 biometric check to make UI report the same capabilities as actual encryption logic (#2334)

Leendert de Borst622d25f6017c
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManager.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManager.kt
index 6dd0420fa..13e426ba0 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManager.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/nativevaultmanager/NativeVaultManager.kt
@@ -1446,6 +1446,23 @@ class NativeVaultManager(reactContext: ReactApplicationContext) :
}
}
+ /**
+ * Check if this device has biometrics that can protect the vault encryption key.
+ * The keystore key requires Class 3 (strong) biometrics, so devices that only offer
+ * Class 2 (weak) biometrics, such as camera-based face unlock only in some devices
+ * will report false here and have to use PIN or password unlock instead.
+ * @param promise The promise to resolve.
+ */
+ @ReactMethod
+ override fun isBiometricsAvailableOnDevice(promise: Promise) {
+ try {
+ promise.resolve(AndroidKeystoreProvider.isStrongBiometricAvailable(reactApplicationContext))
+ } catch (e: Exception) {
+ Log.e(TAG, "Error checking biometric availability", e)
+ promise.reject("ERR_BIOMETRIC_CHECK", "Failed to check biometric availability: ${e.message}", e)
+ }
+ }
+
/**
* Check if biometric unlock is actually available (device + key validation).
* This checks not only if biometrics are configured in auth methods,
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.kt
index 50114b263..31a9ef394 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
@@ -58,12 +58,18 @@ class AndroidKeystoreProvider(
* The filename for the encrypted key.
*/
private const val ENCRYPTED_KEY_FILE = "encrypted_vault_key"
- }
- /**
- * The biometric manager.
- */
- private val _biometricManager = BiometricManager.from(context)
+ /**
+ * Whether the device can perform biometric authentication that is strong enough to
+ * protect the vault key. The key is bound to [KeyProperties.AUTH_BIOMETRIC_STRONG],
+ * so Class 2 (weak) biometrics such as camera-based face unlock can never unlock it.
+ * @param context The context to read the biometric state from
+ * @return Whether Class 3 (strong) biometrics are enrolled and usable
+ */
+ fun isStrongBiometricAvailable(context: Context): Boolean {
+ return BiometricManager.from(context).canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG) == BiometricManager.BIOMETRIC_SUCCESS
+ }
+ }
/**
* The executor.
@@ -83,14 +89,8 @@ class AndroidKeystoreProvider(
* @return Whether the biometric is available and key is valid
*/
override fun isBiometricAvailable(): Boolean {
- // First check if device supports biometrics
- val deviceSupported = _biometricManager.canAuthenticate(
- BiometricManager.Authenticators.BIOMETRIC_WEAK or
- BiometricManager.Authenticators.BIOMETRIC_STRONG or
- BiometricManager.Authenticators.DEVICE_CREDENTIAL,
- ) == BiometricManager.BIOMETRIC_SUCCESS
-
- if (!deviceSupported) {
+ // First check if device supports biometrics strong enough for the key below
+ if (!isStrongBiometricAvailable(context)) {
return false
}
diff --git a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
index c9d887ebf..9c8e105a5 100644
--- a/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
+++ b/apps/mobile-app/ios/NativeVaultManager/RCTNativeVaultManager.mm
@@ -297,6 +297,10 @@
[vaultManager isKeystoreAvailable:resolve rejecter:reject];
}
+- (void)isBiometricsAvailableOnDevice:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
+ [vaultManager isBiometricsAvailableOnDevice:resolve rejecter:reject];
+}
+
- (void)isBiometricUnlockAvailable:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
[vaultManager isBiometricUnlockAvailable:resolve rejecter:reject];
}
diff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
index f3793a9f9..2cc81dbb8 100644
--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
@@ -784,6 +784,19 @@ public class VaultManager: NSObject {
resolve(vaultStore.isKeystoreAvailable())
}
+ /// Check if the device has biometrics that can protect the vault key.
+ /// Face ID and Touch ID always qualify on iOS, unlike Class 2 biometrics some Android devices offer.
+ @objc
+ func isBiometricsAvailableOnDevice(_ resolve: @escaping RCTPromiseResolveBlock,
+ rejecter reject: @escaping RCTPromiseRejectBlock) {
+ let context = LAContext()
+ var error: NSError?
+ let canEvaluate = context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error)
+
+ // A lockout means biometrics are enrolled but temporarily blocked, so still count as available.
+ resolve(canEvaluate || error?.code == LAError.biometryLockout.rawValue)
+ }
+
/// Check if biometric unlock is actually available (device + key validation).
/// This checks not only if biometrics are configured in auth methods,
/// but also validates that the encryption key in Keychain is valid.
diff --git a/apps/mobile-app/specs/NativeVaultManager.ts b/apps/mobile-app/specs/NativeVaultManager.ts
index 4e6c0e175..17c5d7018 100644
--- a/apps/mobile-app/specs/NativeVaultManager.ts
+++ b/apps/mobile-app/specs/NativeVaultManager.ts
@@ -104,6 +104,11 @@ export interface Spec extends TurboModule {
isPinEnabled(): Promise<boolean>;
isKeystoreAvailable(): Promise<boolean>;
+ // Whether the device has biometrics that can protect the vault key. On Android the key
+ // requires Class 3 (strong) biometrics, so devices with only Class 2 (weak) biometrics
+ // such as camera-based face unlock return false here.
+ isBiometricsAvailableOnDevice(): Promise<boolean>;
+
// Biometric unlock validation - checks if biometric unlock is actually available
// Returns true only if device supports biometrics AND the encryption key is valid
// Returns false if key has been invalidated (e.g., biometric enrollment changed)