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.
This commit is contained in:
Loki 2026-10-24 22:05:30 +02:00
parent 41cc0fe632
commit ff051b7480
45 changed files with 1322 additions and 806 deletions

View file

@ -5,7 +5,7 @@ use tokio::io::{AsyncRead, AsyncWrite};
use crate::{
domain::session,
net::io,
proto::{FriendDeclinePayload, PacketId, SessionCrypto, SimpleResponsePayload, to_payload},
proto::{FriendDeclinePayload, PacketId, SimpleResponsePayload, to_payload},
};
pub async fn handle_friend_decline(
@ -13,7 +13,6 @@ pub async fn handle_friend_decline(
seq: &mut u32,
session_id: &str,
payload: &[u8],
crypto: &SessionCrypto,
state: &crate::net::state::State,
) -> Result<()> {
let req = FriendDeclinePayload::decode(payload)?;
@ -26,7 +25,7 @@ pub async fn handle_friend_decline(
.decline_friend_request(&req.from_user_id, &sess.user_id)
.await?;
io::send_encrypted(
io::send_frame(
stream,
PacketId::FriendDecline,
seq,
@ -35,7 +34,6 @@ pub async fn handle_friend_decline(
user_id: None,
role_id: None,
}),
crypto,
)
.await?;
Ok(())

View file

@ -4,14 +4,13 @@ use tokio::io::{AsyncRead, AsyncWrite};
use crate::{
domain::session,
net::{io, state::State},
proto::{FriendInfo, FriendListPayload, PacketId, SessionCrypto, to_payload},
proto::{FriendInfo, FriendListPayload, PacketId, to_payload},
};
pub async fn handle_friend_list(
stream: &mut (impl AsyncRead + AsyncWrite + Unpin),
seq: &mut u32,
session_id: &str,
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let sess = session::get(&state.sessions, session_id)
@ -35,12 +34,11 @@ pub async fn handle_friend_list(
});
}
io::send_encrypted(
io::send_frame(
stream,
PacketId::FriendList,
seq,
&to_payload(&FriendListPayload { friends }),
crypto,
)
.await?;
Ok(())

View file

@ -6,8 +6,8 @@ use crate::{
domain::session,
net::{io, state::State},
proto::{
BlockListPayload, BlockUserPayload, FriendRemovePayload, PacketId, SessionCrypto,
SimpleResponsePayload, UnblockUserPayload, to_payload,
BlockListPayload, BlockUserPayload, FriendRemovePayload, PacketId, SimpleResponsePayload,
UnblockUserPayload, to_payload,
},
};
@ -16,7 +16,6 @@ pub async fn handle_friend_remove(
seq: &mut u32,
session_id: &str,
payload: &[u8],
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let req = FriendRemovePayload::decode(payload)?;
@ -29,7 +28,7 @@ pub async fn handle_friend_remove(
.remove_friend(&sess.user_id, &req.user_id)
.await?;
io::send_encrypted(
io::send_frame(
stream,
PacketId::FriendRemove,
seq,
@ -38,7 +37,6 @@ pub async fn handle_friend_remove(
user_id: None,
role_id: None,
}),
crypto,
)
.await?;
Ok(())
@ -49,7 +47,6 @@ pub async fn handle_block_user(
seq: &mut u32,
session_id: &str,
payload: &[u8],
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let req = BlockUserPayload::decode(payload)?;
@ -62,7 +59,7 @@ pub async fn handle_block_user(
.block_user(&sess.user_id, &req.user_id)
.await?;
io::send_encrypted(
io::send_frame(
stream,
PacketId::BlockUser,
seq,
@ -71,7 +68,6 @@ pub async fn handle_block_user(
user_id: None,
role_id: None,
}),
crypto,
)
.await?;
Ok(())
@ -82,7 +78,6 @@ pub async fn handle_unblock_user(
seq: &mut u32,
session_id: &str,
payload: &[u8],
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let req = UnblockUserPayload::decode(payload)?;
@ -95,7 +90,7 @@ pub async fn handle_unblock_user(
.unblock_user(&sess.user_id, &req.user_id)
.await?;
io::send_encrypted(
io::send_frame(
stream,
PacketId::UnblockUser,
seq,
@ -104,7 +99,6 @@ pub async fn handle_unblock_user(
user_id: None,
role_id: None,
}),
crypto,
)
.await?;
Ok(())
@ -114,7 +108,6 @@ pub async fn handle_block_list(
stream: &mut (impl AsyncRead + AsyncWrite + Unpin),
seq: &mut u32,
session_id: &str,
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let sess = session::get(&state.sessions, session_id)
@ -123,12 +116,11 @@ pub async fn handle_block_list(
let blocked = state.storage.list_blocks(&sess.user_id).await?;
io::send_encrypted(
io::send_frame(
stream,
PacketId::BlockList,
seq,
&to_payload(&BlockListPayload { blocked }),
crypto,
)
.await?;
Ok(())

View file

@ -8,7 +8,7 @@ use tokio::io::{AsyncRead, AsyncWrite};
use crate::{
net::io,
proto::{ErrorPayload, PacketId, SessionCrypto, to_payload},
proto::{ErrorPayload, PacketId, to_payload},
};
async fn send_err(
@ -16,9 +16,8 @@ async fn send_err(
seq: &mut u32,
code: crate::proto::ErrorCode,
msg: &str,
crypto: &SessionCrypto,
) -> Result<()> {
io::send_encrypted(
io::send_frame(
stream,
PacketId::Error,
seq,
@ -26,7 +25,6 @@ async fn send_err(
code: code as u32,
message: msg.into(),
}),
crypto,
)
.await
}

View file

@ -5,10 +5,7 @@ use tokio::io::{AsyncRead, AsyncWrite};
use crate::{
domain::session,
net::{io, state::State},
proto::{
FriendAcceptPayload, FriendEventPayload, FriendRequestPayload, PacketId, SessionCrypto,
to_payload,
},
proto::{FriendAcceptPayload, FriendEventPayload, FriendRequestPayload, PacketId, to_payload},
};
use super::send_err;
@ -18,7 +15,6 @@ pub async fn handle_friend_request(
seq: &mut u32,
session_id: &str,
payload: &[u8],
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let req = FriendRequestPayload::decode(payload)?;
@ -36,7 +32,6 @@ pub async fn handle_friend_request(
seq,
crate::proto::ErrorCode::Blocked,
"you are blocked by this user",
crypto,
)
.await?;
return Ok(());
@ -52,7 +47,6 @@ pub async fn handle_friend_request(
seq,
crate::proto::ErrorCode::InvalidPacket,
"already friends",
crypto,
)
.await?;
return Ok(());
@ -68,7 +62,6 @@ pub async fn handle_friend_request(
seq,
crate::proto::ErrorCode::InvalidPacket,
"already friends or request pending",
crypto,
)
.await?;
return Ok(());
@ -81,14 +74,13 @@ pub async fn handle_friend_request(
};
super::notify_user(state, &req.to_user_id, &ev).await;
io::send_encrypted(
io::send_frame(
stream,
PacketId::FriendRequest,
seq,
&to_payload(&FriendRequestPayload {
to_user_id: req.to_user_id.clone(),
}),
crypto,
)
.await?;
Ok(())
@ -99,7 +91,6 @@ pub async fn handle_friend_accept(
seq: &mut u32,
session_id: &str,
payload: &[u8],
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let req = FriendAcceptPayload::decode(payload)?;
@ -117,7 +108,6 @@ pub async fn handle_friend_accept(
seq,
crate::proto::ErrorCode::InvalidPacket,
"no pending request",
crypto,
)
.await?;
return Ok(());
@ -130,14 +120,13 @@ pub async fn handle_friend_accept(
};
super::notify_user(state, &req.from_user_id, &ev).await;
io::send_encrypted(
io::send_frame(
stream,
PacketId::FriendAccept,
seq,
&to_payload(&FriendAcceptPayload {
from_user_id: req.from_user_id.clone(),
}),
crypto,
)
.await?;
Ok(())