wallet: actually open the wallet file, and remember its passphrase
All checks were successful
ci / test (pull_request) Successful in 6m14s
ci / sdk (pull_request) Successful in 1m44s
android-ci / android (pull_request) Successful in 12m56s
ci / fuzz (pull_request) Successful in 5m1s

`monero-wallet-rpc` starts with no wallet open and keeps one only for the
life of its process, so a restart, a Lock/unlock or a wallet re-point left
a live child answering `-13 No wallet file` to every read while the file
sat on disk. The app now opens the configured catalogue file itself
(`Wallet::open_wallet`, over RPC — never `--wallet-file`/`--password` on
argv, which `ps` exposes) after the child is up, and keeps the passphrase
that does it, sealed with the store data key beside the RPC creds under
its own AAD.

- core: `Wallet::open_wallet`, `WalletConfig::wallet_passphrase`
  (+ `with_wallet_passphrase`, redacted Debug, kept out of the endpoint
  config), `Error::is_unreachable` for the one retryable class (the port
  binds a moment after spawn; a timeout is not a start in progress).
- store: `wallet_config.sealed_passphrase` column (additive, AAD
  `onionwire-store-v1:wallet-passphrase`), read-modify-written so the
  endpoint/login survive; `wallet_save_config` keeps the stored one.
- node: `start_wallet_child` opens the file, `open_wallet_with_passphrase`
  opens a file with a passphrase the user just typed and seals it only
  once a live daemon accepted it, `wallet_status` grows `wallet_open` and
  `needs_passphrase`. A child the RPC refuses is stopped rather than left
  inert; an install with no stored passphrase still starts, and says so.
- tui: one-shot prompt (`WalletSetup::UnlockPass`) on a wallet that needs
  it, reachable from the saved-wallet picker and from `s`.
- sdk: `openWalletWithPassphrase`, the two status fields, README flow.
- docs: WALLET/THREAT_MODEL/README — the passphrase is kept, and the
  consequence (the store passphrase is sufficient to spend) is stated
  rather than implied.

Tests: 4 new node tests drive a real child lifecycle against a loopback
wallet RPC (open on restart, no open without a passphrase, refused
passphrase, sealed-on-success), a `tests/wallet.rs` test asserts the bytes
sent (`open_wallet` + filename + password), and `tests/store.rs` covers
the sealed column and the plaintext->encrypted upgrade with it set.
Mutation-checked: stubbing the two open paths fails all four.
This commit is contained in:
agent 2026-09-22 12:52:08 -04:00
commit ed29131a67
No known key found for this signature in database
12 changed files with 1262 additions and 54 deletions

View file

@ -171,6 +171,17 @@ watch-only wallet detected over RPC via `query_key spend_key` → `-29`).
seed-backed spend-capable wallet makes OnionWire a **local spend authority**
for that file: anyone with the wallet passphrase or the wallet-RPC credentials
can move the balance, and `/tip` is a supported way for a chat peer to get paid.
Those credentials are sealed with the store data key (SQLCipher plus a per-row
AEAD), and so is the **wallet-file passphrase**: it is kept in the same sealed
row, because `monero-wallet-rpc` holds a wallet only for the life of one process
and reopening the file needs it. That is a deliberate decision with a real
consequence — **whoever can unlock the store can spend**: the store passphrase
(or its Keystore wrapper) is now sufficient, and there is no second secret
standing between a seized unlocked device and the wallet's balance. Nothing else
changes: `/tip` still refuses on a view-only wallet before any dial, the
spend-authority warning is still unavoidable at create/restore, the passphrase is
never logged, never in an error string and never on a process argv, and `/wipe`
keeps the wallet file and its passphrase exactly as it kept the file before.
The spend-authority warning is unavoidable at that create/restore step. Loopback
binding is not an authorization boundary. Back up the seed; do not leave a
spend-capable wallet on a device you do not trust; a separate hot wallet with a

View file

