Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add folder encryption key table to client model (#2159)
Leendert de Borstffaf5d2580ab
diff --git a/core/rust/src/uniffi_api.rs b/core/rust/src/uniffi_api.rsindex e601eb71d..022b9642d 100644--- a/core/rust/src/uniffi_api.rs+++ b/core/rust/src/uniffi_api.rs@@ -446,8 +446,9 @@ mod tests {assert!(names.contains(&"FieldValues".to_string()));assert!(names.contains(&"Settings".to_string()));assert!(names.contains(&"EncryptionKeys".to_string()));+ assert!(names.contains(&"SharedFolderEncryptionKeys".to_string()));assert!(!names.contains(&crate::vault_codec::OVERFLOW_TABLE.to_string()), "overflow carrier is not in the merge input; the server base owns it");- assert_eq!(names.len(), 13);+ assert_eq!(names.len(), 14);}#[test]diff --git a/core/rust/src/vault_codec/mod.rs b/core/rust/src/vault_codec/mod.rsindex c23f50e12..aeeaf64e5 100644--- a/core/rust/src/vault_codec/mod.rs+++ b/core/rust/src/vault_codec/mod.rs@@ -29,10 +29,13 @@ pub use manifest::{Manifest, MaterializeInput, MaterializedTables, CodecRecord, CodecTableData, SharedFolderSpec, SharedVault,};pub use scoped_assets::{KIND_BUILTIN as LOGO_KIND_BUILTIN, KIND_CUSTOM as LOGO_KIND_CUSTOM, KIND_FAVICON as LOGO_KIND_FAVICON};-pub use sharing::extract_encryption_key_for_public_key_from_bucket;+pub use sharing::{+ active_shared_folder_encryption_key, extract_encryption_key_for_public_key_from_bucket, extract_shared_folder_encryption_key_for_public_key,+ SHARED_FOLDER_ENCRYPTION_KEYS_TABLE,+};pub use types::{- bucket_categories, bucket_category_for, is_personal_table, tables_for_category, BLOB_COLUMNS, BUCKET_TABLES,- OVERFLOW_ROW_ID, OVERFLOW_TABLE, PERSONAL_TABLES, SCHEMA_VERSION, SKIP_TABLES,+ bucket_categories, bucket_category_for, is_personal_table, is_shared_only_table, tables_for_category, BLOB_COLUMNS,+ BUCKET_TABLES, OVERFLOW_ROW_ID, OVERFLOW_TABLE, PERSONAL_TABLES, SCHEMA_VERSION, SHARED_ONLY_TABLES, SKIP_TABLES,};pub use validate::ValidationResult;@@ -163,6 +166,18 @@ pub fn extract_encryption_key_for_public_key_from_bucket_json(bucket_json: &str,Ok(serde_json::to_string(&extract_encryption_key_for_public_key_from_bucket(&b, public_key))?)}+/// Extract the shared folder encryption key for the public key from the manifest.+pub fn extract_shared_folder_encryption_key_for_public_key_json(manifest_json: &str, public_key: &str) -> VaultResult<String> {+ let m: Manifest = serde_json::from_str(manifest_json)?;+ Ok(serde_json::to_string(&extract_shared_folder_encryption_key_for_public_key(&m, public_key))?)+}++/// Extract the active shared folder encryption key from the manifest.+pub fn active_shared_folder_encryption_key_json(manifest_json: &str) -> VaultResult<String> {+ let m: Manifest = serde_json::from_str(manifest_json)?;+ Ok(serde_json::to_string(&active_shared_folder_encryption_key(&m))?)+}+/// SHA-256 (lowercase hex) of a base64 ciphertext string — storage-layer integrity.pub fn compute_ciphertext_hash(base64_ciphertext: &str) -> String {match BASE64.decode(base64_ciphertext) {diff --git a/core/rust/src/vault_codec/types.rs b/core/rust/src/vault_codec/types.rsindex 98f3e720d..6375dbe7c 100644--- a/core/rust/src/vault_codec/types.rs+++ b/core/rust/src/vault_codec/types.rs@@ -35,6 +35,12 @@ pub static BUCKET_TABLES: &[(&str, &str)] = &[/// are found in a shared manifest anyway.pub static PERSONAL_TABLES: &[&str] = &["EncryptionKeys"];+/// Tables that belong exclusively to a *shared-folder* manifest and never to the root.+// `SharedFolderEncryptionKeys` carries a folder's own email keypair, so that every member+/// of the folder can decrypt mail addressed to the folder's aliases; it is encrypted under+/// the folder VEK and therefore readable by exactly the folder's members.+pub static SHARED_ONLY_TABLES: &[&str] = &["SharedFolderEncryptionKeys"];+/// Manifest / metadata schema version. This is the manifest *wire structure* version and is its own/// axis, independent of the data-model version (which readers derive from the manifest's `migrationId`)./// It starts at 1 for the first manifest generation; bump only on a breaking structural change@@ -91,6 +97,11 @@ pub fn is_personal_table(table_name: &str) -> bool {PERSONAL_TABLES.contains(&table_name) || bucket_category_for(table_name).is_some()}+/// True when a table is shared-only (see [`SHARED_ONLY_TABLES`]): never part of the root manifest.+pub fn is_shared_only_table(table_name: &str) -> bool {+ SHARED_ONLY_TABLES.contains(&table_name)+}+/// The single-column primary key that addresses a row in `table_name`, shared with the merge layer/// (see `vault_merge::types::SYNCABLE_TABLES`) so overflow keying and LWW merge agree on row identity./// Defaults to "Id" for tables outside the registry.diff --git a/core/rust/src/vault_codec/validate.rs b/core/rust/src/vault_codec/validate.rsindex ea27cd443..0e325a3ca 100644--- a/core/rust/src/vault_codec/validate.rs+++ b/core/rust/src/vault_codec/validate.rs@@ -64,6 +64,26 @@ pub fn validate_manifest(manifest: &Manifest) -> ValidationResult {}}+ /*+ * A shared-only table (a folder's own email keypair) belongs to exactly one+ * shared manifest. The root must not carry it at all, and a shared manifest must only carry rows+ * scoped to its own folder.+ */+ let expected_scope = manifest.shared_folder_id.as_deref();+ for name in super::types::SHARED_ONLY_TABLES {+ let rows = table(manifest, name);+ if rows.is_empty() {+ continue;+ }+ if expected_scope.is_none() {+ failed.push("root-manifest-carries-shared-only-table".to_string());+ explain.push(format!("Root manifest carries shared-only table {}", name));+ } else if rows.iter().any(|r| str_field(r, "SharedFolderId") != expected_scope) {+ failed.push("shared-only-table-scope-mismatch".to_string());+ explain.push(format!("{} carries rows scoped to another shared folder", name));+ }+ }+let items = table(manifest, "Items");let folders = table(manifest, "Folders");let tags = table(manifest, "Tags");diff --git a/core/rust/src/vault_merge/types.rs b/core/rust/src/vault_merge/types.rsindex a835e73c9..c41383c5c 100644--- a/core/rust/src/vault_merge/types.rs+++ b/core/rust/src/vault_merge/types.rs@@ -55,6 +55,7 @@ pub static SYNCABLE_TABLES: &[TableConfig] = &[TableConfig::new("FieldHistories"),TableConfig::new("Logos"),TableConfig::new("EncryptionKeys"),+ TableConfig::new("SharedFolderEncryptionKeys"),TableConfig::new("Settings").with_primary_key("Key"),];@@ -77,5 +78,6 @@ pub const SYNCABLE_TABLE_NAMES: &[&str] = &["FieldHistories","Logos","EncryptionKeys",+ "SharedFolderEncryptionKeys","Settings",];