Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update wrap/encrypt wording use (#2159)
Leendert de Borst68b14ba034a6
diff --git a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.tsindex 3794d9db5..770cf6c4c 100644--- a/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts+++ b/apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts@@ -1375,8 +1375,8 @@ async function adoptRemoteVaultKeyIfNeeded(): Promise<boolean> {try {// Decrypt the encrypted Account Key and VEK.- const accountKey = await EncryptionUtility.unwrapVaultEncryptionKey(fetchResult.vaultKey.encryptedAccountKey, sessionKey);- const vek = fetchResult.vaultKey.encryptedVek ? await EncryptionUtility.unwrapVaultEncryptionKey(fetchResult.vaultKey.encryptedVek, accountKey) : accountKey;+ const accountKey = await EncryptionUtility.decryptVaultEncryptionKey(fetchResult.vaultKey.encryptedAccountKey, sessionKey);+ const vek = fetchResult.vaultKey.encryptedVek ? await EncryptionUtility.decryptVaultEncryptionKey(fetchResult.vaultKey.encryptedVek, accountKey) : accountKey;// Re-encrypt the locally persisted vault with the VEK before swapping the session key.if (encryptedVault) {diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsxindex eec2653c0..da9c26894 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx@@ -158,7 +158,7 @@ const Login: React.FC = () => {await app.setAuthTokens(username, token, refreshToken);/*- * KEK/VEK: for migrated accounts the derived key is only the KEK; fetch the vault key and unwrap the VEK,+ * KEK/VEK: for migrated accounts the derived key is only the KEK; fetch the vault key and decrypt the VEK,* which becomes the session encryption key. Legacy accounts keep using the derived key directly.*/const { encryptionKey } = await VaultKeyService.resolveEncryptionKey(passwordHashBase64, webApi);diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsxindex c48eea586..f2ad8ec4e 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx@@ -285,7 +285,7 @@ const Unlock: React.FC = () => {});/*- * KEK/VEK: for migrated accounts the derived key is only the KEK; unwrap the VEK which is the actual+ * KEK/VEK: for migrated accounts the derived key is only the KEK; decrypt the VEK which is the actual* vault encryption key. Throws a decrypt-failed (E-203) error on a wrong password. Legacy accounts keep* using the derived key directly.*/@@ -310,8 +310,8 @@ const Unlock: React.FC = () => {);/*- * KEK/VEK offline: unwrap the locally cached wrapped VEK with the derived key. Throws a decrypt-failed- * (E-203) error on a wrong password. Legacy accounts (no cached wrapped VEK) use the derived key directly.+ * KEK/VEK offline: decrypt the locally cached encrypted VEK with the derived key. Throws a decrypt-failed+ * (E-203) error on a wrong password. Legacy accounts (no cached encrypted VEK) use the derived key directly.*/passwordHashBase64 = await VaultKeyService.resolveEncryptionKeyOffline(credentials.passwordHashBase64);@@ -579,7 +579,7 @@ const Unlock: React.FC = () => {/** The mobile device sends the vault encryption key (the VEK for migrated accounts, or the derived key when- * the mobile app predates the KEK/VEK model). Refresh the local wrapped-VEK cache so offline password unlock+ * the mobile app predates the KEK/VEK model). Refresh the local encrypted-VEK cache so offline password unlock* keeps working, then upgrade the received key to the VEK when it turns out to be the KEK.*/await VaultKeyService.cacheEncryptedVekFromServer(webApi);diff --git a/apps/browser-extension/src/utils/EncryptionUtility.ts b/apps/browser-extension/src/utils/EncryptionUtility.tsindex 9fcfdf6e9..563e50ba9 100644--- a/apps/browser-extension/src/utils/EncryptionUtility.ts+++ b/apps/browser-extension/src/utils/EncryptionUtility.ts@@ -197,17 +197,17 @@ export class EncryptionUtility {}/**- * Wraps (encrypts) a VEK with a KEK using AES-256-GCM. Returns base64(IV | ciphertext | authTag).+ * Encrypts a VEK with a KEK using AES-256-GCM. Returns base64(IV | ciphertext | authTag).*/- public static async wrapVaultEncryptionKey(vekBase64: string, kekBase64: string): Promise<string> {+ public static async encryptVaultEncryptionKey(vekBase64: string, kekBase64: string): Promise<string> {const vekBytes = Uint8Array.from(atob(vekBase64), c => c.charCodeAt(0));return this.symmetricEncryptBytes(vekBytes, kekBase64);}/**- * Unwraps (decrypts) an encrypted VEK with a KEK. Returns the VEK as base64.+ * Decrypts an encrypted VEK with a KEK. Returns the VEK as base64.*/- public static async unwrapVaultEncryptionKey(encryptedVekBase64: string, kekBase64: string): Promise<string> {+ public static async decryptVaultEncryptionKey(encryptedVekBase64: string, kekBase64: string): Promise<string> {const encryptedBytes = Uint8Array.from(atob(encryptedVekBase64), c => c.charCodeAt(0));const vekBytes = await this.symmetricDecryptBytes(encryptedBytes, kekBase64);return btoa(String.fromCharCode(...vekBytes));diff --git a/apps/browser-extension/src/utils/VaultKeyService.ts b/apps/browser-extension/src/utils/VaultKeyService.tsindex 3024c7539..d511eb5c7 100644--- a/apps/browser-extension/src/utils/VaultKeyService.ts+++ b/apps/browser-extension/src/utils/VaultKeyService.ts@@ -95,7 +95,7 @@ export class VaultKeyService {return { encryptionKey: derivedKeyBase64, encryptedVek: null };}- const vek = await VaultKeyService.unwrapChainOrThrow(result.vaultKey, derivedKeyBase64);+ const vek = await VaultKeyService.decryptKeyChainOrThrow(result.vaultKey, derivedKeyBase64);await VaultKeyService.cacheVaultKeyBlobs(result.vaultKey);return { encryptionKey: vek, encryptedVek: result.vaultKey.encryptedAccountKey };}@@ -218,15 +218,15 @@ export class VaultKeyService {const encryptedVek = (await storage.getItem(StorageKeys.ENCRYPTED_VEK)) as string | null;if (encryptedAccountKey) {- const accountKey = await VaultKeyService.unwrapOrThrow(encryptedAccountKey, derivedKeyBase64);- const vek = encryptedVek ? await VaultKeyService.unwrapOrThrow(encryptedVek, accountKey) : accountKey;+ const accountKey = await VaultKeyService.decryptKeyOrThrow(encryptedAccountKey, derivedKeyBase64);+ const vek = encryptedVek ? await VaultKeyService.decryptKeyOrThrow(encryptedVek, accountKey) : accountKey;await VaultKeyService.stageSessionPrivateKey(accountKey, (await storage.getItem(StorageKeys.ENCRYPTED_ACCOUNT_PRIVATE_KEY)) as string | null);return { encryptionKey: vek, encryptedVek: encryptedAccountKey };}if (encryptedVek) {// Pre-encrypted VEK cache: the VEK was encrypted directly with the KEK.- return { encryptionKey: await VaultKeyService.unwrapOrThrow(encryptedVek, derivedKeyBase64), encryptedVek };+ return { encryptionKey: await VaultKeyService.decryptKeyOrThrow(encryptedVek, derivedKeyBase64), encryptedVek };}return { encryptionKey: derivedKeyBase64, encryptedVek: null };@@ -238,9 +238,9 @@ export class VaultKeyService {* @param vaultKey - the server's vault key response* @param derivedKeyBase64 - the password-derived KEK*/- private static async unwrapChainOrThrow(vaultKey: VaultKeyResponse, derivedKeyBase64: string): Promise<string> {- const accountKey = await VaultKeyService.unwrapOrThrow(vaultKey.encryptedAccountKey, derivedKeyBase64);- const vek = vaultKey.encryptedVek ? await VaultKeyService.unwrapOrThrow(vaultKey.encryptedVek, accountKey) : accountKey;+ private static async decryptKeyChainOrThrow(vaultKey: VaultKeyResponse, derivedKeyBase64: string): Promise<string> {+ const accountKey = await VaultKeyService.decryptKeyOrThrow(vaultKey.encryptedAccountKey, derivedKeyBase64);+ const vek = vaultKey.encryptedVek ? await VaultKeyService.decryptKeyOrThrow(vaultKey.encryptedVek, accountKey) : accountKey;await VaultKeyService.stageSessionPrivateKey(accountKey, vaultKey.encryptedAccountPrivateKey ?? null);return vek;}@@ -290,9 +290,9 @@ export class VaultKeyService {* @param encryptedKey - encrypted key blob* @param decryptingKeyBase64 - the key that decrypts it (the KEK derived from the unlock method)*/- private static async unwrapOrThrow(encryptedKey: string, decryptingKeyBase64: string): Promise<string> {+ private static async decryptKeyOrThrow(encryptedKey: string, decryptingKeyBase64: string): Promise<string> {try {- return await EncryptionUtility.unwrapVaultEncryptionKey(encryptedKey, decryptingKeyBase64);+ return await EncryptionUtility.decryptVaultEncryptionKey(encryptedKey, decryptingKeyBase64);} catch {// E-203: decrypt failed, which for the password key type means the entered password is wrong.throw new Error(formatErrorWithCode('Failed to decrypt vault encryption key', AppErrorCode.VAULT_DECRYPT_FAILED));diff --git a/apps/browser-extension/src/utils/VaultSyncService.ts b/apps/browser-extension/src/utils/VaultSyncService.tsindex 1ed2823e7..523712e0d 100644--- a/apps/browser-extension/src/utils/VaultSyncService.ts+++ b/apps/browser-extension/src/utils/VaultSyncService.ts@@ -174,7 +174,7 @@ type ManifestDto = {ownerUsername?: string | null;/** Whether the caller may grant/revoke access to this manifest and publish its email delivery key. */canAdminister?: boolean;- /** How the caller's access to this manifest's VEK is wrapped. */+ /** How the caller's access to this manifest's VEK is encrypted. */keyType?: string | null;/** The manifest VEK encrypted with the caller's public key; set only on manifests we open through a grant. */encryptedVek?: string | null;@@ -790,9 +790,9 @@ export class VaultSyncService {}try {- return await SharingService.unwrapManifestVek(dto.encryptedVek, privateKeyJwk);+ return await SharingService.decryptManifestVek(dto.encryptedVek, privateKeyJwk);} catch (e) {- devWarn(`[V2Pull] Failed to unwrap VEK of shared manifest ${dto.manifestId}, skipping it.`, e);+ devWarn(`[V2Pull] Failed to decrypt VEK of shared manifest ${dto.manifestId}, skipping it.`, e);return null;}}@@ -885,7 +885,7 @@ export class VaultSyncService {): Promise<PushResult> {/** KEK/VEK migration: on the first push after this feature ships, generate a fresh VEK and encrypt everything- * with it; the passed-in password-derived key becomes the KEK that wraps the VEK. On a normal push the+ * with it; the passed-in password-derived key becomes the KEK that encrypts the VEK. On a normal push the* passed-in key IS the VEK and is used directly.*/const migrateToVaultKey = options?.createVaultKey === true;@@ -897,9 +897,9 @@ export class VaultSyncService {*/const accountKey = migrateToVaultKey ? EncryptionUtility.generateVaultEncryptionKey() : null;const accountKeyPair = migrateToVaultKey ? await EncryptionUtility.generateRsaKeyPair() : null;- const encryptedVek = accountKey ? await EncryptionUtility.wrapVaultEncryptionKey(contentKey, accountKey) : null;+ const encryptedVek = accountKey ? await EncryptionUtility.encryptVaultEncryptionKey(contentKey, accountKey) : null;const accountKeys = accountKey && accountKeyPair ? {- encryptedAccountKey: await EncryptionUtility.wrapVaultEncryptionKey(accountKey, vek),+ encryptedAccountKey: await EncryptionUtility.encryptVaultEncryptionKey(accountKey, vek),accountPublicKey: accountKeyPair.publicKey,encryptedAccountPrivateKey: await EncryptionUtility.symmetricEncrypt(accountKeyPair.privateKey, accountKey),} : null;diff --git a/apps/browser-extension/src/utils/__tests__/EncryptionUtility.vek.test.ts b/apps/browser-extension/src/utils/__tests__/EncryptionUtility.vek.test.tsindex 7b6492312..257758fd5 100644--- a/apps/browser-extension/src/utils/__tests__/EncryptionUtility.vek.test.ts+++ b/apps/browser-extension/src/utils/__tests__/EncryptionUtility.vek.test.ts@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest';import EncryptionUtility from '@/utils/EncryptionUtility';-describe('EncryptionUtility VEK wrap/unwrap (KEK/VEK model)', () => {+describe('EncryptionUtility VEK encrypt/decrypt (KEK/VEK model)', () => {it('generates a 256-bit VEK as base64', () => {const vek = EncryptionUtility.generateVaultEncryptionKey();expect(Buffer.from(vek, 'base64').length).toBe(32);@@ -12,45 +12,45 @@ describe('EncryptionUtility VEK wrap/unwrap (KEK/VEK model)', () => {expect(EncryptionUtility.generateVaultEncryptionKey()).not.toBe(EncryptionUtility.generateVaultEncryptionKey());});- it('round-trips a VEK through wrap and unwrap with the same KEK', async () => {+ it('round-trips a VEK through encrypt and decrypt with the same KEK', async () => {const vek = EncryptionUtility.generateVaultEncryptionKey();const kek = EncryptionUtility.generateVaultEncryptionKey();- const wrapped = await EncryptionUtility.wrapVaultEncryptionKey(vek, kek);- expect(wrapped).not.toBe(vek);+ const encrypted = await EncryptionUtility.encryptVaultEncryptionKey(vek, kek);+ expect(encrypted).not.toBe(vek);// IV(12) + ciphertext(32) + tag(16) = 60 bytes.- expect(Buffer.from(wrapped, 'base64').length).toBe(60);+ expect(Buffer.from(encrypted, 'base64').length).toBe(60);- const unwrapped = await EncryptionUtility.unwrapVaultEncryptionKey(wrapped, kek);- expect(unwrapped).toBe(vek);+ const decrypted = await EncryptionUtility.decryptVaultEncryptionKey(encrypted, kek);+ expect(decrypted).toBe(vek);});- it('produces a different wrapped VEK per wrap call (random IV)', async () => {+ it('produces a different encrypted VEK per encrypt call (random IV)', async () => {const vek = EncryptionUtility.generateVaultEncryptionKey();const kek = EncryptionUtility.generateVaultEncryptionKey();- expect(await EncryptionUtility.wrapVaultEncryptionKey(vek, kek)).not.toBe(await EncryptionUtility.wrapVaultEncryptionKey(vek, kek));+ expect(await EncryptionUtility.encryptVaultEncryptionKey(vek, kek)).not.toBe(await EncryptionUtility.encryptVaultEncryptionKey(vek, kek));});- it('rejects unwrapping with a wrong KEK (AES-GCM auth failure doubles as password check)', async () => {+ it('rejects decrypting with a wrong KEK (AES-GCM auth failure doubles as password check)', async () => {const vek = EncryptionUtility.generateVaultEncryptionKey();const kek = EncryptionUtility.generateVaultEncryptionKey();const wrongKek = EncryptionUtility.generateVaultEncryptionKey();- const wrapped = await EncryptionUtility.wrapVaultEncryptionKey(vek, kek);- await expect(EncryptionUtility.unwrapVaultEncryptionKey(wrapped, wrongKek)).rejects.toThrow();+ const encrypted = await EncryptionUtility.encryptVaultEncryptionKey(vek, kek);+ await expect(EncryptionUtility.decryptVaultEncryptionKey(encrypted, wrongKek)).rejects.toThrow();});- it('unwraps a rewrapped VEK after a simulated password change', async () => {+ it('decrypts a re-encrypted VEK after a simulated password change', async () => {const vek = EncryptionUtility.generateVaultEncryptionKey();const oldKek = EncryptionUtility.generateVaultEncryptionKey();const newKek = EncryptionUtility.generateVaultEncryptionKey();- // Password change: unwrap with old KEK, rewrap with new KEK. The VEK itself must survive unchanged.- const wrappedOld = await EncryptionUtility.wrapVaultEncryptionKey(vek, oldKek);- const unwrapped = await EncryptionUtility.unwrapVaultEncryptionKey(wrappedOld, oldKek);- const wrappedNew = await EncryptionUtility.wrapVaultEncryptionKey(unwrapped, newKek);+ // Password change: decrypt with old KEK, re-encrypt with new KEK. The VEK itself must survive unchanged.+ const encryptedOld = await EncryptionUtility.encryptVaultEncryptionKey(vek, oldKek);+ const decrypted = await EncryptionUtility.decryptVaultEncryptionKey(encryptedOld, oldKek);+ const encryptedNew = await EncryptionUtility.encryptVaultEncryptionKey(decrypted, newKek);- expect(await EncryptionUtility.unwrapVaultEncryptionKey(wrappedNew, newKek)).toBe(vek);+ expect(await EncryptionUtility.decryptVaultEncryptionKey(encryptedNew, newKek)).toBe(vek);});it('encrypts and decrypts vault content with a VEK end-to-end', async () => {diff --git a/apps/browser-extension/src/utils/auth/SrpAuthService.ts b/apps/browser-extension/src/utils/auth/SrpAuthService.tsindex 15d8dfc5f..9d928e498 100644--- a/apps/browser-extension/src/utils/auth/SrpAuthService.ts+++ b/apps/browser-extension/src/utils/auth/SrpAuthService.ts@@ -33,7 +33,7 @@ export type PreparedRegistration = {request: RegisterRequest;/** The generated VEK (base64): the vault encryption key to store in session after successful registration. */vaultEncryptionKey: string;- /** The password-derived key (base64): the KEK, only needed for wrapping/SRP, never for vault content. */+ /** The password-derived key (base64): the KEK, only needed for key encryption/SRP, never for vault content. */derivedKey: string;};@@ -328,10 +328,10 @@ export class SrpAuthService {/** KEK/VEK: generate a random VEK that will encrypt the vault content, encrypted with the password-derived KEK.- * The server stores only the wrapped form; the VEK itself stays client-side.+ * The server stores only the encrypted form; the VEK itself stays client-side.*/const vaultEncryptionKey = EncryptionUtility.generateVaultEncryptionKey();- const encryptedVek = await EncryptionUtility.wrapVaultEncryptionKey(vaultEncryptionKey, credentials.passwordHashBase64);+ const encryptedVek = await EncryptionUtility.encryptVaultEncryptionKey(vaultEncryptionKey, credentials.passwordHashBase64);return {request: {diff --git a/apps/browser-extension/src/utils/constants/storageKeys.ts b/apps/browser-extension/src/utils/constants/storageKeys.tsindex e96fc7cd5..02200fa79 100644--- a/apps/browser-extension/src/utils/constants/storageKeys.ts+++ b/apps/browser-extension/src/utils/constants/storageKeys.ts@@ -48,7 +48,7 @@ export const StorageKeys = {ENCRYPTED_VEK: 'local:encryptedVek',/** The Account Key encrypted with the password-derived KEK, as returned by the server. */ENCRYPTED_ACCOUNT_KEY: 'local:encryptedAccountKey',- /** The account public key, used for wrapping shared-manifest VEK grants. */+ /** The account public key, used for encrypting shared-manifest VEK grants. */ACCOUNT_PUBLIC_KEY: 'local:accountPublicKey',/** The account private key encrypted with the Account Key. */ENCRYPTED_ACCOUNT_PRIVATE_KEY: 'local:encryptedAccountPrivateKey',diff --git a/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs b/apps/server/AliasVault.Api/Controllers/V2/VaultController.csindex 2128dd0fe..c36fc2830 100644--- a/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs+++ b/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs@@ -154,7 +154,7 @@ public class VaultController({accessKeysByManifest.TryGetValue(m.ManifestId, out var accessKey);- // An account-key row's ciphertext is not sent: the caller unwrapped that VEK from their password chain before this call.+ // An account-key row's ciphertext is not sent: the caller decrypted that VEK from their password chain before this call.var grant = accessKey != null && ManifestKeyTypes.CarriesEncryptedVek(accessKey.Type) ? accessKey : null;return new Manifest{@@ -436,7 +436,7 @@ public class VaultController(row.ManifestBlob = mw.ManifestBlob;row.ManifestCiphertextHash = mw.ManifestCiphertextHash;- // Deprecated column: manifest-v1 revisions no longer carry a data-model version (see VaultManifestBase.Version).+ // Manifest revisions carry no data-model version, so we make it empty instead.row.Version = string.Empty;row.RevisionNumber = mw.CurrentRevision + 1;row.FileSize = FileHelper.Base64StringToKilobytes(mw.ManifestBlob);@@ -806,7 +806,7 @@ public class VaultController(}/// <summary>- /// Gets the caller's key row on each of the given manifests, whichever way that manifest's VEK is wrapped for+ /// Gets the caller's key row on each of the given manifests, whichever way that manifest's VEK is encrypted for/// them: an account-key row (unlocked through their password chain) or a grant encrypted to one of their public/// keys. An account-key row wins when a manifest has both, being the caller's own direct path to it./// </summary>diff --git a/apps/server/Databases/AliasServerDb/ManifestKeyTypeDefinition.cs b/apps/server/Databases/AliasServerDb/ManifestKeyTypeDefinition.csindex 41d689e9d..3ecee427b 100644--- a/apps/server/Databases/AliasServerDb/ManifestKeyTypeDefinition.cs+++ b/apps/server/Databases/AliasServerDb/ManifestKeyTypeDefinition.cs@@ -23,7 +23,7 @@ public sealed class ManifestKeyTypeDefinitionpublic required string Token { get; init; }/// <summary>- /// Gets a value indicating whether the wrapped VEK travels to the client along with the manifest.+ /// Gets a value indicating whether the encrypted VEK travels to the client along with the manifest./// </summary>public required bool CarriesEncryptedVek { get; init; }}diff --git a/apps/server/Databases/AliasServerDb/ManifestKeyTypes.cs b/apps/server/Databases/AliasServerDb/ManifestKeyTypes.csindex bbe03ef11..fc528e51e 100644--- a/apps/server/Databases/AliasServerDb/ManifestKeyTypes.cs+++ b/apps/server/Databases/AliasServerDb/ManifestKeyTypes.cs@@ -69,7 +69,7 @@ public static class ManifestKeyTypespublic static string ToToken(ManifestKeyType type) => GetDefinition(type).Token;/// <summary>- /// Whether a key type's wrapped VEK is carried to the client alongside the manifest.+ /// Whether a key type's encrypted VEK is carried to the client alongside the manifest./// </summary>/// <param name="type">The key type to check.</param>/// <returns>True when the manifest carries the encrypted VEK.</returns>diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/Manifest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/Manifest.csindex 39597cd57..c7e810b2c 100644--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/Manifest.cs+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/Manifest.cs@@ -51,7 +51,7 @@ public class Manifestpublic bool CanAdminister { get; set; }/// <summary>- /// Gets or sets how the caller's access to this manifest's VEK is wrapped.+ /// Gets or sets how the caller's access to this manifest's VEK is encrypted./// </summary>public string? KeyType { get; set; }