Overwrite a deleted key and truncate the log after it

SQLite's secure_delete was off: a deleted row stayed in the free space of its
page, and the frame of the write-ahead log that held that page kept the key
until the log was reset. Every connection (Store::init) now sets
secure_delete = ON next to foreign_keys, and Store::delete_identity and
KeyStore::remove (how a sign-out deletes the device key, the synced copies and
the account record) run PRAGMA wal_checkpoint(TRUNCATE) after a row was
deleted, so the page with the overwritten row is copied into client.db and the
log is empty.

The truncate is best effort: the delete has happened and a sign-out must still
finish, so a checkpoint that another connection blocks, or that fails, only
logs a warning that the bytes stay in the log until the next checkpoint.
Keys deleted before this change stay in the free pages until a VACUUM; the
architecture notes say so.

Tests read client.db and client.db-wal as bytes: the PKCS#8 text of a Voelin
device key (sign-out with Auto, and with Forget), a synced TeamSpeak copy's key,
a TeamSpeak identity deleted by Store::delete_identity and a key removed
through KeyStore::remove are present before and in neither file after, another
key is still stored and the log is empty; and secure_delete reads 1 on every
connection. Each raw-file test fails with either measure taken out.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-20 08:27:56 +03:00
1 parent 4944a0694b
commit 248955b85c
5 files changed
+199 -1

No files matched your search

+11
View File
@@ -360,6 +360,17 @@ 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 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
`KeyStore::remove` a sign-out deletes with) is followed by a
`PRAGMA wal_checkpoint(TRUNCATE)`, so that the frame of the write-ahead log that
held the key's page goes too: neither `client.db` nor `client.db-wal` has the
key's text afterwards. If another connection blocks the checkpoint the delete
stands, a warning is logged, and the bytes stay in the log until the next
checkpoint. Keys deleted before `secure_delete` was on stay in the free pages
until the database is vacuumed.
`voelin-identity` comes from the private VoelinProtocol repository as a git
dependency pinned by commit ([building.md](building.md#depending-on-voelinprotocol)).