Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Throw update required error on unsupported grant type (#2469)
Leendert de Borstf1f30545311a
diff --git a/core/rust/src/vault_sync/pull.rs b/core/rust/src/vault_sync/pull.rsindex 4e920f3cc..4c5d7b525 100644--- a/core/rust/src/vault_sync/pull.rs+++ b/core/rust/src/vault_sync/pull.rs@@ -33,7 +33,6 @@ pub(crate) struct OpenedManifestSet {pub blob_map: HashMap<String, Vec<u8>>,pub manifest_names: HashMap<String, String>,pub contentless_manifest_ids: Vec<String>,- /// The personal manifest is the empty placeholder of a new account, which this sync has to write.pub personal_needs_first_write: bool,pub personal_revision: i64,pub manifest_revisions: HashMap<String, i64>,@@ -410,7 +409,7 @@ async fn resolve_manifest_vek(ctx: &Ctx, dto: &ManifestDto, personal_manifest_idreturn Ok(personal_vek.to_string());}if key_type != types::KEY_TYPE_GRANT_KEY {- return Err(SyncError::Snapshot(format!("manifest {} states an unknown key type \"{}\" (newer server?), refusing to assemble", dto.manifest_id, key_type)));+ return Err(SyncError::VaultVersionIncompatible(format!("manifest {} states an unknown key type \"{}\"; update the app", dto.manifest_id, key_type)));}resolve_granted_vek(ctx, dto).await}@@ -418,7 +417,7 @@ async fn resolve_manifest_vek(ctx: &Ctx, dto: &ManifestDto, personal_manifest_idasync fn resolve_granted_vek(ctx: &Ctx, dto: &ManifestDto) -> SyncResult<String> {let (encrypted_vek, public_key, algorithm) = grant_of(dto).ok_or_else(|| SyncError::Snapshot(format!("shared manifest {} carries no grant to open it with, refusing to assemble", dto.manifest_id)))?;if algorithm != types::ALGORITHM_RSA_OAEP_SHA256 {- return Err(SyncError::Snapshot(format!("shared manifest {} grants its VEK under an unsupported algorithm \"{}\" (newer server?), refusing to assemble", dto.manifest_id, algorithm)));+ return Err(SyncError::VaultVersionIncompatible(format!("shared manifest {} grants its VEK under an unsupported algorithm \"{}\"; update the app", dto.manifest_id, algorithm)));}let private_key = keys::resolve_grant_private_key(ctx, &public_key).ok_or_else(|| SyncError::Snapshot(format!("this session holds no account private key that opens the grant on shared manifest {}, refusing to assemble", dto.manifest_id)))?;keys::decrypt_manifest_vek(&encrypted_vek, &dto.manifest_id, &private_key).map_err(|e| SyncError::ServerVaultUnreadable(format!("failed to decrypt the VEK of shared manifest {}, refusing to assemble: {}", dto.manifest_id, e)))diff --git a/core/rust/src/vault_sync/tests/unsupported_grant.rs b/core/rust/src/vault_sync/tests/unsupported_grant.rsnew file mode 100644index 000000000..5d1aabf83--- /dev/null+++ b/core/rust/src/vault_sync/tests/unsupported_grant.rs@@ -0,0 +1,54 @@+//! A manifest granted in a format this build does not know ends the session with "update the app", like a newer+//! vault format. A grant-format change ships with a minimum client version bump, so this only catches a missed bump.++use serde_json::{json, Value};++use super::test_host::{self, TestHost};+use super::{insert_item, item_names, request, snapshot_of, PERSONAL_MANIFEST_ID};+use crate::crypto;+use crate::vault_codec;+use crate::vault_sync::session::SyncSession;+use crate::vault_sync::state;++const SHARED_MANIFEST_ID: &str = "22222222-2222-4222-8222-222222222222";++/// Sync a fresh client against a personal snapshot plus a shared manifest granted under `algorithm` and `key_type`.+fn sync_with_shared_grant(algorithm: &str, key_type: &str, blob: &str) -> (TestHost, Value) {+ 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 (mut status, mut vault) = snapshot_of(&server_db, &vek, 7, &vault_codec::generate_manifest_salt());+ vault["manifests"].as_array_mut().unwrap().push(json!({ "manifestId": SHARED_MANIFEST_ID, "blob": blob, "revision": 3, "blobReferences": [], "canAdminister": false, "keyType": key_type, "algorithm": algorithm, "encryptedVek": "future-grant", "encryptionPublicKey": "future-key" }));+ status["manifestRevisions"].as_array_mut().unwrap().push(json!({ "manifestId": SHARED_MANIFEST_ID, "revision": 3 }));+ host.respond("GET", "Status", status);+ host.respond("GET", "Vault", vault);+ let result = host.drive(&SyncSession::new(&request("fullSync", &vek, false, 0)).unwrap());+ (host, result)+}++fn assert_told_to_update(host: &TestHost, result: &Value) {+ assert_eq!(result["success"], false, "{}", result);+ assert_eq!(result["logoutReason"], "vaultVersionIncompatible", "an app too old for the grant format is told to update: {}", result);+ assert!(item_names(&host.local).is_empty(), "nothing is materialized, not even the personal vault");+ assert!(host.store_calls.is_empty());+}++#[test]+fn unknown_grant_algorithm_asks_for_an_app_update() {+ let (host, result) = sync_with_shared_grant("future-x", "grantkey", "bm90LXJlYWRhYmxl");+ assert_told_to_update(&host, &result);+}++#[test]+fn unknown_grant_key_type_asks_for_an_app_update() {+ let (host, result) = sync_with_shared_grant("rsa-oaep-sha256", "future-key-type", "bm90LXJlYWRhYmxl");+ assert_told_to_update(&host, &result);+}++#[test]+fn unknown_grant_algorithm_on_a_contentless_shared_manifest_asks_for_an_app_update() {+ let (host, result) = sync_with_shared_grant("future-x", "grantkey", "");+ assert_told_to_update(&host, &result);+}