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.
91 lines
3.0 KiB
Rust
91 lines
3.0 KiB
Rust
//! The SIP022 record construction used by Shoes (MIT).
|
|
use super::{TAG, invalid};
|
|
use ring::aead::{self, Aad, LessSafeKey, Nonce, UnboundKey};
|
|
use std::io;
|
|
use tokio::io::{AsyncRead, AsyncReadExt};
|
|
use zeroize::{Zeroize, Zeroizing};
|
|
|
|
pub(super) struct Records {
|
|
key: LessSafeKey,
|
|
counter: u128,
|
|
}
|
|
impl Records {
|
|
pub(super) fn new(key: &[u8], salt: &[u8]) -> io::Result<Self> {
|
|
let algorithm = match (key.len(), salt.len()) {
|
|
(16, 16) => &aead::AES_128_GCM,
|
|
(32, 32) => &aead::AES_256_GCM,
|
|
_ => return Err(invalid()),
|
|
};
|
|
let mut hasher = blake3::Hasher::new_derive_key("shadowsocks 2022 session subkey");
|
|
hasher.update(key).update(salt);
|
|
let mut subkey = Zeroizing::new([0; 32]);
|
|
hasher.finalize_xof().fill(&mut subkey[..key.len()]);
|
|
hasher.zeroize();
|
|
let key = UnboundKey::new(algorithm, &subkey[..key.len()]).map_err(|_| invalid())?;
|
|
Ok(Self {
|
|
key: LessSafeKey::new(key),
|
|
counter: 0,
|
|
})
|
|
}
|
|
fn nonce(&mut self) -> io::Result<Nonce> {
|
|
if self.counter >= 1 << 96 {
|
|
return Err(invalid());
|
|
}
|
|
let mut nonce = [0; 12];
|
|
nonce.copy_from_slice(&self.counter.to_le_bytes()[..12]);
|
|
self.counter += 1;
|
|
Ok(Nonce::assume_unique_for_key(nonce))
|
|
}
|
|
pub(super) fn seal(&mut self, plaintext: &[u8]) -> io::Result<Vec<u8>> {
|
|
let nonce = self.nonce()?;
|
|
let mut buf = plaintext.to_vec();
|
|
self.key
|
|
.seal_in_place_append_tag(nonce, Aad::empty(), &mut buf)
|
|
.map_err(|_| invalid())?;
|
|
Ok(buf)
|
|
}
|
|
pub(super) fn open(&mut self, mut buf: Vec<u8>) -> io::Result<Vec<u8>> {
|
|
let nonce = self.nonce()?;
|
|
let size = self
|
|
.key
|
|
.open_in_place(nonce, Aad::empty(), &mut buf)
|
|
.map_err(|_| invalid())?
|
|
.len();
|
|
buf.truncate(size);
|
|
Ok(buf)
|
|
}
|
|
pub(super) async fn read(
|
|
&mut self,
|
|
r: &mut (impl AsyncRead + Unpin),
|
|
len: usize,
|
|
) -> io::Result<Vec<u8>> {
|
|
let mut buf = vec![0; len + TAG];
|
|
r.read_exact(&mut buf).await?;
|
|
self.open(buf)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
#![allow(clippy::unwrap_used)]
|
|
use super::*;
|
|
#[test]
|
|
fn both_methods_authenticate_each_record_and_enforce_nonce_order() {
|
|
for n in [16, 32] {
|
|
let key = &[0x33; 32][..n];
|
|
let salt = &[0x44; 32][..n];
|
|
let mut tx = Records::new(key, salt).unwrap();
|
|
let mut rx = Records::new(key, salt).unwrap();
|
|
let a = tx.seal(b"ab").unwrap();
|
|
let b = tx.seal(b"ab").unwrap();
|
|
assert_ne!(a, b);
|
|
assert_eq!(rx.open(a.clone()).unwrap(), b"ab");
|
|
assert_eq!(rx.open(b).unwrap(), b"ab");
|
|
assert!(rx.open(a.clone()).is_err());
|
|
let mut corrupt = a;
|
|
corrupt[1] ^= 0x40;
|
|
assert!(Records::new(key, salt).unwrap().open(corrupt).is_err());
|
|
}
|
|
}
|
|
}
|