mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 01:14:47 +00:00
vault: opt-in paid email recovery for the personal vault ($5 lifetime)
A second way back into a logicsrc personal vault when the master password and
the offline recovery key are both gone, without the server holding anything
that alone (even with the DB and server env) opens the vault.
Client (packages/opencreds): random escrow key E encrypts the user key K
(AES-256-GCM, AAD "<ns>:vault:email-escrow:v1|<createdAt>"); E is split into
S (random, to the server) and U = E XOR S (emailed once as a checksummed
Crockford recovery code, never stored). `recover --email` checks the code's
check group first, asks the server for a one-time code, claims S, recombines
E, proves K against an item, sets a new password, issues a new offline
recovery key and re-enrolls with fresh shares (warns loudly if that fails).
New `recovery status|buy|enable|disable` commands; the CLI client lives in
packages/cli/src/vault-sync.ts.
Server (apps/pwa): /api/opencreds/recovery/{checkout,enroll,start,claim} +
status/disable. S is sealed under VAULT_ESCROW_KEY (versioned for rotation,
AAD binds the user). Enrollment is pending until the email with U is sent,
else rolled back. One-time codes: 8 digits, HMAC at rest, 15 min, 5 tries,
single use, 3 starts/hour; claims are audited and announced by email.
Purchase via CoinPay checkout (purpose vault_recovery); /api/coinpay/webhook
now verifies once and dispatches by purpose, auto_rotation unchanged.
Settings card with status and a Buy button. Migration 014 in both dialects.
Docs: security.md and crypto.md "Email recovery (opt-in, paid)" sections with
the honest trade-off; cli.md command reference.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4e4fedd35e
commit
8528634e09
21 changed files with 2368 additions and 7 deletions
|
|
@ -52,6 +52,24 @@ opencreds recover # unlock with the recovery key, set a new password
|
|||
A password change re-wraps the user key. Not one item is re-encrypted, which is
|
||||
why it is instant on a vault of any size.
|
||||
|
||||
### Email recovery (`logicsrc vault` only)
|
||||
|
||||
```bash
|
||||
logicsrc vault recovery status [--json] # enrolled? since? email (masked)? purchased?
|
||||
logicsrc vault recovery buy # CoinPay checkout link ($5, lifetime)
|
||||
logicsrc vault recovery enable # enroll; emails a recovery code to keep
|
||||
logicsrc vault recovery disable # server deletes its escrow share and blob
|
||||
logicsrc vault recover --email # recovery code + fresh one-time code, then a new password
|
||||
```
|
||||
|
||||
An opt-in, paid account feature; the standalone `opencreds` binary has no
|
||||
account and exits 1 with a pointer to `logicsrc login`. `enable` exits 1 and
|
||||
prints the checkout link when the purchase is missing. `recover --email` works
|
||||
with the vault locked, exits 3 when the recovery code does not match, prints the
|
||||
new offline recovery key once, and re-enrolls automatically (it warns loudly,
|
||||
exit 0, if that last step fails). The trade-off is in
|
||||
[security.md](./security.md#email-recovery-opt-in-paid).
|
||||
|
||||
## Items
|
||||
|
||||
```bash
|
||||
|
|
|
|||
|
|
@ -122,6 +122,42 @@ rotating the key and re-encrypting, because the key they held is a key they may
|
|||
have kept. Partial sharing is not a feature of a shared key; it is a second
|
||||
vault.
|
||||
|
||||
## Email recovery escrow
|
||||
|
||||
Email recovery (opt-in, paid) is a LogicSRC account feature, not part of the
|
||||
format: a vault that never enrolls is untouched by it. The security trade-off is
|
||||
in [security.md](./security.md#email-recovery-opt-in-paid); the construction is:
|
||||
|
||||
```
|
||||
user key K (32 bytes)
|
||||
│
|
||||
└─ AES-256-GCM(E, K, AAD = "<ns>:vault:email-escrow:v1|<vault createdAt>") → escrow blob
|
||||
|
||||
E (32 random bytes, client-side, never sent whole)
|
||||
├─ S = 32 random bytes → server, AES-256-GCM under VAULT_ESCROW_KEY
|
||||
│ (AAD binds the user id; key_version for rotation)
|
||||
└─ U = E XOR S → emailed once as the recovery code, never stored
|
||||
```
|
||||
|
||||
- **XOR, not a threshold scheme.** Two shares, both required: a 2-of-2 split is
|
||||
XOR, and XOR with a uniformly random S makes U uniformly random too, so each
|
||||
share alone carries no information about E.
|
||||
- **The AAD carries `createdAt`.** It survives password changes and changes on
|
||||
`init`, so an escrow blob cannot be replayed against a different vault.
|
||||
- **The recovery code** is U in Crockford base32 (the alphabet of the offline
|
||||
recovery key): 55 characters for 256 bits plus 19 zero bits, then a 5-character
|
||||
check group, the first 25 bits of
|
||||
`SHA-256("opencreds:email-recovery-code:v1" || U)`. Twelve groups of five. The
|
||||
check group catches a typo before a one-time code is requested or spent;
|
||||
a well-formed but wrong code fails the GCM tag on the escrow blob instead
|
||||
("recovery code doesn't match").
|
||||
- **After recovery** the client re-wraps K under the new password, replaces the
|
||||
offline recovery key, and re-enrolls with a fresh E, S and U. K itself does not
|
||||
change, so not one item is re-encrypted.
|
||||
- **One-time codes** are 8 digits, stored as an HMAC under the server escrow key
|
||||
(a dump of the codes table alone cannot brute-force a live one), 15 minutes,
|
||||
5 attempts, single use.
|
||||
|
||||
## Randomness
|
||||
|
||||
Every IV, salt, user key and recovery key MUST come from a cryptographic RNG
|
||||
|
|
|
|||
|
|
@ -113,6 +113,53 @@ Consequences worth stating in a product's own docs:
|
|||
give them access, because it does not have the key. This is a feature, and it
|
||||
means a grant requires an authorized member to be online.
|
||||
|
||||
## Email recovery (opt-in, paid)
|
||||
|
||||
The LogicSRC account service offers a second way back into a personal (`user`
|
||||
profile) vault: `logicsrc vault recovery enable`, $5 once per account. It is off
|
||||
unless the person turns it on, and it changes the threat model for those who
|
||||
do. A vault that is never enrolled stays exactly as described above: the server
|
||||
holds nothing that can open it.
|
||||
|
||||
**What enrolling stores.** The client draws a random 32-byte escrow key E,
|
||||
encrypts the user key under it, and splits E into two XOR shares, S and U. The
|
||||
server stores the escrowed blob and S, with S encrypted under the server's own
|
||||
escrow key (`VAULT_ESCROW_KEY`). U is rendered as a recovery code, emailed to
|
||||
the account address once ("keep this email"), and dropped: no table has a
|
||||
column for it. Each share alone is uniformly random and says nothing about E.
|
||||
The crypto is in [crypto.md](./crypto.md#email-recovery-escrow).
|
||||
|
||||
**What recovering needs.** `logicsrc vault recover --email` needs the recovery
|
||||
code from the enrollment email (U) and a fresh 8-digit one-time code the server
|
||||
mails at that moment (15 minutes, 5 tries, single use, 3 requests an hour),
|
||||
plus a signed-in LogicSRC CLI. The server releases S only against that code,
|
||||
logs the claim and mails a "your vault email recovery was used" notice. The
|
||||
client recombines E, decrypts the user key, checks it opens an item, sets a new
|
||||
master password, issues a new offline recovery key and re-enrolls with fresh
|
||||
shares, so the code just used is dead.
|
||||
|
||||
What this does and does not hold against, stated plainly:
|
||||
|
||||
- **A stolen database, even with the server's environment (the escrow key):**
|
||||
cannot open an enrolled vault. It yields the blob and S, and E also needs U,
|
||||
which only the enrollment email has.
|
||||
- **The enrollment email alone:** cannot open the vault. It is U without S, and
|
||||
S is released only to a signed-in account that also receives a fresh code.
|
||||
- **A live compromise of the server while a person enrolls or recovers:** can
|
||||
open that vault. Enrollment hands U to the server in transit so it can be
|
||||
mailed, and a claim hands S back out; code running on the server at that
|
||||
moment sees what it needs.
|
||||
- **The person's mailbox together with a live server compromise, or the
|
||||
mailbox together with their LogicSRC sign-in:** can open the vault. The
|
||||
mailbox holds U and receives the one-time code; the account (or the server)
|
||||
supplies S. This is the reason the feature is opt-in: it moves part of the
|
||||
vault's safety onto the security of an email account.
|
||||
- **The account operator** can see that a person enrolled, when, and when they
|
||||
recovered; never the contents.
|
||||
|
||||
Turning it off (`logicsrc vault recovery disable`, or Settings) deletes the
|
||||
escrowed blob and S on the server, after which the emailed code is useless.
|
||||
|
||||
## Reporting
|
||||
|
||||
Security issues in the specification or the reference implementation:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue