39 lines
1.2 KiB
Rust
39 lines
1.2 KiB
Rust
|
|
//! 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");
|
||
|
|
}
|