Skip to content

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

Enforce biometrics for native iOS autofill (#771)

Leendert de Borst71530ef79ddb
diff --git a/apps/mobile-app/app/(tabs)/settings/index.tsx b/apps/mobile-app/app/(tabs)/settings/index.tsx
index 57fe26406..9f76d7559 100644
--- a/apps/mobile-app/app/(tabs)/settings/index.tsx
+++ b/apps/mobile-app/app/(tabs)/settings/index.tsx
@@ -15,12 +15,13 @@ import { useRef, useState, useEffect } from 'react';
export default function SettingsScreen() {
const webApi = useWebApi();
const colors = useColors();
- const { username, getAuthMethodDisplay, shouldShowIosAutofillReminder } = useAuth();
+ const { username, getAuthMethodDisplay, shouldShowIosAutofillReminder, getBiometricDisplayName } = useAuth();
const { getAutoLockTimeout } = useAuth();
const scrollY = useRef(new Animated.Value(0)).current;
const scrollViewRef = useRef<ScrollView>(null);
const [autoLockDisplay, setAutoLockDisplay] = useState<string>('');
const [authMethodDisplay, setAuthMethodDisplay] = useState<string>('');
+ const [biometricDisplayName, setBiometricDisplayName] = useState<string>('');
useEffect(() => {
const loadAutoLockDisplay = async () => {
@@ -44,9 +45,15 @@ export default function SettingsScreen() {
setAuthMethodDisplay(authMethod);
};
+ const loadBiometricDisplayName = async () => {
+ const displayName = await getBiometricDisplayName();
+ setBiometricDisplayName(displayName);
+ };
+
loadAutoLockDisplay();
loadAuthMethodDisplay();
- }, [getAutoLockTimeout, getAuthMethodDisplay]);
+ loadBiometricDisplayName();
+ }, [getAutoLockTimeout, getAuthMethodDisplay, getBiometricDisplayName]);
const handleLogout = async () => {
await webApi.logout();
diff --git a/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx b/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx
index e7360356e..e1dca2de0 100644
--- a/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx
+++ b/apps/mobile-app/app/(tabs)/settings/vault-unlock.tsx
@@ -9,10 +9,11 @@ import { AuthMethod, useAuth } from '@/context/AuthContext';
export default function VaultUnlockSettingsScreen() {
const colors = useColors();
const [initialized, setInitialized] = useState(false);
- const { setAuthMethods, getEnabledAuthMethods } = useAuth();
+ const { setAuthMethods, getEnabledAuthMethods, getBiometricDisplayName } = useAuth();
const [hasFaceID, setHasFaceID] = useState(false);
const [isFaceIDEnabled, setIsFaceIDEnabled] = useState(false);
- const [enabledAuthMethods, setEnabledAuthMethods] = useState<AuthMethod[]>([]);
+ const [biometricDisplayName, setBiometricDisplayName] = useState('Face ID / Touch ID');
+ const [_, setEnabledAuthMethods] = useState<AuthMethod[]>([]);
useEffect(() => {
const initializeAuth = async () => {
@@ -27,11 +28,14 @@ export default function VaultUnlockSettingsScreen() {
setIsFaceIDEnabled(true);
}
+ const displayName = await getBiometricDisplayName();
+ setBiometricDisplayName(displayName);
+
setInitialized(true);
};
initializeAuth();
- }, [getEnabledAuthMethods]);
+ }, [getEnabledAuthMethods, getBiometricDisplayName]);
useEffect(() => {
if (!initialized) {
@@ -155,7 +159,7 @@ export default function VaultUnlockSettingsScreen() {
>
<View style={styles.optionHeader}>
<ThemedText style={[styles.optionText, !hasFaceID && styles.disabledText]}>
- Face ID / Touch ID
+ {biometricDisplayName}
</ThemedText>
<View pointerEvents="none">
<Switch
@@ -165,11 +169,11 @@ export default function VaultUnlockSettingsScreen() {
</View>
</View>
<ThemedText style={styles.helpText}>
- Your vault decryption key will be securely stored on your local device in the iOS Keychain and can be accessed with your face or fingerprint.
+ Your vault decryption key will be securely stored on your local device in the iOS Keychain and can be accessed securely with {biometricDisplayName}.
</ThemedText>
{!hasFaceID && (
<ThemedText style={[styles.helpText, { color: colors.errorBorder }]}>
- Face ID is blocked in iOS settings. Tap to open settings and enable it.
+ {biometricDisplayName} is blocked in iOS settings. Tap to open settings and enable it.
</ThemedText>
)}
</TouchableOpacity>
diff --git a/apps/mobile-app/context/AuthContext.tsx b/apps/mobile-app/context/AuthContext.tsx
index 4ee809c01..e3afea957 100644
--- a/apps/mobile-app/context/AuthContext.tsx
+++ b/apps/mobile-app/context/AuthContext.tsx
@@ -28,6 +28,7 @@ type AuthContextType = {
getAuthMethodDisplay: () => Promise<string>;
getAutoLockTimeout: () => Promise<number>;
setAutoLockTimeout: (timeout: number) => Promise<void>;
+ getBiometricDisplayName: () => Promise<string>;
// iOS Autofill methods
shouldShowIosAutofillReminder: boolean;
markIosAutofillConfigured: () => Promise<void>;
@@ -162,6 +163,35 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
}
}, []);
+ /**
+ * Get the appropriate biometric display name based on device capabilities
+ */
+ const getBiometricDisplayName = useCallback(async (): Promise<string> => {
+ try {
+ const hasFaceID = await LocalAuthentication.hasHardwareAsync();
+ const enrolled = await LocalAuthentication.isEnrolledAsync();
+
+ if (!hasFaceID || !enrolled) {
+ return 'Face ID / Touch ID';
+ }
+
+ const types = await LocalAuthentication.supportedAuthenticationTypesAsync();
+ const hasFaceIDSupport = types.includes(LocalAuthentication.AuthenticationType.FACIAL_RECOGNITION);
+ const hasTouchIDSupport = types.includes(LocalAuthentication.AuthenticationType.FINGERPRINT);
+
+ if (hasFaceIDSupport) {
+ return 'Face ID';
+ } else if (hasTouchIDSupport) {
+ return 'Touch ID';
+ }
+
+ return 'Face ID / Touch ID';
+ } catch (error) {
+ console.error('Failed to get biometric display name:', error);
+ return 'Face ID / Touch ID';
+ }
+ }, []);
+
/**
* Get the display label for the current auth method
* Prefers Face ID if enabled, otherwise falls back to Password
@@ -172,14 +202,14 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
try {
const isEnrolled = await LocalAuthentication.isEnrolledAsync();
if (isEnrolled) {
- return 'Face ID';
+ return await getBiometricDisplayName();
}
} catch (error) {
console.error('Failed to check Face ID enrollment:', error);
}
}
return 'Password';
- }, [getEnabledAuthMethods]);
+ }, [getEnabledAuthMethods, getBiometricDisplayName]);
/**
* Get the auto-lock timeout from the iOS credentials manager
@@ -287,10 +317,11 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
getAuthMethodDisplay,
getAutoLockTimeout,
setAutoLockTimeout,
+ getBiometricDisplayName,
// iOS Autofill methods
shouldShowIosAutofillReminder,
markIosAutofillConfigured,
- }), [isLoggedIn, isInitialized, username, globalMessage, getEnabledAuthMethods, setAuthTokens, login, logout, clearGlobalMessage, initializeAuth, setAuthMethods, getAuthMethodDisplay, isFaceIDEnabled, getAutoLockTimeout, setAutoLockTimeout, shouldShowIosAutofillReminder, markIosAutofillConfigured]);
+ }), [isLoggedIn, isInitialized, username, globalMessage, getEnabledAuthMethods, setAuthTokens, login, logout, clearGlobalMessage, initializeAuth, setAuthMethods, getAuthMethodDisplay, isFaceIDEnabled, getAutoLockTimeout, setAutoLockTimeout, getBiometricDisplayName, shouldShowIosAutofillReminder, markIosAutofillConfigured]);
return (
<AuthContext.Provider value={contextValue}>
diff --git a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
index 92ebe2cff..2fbf62305 100644
--- a/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
+++ b/apps/mobile-app/ios/Autofill/CredentialProviderViewController.swift
@@ -6,6 +6,7 @@
//
import AuthenticationServices
+import LocalAuthentication
import SwiftUI
import VaultStoreKit
import VaultUI
@@ -26,11 +27,43 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
override func viewDidLoad() {
super.viewDidLoad()
+ // Check if Face ID/Touch ID is enabled
+ let vaultStore = VaultStore()
+
+ let context = LAContext()
+ var authMethod = "Face ID / Touch ID"
+ if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
+ switch context.biometryType {
+ case .faceID:
+ authMethod = "Face ID"
+ case .touchID:
+ authMethod = "Touch ID"
+ default:
+ break
+ }
+ }
+
+ if !vaultStore.getAuthMethods().contains(.faceID) {
+ let alert = UIAlertController(
+ title: "\(authMethod) Required",
+ message: "To use Autofill, please enable \(authMethod) as your vault unlock method in the AliasVault app settings.",
+ 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
+ }
+
// Create the ViewModel with INJECTED behaviors
let viewModel = CredentialProviderViewModel(
loader: {
- try VaultStore.shared.initializeDatabase()
- let credentials = try VaultStore.shared.getAllCredentials()
+ try vaultStore.initializeDatabase()
+ let credentials = try vaultStore.getAllCredentials()
await self.registerCredentialIdentities(credentials: credentials)
return credentials
},
@@ -108,7 +141,8 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
override func provideCredentialWithoutUserInteraction(for credentialIdentity: ASPasswordCredentialIdentity) {
do {
- let credentials = try VaultStore.shared.getAllCredentials()
+ let vaultStore = VaultStore()
+ let credentials = try vaultStore.getAllCredentials()
if let matchingCredential = credentials.first(where: { credential in
return credential.id.uuidString == credentialIdentity.recordIdentifier
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStoreKit.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStoreKit.swift
index 81be47a08..9a22e4941 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStoreKit.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStoreKit.swift
@@ -18,6 +18,8 @@ public class VaultStore {
private let keychain = Keychain(service: "net.aliasvault.autofill", accessGroup: "group.net.aliasvault.autofill")
.accessibility(.whenPasscodeSetThisDeviceOnly, authenticationPolicy: .biometryAny)
+ private let userDefaults = UserDefaults(suiteName: "group.net.aliasvault.autofill")!
+
private var db: Connection?
private var encryptionKey: Data?
private var clearCacheTimer: Timer?
@@ -34,14 +36,14 @@ public class VaultStore {
public init() {
// Load saved auth methods from UserDefaults if they exist
- if UserDefaults.standard.object(forKey: authMethodsKey) != nil {
- let savedRawValue = UserDefaults.standard.integer(forKey: authMethodsKey)
+ if userDefaults.object(forKey: authMethodsKey) != nil {
+ let savedRawValue = userDefaults.integer(forKey: authMethodsKey)
enabledAuthMethods = AuthMethods(rawValue: savedRawValue)
}
// Load auto-lock timeout from UserDefaults if it exists
- if UserDefaults.standard.object(forKey: autoLockTimeoutKey) != nil {
- autoLockTimeout = UserDefaults.standard.integer(forKey: autoLockTimeoutKey)
+ if userDefaults.object(forKey: autoLockTimeoutKey) != nil {
+ autoLockTimeout = userDefaults.integer(forKey: autoLockTimeoutKey)
}
// Add notification observers
@@ -93,8 +95,8 @@ public class VaultStore {
// MARK: - Auth Methods Management
public func setAuthMethods(_ methods: AuthMethods) throws {
enabledAuthMethods = methods
- UserDefaults.standard.set(methods.rawValue, forKey: authMethodsKey)
- UserDefaults.standard.synchronize()
+ userDefaults.set(methods.rawValue, forKey: authMethodsKey)
+ userDefaults.synchronize()
if !enabledAuthMethods.contains(.faceID) {
print("Face ID is now disabled, removing key from keychain immediately")
@@ -243,8 +245,8 @@ public class VaultStore {
try base64EncryptedDb.write(to: getEncryptedDbPath(), atomically: true, encoding: .utf8)
// Store metadata in UserDefaults
- UserDefaults.standard.set(metadata, forKey: vaultMetadataKey)
- UserDefaults.standard.synchronize()
+ userDefaults.set(metadata, forKey: vaultMetadataKey)
+ userDefaults.synchronize()
}
// Get the encrypted database as a base64 encoded string
@@ -282,14 +284,14 @@ public class VaultStore {
metadata.vaultRevisionNumber = revisionNumber
if let data = try? JSONEncoder().encode(metadata),
let jsonString = String(data: data, encoding: .utf8) {
- UserDefaults.standard.set(jsonString, forKey: vaultMetadataKey)
- UserDefaults.standard.synchronize()
+ userDefaults.set(jsonString, forKey: vaultMetadataKey)
+ userDefaults.synchronize()
}
}
// Get the vault metadata from UserDefaults
public func getVaultMetadata() -> String? {
- return UserDefaults.standard.string(forKey: vaultMetadataKey)
+ return userDefaults.string(forKey: vaultMetadataKey)
}
// Helper to decode the JSON metadata into VaultMetadata object
@@ -640,10 +642,10 @@ public class VaultStore {
}
// Clear UserDefaults
- UserDefaults.standard.removeObject(forKey: vaultMetadataKey)
- UserDefaults.standard.removeObject(forKey: authMethodsKey)
- UserDefaults.standard.removeObject(forKey: autoLockTimeoutKey)
- UserDefaults.standard.synchronize()
+ userDefaults.removeObject(forKey: vaultMetadataKey)
+ userDefaults.removeObject(forKey: authMethodsKey)
+ userDefaults.removeObject(forKey: autoLockTimeoutKey)
+ userDefaults.synchronize()
print("Cleared UserDefaults")
clearCache()
@@ -800,8 +802,8 @@ public class VaultStore {
public func setAutoLockTimeout(_ timeout: Int) {
print("Setting auto-lock timeout to \(timeout) seconds")
autoLockTimeout = timeout
- UserDefaults.standard.set(timeout, forKey: autoLockTimeoutKey)
- UserDefaults.standard.synchronize()
+ userDefaults.set(timeout, forKey: autoLockTimeoutKey)
+ userDefaults.synchronize()
}
public func getAutoLockTimeout() -> Int {