Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update core/client vault key resolving calls (#2159)
Leendert de Borst1050f10c051e
diff --git a/core/client/src/platform/AppInfo.ts b/core/client/src/platform/AppInfo.tsindex bd7aff3a8..f61ed47c5 100644--- a/core/client/src/platform/AppInfo.ts+++ b/core/client/src/platform/AppInfo.ts@@ -1,25 +1,28 @@+import { DEFAULT_API_URL, DEFAULT_CLIENT_URL, MIN_SERVER_VERSION } from '@aliasvault/models/defaults';+import { getPlatform } from './ClientPlatform';/*** Version and server compatibility information. Version and client name come from the host's- * {@link IAppIdentity}; the server floor and the default URLs are shared by every client.+ * {@link IAppIdentity}; the server floor and the default URLs are shared by every client (see AppDefaults in+ * the models package, which also generates the native AppInfo files).*/export class AppInfo {/*** The minimum supported AliasVault server (API) version. If the server version is below this, the* client will throw an error stating that the server should be updated.*/- public static readonly MIN_SERVER_VERSION = '0.12.0-dev';+ public static readonly MIN_SERVER_VERSION = MIN_SERVER_VERSION;/*** The default AliasVault client URL.*/- public static readonly DEFAULT_CLIENT_URL = 'https://app.aliasvault.com';+ public static readonly DEFAULT_CLIENT_URL = DEFAULT_CLIENT_URL;/*** The default AliasVault web API URL.*/- public static readonly DEFAULT_API_URL = 'https://app.aliasvault.com/api';+ public static readonly DEFAULT_API_URL = DEFAULT_API_URL;/*** Prevent instantiation of this utility classdiff --git a/core/client/src/rust/RustCore.ts b/core/client/src/rust/RustCore.tsindex ea8dc7193..0f1dc51fe 100644--- a/core/client/src/rust/RustCore.ts+++ b/core/client/src/rust/RustCore.ts@@ -17,7 +17,7 @@ import type { Identity } from '@aliasvault/models/identity';import type { Item, PasswordSettings } from '@aliasvault/models/vault';export { AutofillMatchingMode } from './RustCoreTypes';-export type { CodecBlobEntry, CodecBucketLayoutEntry, CodecCanonicalized, CodecCanonicalizeInput, CodecCanonicalMergeInput, CodecCanonicalMergeOutput, CodecDataBucket, CodecManifest, CodecMaterialized, CodecValidation, FaviconTarget, IdentityNameInput, IdentityRequest, ParsedEmail, SharingAccessPartition, SharingManifestRecord, SharingWriteSet } from './RustCoreTypes';+export type { CodecBlobEntry, CodecBucketLayoutEntry, CodecCanonicalized, CodecCanonicalizeInput, CodecCanonicalMergeInput, CodecCanonicalMergeOutput, CodecDataBucket, CodecManifest, CodecMaterialized, CodecTableData, CodecValidation, FaviconTarget, IdentityNameInput, IdentityRequest, ParsedEmail, ParsedEmailAttachment, SharingAccessPartition, SharingManifestRecord, SharingWriteSet } from './RustCoreTypes';/*** The host's Rust core binding.diff --git a/core/client/src/sync/VaultSyncEngine.ts b/core/client/src/sync/VaultSyncEngine.tsindex c612cb9de..75c2028c8 100644--- a/core/client/src/sync/VaultSyncEngine.ts+++ b/core/client/src/sync/VaultSyncEngine.ts@@ -22,7 +22,7 @@ import type { StorageKey } from '../platform/KeyValueStore';import type { ISqliteDatabase, SqliteValue } from '../platform/SqliteEngine';/** The operations the engine runs. */-export type VaultSyncOperation = 'fullSync' | 'migrationStatus' | 'migrateManifest' | 'statusCheck';+export type VaultSyncOperation = 'fullSync' | 'migrationStatus' | 'migrateManifest' | 'statusCheck' | 'resolveVaultKey';/** What the host hands the engine at session start (the Rust `SyncRequest`). */export type VaultSyncEngineRequest = {@@ -45,7 +45,6 @@ export type VaultSyncEngineRequest = {export type VaultSyncSessionUpdates = {encryptionKey?: string;accountPrivateKey?: string;- clearAccountPrivateKey?: boolean;};/** The email routing a pulled vault came with. */@@ -95,6 +94,20 @@ export type VaultSyncMigrateManifestResult = EngineResultBase & {requiresLogout: boolean;};+/**+ * Outcome of the login-time key resolution: the vault key to store as the session key (the VEK behind the+ * account's key chain, or the password-derived key itself for a legacy account without a chain).+ */+export type VaultSyncResolveVaultKeyResult = EngineResultBase & {+ success: boolean;+ hasVaultKey: boolean;+ encryptionKey?: string;+ error?: string;+ errorCode?: string;+ errorKey?: string;+ requiresLogout: boolean;+};+/** Outcome of the lightweight status check. */export type VaultSyncStatusCheckResult = EngineResultBase & {success: boolean;@@ -522,8 +535,6 @@ async function applySessionUpdates(updates: VaultSyncSessionUpdates | undefined)}if (updates.accountPrivateKey) {await storage.set(StorageKeys.ACCOUNT_PRIVATE_KEY, updates.accountPrivateKey);- } else if (updates.clearAccountPrivateKey) {- await storage.remove(StorageKeys.ACCOUNT_PRIVATE_KEY);}}@@ -614,6 +625,23 @@ export async function runVaultStatusCheck(host: IVaultSyncEngineHost, webApi?: Wreturn result;}+/**+ * Resolve the vault key right after login: open the account's key chain with the password-derived key (the cached+ * chain when the server cannot be reached) and store the VEK as the session key. A legacy account keeps the derived+ * key. The sync operations assume the key this stored.+ * @param host - the host+ * @param derivedKeyBase64 - the password-derived key (KEK)+ * @param webApi - the API the HTTP commands run on+ */+export async function runVaultKeyResolution(host: IVaultSyncEngineHost, derivedKeyBase64: string, webApi?: WebApiService): Promise<VaultSyncResolveVaultKeyResult> {+ const request = { ...await buildVaultSyncRequest('resolveVaultKey'), encryptionKey: derivedKeyBase64 };+ const result = await runVaultSyncEngine<VaultSyncResolveVaultKeyResult>(host, request, webApi);+ if (result.success && result.encryptionKey) {+ await getPlatform().storage.set(StorageKeys.ENCRYPTION_KEY, result.encryptionKey);+ }+ return result;+}+/*** Classify the pending local migration.* @param host - the host