Let the elected opener invite its authenticated peer to dial back after a forward TCP attempt fails. Limit the reverse attempt, correlate failure replies with the active generation and cancel it on membership or policy changes. Only mutually enabled carriers with link-reverse v1 participate. Keep native TCP/TLS wire v2 and use the advertised TCP port with direct control-path or configured bootstrap IPs. Race candidate connects, bound handshakes, verify the Ed25519 SPKI and wake every link-close waiter. Add two separately versioned embedded Shoes profiles. VLESS runs over XHTTP stream-one with HTTP/2 and pinned TLS 1.3. Shadowsocks 2022 selects AES-128-GCM or AES-256-GCM per connection. Allocate a new credential and request path or salt for each attempt and admit it once through private mesh control. Both profiles terminate a local mesh service and retain the existing inner WireGuard tunnel. Attribute the adapted Shoes v0.3.8 wire code and keep its MIT license. Preferred ports are 9443 and 9444. Expose WireGuard, iroh, Native and Shoes as collapsible groups in the desktop and Android transport editor. A partial group's checkbox enables all its children. Keep the global protocol priority, save the concrete list per network and preserve explicitly saved choices including none. New networks enable all six carriers. Keep the existing CLI protocol names and unqualified port behavior. Advance local IPC to v30 for the catalog labels and groups. The existing network identity and encrypted data formats for the four original protocols stay compatible. Checked formatting, strict workspace Clippy and the full macOS workspace test suite (684 passed, 8 opted out by default). The initial sandbox denied loopback sockets. A full run also exposed an overly broad control dispatch check in the existing standalone AWG test; restoring the transport contract fixed it. Ran the opt-in upstream Shoes 0.3.8 reference test on loopback for HTTP/2 and both Shadowsocks methods. Checked Android arm64 and Windows GNU targets by cross-compilation. No live DPI or physical-device network measurements were performed.
127 lines
5.1 KiB
Rust
127 lines
5.1 KiB
Rust
//! Optional interoperability against an independently built upstream Shoes server.
|
|
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
use std::{
|
|
fs,
|
|
process::{Child, Command, Stdio},
|
|
time::Duration,
|
|
};
|
|
use tokio::{
|
|
io::{AsyncReadExt, AsyncWriteExt},
|
|
net::{TcpListener, TcpStream},
|
|
};
|
|
use tsunagi::identity::DeviceIdentity;
|
|
use tsunagi_shoes::{Profile, ShoesWire};
|
|
use tsunagi_tcp_tls::cert::generate_self_signed_cert;
|
|
|
|
struct Reference(Child);
|
|
impl Drop for Reference {
|
|
fn drop(&mut self) {
|
|
let _ = self.0.kill();
|
|
let _ = self.0.wait();
|
|
}
|
|
}
|
|
fn pem(label: &str, bytes: &[u8]) -> String {
|
|
format!(
|
|
"-----BEGIN {label}-----\n{}\n-----END {label}-----\n",
|
|
data_encoding::BASE64.encode(bytes)
|
|
)
|
|
}
|
|
#[tokio::test]
|
|
#[ignore = "set TSUNAGI_SHOES_BIN to the upstream Shoes executable (v0.3.8)"]
|
|
async fn upstream_server_accepts_stream_one_and_both_ss2022_methods() {
|
|
let bin = std::env::var_os("TSUNAGI_SHOES_BIN").expect("upstream Shoes path");
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let endpoint = DeviceIdentity::generate();
|
|
let (cert, key) = generate_self_signed_cert(&endpoint.secret_bytes(), "localhost").unwrap();
|
|
fs::write(
|
|
dir.path().join("cert.pem"),
|
|
pem("CERTIFICATE", cert.as_ref()),
|
|
)
|
|
.unwrap();
|
|
fs::write(
|
|
dir.path().join("key.pem"),
|
|
pem("PRIVATE KEY", key.secret_der()),
|
|
)
|
|
.unwrap();
|
|
for (is_vless, use_256) in [(true, false), (false, false), (false, true)] {
|
|
let profile = Profile {
|
|
tag: [0x34; 32],
|
|
secret: [0x53; 32],
|
|
variant: use_256,
|
|
};
|
|
let (wire, protocol): (Box<dyn ShoesWire>, String) = if is_vless {
|
|
let path = hex::encode(profile.tag);
|
|
(
|
|
Box::new(tsunagi_vless_xhttp::VlessXhttp::new(&endpoint).unwrap()),
|
|
format!(
|
|
"type: tls\n default_target:\n cert: cert.pem\n key: key.pem\n alpn_protocols: [h2]\n protocol:\n type: xhttp\n path: /{path}/\n mode: stream-one\n protocol:\n type: vless\n user_id: 53535353-5353-4353-9353-535353535353"
|
|
),
|
|
)
|
|
} else {
|
|
let size = if use_256 { 32 } else { 16 };
|
|
let key = data_encoding::BASE64.encode(&profile.secret[..size]);
|
|
(
|
|
Box::new(tsunagi_ss2022::Shadowsocks2022),
|
|
format!(
|
|
"type: shadowsocks\n cipher: 2022-blake3-aes-{}-gcm\n password: '{key}'",
|
|
size * 8
|
|
),
|
|
)
|
|
};
|
|
let backend = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
|
let backend_address = backend.local_addr().unwrap();
|
|
let reservation = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
|
let address = reservation.local_addr().unwrap();
|
|
fs::write(dir.path().join("reference.yaml"), format!("- address: {address}\n protocol:\n {protocol}\n rules:\n - mask: 127.0.0.1:1\n action: allow\n override_address: {backend_address}\n client_chain: direct\n")).unwrap();
|
|
drop(reservation);
|
|
let mut server = Reference(
|
|
Command::new(&bin)
|
|
.current_dir(dir.path())
|
|
.args(["-t", "1", "--no-reload", "reference.yaml"])
|
|
.stdout(Stdio::null())
|
|
.spawn()
|
|
.unwrap(),
|
|
);
|
|
tokio::time::timeout(Duration::from_secs(15), async {
|
|
let tcp = loop {
|
|
assert!(
|
|
server.0.try_wait().unwrap().is_none(),
|
|
"reference server exited at startup"
|
|
);
|
|
if let Ok(tcp) = TcpStream::connect(address).await {
|
|
break tcp;
|
|
}
|
|
tokio::time::sleep(Duration::from_millis(15)).await;
|
|
};
|
|
let payload = vec![0x8c; 96 * 1024];
|
|
let exchange = async {
|
|
let mut stream = wire
|
|
.connect(tcp, endpoint.endpoint_id(), &profile)
|
|
.await
|
|
.unwrap();
|
|
if !is_vless {
|
|
let mut first = [0; 4];
|
|
stream.read_exact(&mut first).await.unwrap();
|
|
assert_eq!(&first, b"mesh");
|
|
}
|
|
stream.write_all(&payload).await.unwrap();
|
|
let mut returned = vec![0; payload.len()];
|
|
stream.read_exact(&mut returned).await.unwrap();
|
|
assert_eq!(payload, returned);
|
|
};
|
|
let service = async {
|
|
let (mut socket, _) = backend.accept().await.unwrap();
|
|
if !is_vless {
|
|
socket.write_all(b"\0mesh").await.unwrap();
|
|
}
|
|
let mut bytes = vec![0; payload.len()];
|
|
socket.read_exact(&mut bytes).await.unwrap();
|
|
socket.write_all(&bytes).await.unwrap();
|
|
};
|
|
tokio::join!(service, exchange);
|
|
})
|
|
.await
|
|
.expect("reference wire exchange timed out");
|
|
}
|
|
}
|