From 5249a271c50d5b82914a8f5f699bd58029fed036 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 18 Mar 2026 10:59:23 +0800 Subject: [PATCH] punchnet 1.0.1 is ok, no permission is checked --- Cargo.lock | 66 ++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 +- Makefile | 2 +- src/bin/punchnet/api/mod.rs | 4 +-- src/bin/punchnet/main.rs | 9 ++--- src/network/tun_linux.rs | 4 +-- src/network/tun_win.rs | 12 +++---- src/tcp/quic.rs | 8 +++-- 8 files changed, 86 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 320d7ce..2fca88d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,16 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] + [[package]] name = "aes" version = "0.8.4" @@ -347,6 +357,30 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chacha20" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "chacha20poly1305" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" +dependencies = [ + "aead", + "chacha20", + "cipher", + "poly1305", + "zeroize", +] + [[package]] name = "chrono" version = "0.4.43" @@ -368,6 +402,7 @@ checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ "crypto-common", "inout", + "zeroize", ] [[package]] @@ -555,6 +590,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" dependencies = [ "generic-array", + "rand_core 0.6.4", "typenum", ] @@ -1757,6 +1793,12 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + [[package]] name = "openssl-probe" version = "0.2.1" @@ -1856,6 +1898,17 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "poly1305" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" +dependencies = [ + "cpufeatures", + "opaque-debug", + "universal-hash", +] + [[package]] name = "potential_utf" version = "0.1.4" @@ -2009,10 +2062,11 @@ dependencies = [ [[package]] name = "punchnet" -version = "1.0.0" +version = "1.0.1" dependencies = [ "bytes", "cargo-deb", + "chacha20poly1305", "clap 4.5.60", "crc", "crc32fast", @@ -3443,6 +3497,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] + [[package]] name = "untrusted" version = "0.9.0" diff --git a/Cargo.toml b/Cargo.toml index 82ad971..2890bd9 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "punchnet" -version = "1.0.0" +version = "1.0.1" edition = "2021" [dependencies] @@ -35,6 +35,7 @@ rustls-pemfile = "2.2.0" clap = { version = "4.5.60", features = ["derive", "env"] } rpassword = "7.4.0" serde_json = "1.0.149" +chacha20poly1305 = "0.10.1" # rolling-file = { path = "../rolling-file" } [target.'cfg(unix)'.dependencies] diff --git a/Makefile b/Makefile index e144a0a..dad78a4 100755 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ win: pb: cargo run --bin build_pb - mv src/pb/_.rs src/pb/message.rs + # mv src/pb/_.rs src/pb/message.rs libtun-so-clang: cd src/network && clang -fPIC -shared -o libtuntap.so tuntap.c && cd - diff --git a/src/bin/punchnet/api/mod.rs b/src/bin/punchnet/api/mod.rs index 3a60f55..efba5f3 100644 --- a/src/bin/punchnet/api/mod.rs +++ b/src/bin/punchnet/api/mod.rs @@ -68,9 +68,9 @@ where T: Serialize, return Err(SDLanError::IOError("failed to do request".to_owned())); }; - println!("status: {}", response.status()); + // println!("status: {}", response.status()); let text = response.text().await.unwrap(); - println!("text = {}", text); + // println!("text = {}", text); let data = serde_json::from_str(&text).unwrap(); diff --git a/src/bin/punchnet/main.rs b/src/bin/punchnet/main.rs index b20aff8..ccf73e7 100755 --- a/src/bin/punchnet/main.rs +++ b/src/bin/punchnet/main.rs @@ -118,8 +118,6 @@ async fn daemonize_me( ) { let _guard = log::init_log(&format!("{}/.output", get_base_dir())); - println!("identity_id = {}", connect_info.identity_id); - let self_host_name = connect_info.hostname; let (tx, rx) = std::sync::mpsc::channel(); @@ -138,8 +136,6 @@ async fn daemonize_me( return; } - println!("server is {}", server); - // mod_hostname::get_hostname(); /* let hostname = if cmd.hostname.len() == 0 { @@ -249,8 +245,10 @@ async fn daemonize_me( match tokio::signal::ctrl_c().await { Ok(()) => { - let _ = restore_dns(); + edge.quic_endpoint.close(0u32.into(), "bye".as_bytes()); + println!("quic is quitting"); delete_pid_file(); + let _ = restore_dns(); } Err(err) => { eprintln!("failed to listen for shutdown signal: {}", err); @@ -350,7 +348,6 @@ fn main() { let out = OpenOptions::new() .create(true) .truncate(true) - .append(true) .write(true) .open("/tmp/punchnet.out").unwrap(); let err = OpenOptions::new() diff --git a/src/network/tun_linux.rs b/src/network/tun_linux.rs index 8634e92..83cf0d9 100755 --- a/src/network/tun_linux.rs +++ b/src/network/tun_linux.rs @@ -307,10 +307,10 @@ impl TunTapPacketHandler for Iface { send_packet_to_net(edge, target, &msg, size as u64).await; } else { - println!("erro 2"); + error!("erro 2"); } } else { - println!("erro 1"); + error!("erro 1"); } Ok(()) diff --git a/src/network/tun_win.rs b/src/network/tun_win.rs index 8db6a3a..49d6bf1 100755 --- a/src/network/tun_win.rs +++ b/src/network/tun_win.rs @@ -122,11 +122,11 @@ impl Iface { } let gw = ip_to_string(&default_gw); - println!("gw = {}", gw); + debug!("gw = {}", gw); if let Err(e) = set_dns(&self.name, network_domain, &gw, self.if_idx) { - println!("failed to set dns: {:?}", e); + error!("failed to set dns: {:?}", e); } else { - println!("set dns ok"); + error!("set dns ok"); } } @@ -420,7 +420,7 @@ fn create_wintun(path: &str, name: &str) -> Iface { .expect("failed to create tun adapter"), }; let idx = adapter.get_adapter_index().expect("failed to get adapter index"); - println!("idx = {}", idx); + // println!("idx = {}", idx); let session = Arc::new(adapter.start_session(wintun::MAX_RING_CAPACITY).unwrap()); Iface { if_idx: idx, @@ -451,7 +451,7 @@ pub fn set_dns(name: &str, _network_domain: &str, gw: &str, ifidx: u32) -> std:: .creation_flags(0x08000000) .output()?; - println!("res1: {}", res.status.success()); + //println!("res1: {}", res.status.success()); println!("route set ok"); let res = Command::new("netsh") @@ -464,7 +464,7 @@ pub fn set_dns(name: &str, _network_domain: &str, gw: &str, ifidx: u32) -> std:: .arg("validate=no") .creation_flags(0x08000000) .output()?; - println!("res2: {}", res.status.success()); + // println!("res2: {}", res.status.success()); println!("netsh set ok"); diff --git a/src/tcp/quic.rs b/src/tcp/quic.rs index 194658f..be50d1d 100644 --- a/src/tcp/quic.rs +++ b/src/tcp/quic.rs @@ -4,7 +4,7 @@ use futures_util::pin_mut; use prost::Message; use quinn::SendStream; use sdlan_sn_rs::{config::AF_INET, peer::{SdlanSock, V6Info}, utils::{Result, SDLanError, get_current_timestamp, ip_to_string, rsa_decrypt}}; -use tokio::{sync::mpsc::{Receiver, Sender, channel}}; +use tokio::{sync::mpsc::{Receiver, Sender, channel}, time::sleep}; use tokio_util::sync::CancellationToken; use tracing::{debug, error, warn}; @@ -534,7 +534,7 @@ impl ReadWriteActor { Ok(conn) => conn, Err(e) => { error!("failed to connect: {}", e); - println!("failed to connect: {}", e); + // println!("failed to connect: {}", e); self.connected.store(false, Ordering::Relaxed); if keep_reconnect { @@ -548,7 +548,7 @@ impl ReadWriteActor { let conn = match conn.await { Err(e) => { - println!("failed to connect await: {}", e); + // println!("failed to connect await: {}", e); error!("failed to connect await: {}", e); self.connected.store(false, Ordering::Relaxed); if keep_reconnect { @@ -574,6 +574,8 @@ impl ReadWriteActor { self.connected.store(true, Ordering::Relaxed); debug!("connected"); + + sleep(Duration::from_millis(200)).await; on_connected_callback(local_ip, &mut send, start_pkt_id.take()).await; if let Some(ref connecting_chan) = self.connecting_chan {