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

@ -663,3 +663,83 @@ fn a_wallet_without_a_label_or_locator_stores_nulls_and_rejects_a_blank_filename
.expect_err("an empty filename cannot name a wallet file");
assert!(err.to_string().contains("filename"), "{err}");
}
/// The wallet file's passphrase lives in the same sealed row as the RPC login
/// and survives a re-open — the wallet child is restarted far more often than
/// the store is created, and a wallet nobody can open is the bug this exists
/// for. A wrong store passphrase still must not open the store at all.
#[test]
fn the_wallet_passphrase_round_trips_sealed_and_a_wrong_store_passphrase_does_not_open_it() {
use onionwire::wallet::WalletConfig;
let dir = tempfile::tempdir().expect("tempdir");
let cfg = WalletConfig::new("http://127.0.0.1:18083", "ow:cfg-secret-xyz", false)
.with_wallet_passphrase("walletfile-pass-abc");
{
let store = Store::open_at_with_passphrase(dir.path(), "store-pass").expect("open");
assert!(
store.load_wallet_config().expect("load").is_none(),
"a fresh store remembers no passphrase"
);
store.save_wallet_config(&cfg).expect("save");
}
let store = Store::open_at_with_passphrase(dir.path(), "store-pass").expect("reopen");
let got = store.load_wallet_config().expect("load").expect("stored");
assert_eq!(got.wallet_passphrase.as_str(), "walletfile-pass-abc");
assert_eq!(got.rpc_login.as_str(), "ow:cfg-secret-xyz");
// Sealed on disk, like the login: the passphrase is not in the db in the
// clear, and neither is the login.
for name in ["onionwire.db", "onionwire.db-wal", "onionwire.db-shm"] {
let Ok(bytes) = fs::read(dir.path().join(name)) else {
continue;
};
assert!(
!contains(&bytes, b"walletfile-pass-abc"),
"{name} holds the wallet passphrase in the clear"
);
assert!(
!contains(&bytes, b"cfg-secret-xyz"),
"{name} holds the RPC login in the clear"
);
}
// The wrong store passphrase is still refused outright.
assert!(
Store::open_at_with_passphrase(dir.path(), "not-the-store-pass").is_err(),
"a wrong store passphrase must not open the store"
);
// Clearing the F7 endpoint (an empty rpc_url) must not throw the wallet
// passphrase away: it belongs to the wallet file, not to the endpoint.
let store = Store::open_at_with_passphrase(dir.path(), "store-pass").expect("reopen");
let cleared = WalletConfig::new("", "", false).with_wallet_passphrase(
store
.load_wallet_config()
.expect("load")
.expect("stored")
.wallet_passphrase
.as_str(),
);
store.save_wallet_config(&cleared).expect("save cleared");
let got = store
.load_wallet_config()
.expect("load")
.expect("a remembered passphrase keeps the row");
assert_eq!(got.rpc_url, "");
assert_eq!(got.wallet_passphrase.as_str(), "walletfile-pass-abc");
// And with nothing left to remember, the row goes away.
store
.save_wallet_config(&WalletConfig::new("", "", false))
.expect("save empty");
assert!(
store.load_wallet_config().expect("load").is_none(),
"an empty endpoint and no passphrase is an empty row"
);
}
fn contains(haystack: &[u8], needle: &[u8]) -> bool {
haystack.windows(needle.len()).any(|w| w == needle)
}