Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Improve sanity checks for if biometrics are not available (#880)
Leendert de Borst2f7a4370b7b8
diff --git a/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx b/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsxindex a8c0e1f8e..38c975809 100644--- a/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx+++ b/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx@@ -201,7 +201,7 @@ export default function VaultUnlockSettingsScreen() : React.ReactNode {</ThemedText>{!hasBiometrics && (<ThemedText style={[styles.helpText, { color: colors.errorBorder }]}>- {biometricDisplayName} is blocked in device settings. Tap to open settings and enable it.+ {biometricDisplayName} is not available. Tap to open settings and/or go to your device settings to enable and configure it.</ThemedText>)}</TouchableOpacity>diff --git a/apps/mobile-app/app/login.tsx b/apps/mobile-app/app/login.tsxindex 839466552..78367cdb8 100644--- a/apps/mobile-app/app/login.tsx+++ b/apps/mobile-app/app/login.tsx@@ -106,48 +106,61 @@ export default function LoginScreen() : React.ReactNode {) : Promise<void> => {// Get biometric display nameconst biometricDisplayName = await authContext.getBiometricDisplayName();-- // Show biometric prompt- Alert.alert(- `Enable ${biometricDisplayName}?`,- `Would you like to use ${biometricDisplayName} to unlock your vault?`,- [- {- text: 'No',- style: 'destructive',- /**- * Handle disabling biometric authentication- */- onPress: async () : Promise<void> => {- await authContext.setAuthMethods(['password']);- await continueProcessVaultResponse(- token,- refreshToken,- vaultResponseJson,- passwordHashBase64,- initiateLoginResponse- );- }- },- {- text: 'Yes',- isPreferred: true,- /**- * Handle enabling biometric authentication- */- onPress: async () : Promise<void> => {- await authContext.setAuthMethods(['faceid', 'password']);- await continueProcessVaultResponse(- token,- refreshToken,- vaultResponseJson,- passwordHashBase64,- initiateLoginResponse- );+ const isBiometricsEnabledOnDevice = await authContext.isBiometricsEnabledOnDevice();++ if (isBiometricsEnabledOnDevice) {+ // Show biometric prompt if biometrics are available (faceid or fingerprint enrolled) on device.+ Alert.alert(+ `Enable ${biometricDisplayName}?`,+ `Would you like to use ${biometricDisplayName} to unlock your vault?`,+ [+ {+ text: 'No',+ style: 'destructive',+ /**+ * Handle disabling biometric authentication+ */+ onPress: async () : Promise<void> => {+ await authContext.setAuthMethods(['password']);+ await continueProcessVaultResponse(+ token,+ refreshToken,+ vaultResponseJson,+ passwordHashBase64,+ initiateLoginResponse+ );+ }+ },+ {+ text: 'Yes',+ isPreferred: true,+ /**+ * Handle enabling biometric authentication+ */+ onPress: async () : Promise<void> => {+ await authContext.setAuthMethods(['faceid', 'password']);+ await continueProcessVaultResponse(+ token,+ refreshToken,+ vaultResponseJson,+ passwordHashBase64,+ initiateLoginResponse+ );+ }}- }- ]- );+ ]+ );+ } else {+ // If biometrics are not available on device, only allow password authentication.+ await authContext.setAuthMethods(['password']);+ await continueProcessVaultResponse(+ token,+ refreshToken,+ vaultResponseJson,+ passwordHashBase64,+ initiateLoginResponse+ );+ }};/**diff --git a/apps/mobile-app/context/AuthContext.tsx b/apps/mobile-app/context/AuthContext.tsxindex 4e2c08101..9b3dc5fb4 100644--- a/apps/mobile-app/context/AuthContext.tsx+++ b/apps/mobile-app/context/AuthContext.tsx@@ -32,6 +32,7 @@ type AuthContextType = {getAutoLockTimeout: () => Promise<number>;setAutoLockTimeout: (timeout: number) => Promise<void>;getBiometricDisplayName: () => Promise<string>;+ isBiometricsEnabledOnDevice: () => Promise<boolean>;setOfflineMode: (isOffline: boolean) => void;verifyPassword: (password: string) => Promise<string | null>;// Autofill methods@@ -91,13 +92,30 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children}}, []);+ /**+ * Check if biometrics is enabled on the device (regardless of whether it's enabled in the AliasVault app).+ */+ const isBiometricsEnabledOnDevice = useCallback(async (): Promise<boolean> => {+ const hasBiometrics = await LocalAuthentication.hasHardwareAsync();+ if (!hasBiometrics) {+ return false;+ }++ return await LocalAuthentication.isEnrolledAsync();+ }, []);+/*** Check if biometrics is enabled based on enabled auth methods*/const isBiometricsEnabled = useCallback(async (): Promise<boolean> => {+ const deviceHasBiometrics = await isBiometricsEnabledOnDevice();+ if (!deviceHasBiometrics) {+ return false;+ }+const methods = await getEnabledAuthMethods();return methods.includes('faceid');- }, [getEnabledAuthMethods]);+ }, [getEnabledAuthMethods, isBiometricsEnabledOnDevice]);/*** Set auth tokens in storage as part of the login process. After db is initialized, the login method should be called as well.@@ -222,8 +240,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ childrenconst methods = await getEnabledAuthMethods();if (methods.includes('faceid')) {try {- const isEnrolled = await LocalAuthentication.isEnrolledAsync();- if (isEnrolled) {+ if (await isBiometricsEnabledOnDevice()) {return await getBiometricDisplayName();}} catch (error) {@@ -231,7 +248,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children}}return 'Password';- }, [getEnabledAuthMethods, getBiometricDisplayName]);+ }, [getEnabledAuthMethods, getBiometricDisplayName, isBiometricsEnabledOnDevice]);/*** Get the auto-lock timeout from the iOS credentials manager@@ -374,6 +391,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ childrenclearGlobalMessage,setAuthMethods,getAuthMethodDisplay,+ isBiometricsEnabledOnDevice,getAutoLockTimeout,setAutoLockTimeout,getBiometricDisplayName,@@ -398,6 +416,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ childrenclearGlobalMessage,setAuthMethods,getAuthMethodDisplay,+ isBiometricsEnabledOnDevice,getAutoLockTimeout,setAutoLockTimeout,getBiometricDisplayName,diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swiftindex ce8a34d1f..b67d84d7f 100644--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift@@ -178,7 +178,12 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle// Check if Face ID/Touch ID is enabledlet context = LAContext()var authMethod = "Face ID / Touch ID"- if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {+ var biometricsAvailable = false+ var biometricsError: NSError?++ // Check if device supports biometrics+ if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &biometricsError) {+ biometricsAvailable = trueswitch context.biometryType {case .faceID:authMethod = "Face ID"@@ -189,6 +194,24 @@ public class CredentialProviderViewController: ASCredentialProviderViewControlle}}+ // First check if biometrics are available on the device+ if !biometricsAvailable {+ let alert = UIAlertController(+ title: "\(authMethod) Required",+ message: "To use AliasVault Autofill, please enable \(authMethod) in your device settings and/or go to the AliasVault app settings to configure it.",+ preferredStyle: .alert+ )+ alert.addAction(UIAlertAction(title: "OK", style: .default) { [weak self] _ in+ self?.extensionContext.cancelRequest(withError: NSError(+ domain: ASExtensionErrorDomain,+ code: ASExtensionError.userCanceled.rawValue+ ))+ })+ present(alert, animated: true)+ return false+ }++ // Then check if Face ID/Touch ID is enabled in the app settingsif !vaultStore.getAuthMethods().contains(.faceID) {let alert = UIAlertController(title: "\(authMethod) Required",