feat(gateway): TLS 1.3 only control plane and LNEx v3 channel-bound handshake

Replace the X25519/HKDF/ChaCha20 TCP layer with rustls TLS 1.3 (ALPN
vnox-lnex/3). Auto-generate a self-signed certificate keyed by the server
identity or load an operator certificate, publish the SPKI fingerprint,
bind HELLO and AUTH signatures to the TLS exporter, reject plaintext, TLS 1.2
and LNEx v2 peers with an explicit error. BREAKING: protocol v3.

Claude-Session: https://claude.ai/code/session_01GDjxLvBcnJqniFQGUGb1V4
This commit is contained in:
Loki 2026-10-24 22:05:30 +02:00
parent a5b9c324f7
commit 0d2af0ddd6
Signed by: boba
GPG key ID: 253067914055423B
45 changed files with 1322 additions and 806 deletions

View file

@ -11,7 +11,7 @@ use crate::{
},
proto::{
self, E2eeDmKeyExchangeAckPayload, E2eeDmKeyExchangePayload, ErrorCode, PacketId,
SessionCrypto, encode_packet, to_payload,
encode_packet, to_payload,
},
};
@ -20,7 +20,6 @@ pub async fn handle_e2ee_key_exchange(
seq: &mut u32,
session_id: &str,
payload: &[u8],
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let msg = E2eeDmKeyExchangePayload::decode(payload)?;
@ -38,7 +37,7 @@ pub async fn handle_e2ee_key_exchange(
.ok_or_else(|| anyhow::anyhow!("user not in DM"))?;
if state.storage.is_blocked(&other_id, &my_id).await? {
io::send_encrypted(
io::send_frame(
stream,
PacketId::Error,
seq,
@ -46,7 +45,6 @@ pub async fn handle_e2ee_key_exchange(
code: ErrorCode::Blocked as u32,
message: "blocked".into(),
}),
crypto,
)
.await?;
return Ok(());
@ -78,12 +76,11 @@ pub async fn handle_e2ee_key_exchange(
warn!("e2ee key exchange recipient offline: {}", &other_id[..8]);
}
io::send_encrypted(
io::send_frame(
stream,
PacketId::E2eeDmKeyExchange,
seq,
&to_payload(&E2eeDmKeyExchangeAckPayload { dm_id: msg.dm_id }),
crypto,
)
.await?;
Ok(())
@ -94,7 +91,6 @@ pub async fn handle_e2ee_key_exchange_ack(
_seq: &mut u32,
session_id: &str,
payload: &[u8],
_crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let msg = E2eeDmKeyExchangeAckPayload::decode(payload)?;

View file

@ -10,8 +10,8 @@ use crate::{
state::{BroadcastMsg, State},
},
proto::{
self, E2eeDmHistoryPayload, E2eeDmMessagePayload, ErrorCode, PacketId, SessionCrypto,
encode_packet, to_payload,
self, E2eeDmHistoryPayload, E2eeDmMessagePayload, ErrorCode, PacketId, encode_packet,
to_payload,
},
};
@ -20,7 +20,6 @@ pub async fn handle_e2ee_dm_message(
seq: &mut u32,
session_id: &str,
payload: &[u8],
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let msg = E2eeDmMessagePayload::decode(payload)?;
@ -34,7 +33,7 @@ pub async fn handle_e2ee_dm_message(
if !state.rate_limiter.try_consume(session_id) {
state.metrics.inc(&state.metrics.rate_limited_events);
warn!("rate-limited e2ee dm session {session_id}");
io::send_encrypted(
io::send_frame(
stream,
PacketId::Error,
seq,
@ -42,7 +41,6 @@ pub async fn handle_e2ee_dm_message(
code: ErrorCode::RateLimited as u32,
message: "you are sending messages too quickly".into(),
}),
crypto,
)
.await?;
return Ok(());
@ -55,7 +53,7 @@ pub async fn handle_e2ee_dm_message(
.ok_or_else(|| anyhow::anyhow!("user not in DM"))?;
if state.storage.is_blocked(&other_id, &my_id).await? {
io::send_encrypted(
io::send_frame(
stream,
PacketId::Error,
seq,
@ -63,7 +61,6 @@ pub async fn handle_e2ee_dm_message(
code: proto::ErrorCode::Blocked as u32,
message: "blocked".into(),
}),
crypto,
)
.await?;
return Ok(());
@ -103,14 +100,7 @@ pub async fn handle_e2ee_dm_message(
warn!("e2ee dm recipient offline: {}", &other_id[..8]);
}
io::send_encrypted(
stream,
PacketId::E2eeDmMessage,
seq,
&to_payload(&saved),
crypto,
)
.await?;
io::send_frame(stream, PacketId::E2eeDmMessage, seq, &to_payload(&saved)).await?;
Ok(())
}
@ -119,7 +109,6 @@ pub async fn handle_e2ee_dm_history(
seq: &mut u32,
session_id: &str,
payload: &[u8],
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let req = E2eeDmHistoryPayload::decode(payload)?;
@ -147,13 +136,6 @@ pub async fn handle_e2ee_dm_history(
messages,
limit: None,
};
io::send_encrypted(
stream,
PacketId::E2eeDmHistory,
seq,
&to_payload(&resp),
crypto,
)
.await?;
io::send_frame(stream, PacketId::E2eeDmHistory, seq, &to_payload(&resp)).await?;
Ok(())
}