Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update legacy remarks (#2159)
Leendert de Borst1c9569d6a82d
diff --git a/core/client/src/database/SqliteClient.ts b/core/client/src/database/SqliteClient.tsindex 17d9de0ad..e6a992fe3 100644--- a/core/client/src/database/SqliteClient.ts+++ b/core/client/src/database/SqliteClient.ts@@ -404,8 +404,8 @@ export class SqliteClient implements ISyncDatabaseClient {/*** Get the current database version from the migrations history.*- * TODO: part of the sqlite-blob upgrade chain (frozen up to 2.0.0); delete once all users- * have migrated. New schema changes ship via requiresSchemaMigration / migrateVaultToCurrentSchema instead.+ * LEGACY: part of the sqlite-blob upgrade chain (frozen up to 2.0.0); remove once every account+ * has migrated. New schema changes ship via requiresSchemaMigration / migrateVaultToCurrentSchema instead.* @returns The database version information*/public async getDatabaseVersion(): Promise<VaultVersion> {@@ -461,8 +461,8 @@ export class SqliteClient implements ISyncDatabaseClient {/*** Get the latest available database version.*- * TODO: part of the sqlite-blob upgrade chain (frozen up to 2.0.0); delete once all users- * have migrated. New schema changes ship via requiresSchemaMigration / migrateVaultToCurrentSchema instead.+ * LEGACY: part of the sqlite-blob upgrade chain (frozen up to 2.0.0); remove once every account+ * has migrated. New schema changes ship via requiresSchemaMigration / migrateVaultToCurrentSchema instead.* @returns The latest VaultVersion*/public async getLatestDatabaseVersion(): Promise<VaultVersion> {@@ -475,8 +475,8 @@ export class SqliteClient implements ISyncDatabaseClient {* Whether the vault still has to walk the sqlite-blob upgrade chain (VAULT_VERSIONS, frozen at 2.0.0) via the /upgrade* page before it is eligible for anything else.*- * TODO: this is the legacy sqlite-blob migration path, which we will stop supporting later; delete once all- * users have migrated. New schema changes ship via requiresSchemaMigration / migrateVaultToCurrentSchema instead.+ * LEGACY: the sqlite-blob migration path, which will stop being supported later; remove once every+ * account has migrated. New schema changes ship via requiresSchemaMigration / migrateVaultToCurrentSchema instead.* @returns True if there are pending migrations*/public async requiresLegacySqliteBlobMigration(): Promise<boolean> {@@ -500,7 +500,7 @@ export class SqliteClient implements ISyncDatabaseClient {if (await this.requiresLegacySqliteBlobMigration()) {/** Still on the sqlite-blob upgrade chain: that upgrade has to run first, so the migration is not applicable yet.- * TODO: delete once all users have migrated.+ * LEGACY: remove once every account has migrated.*/return false;}diff --git a/core/client/src/rust/RustCoreTypes.ts b/core/client/src/rust/RustCoreTypes.tsindex 85bbf6cdf..4da61e281 100644--- a/core/client/src/rust/RustCoreTypes.ts+++ b/core/client/src/rust/RustCoreTypes.ts@@ -139,6 +139,6 @@ export type CodecCanonicalizeInput = {tables: CodecTableData[];canonicalizedAt: string;manifests: CodecManifestSpec[];- /** For legacy sqlite-blob migration: the manifest that unstamped rows are stamped with. TODO: delete this field once the migration is complete. */+ /** LEGACY: for the sqlite-blob migration, the manifest that unstamped rows are stamped with. Remove once every account has migrated to manifest-v1. */stampUnstampedInto?: string | null;};diff --git a/core/client/src/sync/LegacyStorageModelMigration.ts b/core/client/src/sync/LegacyStorageModelMigration.tsindex 2b05932dd..6c5cfc410 100644--- a/core/client/src/sync/LegacyStorageModelMigration.ts+++ b/core/client/src/sync/LegacyStorageModelMigration.ts@@ -1,7 +1,7 @@/*** Legacy storage model migration specific logic.*- * TODO: these methods and file can be deleted later once all users have migrated from sqlite-blob to manifest-v1.+ * LEGACY: remove once every account has migrated from sqlite-blob to manifest-v1. Deletes as a whole file.*/import { ServerUpdateRequiredError } from '../api/errors/ServerUpdateRequiredError';diff --git a/core/rust/src/vault_codec/canonicalize.rs b/core/rust/src/vault_codec/canonicalize.rsindex 7cc0cb08e..8275dc4a2 100644--- a/core/rust/src/vault_codec/canonicalize.rs+++ b/core/rust/src/vault_codec/canonicalize.rs@@ -70,8 +70,7 @@ pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<Canonicnormalize_id_spelling(bucket_tables);}- // Legacy migration: stamp unstamped rows with the manifest if specified by the caller.- // TODO: delete this once the migration is complete.+ // LEGACY: stamp unstamped rows with the manifest named by the sqlite-blob migration. Remove with that migration.if let Some(stamp_into) = input.stamp_unstamped_into.as_deref() {stamp_unstamped_rows(&mut all_tables, stamp_into);}@@ -106,7 +105,7 @@ pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<Canoniclet mut manifest_tables: HashMap<String, Vec<CodecRecord>> = HashMap::new();for (name, records) in all_tables {// Manifest table: extract any blob column into the content-addressed map.- let out_rows = extract_table_blobs(&name, records, &writing_manifest_salt, &mut blobs);+ let out_rows = extract_table_blobs(&name, records, &writing_manifest_salt, &mut blobs)?;manifest_tables.insert(name, out_rows);}@@ -136,10 +135,10 @@ pub fn canonicalize_from_sqlite(input: CanonicalizeInput) -> VaultResult<Canonic.tables.into_iter().map(|(name, records)| {- let out_rows = extract_table_blobs(&name, records, &partition.manifest_salt, &mut partition_blobs);- (name, out_rows)+ let out_rows = extract_table_blobs(&name, records, &partition.manifest_salt, &mut partition_blobs)?;+ Ok((name, out_rows))})- .collect();+ .collect::<VaultResult<_>>()?;let partition_extra = overflow.manifest_extra(&partition.manifest_id);manifests.push(CanonicalizedManifest {manifest: Manifest {@@ -230,8 +229,7 @@ fn owning_manifest(row: &CodecRecord, manifest_ids: &[String]) -> Option<String>manifest_ids.iter().find(|id| ids_equal(id, stamp)).cloned()}-/// For legacy sqlite-blob migration: the manifest that unstamped rows are stamped with.-/// TODO: delete this function once the migration is complete.+/// LEGACY: only the sqlite-blob migration stamps unstamped rows. Remove once every account has migrated to manifest-v1.////// Stamp every unstamped row of a manifest-scoped table with `manifest_id`. A row that already names a/// manifest keeps it, so a vault that has been converted once pays nothing on later runs.@@ -268,12 +266,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>, manifest_salt: &str, blobs: &mut HashMap<String, BlobEntry>) -> Vec<CodecRecord> {- let Some(spec) = blob_spec_for(table) else { return records };+fn extract_table_blobs(table: &str, records: Vec<CodecRecord>, manifest_salt: &str, blobs: &mut HashMap<String, BlobEntry>) -> VaultResult<Vec<CodecRecord>> {+ let Some(spec) = blob_spec_for(table) else { return Ok(records) };let mut out_rows: Vec<CodecRecord> = Vec::with_capacity(records.len());for mut row in records {let known_hash = row.remove(spec.hash_column);- let mut cell = extract_blob_cell(row.get(spec.column), manifest_salt, spec.kind, blobs);+ let mut cell = extract_blob_cell(row.get(spec.column), manifest_salt, spec.kind, blobs)?;if cell.is_null() && !is_deleted(&row) {if let Some(hash) = known_hash.as_ref().and_then(Value::as_str).filter(|hash| !hash.is_empty()) {cell = blob_ref(hash, spec.kind);@@ -282,7 +280,7 @@ fn extract_table_blobs(table: &str, records: Vec<CodecRecord>, manifest_salt: &srow.insert(spec.column.to_string(), cell);out_rows.push(row);}- out_rows+ Ok(out_rows)}/// Extract a blob column cell: if it holds non-empty `{ "__b64" }` bytes, hash + register them and@@ -292,24 +290,24 @@ fn extract_blob_cell(manifest_salt: &str,kind: &str,blobs: &mut HashMap<String, BlobEntry>,-) -> serde_json::Value {+) -> VaultResult<serde_json::Value> {let b64 = match cell.and_then(inline_b64) {Some(s) => s,- None => return serde_json::Value::Null,+ None => return Ok(serde_json::Value::Null),};let bytes = match crate::encoding::base64_decode(b64) {Ok(b) if !b.is_empty() => b,- _ => return serde_json::Value::Null,+ _ => return Ok(serde_json::Value::Null),};- let hash = salted_blob_hash(&bytes, manifest_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(),});- blob_ref(&hash, kind)+ Ok(blob_ref(&hash, kind))}/// Re-attach overflow columns.diff --git a/core/rust/src/vault_codec/hash.rs b/core/rust/src/vault_codec/hash.rsindex d5a6ed5eb..6a698dcd1 100644--- a/core/rust/src/vault_codec/hash.rs+++ b/core/rust/src/vault_codec/hash.rs@@ -15,6 +15,7 @@use sha2::{Digest, Sha256};use crate::encoding::{hex_decode, hex_encode_lower, uuid_from_bytes};+use crate::error::{VaultError, VaultResult};/// A UUIDv8 derived from a string: the first 16 bytes of its sha256, version and variant bits set.pub fn derived_uuid(material: &str) -> String {@@ -71,12 +72,13 @@ pub fn content_hash(value: &serde_json::Value) -> String {}/// 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_decode(manifest_salt).unwrap_or_default();+/// A missing or malformed salt is an error, since hashing without it would break the per-manifest separation.+pub fn salted_blob_hash(bytes: &[u8], manifest_salt: &str) -> VaultResult<String> {+ let salt_bytes = hex_decode(manifest_salt).filter(|salt| !salt.is_empty()).ok_or_else(|| VaultError::General("manifest salt is missing or not valid hex".to_string()))?;let mut hasher = Sha256::new();hasher.update(&salt_bytes);hasher.update(bytes);- hex_encode_lower(&hasher.finalize())+ Ok(hex_encode_lower(&hasher.finalize()))}#[cfg(test)]@@ -115,7 +117,7 @@ mod tests {#[test]fn salted_hash_is_stable() {// Pinned vector: salt "00ff", bytes [1,2,3].- let h = salted_blob_hash(&[1, 2, 3], "00ff");+ let h = salted_blob_hash(&[1, 2, 3], "00ff").unwrap();// sha256(00 ff 01 02 03)assert_eq!(h, sha256_hex(&[0x00, 0xff, 0x01, 0x02, 0x03]));assert_eq!(h.len(), 64);diff --git a/core/rust/src/vault_codec/manifest.rs b/core/rust/src/vault_codec/manifest.rsindex 4f41b22c1..d6b6e8af1 100644--- a/core/rust/src/vault_codec/manifest.rs+++ b/core/rust/src/vault_codec/manifest.rs@@ -29,6 +29,7 @@ pub struct Manifest {#[serde(default, skip_serializing_if = "Option::is_none")]pub name: Option<String>,/// Tables mapped to arrays of row objects. Blob columns replaced with `{ "__blobRef", "__blobKind" }`.+ #[serde(default)]pub tables: HashMap<String, Vec<CodecRecord>>,/// Unknown top-level keys from a newer writer, carried through the local vault in [`CodecOverflow`].#[serde(flatten)]@@ -43,6 +44,7 @@ pub struct DataBucket {pub schema_version: u32,pub manifest_id: String,pub category: String,+ #[serde(default)]pub tables: HashMap<String, Vec<CodecRecord>>,#[serde(flatten)]pub extra: HashMap<String, serde_json::Value>,@@ -229,8 +231,8 @@ pub struct CanonicalizeInput {pub tables: Vec<CodecTableData>,pub canonicalized_at: String,pub manifests: Vec<ManifestSpec>,- /// For legacy sqlite-blob migration: the manifest that unstamped rows are stamped with.- /// TODO: delete this field once the migration is complete.+ /// LEGACY: for the sqlite-blob migration, the manifest that unstamped rows are stamped with. Remove once every+ /// account has migrated to manifest-v1.#[serde(default)]pub stamp_unstamped_into: Option<String>,}diff --git a/core/rust/src/vault_codec/materialize.rs b/core/rust/src/vault_codec/materialize.rsindex 432c2ed23..bcfeb2ac0 100644--- a/core/rust/src/vault_codec/materialize.rs+++ b/core/rust/src/vault_codec/materialize.rs@@ -11,8 +11,8 @@//! so it lives inside the vault DB itself and `canonicalize_from_sqlite` re-merges it from the//! ordinary table read, this client's next push never drops the data, and no platform has to wire//! (or remember) a separate persistence channel. Unknown top-level keys of a manifest or bucket ride in-//! the same overflow. A manifest or bucket written at a newer major format version is refused and reqiures-/// updating the app to read it.+//! the same overflow. A manifest or bucket written at a newer major format version is refused and requires+//! updating the app to read it.use std::collections::{HashMap, HashSet};diff --git a/core/rust/src/vault_codec/scoped_assets.rs b/core/rust/src/vault_codec/scoped_assets.rsindex 57135e6a9..5d6209f3e 100644--- a/core/rust/src/vault_codec/scoped_assets.rs+++ b/core/rust/src/vault_codec/scoped_assets.rs@@ -42,7 +42,7 @@ const FAVICON_ID_NAMESPACE: &str = "aliasvault:logo:v1";/// collide). `source` is matched case-insensitively (callers already normalize to a lowercase/// hostname or lowercase hex digest; this makes it robust anyway).pub fn logo_id_for(manifest_id: &str, kind: &str, source: &str) -> String {- super::hash::derived_uuid(&format!("{}\n{}\n{}", namespace_for_kind(kind), manifest_id, source.to_lowercase()))+ super::hash::derived_uuid(&format!("{}\n{}\n{}", namespace_for_kind(kind), id_key(manifest_id), source.to_lowercase()))}/// The derivation namespace for a kind. Unknown kinds get one derived from their own name, so a newerdiff --git a/core/rust/src/vault_codec/sharing_tests.rs b/core/rust/src/vault_codec/sharing_tests.rsindex da830fc37..62ed5d643 100644--- a/core/rust/src/vault_codec/sharing_tests.rs+++ b/core/rust/src/vault_codec/sharing_tests.rs@@ -518,8 +518,8 @@ fn split_hashes_blobs_with_per_manifest_salts() {// Shared blob map: shared attachment + both logo copies, hashed with the SHARED salt.assert_eq!(shared.blobs.len(), 3);let logo_bytes = [0xAAu8, 0xBB];- let expected_personal_hash = hash::salted_blob_hash(&logo_bytes, SALT_PERSONAL);- let expected_shared_hash = hash::salted_blob_hash(&logo_bytes, SALT_SHARED);+ let expected_personal_hash = hash::salted_blob_hash(&logo_bytes, SALT_PERSONAL).unwrap();+ let expected_shared_hash = hash::salted_blob_hash(&logo_bytes, SALT_SHARED).unwrap();assert!(out.first().blobs.contains_key(&expected_personal_hash), "github favicon hashed with the personal salt in personal manifest");assert!(shared.blobs.contains_key(&expected_shared_hash), "github favicon hashed with shared salt in shared manifest");assert_ne!(expected_personal_hash, expected_shared_hash);diff --git a/core/rust/src/vault_codec/tests.rs b/core/rust/src/vault_codec/tests.rsindex e0cf5f883..0adccac2c 100644--- a/core/rust/src/vault_codec/tests.rs+++ b/core/rust/src/vault_codec/tests.rs@@ -121,7 +121,7 @@ fn canonicalize_from_sqlite_extracts_blob_columns_and_hashes() {assert_eq!(out.first().blobs.len(), 1);let (hash, entry) = out.first().blobs.iter().next().unwrap();assert_eq!(entry.kind, "favicon");- assert_eq!(hash, &hash::salted_blob_hash(&favicon, "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"));+ assert_eq!(hash, &hash::salted_blob_hash(&favicon, "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff").unwrap());let logos = &out.first().manifest.tables["Logos"][0];let cell = &logos["FileData"];@@ -287,6 +287,19 @@ fn forward_compat_unknown_manifest_fields_preserved() {assert_eq!(reser["futureField"], json!({ "nested": true }));}+#[test]+fn logo_id_ignores_manifest_id_casing() {+ let id = scoped_assets::logo_id_for("6bdd3e29-3add-4c3f-8d63-6ada1e74c8c6", LOGO_KIND_FAVICON, "github.com");+ assert_eq!(id, scoped_assets::logo_id_for("6BDD3E29-3ADD-4C3F-8D63-6ADA1E74C8C6", LOGO_KIND_FAVICON, "GitHub.com"));+}++#[test]+fn salted_blob_hash_refuses_a_missing_or_malformed_salt() {+ assert!(hash::salted_blob_hash(&[1, 2, 3], "").is_err());+ assert!(hash::salted_blob_hash(&[1, 2, 3], "not-hex").is_err());+ assert!(hash::salted_blob_hash(&[1, 2, 3], "abc").is_err());+}+#[test]fn canonicalize_rederives_legacy_logo_ids_and_collapses_duplicate_sources() {// Two clients generated distinct random Ids for the same domain; Items point at each. Canonicalizediff --git a/core/rust/src/vault_sync/legacy.rs b/core/rust/src/vault_sync/legacy.rsindex 23397fa81..d1fb49fee 100644--- a/core/rust/src/vault_sync/legacy.rs+++ b/core/rust/src/vault_sync/legacy.rs@@ -13,12 +13,12 @@ use super::state::{self, Ctx};use super::types::GetResponse;use super::{engine, keys};-/// The `storageFormat` a manifest-v1 snapshot declares; 0 (or absent) is a sqlite blob.-const STORAGE_FORMAT_MANIFEST: i32 = 1;+/// The `storageFormat` of a legacy sqlite-blob snapshot; an absent value means the same.+const STORAGE_FORMAT_SQLITE_BLOB: i32 = 0;/// Whether a snapshot is still on the legacy sqlite-blob format.pub(crate) fn is_legacy_sqlite_blob_snapshot(snapshot: &GetResponse) -> bool {- snapshot.storage_format != Some(STORAGE_FORMAT_MANIFEST)+ matches!(snapshot.storage_format, None | Some(STORAGE_FORMAT_SQLITE_BLOB))}/// Take a legacy snapshot apart for local storage: the blob passes through untouched, the manifest-v1 fingerprintsdiff --git a/core/rust/src/vault_sync/pull.rs b/core/rust/src/vault_sync/pull.rsindex e6d0f8604..d71f64af3 100644--- a/core/rust/src/vault_sync/pull.rs+++ b/core/rust/src/vault_sync/pull.rs@@ -59,7 +59,20 @@ pub(crate) struct PulledVault {/// `GET v2/Vault`.pub(crate) async fn fetch_snapshot(ctx: &Ctx) -> SyncResult<GetResponse> {- http::with_outdated_server_guard(http::get::<GetResponse>(&ctx.host, http::VAULT_ENDPOINT, true).await)+ let snapshot = http::with_outdated_server_guard(http::get::<GetResponse>(&ctx.host, http::VAULT_ENDPOINT, true).await)?;+ ensure_known_storage_format(&snapshot)?;+ Ok(snapshot)+}++/// The `storageFormat` a manifest-v1 snapshot declares.+const STORAGE_FORMAT_MANIFEST: i32 = 1;++/// Refuse a snapshot in a storage format newer than this build knows, instead of reading it as legacy (0 or absent).+fn ensure_known_storage_format(snapshot: &GetResponse) -> SyncResult<()> {+ match snapshot.storage_format {+ None | Some(0) | Some(STORAGE_FORMAT_MANIFEST) => Ok(()),+ Some(format) => Err(SyncError::VaultVersionIncompatible(format!("vault has storage format {}, this app reads up to {}; update the app", format, STORAGE_FORMAT_MANIFEST))),+ }}pub(crate) fn email_routing_of(snapshot: &GetResponse) -> EmailRoutingDto {diff --git a/core/rust/src/vault_sync/tests/mod.rs b/core/rust/src/vault_sync/tests/mod.rsindex 8ab5a4100..eb32d30de 100644--- a/core/rust/src/vault_sync/tests/mod.rs+++ b/core/rust/src/vault_sync/tests/mod.rs@@ -123,6 +123,26 @@ fn fresh_client_pulls_and_materializes_the_server_vault() {assert!(host.requests_to("Vault").len() == 1);}+#[test]+fn unknown_storage_format_is_refused_not_read_as_legacy() {+ let vek = crypto::generate_key_base64();+ let mut host = TestHost::new(&vek);+ host.state.insert(state::ENCRYPTED_ACCOUNT_KEY.to_string(), json!("wrapped"));+ let server_db = test_host::open_schema_db(&host.schema_sql);+ insert_item(&server_db, "aaaaaaaa-0000-4000-8000-000000000001", "Server item", PERSONAL_MANIFEST_ID);+ let (status, mut vault) = snapshot_of(&server_db, &vek, 7, &vault_codec::generate_manifest_salt());+ vault["storageFormat"] = json!(2);+ host.respond("GET", "Status", status);+ host.respond("GET", "Vault", vault);++ let result = host.drive(&SyncSession::new(&request("fullSync", &vek, false, 0)).unwrap());++ assert_eq!(result["success"], false, "{}", result);+ assert_eq!(result["errorKey"], "vaultVersionIncompatible", "an app too old for the format is told to update");+ assert!(item_names(&host.local).is_empty(), "nothing is materialized");+ assert!(host.requests_to("Vault").iter().all(|r| r.method == "GET"), "no legacy migration push");+}+#[test]fn clean_client_in_sync_does_nothing() {let vek = crypto::generate_key_base64();diff --git a/core/vault/src/sql/VaultVersions.ts b/core/vault/src/sql/VaultVersions.tsindex 9b6e7d9ac..14fa1c262 100644--- a/core/vault/src/sql/VaultVersions.ts+++ b/core/vault/src/sql/VaultVersions.ts@@ -14,7 +14,7 @@ import type { VaultVersion } from "../types/VaultVersion";* local SQLite is re-materialized from COMPLETE_SCHEMA_SQL on every vault pull, so schema changes* ship through the full schema only: no individual migration scripts and no version entries here.*- * TODO: delete this once all active users have migrated to 2.0.0++ * LEGACY: remove once every active account has migrated to 2.0.0+.*/export const VAULT_VERSIONS: VaultVersion[] = [{