Expand description
Changing the master password: a new salt, a new key, the same data.
The key is Argon2id over the password and vault.salt, so changing the password changes both
files: vault.db is re-encrypted and vault.salt replaced. Two files cannot be swapped
atomically, so the order is chosen so that a crash at any point leaves a vault that opens with
either the old password or the new one, never neither:
- take a write lock on the old database (a second connection, since
ATTACHcannot run inside a transaction), checkpoint it, and copyvault.dbandvault.saltto*.pre-rekey(the way back); - write the new salt as
vault.salt.new; sqlcipher_exportthe data intovault.db.rekey-newunder the new key;- open that file with the new key and check that it is intact and holds the same rows;
- rename it over
vault.db, then renamevault.salt.newovervault.salt.
A crash before step 5’s first rename leaves the old pair untouched (the leftovers are removed).
A crash between the two renames leaves a new database beside the old salt and a vault.salt.new;
recover_interrupted, which every unlock runs first, sees that the new password opens the
database through vault.salt.new and finishes the rename. The *.pre-rekey copies stay until
the next successful unlock (cleanup_after_unlock). Backups made before the change still open
with the old password, which is the point of a backup, and the documentation says so.
Recovery packages are encrypted to an age recipient, not to the master password, so they are not affected.
Structs§
Enums§
- Stage
- Where a rekey can be stopped, for the tests that prove each stop is survivable.
Constants§
- MIN_
PASSWORD_ CHARS - The shortest new master password the command accepts, as in the desktop app.
Functions§
- cleanup_
after_ unlock - Removes the
*.pre-rekeycopies. Called after an unlock has succeeded, which proves the new pair works; until then they are the way back. - recover_
interrupted - Finishes or abandons a rekey that a crash interrupted. Cheap when there is nothing to do: one existence check. Returns whether it changed anything.
- rekey
rekey_withwithout a stop.- rekey_
with - Re-encrypts the vault under
new_password.stop_afterends the run early with an error, which is what a crash at that point looks like; production callers passNonethroughrekey.