feat(client): TLS 1.3 control connection with SPKI pinning and LNEx v3

Replace the custom X25519/HKDF/ChaCha20 TCP layer with rustls (TLS 1.3 only,
ALPN vnox-lnex/3, no plaintext or fallback). Add a trust store (pin, trust on
first use, public CA), block changed fingerprints and identities, bind the
Ed25519 auth signature to the TLS exporter, add RU/EN trust dialog and
update the interop test and e2e voice tool.
This commit is contained in:
Loki 2026-10-24 22:05:19 +02:00
parent 5f594046a6
commit 29883a3187
31 changed files with 2085 additions and 567 deletions

View file

@ -1,4 +1,5 @@
//! Real gateway fixture. Run with VNOX_GATEWAY_BIN=/path/to/vnox-gateway cargo test --test gateway_interop -- --ignored.
//! Real gateway fixture over TLS 1.3 (LNEx v3).
//! Run with VNOX_GATEWAY_BIN=/path/to/vnox-gateway cargo test --test gateway_interop -- --ignored.
use std::{
path::PathBuf,
process::{Child, Command, Stdio},
@ -6,7 +7,7 @@ use std::{
};
use vnox_client::{
identity,
net::{self, NetCommand, NetEvent, NetHandle},
net::{self, NetCommand, NetEvent, NetHandle, TrustProblem, TrustStore},
};
struct Gateway {
@ -27,15 +28,15 @@ async fn event(handle: &NetHandle, predicate: impl Fn(&NetEvent) -> bool) -> Net
tokio::time::timeout(Duration::from_secs(8), async {
loop {
if let Some(event) = handle.try_recv() {
if predicate(&event) {
return event;
}
if let NetEvent::Disconnected { ref reason, .. } = event {
panic!("unexpected disconnect: {reason}");
}
if let NetEvent::Error { code, ref message } = event {
panic!("gateway error {code}: {message}");
}
if predicate(&event) {
return event;
}
if let NetEvent::WebhookError(ref result) = event {
panic!(
"unexpected webhook error at stage {stage}, request {}: {} ({})",
@ -49,6 +50,43 @@ async fn event(handle: &NetHandle, predicate: impl Fn(&NetEvent) -> bool) -> Net
.await
.unwrap_or_else(|_| panic!("gateway event timeout at stage {stage}"))
}
/// First connection: the client must stop at the untrusted certificate, show the same
/// fingerprint the gateway published, and connect only after the fingerprint is pinned.
async fn connect_with_first_trust(handle: &NetHandle, address: &str, published: &str) {
handle
.send(NetCommand::Connect {
address: address.into(),
auto_reconnect: false,
})
.await;
let prompt = event(handle, |e| matches!(e, NetEvent::TrustProblem(_))).await;
let NetEvent::TrustProblem(TrustProblem::Untrusted { fingerprint, .. }) = prompt else {
panic!("expected the first-use trust prompt, got {prompt:?}");
};
assert_eq!(
fingerprint, published,
"the prompt must show the fingerprint published by the gateway"
);
event(handle, |e| {
matches!(
e,
NetEvent::Disconnected {
will_retry: false,
..
}
)
})
.await;
let key = net::trust::parse_address(address).unwrap().key;
handle.trust().pin(&key, &fingerprint).unwrap();
handle
.send(NetCommand::Connect {
address: address.into(),
auto_reconnect: false,
})
.await;
}
fn free_port() -> u16 {
std::net::TcpListener::bind("127.0.0.1:0")
.unwrap()
@ -59,7 +97,7 @@ fn free_port() -> u16 {
#[tokio::test]
#[ignore = "requires a freshly built current VNOX gateway binary"]
async fn native_network_connects_signed_v2_and_exchanges_protobuf_chat() {
async fn native_network_connects_signed_v3_over_tls_and_exchanges_protobuf_chat() {
let binary = std::env::var_os("VNOX_GATEWAY_BIN")
.expect("set VNOX_GATEWAY_BIN to the current server binary");
let directory = std::env::temp_dir().join(format!("vnox-interop-{}", uuid::Uuid::new_v4()));
@ -95,6 +133,7 @@ mode = "private"
.stderr(Stdio::inherit())
.spawn()
.unwrap();
let data_dir = directory.clone();
let _gateway = Gateway { child, directory };
let address = format!("127.0.0.1:{port}");
tokio::time::timeout(Duration::from_secs(8), async {
@ -110,13 +149,44 @@ mode = "private"
// In-memory identity only; never touch a real profile or encrypted vault.
let alice_identity = identity::generate("interop-alice");
let alice_user_id = alice_identity.pubkey_hex.clone();
let alice = net::spawn(alice_identity);
alice
// Trust is kept in memory: never touch the real ~/.config/vnox/known_servers.json.
let alice = net::spawn_with_trust(alice_identity, TrustStore::in_memory());
let published = std::fs::read_to_string(data_dir.join("tls").join("fingerprint.txt"))
.unwrap()
.trim()
.to_string();
// A client that pinned another fingerprint is blocked before sending anything.
let impostor =
net::spawn_with_trust(identity::generate("interop-pin"), TrustStore::in_memory());
impostor
.trust()
.pin(
&net::trust::parse_address(&address).unwrap().key,
&"ab".repeat(32),
)
.unwrap();
impostor
.send(NetCommand::Connect {
address,
auto_reconnect: false,
address: address.clone(),
auto_reconnect: true,
})
.await;
let blocked = event(&impostor, |e| matches!(e, NetEvent::TrustProblem(_))).await;
assert!(matches!(
blocked,
NetEvent::TrustProblem(TrustProblem::FingerprintChanged { ref actual, .. }) if actual == &published
));
event(&impostor, |e| {
matches!(
e,
NetEvent::Disconnected {
will_retry: false,
..
}
)
})
.await;
connect_with_first_trust(&alice, &address, &published).await;
event(
&alice,
|e| matches!(e,NetEvent::Connected {node_name,..} if node_name=="interop-node"),
@ -260,7 +330,16 @@ mode = "private"
event(&alice,|e|matches!(e,NetEvent::WebhookResult(result) if result.request_id=="revoke-fixture" && result.secret.is_empty() && result.hook.as_ref().is_some_and(|hook|hook.revoked))).await;
let guest_identity = identity::generate("webhook-unprivileged");
let guest_user_id = guest_identity.pubkey_hex.clone();
let guest = net::spawn(guest_identity);
let guest = net::spawn_with_trust(guest_identity, TrustStore::in_memory());
guest
.trust()
.pin(
&net::trust::parse_address(&format!("127.0.0.1:{port}"))
.unwrap()
.key,
&published,
)
.unwrap();
guest
.send(NetCommand::Connect {
address: format!("127.0.0.1:{port}"),
@ -301,6 +380,22 @@ mode = "private"
.await;
alice.send(NetCommand::FriendList).await;
event(&alice,|e|matches!(e,NetEvent::FriendList {friends} if friends.iter().any(|friend|friend.user_id==guest_user_id))).await;
// The server identity was stored after the first authenticated handshake.
let identity_file: serde_json::Value =
serde_json::from_slice(&std::fs::read(data_dir.join("server_identity.json")).unwrap())
.unwrap();
let record = alice
.trust()
.get(
&net::trust::parse_address(&format!("127.0.0.1:{port}"))
.unwrap()
.key,
)
.unwrap();
assert_eq!(
record.identity.as_deref(),
identity_file["pubkey_hex"].as_str()
);
guest.send(NetCommand::Disconnect).await;
alice.send(NetCommand::Disconnect).await;
}