Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update registration related models (#2159)
Leendert de Borst947d9e402d84
diff --git a/core/client/src/auth/SrpAuthService.ts b/core/client/src/auth/SrpAuthService.tsindex 25484fc61..1d9879024 100644--- a/core/client/src/auth/SrpAuthService.ts+++ b/core/client/src/auth/SrpAuthService.ts@@ -5,6 +5,7 @@ import {srpGenerateEphemeral,srpDeriveSession,} from '../../wasm/aliasvault_core.js';+import { createAccountKeyHierarchy, type AccountKeyBlobs, type AccountKeyHierarchy } from '../crypto/AccountKeys';import { EncryptionUtility } from '../crypto/EncryptionUtility';import { initRustCore } from '../rust/RustCore';@@ -13,14 +14,13 @@ import type { TokenModel, LoginResponse, BadRequestResponse } from '@aliasvault//*** Register request type for creating a new user.*/-export type RegisterRequest = {+export type RegisterRequest = AccountKeyBlobs & {username: string;salt: string;verifier: string;encryptionType: string;encryptionSettings: string;srpIdentity: string;- encryptedVek: string;};/**@@ -28,7 +28,7 @@ export type RegisterRequest = {*/export type PreparedRegistration = {request: RegisterRequest;- vaultEncryptionKey: string;+ keys: AccountKeyHierarchy;derivedKey: string;};@@ -39,7 +39,9 @@ export type RegistrationResult = {success: boolean;token?: TokenModel;encryptionKey?: string;- encryptedVek?: string;+ derivedKey?: string;+ accountKeys?: AccountKeyBlobs;+ accountPrivateKey?: string;error?: string;};@@ -329,20 +331,9 @@ export class SrpAuthService {password: string): Promise<PreparedRegistration> {const normalizedUsername = SrpAuthService.normalizeUsername(username);-- /**- * Generate a random GUID for SRP identity. This is used for all SRP operations,- * is set during registration, and never changes.- */const srpIdentity = SrpAuthService.generateSrpIdentity();const material = await SrpAuthService.prepareNewPassword(password, srpIdentity);-- /*- * KEK/VEK: generate a random VEK that will encrypt the vault content, encrypted with the password-derived KEK.- * The server stores only the encrypted form; the VEK itself stays client-side.- */- const vaultEncryptionKey = EncryptionUtility.generateVaultEncryptionKey();- const encryptedVek = await EncryptionUtility.encryptVaultEncryptionKey(vaultEncryptionKey, material.kekBase64);+ const hierarchy = await createAccountKeyHierarchy(material.kekBase64);return {request: {@@ -352,9 +343,9 @@ export class SrpAuthService {encryptionType: material.encryptionType,encryptionSettings: material.encryptionSettings,srpIdentity,- encryptedVek,+ ...hierarchy.accountKeys,},- vaultEncryptionKey,+ keys: hierarchy,derivedKey: material.kekBase64,};}@@ -401,7 +392,14 @@ export class SrpAuthService {}const tokenModel = (await response.json()) as TokenModel;- return { success: true, token: tokenModel, encryptionKey: prepared.vaultEncryptionKey, encryptedVek: prepared.request.encryptedVek };+ return {+ success: true,+ token: tokenModel,+ encryptionKey: prepared.keys.vaultEncryptionKey,+ derivedKey: prepared.derivedKey,+ accountKeys: prepared.keys.accountKeys,+ accountPrivateKey: prepared.keys.accountPrivateKey,+ };} catch (error) {return {success: false,diff --git a/core/client/src/crypto/AccountKeys.ts b/core/client/src/crypto/AccountKeys.tsnew file mode 100644index 000000000..62791474b--- /dev/null+++ b/core/client/src/crypto/AccountKeys.ts@@ -0,0 +1,42 @@+import { EncryptionUtility } from './EncryptionUtility';++/**+ * The wrapped halves of an account key hierarchy: what the server stores, sent as-is in a register or+ * migration payload.+ */+export type AccountKeyBlobs = {+ encryptedAccountKey: string;+ encryptedVek: string;+ accountPublicKey: string;+ encryptedAccountPrivateKey: string;+};++/**+ * A newly created account key hierarchy: the wrapped blobs plus the plaintext halves the client keeps.+ */+export type AccountKeyHierarchy = {+ vaultEncryptionKey: string;+ accountPrivateKey: string;+ accountKeys: AccountKeyBlobs;+};++/**+ * Create a new account key hierarchy.+ * @param kek - the password-derived key this account's key material is wrapped with+ */+export async function createAccountKeyHierarchy(kek: string): Promise<AccountKeyHierarchy> {+ const vaultEncryptionKey = EncryptionUtility.generateVaultEncryptionKey();+ const accountKey = EncryptionUtility.generateVaultEncryptionKey();+ const accountKeyPair = await EncryptionUtility.generateRsaKeyPair();++ return {+ vaultEncryptionKey,+ accountPrivateKey: accountKeyPair.privateKey,+ accountKeys: {+ encryptedAccountKey: await EncryptionUtility.encryptVaultEncryptionKey(accountKey, kek),+ encryptedVek: await EncryptionUtility.encryptVaultEncryptionKey(vaultEncryptionKey, accountKey),+ accountPublicKey: accountKeyPair.publicKey,+ encryptedAccountPrivateKey: await EncryptionUtility.symmetricEncrypt(accountKeyPair.privateKey, accountKey),+ },+ };+}diff --git a/core/client/src/rust/RustCore.ts b/core/client/src/rust/RustCore.tsindex 151435337..aea30519b 100644--- a/core/client/src/rust/RustCore.ts+++ b/core/client/src/rust/RustCore.ts@@ -498,6 +498,14 @@ export async function vaultCodecOverflowTable(): Promise<string> {return core.vaultCodecOverflowTable();}+/**+ * The vault tables that take part in sync, as declared by the shared vault table registry.+ */+export async function getSyncableTableNames(): Promise<string[]> {+ await initRustCore();+ return core.getSyncableTableNames();+}+/*** The bucket layout: every category and the tables it owns.*/diff --git a/core/client/src/sync/LegacyStorageModelMigration.ts b/core/client/src/sync/LegacyStorageModelMigration.tsindex f2982e884..7543d7338 100644--- a/core/client/src/sync/LegacyStorageModelMigration.ts+++ b/core/client/src/sync/LegacyStorageModelMigration.ts@@ -8,7 +8,7 @@ import { ApiRequestError } from '../api/errors/ApiRequestError';import { ServerUpdateRequiredError } from '../api/errors/ServerUpdateRequiredError';import { VaultKeyService } from '../auth/VaultKeyService';import { StorageKeys } from '../constants/StorageKeys';-import { EncryptionUtility } from '../crypto/EncryptionUtility';+import { mintAccountKeyHierarchy, type AccountKeyBlobs } from '../crypto/AccountKeys';import { getPlatform } from '../platform/ClientPlatform';import { devLog } from '../platform/Logger';@@ -175,16 +175,7 @@ export type LegacyAccountKeyMigration = {/** The new VEK: everything this push writes is encrypted with it, and the caller adopts it as the session key. */contentKey: string;/** The whole hierarchy, sent as-is in the write payload. */- accountKeys: {- /** The Account Key encrypted with the password-derived KEK. */- encryptedAccountKey: string;- /** The new VEK encrypted with the Account Key. */- encryptedVek: string;- /** Public half of the new account keypair, used by others to grant this user access to a shared manifest. */- accountPublicKey: string;- /** Private half of the new account keypair, encrypted with the Account Key. */- encryptedAccountPrivateKey: string;- };+ accountKeys: AccountKeyBlobs;/** Plaintext private half of the new account keypair, staged into the session once the push commits. */accountPrivateKey: string;};@@ -198,26 +189,12 @@ export async function requiresLegacyAccountKeyMigration(): Promise<boolean> {}/**- * Mint the full account key hierarchy for a migration push: a random Account Key (AK) encrypted with the- * password-derived key, which from then on is only the KEK; a fresh VEK encrypted with the AK; and the account- * keypair whose private half is encrypted with the AK too.+ * Mint the account key hierarchy for a migration push.* @param kek - the password-derived key this vault is currently encrypted with, which becomes the KEK*/export async function prepareLegacyAccountKeyMigration(kek: string): Promise<LegacyAccountKeyMigration> {- const contentKey = EncryptionUtility.generateVaultEncryptionKey();- const accountKey = EncryptionUtility.generateVaultEncryptionKey();- const accountKeyPair = await EncryptionUtility.generateRsaKeyPair();-- return {- contentKey,- accountKeys: {- encryptedAccountKey: await EncryptionUtility.encryptVaultEncryptionKey(accountKey, kek),- encryptedVek: await EncryptionUtility.encryptVaultEncryptionKey(contentKey, accountKey),- accountPublicKey: accountKeyPair.publicKey,- encryptedAccountPrivateKey: await EncryptionUtility.symmetricEncrypt(accountKeyPair.privateKey, accountKey),- },- accountPrivateKey: accountKeyPair.privateKey,- };+ const hierarchy = await mintAccountKeyHierarchy(kek);+ return { contentKey: hierarchy.vaultEncryptionKey, accountKeys: hierarchy.accountKeys, accountPrivateKey: hierarchy.accountPrivateKey };}/**