Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Rename user_salt to manifest_salt (#2159)
Leendert de Borst6191532c7be9
diff --git a/apps/browser-extension/src/utils/RustCore.ts b/apps/browser-extension/src/utils/RustCore.tsindex e3edef5f2..e44d839b2 100644--- a/apps/browser-extension/src/utils/RustCore.ts+++ b/apps/browser-extension/src/utils/RustCore.ts@@ -255,7 +255,7 @@ export type CodecManifest = {schemaVersion: number;/** Latest EF migration ID; readers derive the data-model version label from it. */migrationId: string;- userSalt: string;+ manifestSalt: string;canonicalizedAt: string;manifestId: string;name?: string | null;@@ -268,7 +268,7 @@ export type CodecManifest = {*/export type CodecManifestSpec = {manifestId: string;- userSalt: string;+ manifestSalt: string;name?: string | null;};@@ -412,11 +412,11 @@ export async function vaultCodecLogoContentHash(bytes: Uint8Array): Promise<stri}/**- * Generate a fresh 32-byte per-user salt (lowercase hex).+ * Generate a fresh 32-byte per-manifest blob-hashing salt (lowercase hex).*/-export async function vaultCodecGenerateUserSalt(): Promise<string> {+export async function vaultCodecGenerateManifestSalt(): Promise<string> {await initRustCore();- return core.vaultCodecGenerateUserSalt();+ return core.vaultCodecGenerateManifestSalt();}/**diff --git a/apps/browser-extension/src/utils/VaultSyncService.ts b/apps/browser-extension/src/utils/VaultSyncService.tsindex 0ad3157ce..f13fa5557 100644--- a/apps/browser-extension/src/utils/VaultSyncService.ts+++ b/apps/browser-extension/src/utils/VaultSyncService.ts@@ -13,7 +13,7 @@ import type { VaultResponse } from '@/utils/dist/core/models/webapi';import { VaultSqlGenerator } from '@/utils/dist/core/vault';import { buildEmailRouting } from '@/utils/EmailRouting';import { EncryptionUtility } from '@/utils/EncryptionUtility';-import {vaultCodecComputeCiphertextHash, vaultCodecComputeContentFingerprint, vaultCodecCanonicalizeFromSqlite, vaultCodecExtractEncryptionKeyForPublicKey, vaultCodecGenerateUserSalt, vaultCodecUnpackPayload, vaultCodecMaterializeAsSqlite, vaultCodecPackPayload, vaultCodecValidateManifest, vaultCodecValidateDataBucket, type CodecBlobEntry, type CodecCanonicalized, type CodecManifest, type CodecManifestSpec, type CodecMaterialized} from '@/utils/RustCore';+import {vaultCodecComputeCiphertextHash, vaultCodecComputeContentFingerprint, vaultCodecCanonicalizeFromSqlite, vaultCodecExtractEncryptionKeyForPublicKey, vaultCodecGenerateManifestSalt, vaultCodecUnpackPayload, vaultCodecMaterializeAsSqlite, vaultCodecPackPayload, vaultCodecValidateManifest, vaultCodecValidateDataBucket, type CodecBlobEntry, type CodecCanonicalized, type CodecManifest, type CodecManifestSpec, type CodecMaterialized} from '@/utils/RustCore';import { SharingService, type SessionSharedManifest } from '@/utils/SharingService';import { SqliteClient } from '@/utils/SqliteClient';import { getItemWithFallback } from '@/utils/StorageUtility';@@ -520,10 +520,10 @@ export class VaultSyncService {if (dto.isRoot) {/*- * Persist the user salt locally so subsequent canonicalizes hash blobs the same way, and the root+ * Persist the root manifest's blob salt locally so subsequent canonicalizes hash blobs the same way, and the root* manifest id so a push can resolve it even before the vault DB records it (see `recordOwnManifestId`).*/- await storage.setItem(StorageKeys.VAULT_V2_USER_SALT, entry.manifest.userSalt);+ await storage.setItem(StorageKeys.VAULT_V2_MANIFEST_SALT, entry.manifest.manifestSalt);await storage.setItem(StorageKeys.VAULT_V2_ROOT_MANIFEST_ID, entry.manifestId);continue;}@@ -536,7 +536,7 @@ export class VaultSyncService {folderId,manifestId: dto.manifestId,vek: manifestKey,- salt: entry.manifest.userSalt,+ salt: entry.manifest.manifestSalt,revision: entry.revision,name: entry.manifest.name ?? dto.name ?? null,ownerUsername: dto.ownerUsername ?? null,@@ -1201,16 +1201,16 @@ export class VaultSyncService {}/**- * Canonicalize the local vault into the manifest-v1 format using the persisted user salt (generated on first+ * Canonicalize the local vault into the manifest-v1 format using the root manifest's persisted blob salt (generated on first* save), splitting off each shared manifest's anchor subtree into its own manifest.* @param sqliteClient - the in-memory SQLite database to canonicalize* @returns The canonicalized set plus the resolved shared-manifest session records*/private async canonicalizeVault(sqliteClient: SqliteClient, options?: { adoptUnstampedInto?: string | null }): Promise<CanonicalizedVaultSet> {- let userSalt = (await storage.getItem(StorageKeys.VAULT_V2_USER_SALT)) as string | null;- if (!userSalt) {- userSalt = await vaultCodecGenerateUserSalt();- await storage.setItem(StorageKeys.VAULT_V2_USER_SALT, userSalt);+ let manifestSalt = (await storage.getItem(StorageKeys.VAULT_V2_MANIFEST_SALT)) as string | null;+ if (!manifestSalt) {+ manifestSalt = await vaultCodecGenerateManifestSalt();+ await storage.setItem(StorageKeys.VAULT_V2_MANIFEST_SALT, manifestSalt);}// Read tables from the SQLite database and apply the manifest-v1 format rules.@@ -1230,7 +1230,7 @@ export class VaultSyncService {*/const sharedManifestSpecs: CodecManifestSpec[] = Object.values(sharedManifestRecords).map(r => ({manifestId: r.manifestId,- userSalt: r.salt,+ manifestSalt: r.salt,name: r.name ?? null,}));@@ -1250,7 +1250,7 @@ export class VaultSyncService {migrationId,canonicalizedAt: new Date().toISOString(),// The manifest being written from goes first; the rest are the shared manifests split out of it.- manifests: [{ manifestId: rootManifestId, userSalt }, ...sharedManifestSpecs],+ manifests: [{ manifestId: rootManifestId, manifestSalt }, ...sharedManifestSpecs],adoptUnstampedInto: options?.adoptUnstampedInto ?? null,}));diff --git a/apps/browser-extension/src/utils/constants/storageKeys.ts b/apps/browser-extension/src/utils/constants/storageKeys.tsindex 72a5bf853..edb576d02 100644--- a/apps/browser-extension/src/utils/constants/storageKeys.ts+++ b/apps/browser-extension/src/utils/constants/storageKeys.ts@@ -67,8 +67,8 @@ export const StorageKeys = {LAST_SYNC_ERROR: 'local:lastSyncError',/** The client's last known revision per non-root (shared) manifest. */SERVER_MANIFEST_REVISIONS: 'local:serverManifestRevisions',- /** Per-user salt used to canonicalize the vault into the manifest-v1 format. */- VAULT_V2_USER_SALT: 'local:vaultV2UserSalt',+ /** The root manifest's blob-hashing salt, cached from the last pull; see `CodecManifest.manifestSalt`. */+ VAULT_V2_MANIFEST_SALT: 'local:vaultV2ManifestSalt',/*** The server-side id of the user's root manifest, learned from GET /v2/Vault. Fallback source for@@ -275,7 +275,7 @@ export const allVaultDataStorageKeys = (): StorageKey[] => [StorageKeys.SERVER_REVISION,StorageKeys.LEGACY_VAULT_REVISION_NUMBER,StorageKeys.SERVER_MANIFEST_REVISIONS,- StorageKeys.VAULT_V2_USER_SALT,+ StorageKeys.VAULT_V2_MANIFEST_SALT,StorageKeys.VAULT_V2_ROOT_MANIFEST_ID,StorageKeys.VAULT_V2_CONTENT_FINGERPRINTS,StorageKeys.VAULT_V2_BLOB_CIPHER_CACHE,diff --git a/apps/browser-extension/tests/helpers/manifest-v2-api.ts b/apps/browser-extension/tests/helpers/manifest-v2-api.tsindex 8e1852d02..971524f73 100644--- a/apps/browser-extension/tests/helpers/manifest-v2-api.ts+++ b/apps/browser-extension/tests/helpers/manifest-v2-api.ts@@ -39,7 +39,7 @@ export type VaultSnapshot = {export type DecryptedManifest = {schemaVersion: number;migrationId: string;- userSalt: string;+ manifestSalt: string;canonicalizedAt: string;tables: Record<string, Array<Record<string, unknown>>>;[key: string]: unknown;diff --git a/core/rust/src/ffi.rs b/core/rust/src/ffi.rsindex ff65e5f36..afdad8994 100644--- a/core/rust/src/ffi.rs+++ b/core/rust/src/ffi.rs@@ -298,13 +298,13 @@ pub extern "C" fn vault_codec_bucket_layout_ffi() -> *mut c_char {}}-/// Generate a fresh per-user salt (lowercase hex).+/// Generate a fresh per-manifest blob-hashing salt (lowercase hex).////// # Safety/// Free the result with `free_string`.#[no_mangle]-pub extern "C" fn vault_codec_generate_user_salt_ffi() -> *mut c_char {- string_to_c_char(crate::vault_codec::generate_user_salt())+pub extern "C" fn vault_codec_generate_manifest_salt_ffi() -> *mut c_char {+ string_to_c_char(crate::vault_codec::generate_manifest_salt())}/// SHA-256 (lowercase hex) of a base64 ciphertext string.diff --git a/core/rust/src/lib.rs b/core/rust/src/lib.rsindex f6011dffc..c7d3fea0c 100644--- a/core/rust/src/lib.rs+++ b/core/rust/src/lib.rs@@ -32,7 +32,7 @@ pub use vault_merge::{};pub use vault_codec::{compute_ciphertext_hash, compute_content_fingerprint, canonicalize_from_sqlite,- extract_bucket, generate_user_salt, unpack_payload, materialize_as_sqlite, pack_payload,+ extract_bucket, generate_manifest_salt, unpack_payload, materialize_as_sqlite, pack_payload,validate_manifest, validate_data_bucket, BlobEntry,CanonicalizeInput, CanonicalizedManifest, CanonicalizedVault, CodecRecord, CodecTableData, DataBucket, Manifest,MaterializeInput, MaterializedTables, ManifestSpec, ValidationResult,diff --git a/core/rust/src/uniffi_api.rs b/core/rust/src/uniffi_api.rsindex 3637ecd05..6964df57a 100644--- a/core/rust/src/uniffi_api.rs+++ b/core/rust/src/uniffi_api.rs@@ -226,10 +226,10 @@ pub fn vault_codec_bucket_layout() -> Result<String, VaultError> {crate::vault_codec::bucket_layout_json()}-/// Generate a fresh 32-byte per-user salt (lowercase hex).+/// Generate a fresh 32-byte per-manifest blob-hashing salt (lowercase hex).#[uniffi::export]-pub fn vault_codec_generate_user_salt() -> String {- crate::vault_codec::generate_user_salt()+pub fn vault_codec_generate_manifest_salt() -> String {+ crate::vault_codec::generate_manifest_salt()}/// The `Logos.Id` to use for `source` inside the manifest with id `manifest_id`.diff --git a/core/rust/src/vault_codec/canonicalize.rs b/core/rust/src/vault_codec/canonicalize.rsindex a96df1560..fd4ac5cb3 100644--- a/core/rust/src/vault_codec/canonicalize.rs+++ b/core/rust/src/vault_codec/canonicalize.rs@@ -35,7 +35,7 @@ pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<CanonicNone => return Err(crate::error::VaultError::General("canonicalize input declares no manifests".to_string())),};let writing_manifest_id = writing_spec.manifest_id.clone();- let writing_user_salt = writing_spec.user_salt.clone();+ let writing_manifest_salt = writing_spec.manifest_salt.clone();// Collect every non-skip table into a name > rows map (row order preserved per table). Blob// extraction and bucket-splitting happen below.@@ -116,7 +116,7 @@ pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<Canonic}// Manifest table: extract any blob column into the content-addressed map.- let out_rows = extract_table_blobs(&name, records, &writing_user_salt, &mut blobs);+ let out_rows = extract_table_blobs(&name, records, &writing_manifest_salt, &mut blobs);manifest_tables.insert(name, out_rows);}@@ -142,7 +142,7 @@ pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<Canonicmanifest: Manifest {schema_version: SCHEMA_VERSION,migration_id: input.migration_id.clone(),- user_salt: writing_user_salt,+ manifest_salt: writing_manifest_salt,canonicalized_at: input.canonicalized_at.clone(),manifest_id: writing_manifest_id,name: writing_spec.name.clone(),@@ -159,7 +159,7 @@ pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<Canonic.tables.into_iter().map(|(name, records)| {- let out_rows = extract_table_blobs(&name, records, &partition.user_salt, &mut partition_blobs);+ let out_rows = extract_table_blobs(&name, records, &partition.manifest_salt, &mut partition_blobs);(name, out_rows)}).collect();@@ -167,7 +167,7 @@ pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<Canonicmanifest: Manifest {schema_version: SCHEMA_VERSION,migration_id: input.migration_id.clone(),- user_salt: partition.user_salt,+ manifest_salt: partition.manifest_salt,canonicalized_at: input.canonicalized_at.clone(),manifest_id: partition.manifest_id,name: partition.name,@@ -217,12 +217,12 @@ fn is_unstamped(row: &CodecRecord) -> bool {}/// Extract `table`'s blob column (if it owns one) into `blobs`, returning the rewritten rows.-fn extract_table_blobs(table: &str, records: Vec<CodecRecord>, user_salt: &str, blobs: &mut HashMap<String, BlobEntry>) -> Vec<CodecRecord> {+fn extract_table_blobs(table: &str, records: Vec<CodecRecord>, manifest_salt: &str, blobs: &mut HashMap<String, BlobEntry>) -> Vec<CodecRecord> {let blob_spec = blob_spec_for(table);let mut out_rows: Vec<CodecRecord> = Vec::with_capacity(records.len());for mut row in records {if let Some((_, blob_col, kind)) = blob_spec {- let extracted = extract_blob_cell(row.get(*blob_col), user_salt, kind, blobs);+ let extracted = extract_blob_cell(row.get(*blob_col), manifest_salt, kind, blobs);row.insert((*blob_col).to_string(), extracted);}out_rows.push(row);@@ -234,7 +234,7 @@ fn extract_table_blobs(table: &str, records: Vec<CodecRecord>, user_salt: &str,/// return a blob-ref; otherwise return JSON null.fn extract_blob_cell(cell: Option<&serde_json::Value>,- user_salt: &str,+ manifest_salt: &str,kind: &str,blobs: &mut HashMap<String, BlobEntry>,) -> serde_json::Value {@@ -248,7 +248,7 @@ fn extract_blob_cell(_ => return serde_json::Value::Null,};- let hash = salted_blob_hash(&bytes, user_salt);+ let hash = salted_blob_hash(&bytes, manifest_salt);blobs.entry(hash.clone()).or_insert_with(|| BlobEntry {kind: kind.to_string(),bytes_base64: b64.to_string(),diff --git a/core/rust/src/vault_codec/hash.rs b/core/rust/src/vault_codec/hash.rsindex 34c302851..1fcd03b69 100644--- a/core/rust/src/vault_codec/hash.rs+++ b/core/rust/src/vault_codec/hash.rs@@ -94,12 +94,9 @@ pub fn content_hash(value: &serde_json::Value) -> String {sha256_hex(canonical_json(value).as_bytes())}-/// Per-user salted blob hash `sha256(salt_bytes ‖ plaintext_bytes)`, lowercase hex.-///-/// `user_salt` is a hex string (decoded to bytes before concatenation).-/// Per-user salt means the server cannot enumerate which blobs a user has across users.-pub fn salted_blob_hash(bytes: &[u8], user_salt: &str) -> String {- let salt_bytes = hex_to_bytes(user_salt).unwrap_or_default();+/// Per-manifest salted blob hash `sha256(salt_bytes ‖ plaintext_bytes)`, lowercase hex.+pub fn salted_blob_hash(bytes: &[u8], manifest_salt: &str) -> String {+ let salt_bytes = hex_to_bytes(manifest_salt).unwrap_or_default();let mut hasher = Sha256::new();hasher.update(&salt_bytes);hasher.update(bytes);diff --git a/core/rust/src/vault_codec/manifest.rs b/core/rust/src/vault_codec/manifest.rsindex 46afaa535..bbda5ad70 100644--- a/core/rust/src/vault_codec/manifest.rs+++ b/core/rust/src/vault_codec/manifest.rs@@ -19,7 +19,7 @@ pub struct Manifest {/// Per-manifest salt for blob hashing (hex). For a shared manifest this salt is shared by/// every participant (it lives inside the encrypted manifest itself) so all of them compute the/// same content-addressed blob hashes.- pub user_salt: String,+ pub manifest_salt: String,/// Timestamp when this canonical snapshot was produced (ISO-8601).pub canonicalized_at: String,/// The server-side id of the manifest this snapshot belongs to.@@ -81,7 +81,7 @@ pub struct BlobEntry {pub struct ManifestSpec {pub manifest_id: String,/// Per-manifest salt for this manifest's blob hashing.- pub user_salt: String,+ pub manifest_salt: String,/// Display name written into the manifest. See [`Manifest::name`].#[serde(default)]pub name: Option<String>,diff --git a/core/rust/src/vault_codec/mod.rs b/core/rust/src/vault_codec/mod.rsindex 854f6182a..6804c2017 100644--- a/core/rust/src/vault_codec/mod.rs+++ b/core/rust/src/vault_codec/mod.rs@@ -86,8 +86,8 @@ pub fn logo_content_hash(bytes: &[u8]) -> String {hash::sha256_hex(bytes)}-/// Generate a fresh 32-byte per-user salt as a lowercase hex string.-pub fn generate_user_salt() -> String {+/// Generate a fresh 32-byte per-manifest blob-hashing salt as a lowercase hex string.+pub fn generate_manifest_salt() -> String {use rand::RngCore;let mut bytes = [0u8; 32];rand::rng().fill_bytes(&mut bytes);diff --git a/core/rust/src/vault_codec/validate.rs b/core/rust/src/vault_codec/validate.rsindex ad0634d02..31dbf7b05 100644--- a/core/rust/src/vault_codec/validate.rs+++ b/core/rust/src/vault_codec/validate.rs@@ -39,8 +39,8 @@ pub fn validate_manifest(manifest: &Manifest) -> ValidationResult {if manifest.schema_version < 1 {failed.push("schemaVersion-missing-or-too-low".to_string());}- if manifest.user_salt.len() < 32 {- failed.push("userSalt-missing-or-short".to_string());+ if manifest.manifest_salt.len() < 32 {+ failed.push("manifestSalt-missing-or-short".to_string());}// Every manifest carries its own id: rows inside are stamped with it.if manifest.manifest_id.is_empty() {diff --git a/core/rust/src/wasm.rs b/core/rust/src/wasm.rsindex f44a4794a..a0394b65f 100644--- a/core/rust/src/wasm.rs+++ b/core/rust/src/wasm.rs@@ -193,10 +193,10 @@ pub fn vault_codec_overflow_table_js() -> String {vault_codec::OVERFLOW_TABLE.to_string()}-/// Generate a fresh 32-byte per-user salt (lowercase hex).-#[wasm_bindgen(js_name = vaultCodecGenerateUserSalt)]-pub fn vault_codec_generate_user_salt_js() -> String {- vault_codec::generate_user_salt()+/// Generate a fresh 32-byte per-manifest blob-hashing salt (lowercase hex).+#[wasm_bindgen(js_name = vaultCodecGenerateManifestSalt)]+pub fn vault_codec_generate_manifest_salt_js() -> String {+ vault_codec::generate_manifest_salt()}/// Pack a payload JSON string into gzip(envelope{contentHash, payload}). Encryption is done by platform.