Skip to content

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

Update unlock flow (#1776)

Leendert de Borstb06c4174bba8
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt
index a3a592742..78a0af9fa 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/MainActivity.kt
@@ -254,10 +254,36 @@ class MainActivity : ReactActivity() {
val encryptionKeyBase64 = data?.getStringExtra(
net.aliasvault.app.passwordunlock.PasswordUnlockActivity.EXTRA_ENCRYPTION_KEY,
)
- // For showPasswordUnlock(), resolve with encryption key
- passwordPromise?.resolve(encryptionKeyBase64)
- // For authenticateUser(), resolve with boolean success
- authPromise?.resolve(true)
+
+ if (encryptionKeyBase64 == null) {
+ passwordPromise?.resolve(null)
+ authPromise?.resolve(false)
+ return
+ }
+
+ val vaultStore = net.aliasvault.app.vaultstore.VaultStore.getInstance(
+ net.aliasvault.app.vaultstore.keystoreprovider.AndroidKeystoreProvider(this) { null },
+ net.aliasvault.app.vaultstore.storageprovider.AndroidStorageProvider(this),
+ )
+
+ // Run on IO thread to avoid blocking main thread
+ kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.IO).launch {
+ try {
+ // Store encryption key in memory only
+ vaultStore.storeEncryptionKeyInMemory(encryptionKeyBase64)
+
+ // Unlock the vault with the key now in memory
+ vaultStore.unlockVault()
+
+ // For both showPasswordUnlock() and authenticateUser(), resolve with success (true)
+ passwordPromise?.resolve(true)
+ authPromise?.resolve(true)
+ } catch (e: Exception) {
+ android.util.Log.e("MainActivity", "Failed to unlock vault with password", e)
+ passwordPromise?.resolve(null)
+ authPromise?.resolve(false)
+ }
+ }
}
net.aliasvault.app.passwordunlock.PasswordUnlockActivity.RESULT_CANCELLED -> {
// For showPasswordUnlock(), resolve with null
diff --git a/apps/mobile-app/app/unlock.tsx b/apps/mobile-app/app/unlock.tsx
index 1e1861536..3d188c32e 100644
--- a/apps/mobile-app/app/unlock.tsx
+++ b/apps/mobile-app/app/unlock.tsx
@@ -105,25 +105,17 @@ export default function UnlockScreen() : React.ReactNode {
return;
}
- const encryptionKeyBase64 = await NativeVaultManager.showPasswordUnlock(
+ const unlocked = await NativeVaultManager.showPasswordUnlock(
t('auth.unlockVault'),
t('auth.enterPassword')
);
- if (!encryptionKeyBase64) {
+ if (!unlocked) {
// User cancelled - show the unlock screen
setIsLoading(false);
return;
}
- /*
- * Store key in memory only, don't persist to keychain.
- * User is doing password unlock because biometric failed/cancelled,
- * so they can't authenticate biometrically to store in keychain.
- * The old key in keychain is preserved for future biometric unlocks.
- */
- await dbContext.testDatabaseConnection(encryptionKeyBase64, false);
-
if (await dbContext.hasPendingMigrations()) {
router.replace('/upgrade');
return;
@@ -191,26 +183,17 @@ export default function UnlockScreen() : React.ReactNode {
}
// Show native password unlock screen
- const encryptionKeyBase64 = await NativeVaultManager.showPasswordUnlock(
+ const unlocked = await NativeVaultManager.showPasswordUnlock(
t('auth.unlockVault'),
t('auth.enterPassword')
);
// User cancelled
- if (!encryptionKeyBase64) {
+ if (!unlocked) {
setIsLoading(false);
return;
}
- /*
- * Test the database connection with the encryption key.
- * Store in memory only - don't persist to keychain.
- * User chose password unlock because biometric/PIN failed or was cancelled,
- * so they can't authenticate biometrically to update keychain.
- * This preserves the existing keychain entry for future biometric unlocks.
- */
- await dbContext.testDatabaseConnection(encryptionKeyBase64, false);
-
// Check if the vault is up to date, if not, redirect to the upgrade page.
if (await dbContext.hasPendingMigrations()) {
router.replace('/upgrade');
@@ -229,8 +212,6 @@ export default function UnlockScreen() : React.ReactNode {
return;
}
- console.error('Unlock error:', err);
-
// Try to extract error code from the error
const errorCode = getAppErrorCode(err);
@@ -272,13 +253,7 @@ export default function UnlockScreen() : React.ReactNode {
}
// Not unlocked means user cancelled - return false but don't show error
return false;
- } catch (err) {
- // User cancelled or PIN unlock failed
- const errorMessage = err instanceof Error ? err.message : '';
- if (!errorMessage.includes('cancelled') && !errorMessage.includes('canceled')) {
- console.error('PIN unlock error:', err);
- setError(t('auth.errors.pinFailed'));
- }
+ } catch {
return false;
}
};
diff --git a/apps/mobile-app/i18n/locales/en.json b/apps/mobile-app/i18n/locales/en.json
index fc8731019..1bf119e14 100644
--- a/apps/mobile-app/i18n/locales/en.json
+++ b/apps/mobile-app/i18n/locales/en.json
@@ -51,7 +51,6 @@
"unlockWithPin": "Unlock with PIN",
"unlockWithPassword": "Unlock with Password",
"enterPassword": "Enter your password to unlock your vault",
- "enterPasswordToUnlock": "Enter your password to unlock your vault",
"enterPasswordPlaceholder": "Password",
"enterAuthCode": "Enter 6-digit code",
"usernamePlaceholder": "name / [email protected]",
diff --git a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
index 8aa178d0c..fe6c8143a 100644
--- a/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
+++ b/apps/mobile-app/ios/NativeVaultManager/VaultManager.swift
@@ -841,15 +841,21 @@ public class VaultManager: NSObject {
throw NSError(domain: "VaultManager", code: -1, userInfo: [NSLocalizedDescriptionKey: "Incorrect password"])
}
+ // Store encryption key in memory only
+ try self.vaultStore.storeEncryptionKeyInMemory(base64Key: encryptionKeyBase64)
+
+ // Unlock the vault
+ try self.vaultStore.unlockVault()
+
await MainActor.run {
rootVC.dismiss(animated: true) {
- resolve(encryptionKeyBase64)
+ resolve(true)
}
}
},
cancelHandler: {
rootVC.dismiss(animated: true) {
- resolve(NSNull())
+ resolve(nil)
}
}
)
@@ -1102,10 +1108,12 @@ public class VaultManager: NSObject {
}
// Verify password and get encryption key
- guard let _ = try self.vaultStore.verifyPassword(password) else {
+ guard let encryptionKey = try self.vaultStore.verifyPassword(password) else {
throw NSError(domain: "VaultManager", code: -1, userInfo: [NSLocalizedDescriptionKey: "Incorrect password"])
}
+ try self.vaultStore.storeEncryptionKeyInMemory(base64Key: encryptionKey)
+
// Success - dismiss and resolve
await MainActor.run {
rootVC.dismiss(animated: true) {