Refuse to store the device key as a synced copy
KeyStore::sign_out deletes every identity bound with synced = true in its first step, before it reads the account record that says which Voelin key is the device key and whether it predates the account. A device key stored with synced = true was therefore deleted even where the record says to keep it. Nothing in this crate stored such a key, but the store accepted it. SqliteKeyStore::put now refuses, with an error that names the key and the record and says why, a voelin blob with synced = true while an account record names its uid as the device key, and also while an account record cannot be read (it may name the key, and the sign-out would delete it on that guess). The state is also reached from the other side, so a put of an account record whose device key is already stored as a synced copy is refused as well. A binding with synced = false is accepted: a sign-out unbinds it and then follows the record. The check runs before the binding-only fast path, so a put of the key's own data cannot rebind it as synced. Documented in keystore.rs and docs/architecture.md. Tests cover the refusal for records that keep and that delete the key (the error text, the row left untouched, the sign-out still following the record), another key that may be synced, no record or a record naming another key, a record put naming a synced copy, and unreadable records; the three refusal tests fail without the check. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
248955b85c
commit
3c59f24608
3 files changed
+244
-1
No files matched your search
@@ -360,6 +360,18 @@ record says it predates the account, and deletes it when it does not or when
|
||||
the caller asks to forget it. The engine and the UI do not use the key store
|
||||
yet; accounts, sign-in and the integrations page are later steps.
|
||||
|
||||
The device key is never a synced copy. The trait's `sign_out` deletes every
|
||||
identity bound with `synced = true` in its first step, before it reads the
|
||||
record, so a device key stored that way would be deleted even where the record
|
||||
says to keep it. `SqliteKeyStore` therefore refuses, with an error that names
|
||||
the key and the record, a `put` of a `voelin` blob with `synced = true` while an
|
||||
account record names its uid as the device key, or while an account record
|
||||
cannot be read (it may name the key); and a `put` of an account record whose
|
||||
device key is stored as a synced copy. A key bound with `synced = false` is
|
||||
accepted: a sign-out unbinds it and then follows the record. The check is made
|
||||
under the store's lock; it is defence in depth against the code that signs in,
|
||||
which does not exist yet.
|
||||
|
||||
The rows are private keys, so a deleted key must not stay in the file. Every
|
||||
connection to the database sets `secure_delete`, which makes SQLite overwrite
|
||||
what it deletes, and deleting a key (`Store::delete_identity`, and the
|
||||
|
||||
Reference in new issue
Block a user