wallet: actually open the wallet file, and remember its passphrase
`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:
parent
c5725856ad
commit
ed29131a67
12 changed files with 1262 additions and 54 deletions
|
|
@ -111,6 +111,15 @@ val active: String? = wire.activeWalletFilename() // the open file, or null
|
|||
val open = wallets.firstOrNull { it.walletFilename == active }
|
||||
wire.openWallet("onionwire-2") // may restart a running wallet child; a name
|
||||
// outside the catalogue is refused
|
||||
// A wallet child is up but its file is not open -> the child answers `-13 No
|
||||
// wallet file` to every read. `walletStatus()` says which:
|
||||
val st: WalletChildStatus = wire.walletStatus()
|
||||
if (st.running && !st.walletOpen && st.needsPassphrase) {
|
||||
val pass = askForTheWalletPassphrase() // your own input surface, echo off
|
||||
wire.openWalletWithPassphrase(active!!, pass) // stored (sealed) on success;
|
||||
// a refused passphrase is an
|
||||
// error and is NOT stored
|
||||
}
|
||||
val keys: WalletKeys = wire.walletKeys() // the OPEN wallet's private keys
|
||||
// keys.spendKey == null -> a view-only wallet (the RPC's -29 watch-only answer).
|
||||
// That is not an error. The seed (`walletSeed()`) and these keys always belong
|
||||
|
|
|
|||
|
|
@ -574,6 +574,35 @@ impl Wire {
|
|||
self.node()?.open_wallet(&filename).map_err(WireError::new)
|
||||
}
|
||||
|
||||
/// Open a saved wallet with a passphrase the user just typed, and remember
|
||||
/// it (sealed) once the wallet daemon has accepted it.
|
||||
///
|
||||
/// This is what ends a [`WalletChildStatus`] with
|
||||
/// `needs_passphrase = true` — a wallet created before the passphrase was
|
||||
/// stored, or created on another install. After it succeeds, every later
|
||||
/// [`Wire::start_wallet_child`] opens the file on its own.
|
||||
///
|
||||
/// Same refusals as [`Wire::open_wallet`]: a `filename` the catalogue does
|
||||
/// not hold, an empty passphrase, or no configured wallet RPC at all are
|
||||
/// `WireError.Failed` before anything is dialled. A passphrase the daemon
|
||||
/// refuses is reported as such, and is **not** stored — the file stays
|
||||
/// `needs_passphrase`. Runs on `spawn_blocking`: the RPC can wait for a
|
||||
/// freshly spawned child to bind. `WireError.Stopped` after `shutdown`.
|
||||
pub async fn open_wallet_with_passphrase(
|
||||
&self,
|
||||
filename: String,
|
||||
passphrase: String,
|
||||
) -> WResult<()> {
|
||||
let node = self.node()?;
|
||||
let blocking = node.clone();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
blocking.open_wallet_with_passphrase(&filename, &passphrase)
|
||||
})
|
||||
.await
|
||||
.map_err(|e| WireError::new(format!("open wallet join: {e}")))?
|
||||
.map_err(WireError::new)
|
||||
}
|
||||
|
||||
/// The wallet file the child is currently pointed at, or `None` when no
|
||||
/// wallet-child settings were ever stored (a fresh install has no open
|
||||
/// wallet).
|
||||
|
|
@ -1029,6 +1058,8 @@ fn child_status(
|
|||
WalletChildStatus {
|
||||
state: status.state.as_str().to_string(),
|
||||
running: status.running,
|
||||
wallet_open: status.wallet_open,
|
||||
needs_passphrase: status.needs_passphrase,
|
||||
configured: status.configured,
|
||||
chain_source: status.chain_source,
|
||||
chain_in_process: in_process,
|
||||
|
|
@ -1322,6 +1353,16 @@ pub struct WalletChildStatus {
|
|||
pub state: String,
|
||||
/// A `monero-wallet-rpc` child is alive right now.
|
||||
pub running: bool,
|
||||
/// The wallet **file** the child is pointed at is open in that RPC. A live
|
||||
/// child is not a usable wallet: `monero-wallet-rpc` starts with no wallet
|
||||
/// open, and every read then answers `-13 No wallet file`. `false` for an
|
||||
/// off/exited child, and while `needs_passphrase` holds.
|
||||
pub wallet_open: bool,
|
||||
/// A saved wallet is configured but not open, because this install holds no
|
||||
/// passphrase that opens it (or the one it holds was refused). Show the
|
||||
/// passphrase prompt and call [`Wire::open_wallet_with_passphrase`]; it is
|
||||
/// not a start failure and the child is still running.
|
||||
pub needs_passphrase: bool,
|
||||
/// A chain source is configured (anything but receive-only).
|
||||
pub configured: bool,
|
||||
/// The chain-source label.
|
||||
|
|
@ -2161,6 +2202,8 @@ mod tests {
|
|||
onionwire::wallet_child::WalletChildStatus {
|
||||
state,
|
||||
running: true,
|
||||
wallet_open: true,
|
||||
needs_passphrase: false,
|
||||
configured: true,
|
||||
chain_source: "in-process node".to_string(),
|
||||
height: 0,
|
||||
|
|
@ -2262,6 +2305,42 @@ mod tests {
|
|||
assert_eq!(status.target_height, 0);
|
||||
}
|
||||
|
||||
/// The two states a client has to tell apart, mapped from the core: a child
|
||||
/// whose wallet file is open, and one that is live but waiting for its
|
||||
/// passphrase (a wallet created before the passphrase was stored).
|
||||
#[test]
|
||||
fn a_locked_wallet_is_reported_as_needing_a_passphrase_not_as_off() {
|
||||
let locked = onionwire::wallet_child::WalletChildStatus {
|
||||
state: WalletChildState::Connecting,
|
||||
running: true,
|
||||
wallet_open: false,
|
||||
needs_passphrase: true,
|
||||
configured: true,
|
||||
chain_source: "remote daemon".to_string(),
|
||||
height: 0,
|
||||
target_height: 0,
|
||||
last_error: Some("wallet file onionwire-1 is not open".to_string()),
|
||||
};
|
||||
let got = child_status(locked, &ChainSource::None);
|
||||
assert!(
|
||||
got.running,
|
||||
"the child is up, it is the wallet that is not open"
|
||||
);
|
||||
assert!(!got.wallet_open, "{got:?}");
|
||||
assert!(got.needs_passphrase, "{got:?}");
|
||||
assert_eq!(got.state, "connecting");
|
||||
|
||||
let open = onionwire::wallet_child::WalletChildStatus {
|
||||
wallet_open: true,
|
||||
needs_passphrase: false,
|
||||
last_error: None,
|
||||
..core_status(WalletChildState::Ready)
|
||||
};
|
||||
let got = child_status(open, &ChainSource::None);
|
||||
assert!(got.wallet_open, "{got:?}");
|
||||
assert!(!got.needs_passphrase, "{got:?}");
|
||||
}
|
||||
|
||||
/// A live probe on a node with no child is `off` — the same record the
|
||||
/// cheap read reports — never an error and never an invented state.
|
||||
///
|
||||
|
|
@ -2279,6 +2358,8 @@ mod tests {
|
|||
let core = onionwire::wallet_child::WalletChildStatus {
|
||||
state: WalletChildState::Off,
|
||||
running: false,
|
||||
wallet_open: false,
|
||||
needs_passphrase: false,
|
||||
configured: false,
|
||||
chain_source: "receive-only".to_string(),
|
||||
height: 0,
|
||||
|
|
@ -2289,6 +2370,8 @@ mod tests {
|
|||
let want = WalletChildStatus {
|
||||
state: "off".to_string(),
|
||||
running: false,
|
||||
wallet_open: false,
|
||||
needs_passphrase: false,
|
||||
configured: false,
|
||||
chain_source: "receive-only".to_string(),
|
||||
chain_in_process: false,
|
||||
|
|
@ -2307,6 +2390,8 @@ mod tests {
|
|||
] {
|
||||
assert_eq!(got.state, want.state);
|
||||
assert_eq!(got.running, want.running);
|
||||
assert_eq!(got.wallet_open, want.wallet_open);
|
||||
assert_eq!(got.needs_passphrase, want.needs_passphrase);
|
||||
assert_eq!(got.configured, want.configured);
|
||||
assert_eq!(got.chain_source, want.chain_source);
|
||||
assert_eq!(got.chain_in_process, want.chain_in_process);
|
||||
|
|
|
|||
Loading…
Reference in a new issue