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
|
|
@ -1761,3 +1761,75 @@ async fn an_in_process_cuprate_node_answers_the_typed_daemon_client() {
|
|||
"the unrestricted RPC was still accepting after shutdown"
|
||||
);
|
||||
}
|
||||
|
||||
/// The call the whole restart story hangs on. Assert the bytes the client
|
||||
/// **sent**: a mock that answers whatever it is asked stays green for a client
|
||||
/// that never issued `open_wallet` at all — which is exactly how a wallet came
|
||||
/// back from a restart answering `-13 No wallet file` while the suite passed.
|
||||
#[tokio::test]
|
||||
async fn open_wallet_issues_the_rpc_method_with_the_file_and_passphrase() {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
let log = Arc::new(Mutex::new(Vec::new()));
|
||||
tokio::spawn(serve_recording(
|
||||
listener,
|
||||
Arc::clone(&log),
|
||||
Arc::new(|_: &str| rpc_result("{}")),
|
||||
));
|
||||
|
||||
recording_wallet(port)
|
||||
.open_wallet("onionwire-1", "walletfile-pass")
|
||||
.await
|
||||
.expect("open_wallet");
|
||||
|
||||
let sent = log.lock().unwrap().join("\n");
|
||||
assert!(
|
||||
sent.contains(r#""method":"open_wallet""#),
|
||||
"the client never asked to open the file: {sent}"
|
||||
);
|
||||
assert!(sent.contains(r#""filename":"onionwire-1""#), "{sent}");
|
||||
assert!(sent.contains(r#""password":"walletfile-pass""#), "{sent}");
|
||||
}
|
||||
|
||||
/// Same refusals as `create_wallet`: an empty file name or an empty passphrase
|
||||
/// is a local error, before any socket is opened.
|
||||
#[tokio::test]
|
||||
async fn open_wallet_refuses_a_blank_filename_or_passphrase_locally() {
|
||||
let w = Wallet::disabled();
|
||||
let err = w.open_wallet(" ", "pw").await.expect_err("no filename");
|
||||
assert!(err.to_string().contains("filename"), "{err}");
|
||||
let err = w
|
||||
.open_wallet("onionwire-1", "")
|
||||
.await
|
||||
.expect_err("no passphrase");
|
||||
assert!(err.to_string().contains("passphrase"), "{err}");
|
||||
}
|
||||
|
||||
/// A refused passphrase is the RPC's own message, not a rewritten generic one:
|
||||
/// the caller has to be able to tell it apart from a daemon that never answered.
|
||||
#[tokio::test]
|
||||
async fn open_wallet_surfaces_the_rpcs_own_refusal() {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
tokio::spawn(serve_recording(
|
||||
listener,
|
||||
Arc::new(Mutex::new(Vec::new())),
|
||||
Arc::new(|_: &str| {
|
||||
r#"{"jsonrpc":"2.0","id":"0","error":{"code":-1,"message":"Failed to open wallet"}}"#
|
||||
.to_string()
|
||||
}),
|
||||
));
|
||||
|
||||
let err = recording_wallet(port)
|
||||
.open_wallet("onionwire-1", "wrong-pass")
|
||||
.await
|
||||
.expect_err("the RPC refused");
|
||||
assert!(
|
||||
err.to_string().contains("Failed to open wallet"),
|
||||
"the RPC's own reason is what a caller needs: {err}"
|
||||
);
|
||||
assert!(
|
||||
!err.to_string().contains("wrong-pass"),
|
||||
"the passphrase must never be echoed back in an error: {err}"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue