feat(passwd): logicsrc passwd --email resets the vault and the keyring with one password (#302)

Email recovery reset the vault only. The SSH keyring kept its old passphrase,
so someone who had forgotten everything recovered the vault and was then
refused by `keyring restore` ("Wrong keyring passphrase").

- `logicsrc passwd --email`: opens the vault with the two emailed codes, then
  puts the vault and the keyring under one new password. New vault recovery
  key, email recovery re-armed, same end state as `vault recover --email`.
- Every `passwd` run stores the keyring's user key as an item in the vault
  (found by a stable id, verified against a keyring entry before use), so the
  vault's way back in is the keyring's too and nobody is asked a second secret.
- A keyring nothing opens is set aside (kept as keyring.bak-NNN) and started
  fresh; keys whose files are still under ~/.ssh with the same fingerprint are
  put back, the rest are named.
- The re-arm email after a recovery had the first-time wording ("run
  logicsrc vault recover --email"), which read as an instruction to recover
  again: three recoveries in five minutes on one account. It now says the
  recovery is complete and there is nothing to do. The CLI says so too.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-12-02 21:42:04 -08:00 • committed by GitHub
parent f10c94ca38
commit ef965b0aaa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 517 additions and 20 deletions

View file

@ -287,7 +287,38 @@ export function parseEnrollment(body) {
return { escrowBlob: body.escrowBlob, escrowIv: body.escrowIv, serverShare, userShare, vaultCreatedAt: createdAt };
}
export function enrollmentEmail(code) {
/** A recovery that finished in the last half hour: this enrollment is the automatic re-arm after it. */
const REARM_WINDOW_MS = 30 * 60 * 1000;
async function followsRecovery(userId, now) {
const last = await get(`SELECT action, created_at FROM vault_recovery_audit WHERE user_id = ? ORDER BY created_at DESC LIMIT 1`, [userId]).catch(() => null);
return Boolean(last && last.action === "claim" && now - Number(last.created_at) <= REARM_WINDOW_MS);
}
/**
* The mail that carries U. After a recovery the same mail read as "run recover
* --email", and people ran it again, and got another: so the re-arm says the
* recovery is finished and there is nothing to do.
*/
export function enrollmentEmail(code, { afterRecovery = false } = {}) {
if (afterRecovery) {
return {
subject: "Your LogicSRC vault email-recovery code was replaced — recovery complete, nothing to do",
text:
"Your LogicSRC personal vault was just recovered by email and has a new master password. " +
"You are done: there is nothing to run now.\n\n" +
"Using a recovery code spends it, so here is the replacement, for the next time you ever need it:\n\n" +
` ${code}\n\n` +
"Keep this email and delete the older recovery-code emails: those codes no longer work.\n\n" +
"Only if you lose your master password again, run `logicsrc passwd --email` (or `logicsrc vault recover --email`) " +
"and type this code when it asks.\n\n" +
"LogicSRC does not store this code. It is one half of the key to your vault: the other half is on our " +
"server, and neither half opens anything alone. Someone who has this email AND can sign in to your " +
"LogicSRC account could recover your vault, so keep this mailbox secure.\n\n" +
"If you did not just recover your vault, someone else did: sign in, turn email recovery off (Settings, or " +
"`logicsrc vault recovery disable`), change your password and secure this mailbox.",
};
}
return {
subject: "Your LogicSRC vault email-recovery code — keep this email",
text:
@ -320,7 +351,7 @@ export async function enroll(user, parsed, ctx = {}, now = Date.now()) {
);
let sent = false;
try {
const mail = enrollmentEmail(renderRecoveryCode(parsed.userShare));
const mail = enrollmentEmail(renderRecoveryCode(parsed.userShare), { afterRecovery: await followsRecovery(user.id, now) });
sent = await sendMail(user.email, mail.subject, mail.text);
} finally {
parsed.userShare.fill(0);

View file

@ -360,3 +360,23 @@ test("the Settings card: a Buy button before the purchase, the CLI hint after, a
assert.match(on, /action="\/settings\/vault-recovery\/disable"/);
assert.match(on, /u\*\*\*@example\.com/);
});
test("the re-arm after a recovery says it is finished, so nobody recovers again because of the email", async () => {
const after = vr.enrollmentEmail("AAAAA-BBBBB", { afterRecovery: true });
assert.match(after.subject, /^Your LogicSRC vault email-recovery code was replaced/);
assert.match(after.text, /You are done: there is nothing to run now\./);
assert.match(after.text, /AAAAA-BBBBB/);
const first = vr.enrollmentEmail("AAAAA-BBBBB");
assert.equal(first.subject, "Your LogicSRC vault email-recovery code — keep this email");
assert.doesNotMatch(first.text, /You are done/);
});
test("an enroll right after a claim sends the finished wording; a later one sends the ordinary one", async () => {
await vr.audit("u_a", "claim");
assert.equal((await call(keys.u_a, "POST", "/api/opencreds/recovery/enroll", await enrollPayload())).status, 201);
assert.match(mail.at(-1).subject, /was replaced — recovery complete, nothing to do$/);
assert.ok(codeIn(mail.at(-1).text), "the replacement code is in the email");
// The enroll itself is now the latest event, so the next enroll is an ordinary one.
assert.equal((await call(keys.u_a, "POST", "/api/opencreds/recovery/enroll", await enrollPayload())).status, 201);
assert.equal(mail.at(-1).subject, "Your LogicSRC vault email-recovery code — keep this email");
});