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

@ -1307,6 +1307,14 @@ enum WalletSetup {
CreateSeed { seed: Zeroizing<String>, typed: String },
ImportSeed { buf: Zeroizing<String> },
ImportPass { seed: Zeroizing<String>, entry: PassphraseEntry },
/// The wallet file the child is pointed at is not open because this install
/// has no passphrase for it. Same prompt idiom as the create path: one
/// hidden entry, `Enter` submits, `Esc` cancels, and the buffer is zeroized
/// on every exit.
UnlockPass {
filename: String,
entry: PassphraseEntry,
},
}
/// A function key the TUI answers before the per-screen `match`; the screen's
@ -2112,8 +2120,26 @@ impl App {
let opened = self.select_wallet(index);
match opened {
Ok(label) => {
self.status_note = Some(format!("opened wallet {label}"));
self.screen = Screen::Main;
// The child is pointed at the file either way; whether
// it could *open* it is a separate fact, and the one the
// user has to answer for when this install holds no
// passphrase (a wallet created before one was stored).
if self.node.wallet_child_status().needs_passphrase {
let filename = self
.node
.active_wallet_filename()
.ok()
.flatten()
.unwrap_or_default();
self.status_note = Some(format!("wallet {label} needs its passphrase"));
self.screen = Screen::WalletSetup(WalletSetup::UnlockPass {
filename,
entry: PassphraseEntry::new(),
});
} else {
self.status_note = Some(format!("opened wallet {label}"));
self.screen = Screen::Main;
}
}
Err(e) => self.alert = Some(e),
}
@ -2247,6 +2273,26 @@ impl App {
Ok(()) => self.wallet_child_note(),
Err(e) => format!("wallet child: {e}"),
});
self.prompt_for_wallet_passphrase();
}
/// A started child whose wallet file is not open: ask for the passphrase
/// instead of leaving the user with a child that answers `-13` to every
/// read. Reuses the create path's prompt.
fn prompt_for_wallet_passphrase(&mut self) {
if !self.node.wallet_child_status().needs_passphrase {
return;
}
let filename = self
.node
.active_wallet_filename()
.ok()
.flatten()
.unwrap_or_default();
self.screen = Screen::WalletSetup(WalletSetup::UnlockPass {
filename,
entry: PassphraseEntry::new(),
});
}
/// Key `x`: stop the child (idempotent) and drop back to the stored/env
@ -2341,7 +2387,9 @@ impl App {
};
if key.code == KeyCode::Esc {
match setup {
WalletSetup::CreatePass { entry } | WalletSetup::ImportPass { entry, .. } => {
WalletSetup::CreatePass { entry }
| WalletSetup::ImportPass { entry, .. }
| WalletSetup::UnlockPass { entry, .. } => {
entry.close();
}
WalletSetup::CreateSeed { seed, .. } => seed.zeroize(),
@ -2476,6 +2524,33 @@ impl App {
}
_ => {}
},
WalletSetup::UnlockPass { filename, entry } => match key.code {
KeyCode::Backspace => entry.backspace(),
KeyCode::Char(c) if !key.modifiers.contains(KeyModifiers::CONTROL) => {
entry.push(c);
}
KeyCode::Enter => {
// One entry, no confirm: this passphrase is already the
// file's, and a re-type would only be a second chance to
// typo it.
let pass = entry.take_buf();
let filename = filename.clone();
match self
.node
.open_wallet_with_passphrase(&filename, pass.as_str())
{
Ok(()) => {
self.status_note = Some(format!("opened wallet {filename}"));
self.screen = Screen::Main;
}
Err(e) => {
self.alert = Some(e);
self.screen = Screen::Main;
}
}
}
_ => {}
},
}
Ok(())
}
@ -3326,7 +3401,11 @@ match screen {
"c create i import r qr w wallets s/x child 1 pruned 2 full 3 testnet Esc back ? help"
}
Screen::WalletSetup(WalletSetup::CreateWarn { .. }) => "type SPEND Esc cancel ? help",
Screen::WalletSetup(WalletSetup::CreatePass { .. } | WalletSetup::ImportPass { .. }) => {
Screen::WalletSetup(
WalletSetup::CreatePass { .. }
| WalletSetup::ImportPass { .. }
| WalletSetup::UnlockPass { .. },
) => {
"Enter submit Esc cancel ? help"
}
Screen::WalletSetup(WalletSetup::CreateSeed { .. }) => "type SEEN Esc cancel ? help",
@ -5222,6 +5301,14 @@ fn draw_wallet_setup(f: &mut Frame, setup: &WalletSetup) {
"passphrase for the imported wallet file\n\nEnter continues Esc cancels".into()
},
),
WalletSetup::UnlockPass { filename, .. } => (
"wallet passphrase",
format!(
"the wallet file {filename} is not open\n\
enter its passphrase to open it (it is then remembered, sealed)\n\n\
Enter submits Esc cancels"
),
),
};
draw_text_overlay(f, title, &body);
}