@ -41,7 +41,10 @@ env var:
- **`monero-wallet-rpc`** is spawned with `--rpc-bind-ip 127.0.0.1`, a **random
free loopback port**, a generated `--rpc-login` (`user:pass`, random
`[a-z0-9]`), and `--wallet-dir $ONIONWIRE_HOME/wallet`.
`[a-z0-9]`), and `--wallet-dir $ONIONWIRE_HOME/wallet`. No `--wallet-file` and
no `--password`: argv is world-readable to the same user through `ps`, so the
wallet is opened **over RPC** (`open_wallet`) once the child is up, and never
named on the command line.
- **`monerod`** is spawned when the chain source is *local*:
`--non-interactive --data-dir <datadir> --rpc-bind-ip 127.0.0.1 --rpc-bind-port
18081`. The wallet child dials `127.0.0.1:18081`.
@ -55,21 +58,48 @@ env var:
Generated `user:pass` is sealed with the store data key in the SQLCipher
`wallet_child` table. It never appears in `ONIONWIRE_WALLET_RPC`.
The wallet passphrase for `create_wallet` / `restore_deterministic_wallet` is
your runtime choice, not stored by the app.
`monero-wallet-rpc` starts with **no wallet open** and keeps one open only for
the life of its process, so a restart (app relaunch, Lock/unlock, a wallet
re-point) would otherwise answer every read with `-13 No wallet file` while the
file sits on disk. After the child is up the app therefore issues `open_wallet`
for the configured catalogue row.
That needs the passphrase, and the app **keeps it**: the passphrase you type at
create/import (or the one you enter once for a wallet that predates this) is
sealed with the store data key in the SQLCipher `wallet_config` row, beside the
RPC creds, under its own AAD. It is never logged, never put in an error string,
and never on a process argv. The consequence is deliberate and stated in
[THREAT_MODEL.md](THREAT_MODEL.md): **the store passphrase is now sufficient to
spend** — an attacker who has it can open the wallet file and move the balance,
without a second secret. The spend-authority warning at create/restore is
unchanged and is not made weaker by this.
Wipe semantics: `/wipe` keeps the wallet file and its passphrase (the file
survives `/wipe` today); `/wipe-all` removes the data dir, as before.
If the stored passphrase does not open the configured file — a wallet the
catalogue holds but whose passphrase changed, or one created on another install —
the app reports it against that file and does **not** overwrite the stored one.
The child is stopped rather than left answering `-13`, and the status reports
`needs passphrase`; open the file once with its real passphrase
(`open_wallet_with_passphrase`, or the TUI/Android prompt) and it is remembered.
Nothing spawns the child at boot. `Node::start_wallet_child` is the only start
path. The desktop TUI drives it from `F6`:
| Key | Effect |
|---|---|
| `s` | Start the child, then probe it once. |
| `s` | Start the child, then probe it once. A child whose wallet file needs a passphrase opens the passphrase prompt instead of leaving every read at `-13`. |
| `x` | Stop it (idempotent). |
| `p` | Probe: is wallet RPC answering, is the chain at the tip? |
| `1` / `2` / `3` | Store in-process Cuprate as mainnet-pruned / mainnet-full / testnet. |
State shown: `off` / `connecting` / `syncing` / `ready` / `exited`, plus a
chain-source label. `ready` is never reported for a child that has died.
chain-source label, plus `wallet locked` while a catalogue wallet is configured
but not open in the child's RPC. `ready` is never reported for a child that has
died. A live child is not a usable wallet: `wallet_status()` carries
`wallet_open` and `needs_passphrase` so a client can tell "the wallet is open"
from "the child is up and waiting for a passphrase".
Once a probe has read the daemon, the line can include `sync <height>/<target>`
— the **daemon's** height and the tip it is syncing towards (wallet RPC
@ -213,7 +243,11 @@ mark the open row. `open_wallet(filename)` switches to a catalogue row: a
running child is stopped and restarted onto the new file, an idle one is only
re-pointed (the change applies at the next `start_wallet_child`), and a file the
catalogue does not hold is refused — the catalogue is the only directory this app
keeps wallets in.
keeps wallets in. The restarted child then opens that file with the stored
passphrase; when this install has none for it, the call still succeeds and the
status says `needs_passphrase` — that is what the prompt is for, and
`open_wallet_with_passphrase(filename, passphrase)` is the API behind it. It
stores the passphrase only after a live daemon has opened the file with it.
## Secrets belong to the open wallet
@ -237,13 +271,15 @@ are displayable on demand".
`/wallet create` (`F6` then `c`) → `create_wallet`, then seed **once**
(`query_key mnemonic`). Type `SPEND`, set a passphrase, write the seed, type
`SEEN`.
`SEEN`. The passphrase you set is sealed in the store (above), so the wallet
reopens on the next start without asking for it again.
`/wallet import` (`F6` then `i`) → `restore_deterministic_wallet` from a
25-word seed. Do not put the seed on the composer.
RPC must be started with `--wallet-dir` (not only `--wallet-file`). Filename:
`onionwire`.
RPC must be started with `--wallet-dir` (not only `--wallet-file`). A created
wallet gets its own file name (`onionwire-1`, `onionwire-2`, …): `wallet_filename`
is UNIQUE in the catalogue, so a second create must not reuse the first file.
## Recommended topology (view-only)