diff --git a/README.md b/README.md index af99a12..c2de0b2 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ features说明 | sm4_cbc | 支持sm4_cbc加密 | 是 | | server_encrypt | 支持服务端加密 | 是 | | ip_proxy | 内置ip代理 | 是 | +| port_mapping | 端口映射 | 是 | ### ip转发/代理 如果编译时去除了内置的ip代理(或使用--no-proxy关闭了代理),则可以使用网卡NAT转发来实现点对网, diff --git a/vnt-cli/src/command/mod.rs b/vnt-cli/src/command/mod.rs index eee969c..fc1cd1c 100644 --- a/vnt-cli/src/command/mod.rs +++ b/vnt-cli/src/command/mod.rs @@ -185,7 +185,10 @@ pub fn command_info(vnt: &Vnt) -> Info { .unwrap_or("None".to_string()); let up = vnt.up_stream(); let down = vnt.down_stream(); + #[cfg(feature = "port_mapping")] let port_mapping_list = vnt.config().port_mapping_list.clone(); + #[cfg(not(feature = "port_mapping"))] + let port_mapping_list = vec![]; let in_ips = vnt.config().in_ips.clone(); let out_ips = vnt.config().out_ips.clone(); Info { diff --git a/vnt/src/cipher/cipher.rs b/vnt/src/cipher/cipher.rs index 5030f78..3ab71ff 100644 --- a/vnt/src/cipher/cipher.rs +++ b/vnt/src/cipher/cipher.rs @@ -52,9 +52,13 @@ pub enum CipherModel { impl Display for CipherModel { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let str = match self { + #[cfg(any(feature = "aes_gcm", feature = "server_encrypt"))] CipherModel::AesGcm => "aes_gcm".to_string(), + #[cfg(feature = "aes_cbc")] CipherModel::AesCbc => "aes_cbc".to_string(), + #[cfg(feature = "aes_ecb")] CipherModel::AesEcb => "aes_ecb".to_string(), + #[cfg(feature = "sm4_cbc")] CipherModel::Sm4Cbc => "sm4_cbc".to_string(), CipherModel::None => "none".to_string(), }; diff --git a/vnt/src/core/conn.rs b/vnt/src/core/conn.rs index 00308fb..960b7d6 100644 --- a/vnt/src/core/conn.rs +++ b/vnt/src/core/conn.rs @@ -6,7 +6,7 @@ use std::time::Duration; use crossbeam_utils::atomic::AtomicCell; use parking_lot::{Mutex, RwLock}; use rand::Rng; -use rsa::signature::digest::Digest; +use sha2::Digest; #[cfg(not(target_os = "android"))] use tun::device::IFace; @@ -167,7 +167,10 @@ impl Vnt { let down_counter = U64Adder::with_capacity(config.ports.as_ref().map(|v| v.len()).unwrap_or_default() + 8); let down_count_watcher = down_counter.watch(); - let handshake = Handshake::new(rsa_cipher.clone()); + let handshake = Handshake::new( + #[cfg(feature = "server_encrypt")] + rsa_cipher.clone(), + ); let up_counter = SingleU64Adder::new(); let up_count_watcher = up_counter.watch(); let tun_helper = TunDeviceHelper::new( diff --git a/vnt/src/handle/handshaker.rs b/vnt/src/handle/handshaker.rs index 4d5b269..9ee3493 100644 --- a/vnt/src/handle/handshaker.rs +++ b/vnt/src/handle/handshaker.rs @@ -4,6 +4,7 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use crossbeam_utils::atomic::AtomicCell; +#[cfg(feature = "server_encrypt")] use parking_lot::Mutex; use protobuf::Message; @@ -28,12 +29,16 @@ pub enum HandshakeEnum { #[derive(Clone)] pub struct Handshake { time: Arc>, + #[cfg(feature = "server_encrypt")] rsa_cipher: Arc>>, } impl Handshake { - pub fn new(rsa_cipher: Arc>>) -> Self { + pub fn new( + #[cfg(feature = "server_encrypt")] rsa_cipher: Arc>>, + ) -> Self { Handshake { time: Arc::new(AtomicCell::new(Instant::now() - Duration::from_secs(60))), + #[cfg(feature = "server_encrypt")] rsa_cipher, } } @@ -54,6 +59,7 @@ impl Handshake { let mut request = HandshakeRequest::new(); request.secret = secret; request.version = crate::VNT_VERSION.to_string(); + #[cfg(feature = "server_encrypt")] if let Some(finger) = self.rsa_cipher.lock().as_ref().map(|v| v.finger().clone()) { request.key_finger = finger; } diff --git a/vnt/src/handle/recv_data/server.rs b/vnt/src/handle/recv_data/server.rs index 71ce3d0..877ecd9 100644 --- a/vnt/src/handle/recv_data/server.rs +++ b/vnt/src/handle/recv_data/server.rs @@ -193,6 +193,7 @@ impl PacketHandler for ServerPacketHandler { } return Ok(()); } + #[cfg(feature = "server_encrypt")] if let Ok(rsa_cipher) = RsaCipher::new(&response.public_key) { self.rsa_cipher.lock().replace(rsa_cipher); } diff --git a/vnt/src/handle/tun_tap/tun_handler.rs b/vnt/src/handle/tun_tap/tun_handler.rs index cda5e3c..94e1bd7 100644 --- a/vnt/src/handle/tun_tap/tun_handler.rs +++ b/vnt/src/handle/tun_tap/tun_handler.rs @@ -19,6 +19,7 @@ use crate::handle::tun_tap::channel_group::channel_group; use crate::handle::{check_dest, CurrentDeviceInfo, PeerDeviceInfo}; #[cfg(feature = "ip_proxy")] use crate::ip_proxy::IpProxyMap; +#[cfg(feature = "ip_proxy")] use crate::ip_proxy::ProxyHandler; use crate::protocol; use crate::protocol::body::ENCRYPTION_RESERVED; diff --git a/vnt/src/handle/tun_tap/windows.rs b/vnt/src/handle/tun_tap/windows.rs index 8546bff..01d317a 100644 --- a/vnt/src/handle/tun_tap/windows.rs +++ b/vnt/src/handle/tun_tap/windows.rs @@ -3,6 +3,7 @@ use crate::cipher::Cipher; use crate::external_route::ExternalRoute; use crate::handle::tun_tap::channel_group::GroupSyncSender; use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo}; +#[cfg(feature = "ip_proxy")] use crate::ip_proxy::IpProxyMap; use crate::util::{SingleU64Adder, StopManager}; use crossbeam_utils::atomic::AtomicCell; diff --git a/vnt/src/tun_tap_device/tun_create_helper.rs b/vnt/src/tun_tap_device/tun_create_helper.rs index 1b71cea..2f83423 100644 --- a/vnt/src/tun_tap_device/tun_create_helper.rs +++ b/vnt/src/tun_tap_device/tun_create_helper.rs @@ -10,6 +10,7 @@ use crate::channel::context::ChannelContext; use crate::cipher::Cipher; use crate::external_route::ExternalRoute; use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo}; +#[cfg(feature = "ip_proxy")] use crate::ip_proxy::IpProxyMap; use crate::util::{SingleU64Adder, StopManager}; #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] @@ -98,6 +99,7 @@ impl TunDeviceHelper { context, current_device, ip_route, + #[cfg(feature = "ip_proxy")] ip_proxy_map, client_cipher, server_cipher,