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
|
|
@ -21,6 +21,10 @@ use crate::store::Store;
|
|||
|
||||
pub use crate::store::{OutboxEntry, OutboxStatus};
|
||||
|
||||
/// Where one dial goes: locator, Noise static, and the friend's ML-KEM key
|
||||
/// (`None` = legacy v1 friend, classical session).
|
||||
type Target = (String, Vec<u8>, Option<Vec<u8>>);
|
||||
|
||||
/// First retry waits this long.
|
||||
pub const BACKOFF_START_SECS: i64 = 30;
|
||||
/// Backoff never sleeps longer than this.
|
||||
|
|
@ -50,6 +54,8 @@ const PERMANENT_ERRORS: &[&str] = &[
|
|||
"fingerprint mismatch",
|
||||
"bad identity proof",
|
||||
"unexpected handshake payload",
|
||||
"prelude required",
|
||||
"unexpected prelude",
|
||||
"frame too large",
|
||||
"bad version",
|
||||
"length mismatch",
|
||||
|
|
@ -69,6 +75,7 @@ pub trait Deliverer: Send + Sync {
|
|||
pinned_id: &'a [u8],
|
||||
prekey: &'a [u8],
|
||||
plaintext: &'a [u8],
|
||||
remote_kem: Option<&'a [u8]>,
|
||||
) -> BoxFut<'a, Result<(), String>>;
|
||||
}
|
||||
|
||||
|
|
@ -92,6 +99,7 @@ impl Deliverer for ArtiDeliverer {
|
|||
pinned_id: &'a [u8],
|
||||
prekey: &'a [u8],
|
||||
plaintext: &'a [u8],
|
||||
remote_kem: Option<&'a [u8]>,
|
||||
) -> BoxFut<'a, Result<(), String>> {
|
||||
Box::pin(async move {
|
||||
let mut stream = self
|
||||
|
|
@ -100,7 +108,7 @@ impl Deliverer for ArtiDeliverer {
|
|||
.await
|
||||
.map_err(|e| format!("connect {onion}:{HS_PORT}: {e}"))?;
|
||||
let mut sess =
|
||||
session::handshake_initiator(&mut stream, &self.keys, pinned_id, prekey)
|
||||
session::handshake_initiator(&mut stream, &self.keys, pinned_id, prekey, remote_kem)
|
||||
.await
|
||||
.map_err(|e| e.into_message())?;
|
||||
let ct = sess.encrypt(plaintext).map_err(|e| e.into_message())?;
|
||||
|
|
@ -172,9 +180,12 @@ impl Outbox {
|
|||
plaintext: &[u8],
|
||||
payload: Option<&[u8]>,
|
||||
) -> Result<OutboxStatus, String> {
|
||||
let (onion, prekey) = self.target(friend_pk)?;
|
||||
let (onion, prekey, kem) = self.target(friend_pk)?;
|
||||
let wire = payload.unwrap_or(plaintext);
|
||||
match self.deliverer.deliver(&onion, friend_pk, &prekey, wire).await {
|
||||
match self
|
||||
.deliverer
|
||||
.deliver(&onion, friend_pk, &prekey, wire, kem.as_deref())
|
||||
.await {
|
||||
Ok(()) => {
|
||||
self.store()?.append_message(friend_pk, "out", plaintext)?;
|
||||
Ok(OutboxStatus::Sent)
|
||||
|
|
@ -266,7 +277,7 @@ impl Outbox {
|
|||
let mut out = Vec::with_capacity(rows.len());
|
||||
for entry in rows {
|
||||
self.store()?.mark_outbox_sending(entry.id, now)?;
|
||||
let (onion, prekey) = match self.target(&entry.friend_pk) {
|
||||
let (onion, prekey, kem) = match self.target(&entry.friend_pk) {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
self.store()?.mark_outbox_failed(entry.id, now, &e)?;
|
||||
|
|
@ -282,6 +293,7 @@ impl Outbox {
|
|||
&prekey,
|
||||
// Chat stores its frame here; everything else sends its body.
|
||||
entry.payload.as_deref().unwrap_or(&entry.body),
|
||||
kem.as_deref(),
|
||||
)
|
||||
.await;
|
||||
let status = match result {
|
||||
|
|
@ -311,9 +323,10 @@ impl Outbox {
|
|||
Ok(out)
|
||||
}
|
||||
|
||||
/// Friend's current locator + Noise static. Missing prekey means the invite
|
||||
/// was never completed — retrying cannot fix that, so it is fatal.
|
||||
fn target(&self, friend_pk: &[u8]) -> Result<(String, Vec<u8>), String> {
|
||||
/// Friend's current locator, Noise static, and KEM encapsulation key.
|
||||
/// Missing prekey means the invite was never completed — retrying cannot
|
||||
/// fix that, so it is fatal. `None` kem is a legacy v1 friend.
|
||||
fn target(&self, friend_pk: &[u8]) -> Result<Target, String> {
|
||||
let store = self.store()?;
|
||||
let f = store
|
||||
.get_friend(friend_pk)
|
||||
|
|
@ -322,7 +335,7 @@ impl Outbox {
|
|||
if f.prekey.len() != 32 {
|
||||
return Err("friend missing prekey".into());
|
||||
}
|
||||
Ok((f.onion, f.prekey))
|
||||
Ok((f.onion, f.prekey, f.kem_pk))
|
||||
}
|
||||
|
||||
fn store(&self) -> Result<MutexGuard<'_, Store>, String> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue