Add Noise IK encrypted stream over Arti.
M3: framed Noise_IK_25519_ChaChaPoly_BLAKE2s on the onion pipe, QR-pinned identity proofs, plaintext only in sqlite. Live two_node send of hello wire.
This commit is contained in:
parent
4fb4648552
commit
a2dfe3b2b8
12 changed files with 1208 additions and 47 deletions
38
tests/protocol.rs
Normal file
38
tests/protocol.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
//! M3 protocol: framed Noise IK, identity pin, ciphertext on the wire.
|
||||
|
||||
use onionwire::session::{self, Keys};
|
||||
use onionwire::{frame, tui};
|
||||
|
||||
#[test]
|
||||
fn frame_roundtrip() {
|
||||
let f = frame::encode(b"hi").expect("encode");
|
||||
assert_eq!(f[0], 1, "version byte");
|
||||
assert_eq!(&f[1..5], &(2u32).to_be_bytes());
|
||||
assert_eq!(frame::decode(&f).expect("decode"), b"hi");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn noise_ik_roundtrip_hides_plaintext() {
|
||||
let a = Keys::generate();
|
||||
let b = Keys::generate();
|
||||
let (mut sa, mut sb) = session::handshake(&a, &b).expect("handshake");
|
||||
let ct = sa.encrypt(b"hello wire").expect("enc");
|
||||
assert!(
|
||||
!ct.windows(10).any(|w| w == b"hello wire"),
|
||||
"plaintext must not appear in ciphertext"
|
||||
);
|
||||
assert_eq!(sb.decrypt(&ct).expect("dec"), b"hello wire");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fingerprint_mismatch_is_hard_fail() {
|
||||
let a = Keys::generate();
|
||||
let b = Keys::generate();
|
||||
let evil = Keys::generate();
|
||||
let err = match session::handshake_pinned(&a, &b, &evil.identity_pk) {
|
||||
Err(e) => e,
|
||||
Ok(_) => panic!("expected fingerprint mismatch"),
|
||||
};
|
||||
assert!(err.is_fingerprint_mismatch(), "{err}");
|
||||
assert_eq!(tui::fingerprint_mismatch_banner(), "fingerprint mismatch");
|
||||
}
|
||||
|
|
@ -116,3 +116,50 @@ fn unknown_pubkey_inserts_new_row() {
|
|||
assert_eq!(store.get_friend(&pk(1)).unwrap().unwrap().onion, "a.onion");
|
||||
assert_eq!(store.get_friend(&pk(2)).unwrap().unwrap().onion, "b.onion");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_at_two_homes_are_independent() {
|
||||
let a = tempfile::tempdir().expect("a");
|
||||
let b = tempfile::tempdir().expect("b");
|
||||
let sa = onionwire::Store::open_at(a.path()).expect("open a");
|
||||
let sb = onionwire::Store::open_at(b.path()).expect("open b");
|
||||
let ia = sa.self_identity().unwrap();
|
||||
let ib = sb.self_identity().unwrap();
|
||||
assert_ne!(ia.identity_pk, ib.identity_pk);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incoming_message_persists_plaintext() {
|
||||
let _home = TempHome::new();
|
||||
let store = Store::open().expect("open");
|
||||
store.upsert_friend(&pk(1), "b.onion", None).unwrap();
|
||||
store.append_message(&pk(1), "in", b"hello wire").unwrap();
|
||||
let msgs = store.list_messages(&pk(1)).unwrap();
|
||||
assert_eq!(msgs.len(), 1);
|
||||
assert_eq!(msgs[0].dir, "in");
|
||||
assert_eq!(msgs[0].plaintext, b"hello wire");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn self_has_x25519_prekey_and_set_onion() {
|
||||
let _home = TempHome::new();
|
||||
let store = Store::open().expect("open");
|
||||
let me = store.self_identity().unwrap();
|
||||
assert_eq!(me.prekey_pk.len(), 32);
|
||||
assert_eq!(me.prekey_sk.len(), 32);
|
||||
assert_ne!(me.prekey_pk, me.prekey_sk);
|
||||
store.set_onion("abc.onion").unwrap();
|
||||
assert_eq!(store.self_identity().unwrap().onion, "abc.onion");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn friend_prekey_lookup() {
|
||||
let _home = TempHome::new();
|
||||
let store = Store::open().expect("open");
|
||||
let spk = [9u8; 32];
|
||||
store.upsert_friend(&pk(1), "b.onion", None).unwrap();
|
||||
store.set_friend_prekey(&pk(1), &spk).unwrap();
|
||||
let f = store.get_friend_by_prekey(&spk).unwrap().expect("found");
|
||||
assert_eq!(f.pubkey, pk(1));
|
||||
assert_eq!(f.prekey, spk);
|
||||
}
|
||||
|
|
|
|||
75
tests/two_node.rs
Normal file
75
tests/two_node.rs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
//! M3: two live Arti nodes, encrypted send, plaintext only in sqlite.
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use onionwire::node::{self, Node};
|
||||
|
||||
const HELLO: &[u8] = b"hello wire";
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
#[ignore = "needs live Tor network"]
|
||||
async fn alice_sends_hello_wire_bob_sqlite_has_plaintext() {
|
||||
let _ = tracing_subscriber::fmt()
|
||||
.with_env_filter(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into()),
|
||||
)
|
||||
.with_test_writer()
|
||||
.try_init();
|
||||
|
||||
let root = tempfile::tempdir().expect("tempdir");
|
||||
let alice_home = root.path().join("alice");
|
||||
let bob_home = root.path().join("bob");
|
||||
|
||||
eprintln!("starting alice + bob nodes…");
|
||||
let (alice, bob) = tokio::join!(
|
||||
Node::start(alice_home.clone()),
|
||||
Node::start(bob_home.clone())
|
||||
);
|
||||
let alice = alice.expect("alice node");
|
||||
let bob = bob.expect("bob node");
|
||||
eprintln!("alice onion={}", alice.onion());
|
||||
eprintln!("bob onion={}", bob.onion());
|
||||
assert_ne!(alice.onion(), bob.onion());
|
||||
|
||||
let a_qr = alice.qr_payload().expect("alice qr");
|
||||
let b_qr = bob.qr_payload().expect("bob qr");
|
||||
alice.add_friend_from_qr(&b_qr).expect("alice adds bob");
|
||||
bob.add_friend_from_qr(&a_qr).expect("bob adds alice");
|
||||
|
||||
eprintln!("alice → bob hello wire");
|
||||
alice
|
||||
.send(&bob.identity_pk(), HELLO)
|
||||
.await
|
||||
.expect("alice send");
|
||||
|
||||
let deadline = Instant::now() + Duration::from_secs(30);
|
||||
loop {
|
||||
let msgs = bob
|
||||
.list_messages(&alice.identity_pk())
|
||||
.expect("bob messages");
|
||||
if msgs.iter().any(|m| m.dir == "in" && m.plaintext == HELLO) {
|
||||
break;
|
||||
}
|
||||
if Instant::now() >= deadline {
|
||||
panic!("bob sqlite missing incoming hello wire; got {msgs:?}");
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(200)).await;
|
||||
}
|
||||
|
||||
assert!(
|
||||
!node::dir_contains_bytes(&alice.arti_dir(), HELLO),
|
||||
"plaintext leaked into alice arti dir"
|
||||
);
|
||||
assert!(
|
||||
!node::dir_contains_bytes(&bob.arti_dir(), HELLO),
|
||||
"plaintext leaked into bob arti dir"
|
||||
);
|
||||
assert!(
|
||||
!node::dir_contains_bytes(&alice.cache_dir(), HELLO),
|
||||
"plaintext leaked into alice cache dir"
|
||||
);
|
||||
assert!(
|
||||
!node::dir_contains_bytes(&bob.cache_dir(), HELLO),
|
||||
"plaintext leaked into bob cache dir"
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue