wallet: optional seed-offset passphrase on import
Monero's `restore_deterministic_wallet` takes a `seed_offset`: a second spend secret mixed into the 25 words at restore time, so the same words with a different offset open a different wallet. It is not the wallet-file passphrase and must never be sealed, stored, logged or put on an argv. - `Wallet::restore_wallet` gains `seed_offset: Option<&str>`: None, empty or whitespace-only leaves the field out of the JSON entirely; otherwise the ends are trimmed and it is sent beside the seed. - `Node::wallet_restore` passes it through and still seals only the file passphrase. - SDK: `import_wallet` keeps its signature (None) and `import_wallet_with_offset` is added (Kotlin `importWalletWithOffset`). - TUI: a new `ImportOffset` step between the seed and the file passphrase (blank Enter skips, a real one is confirmed, a mismatch never dials), and `ImportOffsetSeen` after a successful import that used one -- Esc cannot leave it, only SEEN, and the offset is not drawn anywhere. - Docs: WALLET.md, THREAT_MODEL.md, TUI.md, one README sentence.
This commit is contained in:
parent
6d815b0fe8
commit
f6a7daf892
9 changed files with 623 additions and 34 deletions
152
tests/wallet.rs
152
tests/wallet.rs
|
|
@ -618,6 +618,7 @@ fn create_wallet_empty_filename_or_password_is_local_error() {
|
|||
}
|
||||
|
||||
/// Import is the only path that takes an existing secret (the 25-word seed).
|
||||
/// An absent seed offset is not a field: the request must not carry one.
|
||||
#[tokio::test]
|
||||
async fn restore_wallet_sends_seed_to_restore_deterministic_wallet() {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
|
|
@ -634,7 +635,12 @@ async fn restore_wallet_sends_seed_to_restore_deterministic_wallet() {
|
|||
}),
|
||||
));
|
||||
recording_wallet(port)
|
||||
.restore_wallet("onionwire", "hunter2", "lumber tacit lemon ivory risk")
|
||||
.restore_wallet(
|
||||
"onionwire",
|
||||
"hunter2",
|
||||
"lumber tacit lemon ivory risk",
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.expect("restore_wallet");
|
||||
let seen = log.lock().expect("log").clone();
|
||||
|
|
@ -646,6 +652,148 @@ async fn restore_wallet_sends_seed_to_restore_deterministic_wallet() {
|
|||
restore.contains("lumber tacit lemon ivory risk"),
|
||||
"seed missing: {restore}"
|
||||
);
|
||||
assert!(
|
||||
!restore.contains("seed_offset"),
|
||||
"an absent offset must not become a field: {restore}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The seed offset is a second spend secret, sent beside the seed when present.
|
||||
#[tokio::test]
|
||||
async fn restore_wallet_sends_a_non_empty_seed_offset() {
|
||||
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(|method| match method {
|
||||
"restore_deterministic_wallet" => rpc_result(
|
||||
r#"{"address":"4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","seed":"lumber tacit lemon ivory risk"}"#,
|
||||
),
|
||||
_ => rpc_error(-1, "unexpected method"),
|
||||
}),
|
||||
));
|
||||
recording_wallet(port)
|
||||
.restore_wallet(
|
||||
"onionwire",
|
||||
"hunter2",
|
||||
"lumber tacit lemon ivory risk",
|
||||
Some("harbor-offset"),
|
||||
)
|
||||
.await
|
||||
.expect("restore_wallet");
|
||||
let seen = log.lock().expect("log").clone();
|
||||
let restore = seen
|
||||
.iter()
|
||||
.find(|r| r.contains(r#""method":"restore_deterministic_wallet""#))
|
||||
.expect("restore RPC");
|
||||
assert!(
|
||||
restore.contains(r#""seed_offset":"harbor-offset""#),
|
||||
"offset missing: {restore}"
|
||||
);
|
||||
assert!(
|
||||
restore.contains("lumber tacit lemon ivory risk"),
|
||||
"seed missing: {restore}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Blank or whitespace-only is the same as none: no `seed_offset` field at all,
|
||||
/// never `"seed_offset":""`.
|
||||
#[tokio::test]
|
||||
async fn restore_wallet_omits_a_whitespace_only_seed_offset() {
|
||||
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(|method| match method {
|
||||
"restore_deterministic_wallet" => rpc_result(
|
||||
r#"{"address":"4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","seed":"lumber tacit lemon ivory risk"}"#,
|
||||
),
|
||||
_ => rpc_error(-1, "unexpected method"),
|
||||
}),
|
||||
));
|
||||
recording_wallet(port)
|
||||
.restore_wallet(
|
||||
"onionwire",
|
||||
"hunter2",
|
||||
"lumber tacit lemon ivory risk",
|
||||
Some(" "),
|
||||
)
|
||||
.await
|
||||
.expect("blank offset restore");
|
||||
let seen = log.lock().expect("log").clone();
|
||||
assert!(
|
||||
seen.iter()
|
||||
.filter(|r| r.contains(r#""method":"restore_deterministic_wallet""#))
|
||||
.all(|r| !r.contains("seed_offset")),
|
||||
"a blank offset must not become a field: {seen:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Only the ends trim: an offset with interior spaces is sent as typed.
|
||||
#[tokio::test]
|
||||
async fn restore_wallet_trims_the_ends_of_a_seed_offset() {
|
||||
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(|method| match method {
|
||||
"restore_deterministic_wallet" => rpc_result(
|
||||
r#"{"address":"4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","seed":"lumber tacit lemon ivory risk"}"#,
|
||||
),
|
||||
_ => rpc_error(-1, "unexpected method"),
|
||||
}),
|
||||
));
|
||||
recording_wallet(port)
|
||||
.restore_wallet(
|
||||
"onionwire",
|
||||
"hunter2",
|
||||
"lumber tacit lemon ivory risk",
|
||||
Some(" harbor offset "),
|
||||
)
|
||||
.await
|
||||
.expect("trimmed offset restore");
|
||||
let seen = log.lock().expect("log").clone();
|
||||
assert!(
|
||||
seen.iter()
|
||||
.any(|r| r.contains(r#""seed_offset":"harbor offset""#)),
|
||||
"ends trim, interior spaces stay: {seen:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The offset is a spend secret: an RPC refusal must not echo it back.
|
||||
#[tokio::test]
|
||||
async fn a_failed_restore_does_not_echo_the_seed_offset() {
|
||||
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(|_method| rpc_error(-1, "restore refused")),
|
||||
));
|
||||
let err = recording_wallet(port)
|
||||
.restore_wallet(
|
||||
"onionwire",
|
||||
"hunter2",
|
||||
"lumber tacit lemon ivory risk",
|
||||
Some("harbor-offset"),
|
||||
)
|
||||
.await
|
||||
.unwrap_err()
|
||||
.to_string();
|
||||
assert!(
|
||||
!err.contains("harbor-offset"),
|
||||
"offset leaked in the error string: {err}"
|
||||
);
|
||||
assert!(
|
||||
!err.contains("lumber tacit lemon ivory risk"),
|
||||
"seed leaked in the error string: {err}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -655,7 +803,7 @@ fn restore_wallet_empty_seed_is_local_error() {
|
|||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(w.restore_wallet("onionwire", "pw", " "))
|
||||
.block_on(w.restore_wallet("onionwire", "pw", " ", None))
|
||||
.unwrap_err()
|
||||
.to_string();
|
||||
assert!(err.to_ascii_lowercase().contains("seed"), "got {err}");
|
||||
|
|
|
|||
Loading…
Reference in a new issue