diff --git a/Cargo.lock b/Cargo.lock index 28d5774..06e2cda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9578,7 +9578,7 @@ dependencies = [ [[package]] name = "voelin-identity" version = "0.2.0" -source = "git+ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git?rev=c8e0e5a17c1ff5dfaefa087f49b395d2918af650#c8e0e5a17c1ff5dfaefa087f49b395d2918af650" +source = "git+ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git?rev=c5bb6b914bdab86eb36f6e32a1a5bc9ac4785562#c5bb6b914bdab86eb36f6e32a1a5bc9ac4785562" dependencies = [ "aws-lc-rs", "base64 0.23.1", @@ -9637,7 +9637,7 @@ dependencies = [ [[package]] name = "voelin-model" version = "0.1.0" -source = "git+ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git?rev=c8e0e5a17c1ff5dfaefa087f49b395d2918af650#c8e0e5a17c1ff5dfaefa087f49b395d2918af650" +source = "git+ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git?rev=c5bb6b914bdab86eb36f6e32a1a5bc9ac4785562#c5bb6b914bdab86eb36f6e32a1a5bc9ac4785562" dependencies = [ "prost", "serde", @@ -9676,7 +9676,7 @@ dependencies = [ [[package]] name = "voelin-proto" version = "0.2.0" -source = "git+ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git?rev=c8e0e5a17c1ff5dfaefa087f49b395d2918af650#c8e0e5a17c1ff5dfaefa087f49b395d2918af650" +source = "git+ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git?rev=c5bb6b914bdab86eb36f6e32a1a5bc9ac4785562#c5bb6b914bdab86eb36f6e32a1a5bc9ac4785562" dependencies = [ "bytes", "prost", diff --git a/Cargo.toml b/Cargo.toml index 10350af..61c3b6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,13 +58,14 @@ publish = false # docs/development.md names, so that a per-developer .cargo/config.toml [patch] # can point it at a sibling checkout (docs/building.md, "Working with a sibling # VoelinProtocol checkout"). Pinned by commit until the protocol tags a release: -# the three crates below are at one revision (main c8e0e5a: the account-bound -# KeyStore of Phase 2 task 28, the account types of the session seam). -voelin-identity = { git = "ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git", rev = "c8e0e5a17c1ff5dfaefa087f49b395d2918af650" } +# the three crates below are at one revision (main c5bb6b9: the account-bound +# KeyStore whose sign-out keeps every device key and the release of a device key, +# Phase 2 task 34; the account types of the session seam). +voelin-identity = { git = "ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git", rev = "c5bb6b914bdab86eb36f6e32a1a5bc9ac4785562" } # The backend-neutral session seam (`voelin_proto::link`) and the v1 messages. -voelin-proto = { git = "ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git", rev = "c8e0e5a17c1ff5dfaefa087f49b395d2918af650" } +voelin-proto = { git = "ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git", rev = "c5bb6b914bdab86eb36f6e32a1a5bc9ac4785562" } # The UI-facing domain model and the client's replica of v1 entities. -voelin-model = { git = "ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git", rev = "c8e0e5a17c1ff5dfaefa087f49b395d2918af650" } +voelin-model = { git = "ssh://gitea@git.faumaray.com/Voelin/VoelinProtocol.git", rev = "c5bb6b914bdab86eb36f6e32a1a5bc9ac4785562" } [workspace.lints.rust] # deny, not forbid: generated code (Slint) needs a local allow. diff --git a/crates/voelin-core/src/link/fake_tests.rs b/crates/voelin-core/src/link/fake_tests.rs index f428d5c..a04b9ee 100644 --- a/crates/voelin-core/src/link/fake_tests.rs +++ b/crates/voelin-core/src/link/fake_tests.rs @@ -313,7 +313,7 @@ async fn the_conformance_suite_passes_on_a_session_of_the_registry() { } let report = conformance::run(&through_the_registry).await; assert_eq!(report.cases.len(), conformance::CASES.len()); - assert_eq!(report.cases.len(), 17, "the suite of c8e0e5a has 17 cases"); + assert_eq!(report.cases.len(), 17, "the suite of c5bb6b9 has 17 cases"); assert!( report.cases.iter().all(|(_, verdict)| *verdict == Verdict::Passed), "{:?}", diff --git a/crates/voelin-core/src/ts/ts_session/live_tests.rs b/crates/voelin-core/src/ts/ts_session/live_tests.rs index 87966e7..ba51e9a 100644 --- a/crates/voelin-core/src/ts/ts_session/live_tests.rs +++ b/crates/voelin-core/src/ts/ts_session/live_tests.rs @@ -333,7 +333,7 @@ enum Expect { } use Expect::{NotRun, Passes, Skipped}; -/// Every case of the suite of the protocol repository at `c8e0e5a`, in its +/// Every case of the suite of the protocol repository at `c5bb6b9`, in its /// order, with what a TeamSpeak session does with it. A case the suite gains /// fails `the_suite_is_known` until it is listed here. /// diff --git a/crates/voelin-store/tests/keystore.rs b/crates/voelin-store/tests/keystore.rs index 5da0b3e..4bc5eec 100644 --- a/crates/voelin-store/tests/keystore.rs +++ b/crates/voelin-store/tests/keystore.rs @@ -803,8 +803,9 @@ fn the_record_fixture_is_what_the_protocol_writes() { } #[test] -fn signing_out_deletes_the_copies_and_keeps_the_device_secrets() { - // The device key was made for the account: signing out deletes it. +fn signing_out_deletes_the_copies_and_keeps_the_keys_and_the_device_secrets() { + // The device key was made for the account: signing out keeps it all the + // same, unbound (open question 10 of the accounts design). let Install { store, synced, device_only, local } = signed_in_install(false); let mine = binding().account; let theirs = account_uid(&issuer(), &AccountId::from_bytes([9; 16])); @@ -815,19 +816,20 @@ fn signing_out_deletes_the_copies_and_keeps_the_device_secrets() { store.put_voelin_key(&other_key).unwrap(); let done = store.sign_out(&mine, DeviceKeyChoice::Auto).unwrap(); - let mut expected_removed = vec![ - (KIND_ACCOUNT.to_owned(), record().blob_uid()), - pair(&synced), - (KIND_VOELIN.to_owned(), key().uid().to_base32()), - ]; + let mut expected_removed = vec![(KIND_ACCOUNT.to_owned(), record().blob_uid()), pair(&synced)]; expected_removed.sort(); assert_eq!(sorted(done.removed.clone()), expected_removed, "{done:?}"); - assert_eq!(done.unbound, vec![info_of(&device_only.clone().with_binding(None))]); + assert_eq!( + sorted(done.unbound.clone()), + sorted(vec![device_key_info(), info_of(&device_only.clone().with_binding(None))]), + "{done:?}" + ); - // What is left: the device secret unbound and byte for byte as it was, the - // local and the other account's identities as they were, the other key. + // What is left: the device key, the device secret unbound and byte for + // byte as it was, the local and the other account's identities as they + // were, the other key. assert!(store.get(KIND_TEAMSPEAK, &synced.uid).unwrap().is_none()); - assert!(store.voelin_key(&key().uid()).unwrap().is_none()); + assert_eq!(store.voelin_key(&key().uid()).unwrap().unwrap().uid(), key().uid()); assert_eq!(store.account_record().unwrap(), None); let kept = store.get(KIND_TEAMSPEAK, &device_only.uid).unwrap().unwrap(); assert_eq!(kept, device_only.clone().with_binding(None)); @@ -835,11 +837,11 @@ fn signing_out_deletes_the_copies_and_keeps_the_device_secrets() { assert_eq!(store.get(KIND_TEAMSPEAK, &local.uid).unwrap().unwrap(), local); assert_eq!(store.get(KIND_TEAMSPEAK, &theirs_blob.uid).unwrap().unwrap(), theirs_blob); assert!(store.voelin_key(&other_key.uid()).unwrap().is_some()); - assert_eq!(store.list().unwrap().len(), 4); + assert_eq!(store.list().unwrap().len(), 5); // Signing out again finds nothing to do. assert_eq!(store.sign_out(&mine, DeviceKeyChoice::Auto).unwrap(), SignOut::default()); - assert_eq!(store.list().unwrap().len(), 4); + assert_eq!(store.list().unwrap().len(), 5); // Another account's sign-out acts on that account's identities only. assert_eq!( store.sign_out(&theirs, DeviceKeyChoice::Auto).unwrap().removed, @@ -892,17 +894,38 @@ fn signing_out_keeps_a_device_key_that_predates_the_account() { } #[test] -fn signing_out_deletes_a_device_key_the_client_made_for_the_account() { +fn signing_out_keeps_a_device_key_the_client_made_for_the_account_too() { + // Open question 10 of the accounts design (answered 2026-10-24): a key that + // the client made for the account is the user's identity at every host + // without accounts that the user reached with it as well, so `Auto` keeps + // it like a key that predates the account. Only `Forget` deletes it. let Install { store, device_only, local, .. } = signed_in_install(false); + let key_before = store.get(KIND_VOELIN, &key().uid().to_base32()).unwrap().unwrap(); + let signature = key().sign(b"the same key, signed before and after"); + let done = store.sign_out(&binding().account, DeviceKeyChoice::Auto).unwrap(); - assert!(done.removed.contains(&device_key_info()), "{done:?}"); - assert!(!done.unbound.contains(&device_key_info()), "{done:?}"); - assert!(store.voelin_key(&key().uid()).unwrap().is_none()); + assert!(!done.removed.contains(&device_key_info()), "{done:?}"); + assert!(done.unbound.contains(&device_key_info()), "{done:?}"); + let kept = store.voelin_key(&key().uid()).unwrap().expect("the key stays"); + assert_eq!(kept.sign(b"the same key, signed before and after"), signature); + let key_after = store.get(KIND_VOELIN, &key().uid().to_base32()).unwrap().unwrap(); + assert_eq!(key_after, key_before, "the stored blob is untouched"); + assert_eq!(key_after.binding, None); let mut left = sorted(store.list().unwrap()); left.sort(); - let mut expected = vec![pair(&device_only), pair(&local)]; + let mut expected = vec![pair(&device_only), pair(&local), pair(&key_after)]; expected.sort(); - assert_eq!(left, expected, "the device secret and the local one"); + assert_eq!(left, expected, "the key, the device secret and the local one"); + + // The flag changes nothing: a key that predates the account gets the same + // treatment. (The other identities of the two installs are fresh ones, so + // the reports differ in them.) + let existing = signed_in_install(true); + let again = existing.store.sign_out(&binding().account, DeviceKeyChoice::Auto).unwrap(); + assert!(again.unbound.contains(&device_key_info()), "{again:?}"); + assert!(!again.removed.contains(&device_key_info()), "{again:?}"); + assert_eq!(again.removed.len(), done.removed.len()); + assert_eq!(again.unbound.len(), done.unbound.len()); } #[test] @@ -1282,16 +1305,10 @@ impl OnFile { /// What a sign-out of `choice` must have done, whatever else was damaged: /// the record and the synced copy are gone, the device-only secret is /// unbound and the local identity is as it was; the device key is deleted - /// when the user forgot it or the client made it for the account, and - /// reported as kept and unbound otherwise. - fn assert_signed_out( - &self, - done: &SignOut, - bound_existing_key: bool, - choice: DeviceKeyChoice, - label: &str, - ) { - let key_goes = matches!(choice, DeviceKeyChoice::Forget(_)) || !bound_existing_key; + /// when the user forgot it, and reported as kept and unbound otherwise, + /// whether it predates the account or not. + fn assert_signed_out(&self, done: &SignOut, choice: DeviceKeyChoice, label: &str) { + let key_goes = matches!(choice, DeviceKeyChoice::Forget(_)); let mut removed = vec![(KIND_ACCOUNT.to_owned(), record().blob_uid()), pair(&self.synced)]; let mut unbound = vec![pair(&self.device_only)]; let device_key = (KIND_VOELIN.to_owned(), key().uid().to_base32()); @@ -1335,7 +1352,7 @@ const RECORD_ROW_DAMAGE: [&str; 5] = [ fn a_damaged_account_record_row_does_not_keep_a_sign_out_from_finishing() { // The record carries no binding, so damage in those columns says nothing // about the record: it is read, and the sign-out does what it always does. - // `Forget` deletes the key it names; `Auto` follows the record. + // `Forget` deletes the key it names; `Auto` keeps it. for bound_existing_key in [true, false] { for damage in RECORD_ROW_DAMAGE { for choice in [DeviceKeyChoice::Auto, DeviceKeyChoice::Forget(key().uid())] { @@ -1346,7 +1363,7 @@ fn a_damaged_account_record_row_does_not_keep_a_sign_out_from_finishing() { .store .sign_out(&binding().account, choice) .unwrap_or_else(|error| panic!("{label}: {error}")); - install.assert_signed_out(&done, bound_existing_key, choice, &label); + install.assert_signed_out(&done, choice, &label); } } } @@ -1354,8 +1371,9 @@ fn a_damaged_account_record_row_does_not_keep_a_sign_out_from_finishing() { #[test] fn a_damaged_device_key_row_does_not_keep_a_sign_out_from_finishing() { - // With `Auto` and a key that predates the account, the trait reads the key - // to report it as kept. Damage in its binding columns must not fail that. + // With `Auto` the trait reads the key to report it as kept, whether it + // predates the account or not. Damage in its binding columns must not fail + // that. for bound_existing_key in [true, false] { for damage in [ "UPDATE identities SET synced = 2 WHERE kind = 'voelin'", @@ -1369,12 +1387,10 @@ fn a_damaged_device_key_row_does_not_keep_a_sign_out_from_finishing() { .store .sign_out(&binding().account, DeviceKeyChoice::Auto) .unwrap_or_else(|error| panic!("{label}: {error}")); - install.assert_signed_out(&done, bound_existing_key, DeviceKeyChoice::Auto, &label); - if bound_existing_key { - // The key was kept, as it was stored. - let kept = install.store.voelin_key(&key().uid()).unwrap().unwrap(); - assert_eq!(&kept.to_pkcs8().unwrap()[..], &key().to_pkcs8().unwrap()[..]); - } + install.assert_signed_out(&done, DeviceKeyChoice::Auto, &label); + // The key was kept, as it was stored. + let kept = install.store.voelin_key(&key().uid()).unwrap().unwrap(); + assert_eq!(&kept.to_pkcs8().unwrap()[..], &key().to_pkcs8().unwrap()[..]); } } } @@ -1423,7 +1439,7 @@ fn an_account_row_whose_data_is_not_text_is_deleted_like_an_unreadable_record() assert!(store.get(KIND_TEAMSPEAK, &install.synced.uid).unwrap().is_none(), "{label}"); let secret = store.get(KIND_TEAMSPEAK, &install.device_only.uid).unwrap().unwrap(); assert_eq!(secret.binding, None, "{label}"); - // `Auto` cannot find the key the record named, and keeps it. + // `Auto` keeps the key, as it always does; `Forget` deleted it first. let forgot = matches!(choice, DeviceKeyChoice::Forget(_)); assert_eq!(store.voelin_key(&key().uid()).unwrap().is_none(), forgot, "{label}"); assert_eq!(store.sign_out(&binding().account, choice).unwrap(), SignOut::default()); @@ -1623,14 +1639,13 @@ fn key_text(json: &str, field: &str) -> String { } #[test] -fn a_key_deleted_by_a_sign_out_is_in_neither_the_database_file_nor_its_log() { - // The device key the client made for the account goes with `Auto`, and a - // key that predates the account goes when the user forgets it. Either way - // its PKCS#8 text, and a synced TeamSpeak copy's key, must not stay in the - // free pages of `client.db` or in a frame of `client.db-wal`. - for (bound_existing_key, choice) in - [(false, DeviceKeyChoice::Auto), (true, DeviceKeyChoice::Forget(key().uid()))] - { +fn a_key_forgotten_by_a_sign_out_is_in_neither_the_database_file_nor_its_log() { + // The device key goes when the user forgets it, whether it predates the + // account or the client made it for the account. Its PKCS#8 text, and a + // synced TeamSpeak copy's key, must not stay in the free pages of + // `client.db` or in a frame of `client.db-wal`. + for bound_existing_key in [true, false] { + let choice = DeviceKeyChoice::Forget(key().uid()); let scratch = Scratch::new("scrub-signout"); let store = SqliteKeyStore::open(&scratch.db()).unwrap(); let device = IdentityBlob::voelin(&key()).unwrap(); @@ -1736,14 +1751,14 @@ fn a_reader_that_blocks_the_checkpoint_costs_milliseconds_and_starves_no_writer( (writes, errors) }); let started = Instant::now(); - let done = store.sign_out(&binding().account, DeviceKeyChoice::Auto); + let done = store.sign_out(&binding().account, DeviceKeyChoice::Forget(key().uid())); let elapsed = started.elapsed(); stop.store(true, Ordering::Relaxed); let (writes, errors) = writer.join().unwrap(); (done.unwrap(), elapsed, writes, errors) }); - // Four removals: the two copies, the device key the client made, the record. + // Four removals: the two copies, the device key the user forgot, the record. assert_eq!(done.removed.len(), 4, "{done:?}"); assert!(store.list().unwrap().is_empty()); assert!(writes > 0, "the writer never ran"); @@ -1798,15 +1813,15 @@ fn a_synced_binding_on_the_device_key_is_refused_with_a_precise_error() { assert_eq!(store.list().unwrap().iter().filter(|i| i.binding.is_some()).count(), 0); // A binding that is not synced is a device-only secret: accepted, and a - // sign-out unbinds it and keeps it (or deletes it, as the record says). + // sign-out unbinds it and keeps it. let device_only = AccountBinding { synced: false, ..binding() }; store.put(&IdentityBlob::voelin(&key()).unwrap().with_binding(device_only)).unwrap(); store.put(&before).unwrap(); - // So the sign-out still does what the record says with the key. + // So the sign-out keeps the key, whether it predates the account or not. let done = store.sign_out(&binding().account, DeviceKeyChoice::Auto).unwrap(); - assert_eq!(done.unbound.contains(&device_key_info()), bound_existing_key, "{done:?}"); - assert_eq!(store.voelin_key(&key().uid()).unwrap().is_some(), bound_existing_key); + assert!(done.unbound.contains(&device_key_info()), "{done:?}"); + assert!(store.voelin_key(&key().uid()).unwrap().is_some()); } }