transport: ML-KEM-768 hybrid prelude and onionwire:v2 invites
Adds an ML-KEM-768 install key beside the ed25519 identity and x25519 prekey. A friend added from a v2 invite always gets a version-2 PQ prelude before Noise msg 1, and both sides bind (ct, ss_kem) into the Noise prologue (onionwire-v2 \0 ct \0 ss_kem). The row decides: a kem_pk friend without a prelude is rejected with 'prelude required', a prelude for a classical row with 'unexpected prelude'. Invites are now onionwire:v2 with kem=<base64url pk>; decode still accepts v1 (no kem) and yields a classical friend. F8 rotates the KEM key with the prekey and hard-cuts stored ratchet state. The TUI labels a legacy friend 'classical'. Docs: PROTOCOL (keys, framing, prologues, no-downgrade, invite v2), THREAT_MODEL (what PQ transport does and does not buy; epoch 0 stays classical), README (invite size, F8, legacy caveat). SDK exposes pq on InviteInfo/FriendInfo and gains a v2 decode round-trip test.
This commit is contained in:
parent
00bb95675f
commit
c741b660e4
26 changed files with 1637 additions and 177 deletions
|
|
@ -25,6 +25,7 @@ struct Flaky {
|
|||
err: String,
|
||||
calls: AtomicUsize,
|
||||
delivered: Mutex<Vec<Vec<u8>>>,
|
||||
kems: Mutex<Vec<Option<Vec<u8>>>>,
|
||||
}
|
||||
|
||||
impl Flaky {
|
||||
|
|
@ -34,6 +35,7 @@ impl Flaky {
|
|||
err: err.into(),
|
||||
calls: AtomicUsize::new(0),
|
||||
delivered: Mutex::new(Vec::new()),
|
||||
kems: Mutex::new(Vec::new()),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -53,8 +55,13 @@ impl Deliverer for Flaky {
|
|||
_pinned_id: &'a [u8],
|
||||
_prekey: &'a [u8],
|
||||
plaintext: &'a [u8],
|
||||
_remote_kem: Option<&'a [u8]>,
|
||||
) -> BoxFut<'a, Result<(), String>> {
|
||||
self.calls.fetch_add(1, Ordering::SeqCst);
|
||||
self.kems
|
||||
.lock()
|
||||
.unwrap()
|
||||
.push(_remote_kem.map(|k| k.to_vec()));
|
||||
let left = self.fail_times.load(Ordering::SeqCst);
|
||||
if left > 0 {
|
||||
self.fail_times.fetch_sub(1, Ordering::SeqCst);
|
||||
|
|
@ -366,3 +373,42 @@ async fn missing_prekey_is_fatal_not_queued() {
|
|||
assert!(err.contains("prekey"), "got {err}");
|
||||
assert!(ob.pending(&pk(2)).unwrap().is_empty());
|
||||
}
|
||||
|
||||
/// The outbound rule is derived from the friend row: a v2 friend always gets
|
||||
/// the KEM key handed to the dialer (which then sends the prelude), a v1 friend
|
||||
/// gets `None` and stays classical. The outbox never decides from wire input.
|
||||
#[tokio::test]
|
||||
async fn the_outbox_hands_the_kem_key_from_the_friend_row_to_the_dialer() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let store = store_and_friend(dir.path(), "pq.onion");
|
||||
let kp = onionwire::kem::generate();
|
||||
store
|
||||
.lock()
|
||||
.unwrap()
|
||||
.set_friend_kem(&pk(1), Some(&kp.pk))
|
||||
.unwrap();
|
||||
|
||||
let pq = Flaky::new(0, "");
|
||||
outbox(Arc::clone(&store), Arc::clone(&pq) as Arc<dyn Deliverer>, 8)
|
||||
.send(&pk(1), b"pq")
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
pq.kems.lock().unwrap().as_slice(),
|
||||
[Some(kp.pk.to_vec())],
|
||||
"a v2 friend must always send the prelude"
|
||||
);
|
||||
|
||||
// A legacy row (v1 invite) has no kem column value -> classical session.
|
||||
let legacy = Flaky::new(0, "");
|
||||
store.lock().unwrap().set_friend_kem(&pk(1), None).unwrap();
|
||||
outbox(Arc::clone(&store), Arc::clone(&legacy) as Arc<dyn Deliverer>, 8)
|
||||
.send(&pk(1), b"legacy")
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
legacy.kems.lock().unwrap().as_slice(),
|
||||
[None],
|
||||
"a v1 friend stays classical; no invented PQ protection"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue