voelin-store: the local half of releasing a device key is the sign-out, and the store needs nothing more
AccountClient::release (voelin-account-client at c5bb6b9) asks the service to release the key and then runs KeyStore::sign_out with DeviceKeyChoice::Auto, so the unbind of one key that keeps its data is the sign-out's own step (and a put of the blob without its binding for a single key). Open question 10 and protocol 13.6 ask the client to remember nothing: the service holds the registration of the key, and the client learns that a key is still registered with an account it signed out of from the service's answer to a sign-in or a sign-up (CONFLICT, field device). So there is no "released" record and no new store call; keystore.rs says so, and says the same of the deletion of an account, whose local half is this sign-out. Two tests pin what the client relies on after a release: the key is kept byte for byte and unbound, then is the device key of a record of another account, and a sign-out of that account keeps it again (its copies go); and a release whose local half was cut short is finished by a sign-out with Auto, and a second one finds nothing to do. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c0e8a533a4
commit
ca142fd3f2
2 files changed
+82
No files matched your search
@@ -71,6 +71,26 @@
|
||||
//! key stays registered with the account there. The release is its own
|
||||
//! operation, see below.
|
||||
//!
|
||||
//! # Releasing a device key
|
||||
//!
|
||||
//! The release of the device key from its account (part 2 of open question 10)
|
||||
//! is the account service's operation followed by a local unbind, and the unbind
|
||||
//! is a sign-out: `AccountClient::release` of `voelin-account-client` calls
|
||||
//! `POST /v1/devices/<own>/release` after a password check, and then runs
|
||||
//! [`KeyStore::sign_out`] with [`DeviceKeyChoice::Auto`], which keeps the key,
|
||||
//! unbound. So the store needs nothing of its own for it: no call that unbinds
|
||||
//! one key (a [`KeyStore::put`] of the blob without its binding does that, and
|
||||
//! keeps the data, as the sign-out does), and no record that the key was
|
||||
//! released. The accounts design asks the client to remember nothing of the
|
||||
//! kind: the service holds the registration of the key (after a release it is
|
||||
//! registered with no account, after a sign-out with the account that was
|
||||
//! signed out of), and the client learns which at the next sign-in or sign-up,
|
||||
//! from the service's answer (`CONFLICT`, field `device`), not from a note kept
|
||||
//! here. The deletion of the account (`AccountClient::delete_account`) is the
|
||||
//! same: the service writes a DEVICE and a RELEASED entry for every device key
|
||||
//! of the account, and the local half is this sign-out, which keeps this
|
||||
//! device's key.
|
||||
//!
|
||||
//! # Forgetting the device's identity
|
||||
//!
|
||||
//! "Forget this device's identity" is the user's explicit choice and the only
|
||||
|
||||
@@ -1956,6 +1956,68 @@ fn a_key_kept_by_a_sign_out_is_exported_and_then_forgotten_without_a_trace() {
|
||||
assert_eq!(store.get(KIND_VOELIN, &uid.to_base32()).unwrap().unwrap(), stored);
|
||||
}
|
||||
|
||||
// ------------------------------------------ releasing the device key from its account
|
||||
//
|
||||
// `AccountClient::release` asks the service to release the key and then runs the
|
||||
// local sign-out with `Auto` (protocol 13.6, "Releasing this device's key"), so
|
||||
// the store's part is the sign-out of the tests above, and the key has to be
|
||||
// usable for another account afterwards.
|
||||
|
||||
#[test]
|
||||
fn the_local_half_of_a_release_keeps_the_key_and_it_serves_another_account() {
|
||||
let Install { store, .. } = signed_in_install(false);
|
||||
let uid = key().uid().to_base32();
|
||||
let before = store.get(KIND_VOELIN, &uid).unwrap().unwrap();
|
||||
let signature = key().sign(b"the same key, before and after the release");
|
||||
|
||||
// The service released the key; the device finishes with a local sign-out.
|
||||
let done = store.sign_out(&binding().account, DeviceKeyChoice::Auto).unwrap();
|
||||
assert!(done.unbound.contains(&device_key_info()), "{done:?}");
|
||||
assert!(!done.removed.contains(&device_key_info()), "{done:?}");
|
||||
assert_eq!(store.get(KIND_VOELIN, &uid).unwrap().unwrap(), before, "byte for byte");
|
||||
assert_eq!(store.account_record().unwrap(), None);
|
||||
|
||||
// The key is registered with no account and signs up for another one: its
|
||||
// record names the same key, and a copy of the new account's material is
|
||||
// bound to it.
|
||||
let other_id = AccountId::from_bytes([42; 16]);
|
||||
let other = AccountRecord { account_id: other_id, login: "bob".into(), ..record() };
|
||||
store.put_account_record(&other).unwrap();
|
||||
assert_eq!(store.account_record().unwrap(), Some(other.clone()));
|
||||
let other_binding = AccountBinding { account: account_uid(&issuer(), &other_id), ..binding() };
|
||||
let other_copy = fresh_teamspeak(other_binding);
|
||||
store.put(&other_copy).unwrap();
|
||||
|
||||
// Signing out of the new account keeps the key again, and the copy goes.
|
||||
let done = store.sign_out(&other_binding.account, DeviceKeyChoice::Auto).unwrap();
|
||||
assert!(done.unbound.contains(&device_key_info()), "{done:?}");
|
||||
assert!(done.removed.contains(&info_of(&other_copy)), "{done:?}");
|
||||
let kept = store.voelin_key(&key().uid()).unwrap().expect("the key stays");
|
||||
assert_eq!(kept.sign(b"the same key, before and after the release"), signature);
|
||||
assert_eq!(store.get(KIND_VOELIN, &uid).unwrap().unwrap(), before, "byte for byte");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_release_whose_local_half_was_cut_short_is_finished_by_a_sign_out() {
|
||||
// The service released the device and the call was dropped before the local
|
||||
// sign-out took the slot: the record and the copies are still here, and the
|
||||
// key is still the record's device key. A sign-out with `Auto` finishes it
|
||||
// and keeps the key; running it again finds nothing to do.
|
||||
let Install { store, synced, device_only, .. } = signed_in_install(true);
|
||||
let uid = key().uid().to_base32();
|
||||
let before = store.get(KIND_VOELIN, &uid).unwrap().unwrap();
|
||||
|
||||
let done = store.sign_out(&binding().account, DeviceKeyChoice::Auto).unwrap();
|
||||
assert!(done.removed.contains(&info_of(&synced)), "{done:?}");
|
||||
assert!(done.unbound.contains(&info_of(&device_only.clone().with_binding(None))), "{done:?}");
|
||||
assert_eq!(store.account_record().unwrap(), None);
|
||||
assert_eq!(store.get(KIND_VOELIN, &uid).unwrap().unwrap(), before);
|
||||
assert_eq!(
|
||||
store.sign_out(&binding().account, DeviceKeyChoice::Auto).unwrap(),
|
||||
SignOut::default()
|
||||
);
|
||||
}
|
||||
|
||||
// -------------------------------------- the device key is never a synced copy
|
||||
//
|
||||
// `KeyStore::sign_out` deletes everything bound with `synced = true` in its
|
||||
|
||||
Reference in new issue
Block a user