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
|
|
@ -19,6 +19,20 @@ impl std::fmt::Display for Error {
|
|||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
impl Error {
|
||||
/// Is this failure "the wallet RPC is not answering yet"? That is the one
|
||||
/// class a retry can fix — a freshly spawned `monero-wallet-rpc` binds its
|
||||
/// port a moment after `spawn` returns. Everything else (a refused
|
||||
/// passphrase, a protocol error) is the RPC's own answer and retrying it
|
||||
/// would only repeat it.
|
||||
///
|
||||
/// Deliberately *not* the timeout: a hung child is not a start in progress.
|
||||
pub fn is_unreachable(&self) -> bool {
|
||||
let msg = self.0.as_str();
|
||||
msg.starts_with("wallet connect:") || msg.starts_with("wallet write:")
|
||||
}
|
||||
}
|
||||
|
||||
/// Which Monero network an on-device daemon follows.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ChainNetwork {
|
||||
|
|
@ -147,6 +161,17 @@ pub struct WalletConfig {
|
|||
pub rpc_login: Zeroizing<String>,
|
||||
/// View-only deployment: `/tip` is refused locally, before any dial.
|
||||
pub no_spend: bool,
|
||||
/// The passphrase that opens the wallet *file* the child is pointed at
|
||||
/// ([`Wallet::open_wallet`]). Sealed at rest beside `rpc_login`; empty when
|
||||
/// this install has never been told one (a wallet that predates the field,
|
||||
/// or a remote-mode wallet the user runs themselves).
|
||||
///
|
||||
/// Keeping it is deliberate: it makes the store passphrase sufficient to
|
||||
/// spend, and it is why the app can reopen a wallet file across a restart
|
||||
/// at all — `monero-wallet-rpc` holds an open file only for the life of the
|
||||
/// process, and re-opening it needs the passphrase. See
|
||||
/// `docs/THREAT_MODEL.md`.
|
||||
pub wallet_passphrase: Zeroizing<String>,
|
||||
}
|
||||
|
||||
impl WalletConfig {
|
||||
|
|
@ -155,9 +180,19 @@ impl WalletConfig {
|
|||
rpc_url: rpc_url.trim().to_string(),
|
||||
rpc_login: Zeroizing::new(rpc_login.trim().to_string()),
|
||||
no_spend,
|
||||
wallet_passphrase: Zeroizing::new(String::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the passphrase that opens the wallet file this config's child is
|
||||
/// pointed at. Chainable, and the only way to supply it from outside the
|
||||
/// crate: the field is public too, but a builder keeps a caller from
|
||||
/// forgetting that it is sealed beside the login.
|
||||
pub fn with_wallet_passphrase(mut self, passphrase: &str) -> Self {
|
||||
self.wallet_passphrase = Zeroizing::new(passphrase.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
/// The password half of `user:pass` (the whole string when there is no
|
||||
/// colon), for redaction. Never rendered anywhere.
|
||||
pub fn secret(&self) -> &str {
|
||||
|
|
@ -176,6 +211,14 @@ impl std::fmt::Debug for WalletConfig {
|
|||
.field("rpc_url", &self.rpc_url)
|
||||
.field("rpc_login", &"<redacted>")
|
||||
.field("no_spend", &self.no_spend)
|
||||
.field(
|
||||
"wallet_passphrase",
|
||||
&if self.wallet_passphrase.is_empty() {
|
||||
"<none>"
|
||||
} else {
|
||||
"<redacted>"
|
||||
},
|
||||
)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
@ -185,6 +228,7 @@ impl PartialEq for WalletConfig {
|
|||
self.rpc_url == other.rpc_url
|
||||
&& self.rpc_login.as_str() == other.rpc_login.as_str()
|
||||
&& self.no_spend == other.no_spend
|
||||
&& self.wallet_passphrase.as_str() == other.wallet_passphrase.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -525,6 +569,10 @@ impl Wallet {
|
|||
rpc_url: format!("http://{}{}", host_header(&ep.host, ep.port), ep.path),
|
||||
rpc_login: Zeroizing::new(format!("{}:{}", ep.user, ep.pass.as_str())),
|
||||
no_spend: self.no_spend,
|
||||
// Not known here: the passphrase is the *file's*, and this builds
|
||||
// the config of the RPC endpoint in use. Callers that persist a
|
||||
// config do a read-modify-write so the stored one survives.
|
||||
wallet_passphrase: Zeroizing::new(String::new()),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -809,6 +857,41 @@ impl Wallet {
|
|||
json_str(&v, "key")
|
||||
}
|
||||
|
||||
/// Open a wallet *file* on the RPC (`open_wallet`).
|
||||
///
|
||||
/// `monero-wallet-rpc` starts with no wallet open, and `create_wallet` /
|
||||
/// `restore_deterministic_wallet` leave theirs open for that process only:
|
||||
/// after a restart every read answers `-13 No wallet file` even though the
|
||||
/// file is on disk. This is the call that opens it, and the only way a
|
||||
/// wallet survives the child being restarted.
|
||||
///
|
||||
/// The passphrase travels in the JSON-RPC body, never on the argv: `ps` is
|
||||
/// world-readable for the same user, and `--wallet-file`/`--password`
|
||||
/// would put the secret there. `filename` is a name inside the child's
|
||||
/// `--wallet-dir`, never a path.
|
||||
///
|
||||
/// A wrong passphrase is the RPC's own error (the daemon does not open a
|
||||
/// file it cannot decrypt); it is surfaced as-is, never retried into a
|
||||
/// generic failure by the caller.
|
||||
pub async fn open_wallet(&self, filename: &str, password: &str) -> Result<()> {
|
||||
let filename = filename.trim();
|
||||
if filename.is_empty() {
|
||||
return Err(Error("wallet filename required".into()));
|
||||
}
|
||||
if password.is_empty() {
|
||||
return Err(Error("wallet passphrase required".into()));
|
||||
}
|
||||
self.rpc(
|
||||
"open_wallet",
|
||||
serde_json::json!({
|
||||
"filename": filename,
|
||||
"password": password,
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Re-read the seed of the wallet file the RPC has open (`query_key
|
||||
/// mnemonic`). After `create_wallet` this is the **only** way to recover a
|
||||
/// created wallet's seed, so the UI can offer a backup action instead of
|
||||
|
|
|
|||
Loading…
Reference in a new issue