warnings fix

This commit is contained in:
2026-03-20 15:36:56 +07:00
parent 1e5c8e899b
commit 4b3b1ef67b
20 changed files with 46 additions and 89 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
use crate::connections::ip_store::FakeIpStore; use crate::connections::ip_store::FakeIpStore;
use hickory_proto::op::{Message, MessageType, ResponseCode}; use hickory_proto::op::{Message, MessageType, ResponseCode};
use hickory_proto::rr::{RData, Record, RecordType}; use hickory_proto::rr::{RData, Record, RecordType};
use netrunner_logger::{debug, error, info, warn}; use netrunner_logger::{error, info};
use std::collections::HashSet; use std::collections::HashSet;
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};
use tokio::fs::{self, File}; use tokio::fs::{self, File};
+2 -2
View File
@@ -2,8 +2,8 @@ uniffi::setup_scaffolding!();
pub mod connections; pub mod connections;
pub mod tun; pub mod tun;
use netrunner_logger::info; use netrunner_logger::info;
use std::{sync::OnceLock, time::Duration}; use std::sync::OnceLock;
use tokio::{fs::File, io::AsyncWriteExt, runtime::Runtime}; use tokio::runtime::Runtime;
use tokio_util::sync::CancellationToken; use tokio_util::sync::CancellationToken;
use crate::tun::routing::reset_platform_routing; use crate::tun::routing::reset_platform_routing;
+1 -1
View File
@@ -33,7 +33,7 @@ async fn main() -> anyhow::Result<()> {
.expect("Failed to initialize TUN device"); .expect("Failed to initialize TUN device");
let remote_address: String = "62.60.244.156:443".into(); let remote_address: String = "62.60.244.156:443".into();
setup_platform_routing(&remote_address); let _ = setup_platform_routing(&remote_address);
info!("TUN interface is UP: 10.0.0.1/24"); info!("TUN interface is UP: 10.0.0.1/24");
-1
View File
@@ -1,6 +1,5 @@
use super::{Session, SessionManager}; use super::{Session, SessionManager};
use std::sync::Arc; use std::sync::Arc;
use uniffi;
impl SessionManager { impl SessionManager {
pub fn start_desktop(&self, remote_address: String) -> Arc<Session> { pub fn start_desktop(&self, remote_address: String) -> Arc<Session> {
+4 -20
View File
@@ -1,14 +1,11 @@
use netrunner_core::protocol::codec::socks::TargetAddress; use netrunner_core::protocol::codec::socks::TargetAddress;
use netrunner_logger::{debug, error, info, warn}; use netrunner_logger::{debug, info, warn};
use smoltcp::{ use smoltcp::{
iface::{SocketHandle, SocketSet}, iface::{SocketHandle, SocketSet},
socket::{AnySocket, icmp, tcp, udp}, socket::{AnySocket, icmp, tcp, udp},
wire::{IpListenEndpoint, IpProtocol, Ipv4Packet, TcpPacket}, wire::{IpListenEndpoint, IpProtocol, Ipv4Packet, TcpPacket},
}; };
use std::{ use std::{collections::HashMap, time::Instant as StdInstant};
collections::HashMap,
time::{Duration, Instant as StdInstant},
};
use crate::connections::{ use crate::connections::{
dns::DnsHandler, ip_store::FakeIpStore, tcp_connection::TcpConnection, dns::DnsHandler, ip_store::FakeIpStore, tcp_connection::TcpConnection,
@@ -17,7 +14,7 @@ use crate::connections::{
pub struct ConnectionManager { pub struct ConnectionManager {
last_activity: HashMap<SocketHandle, StdInstant>, last_activity: HashMap<SocketHandle, StdInstant>,
active_tcp_sessions: HashMap<SocketHandle, TcpConnection>, active_tcp_sessions: HashMap<SocketHandle, TcpConnection>,
active_udp_sessions: HashMap<SocketHandle, UdpConnection>, _active_udp_sessions: HashMap<SocketHandle, UdpConnection>,
dns_handler: DnsHandler, dns_handler: DnsHandler,
fake_ip_store: FakeIpStore, fake_ip_store: FakeIpStore,
proxy_ip: String, proxy_ip: String,
@@ -30,7 +27,7 @@ impl ConnectionManager {
Self { Self {
last_activity: HashMap::new(), last_activity: HashMap::new(),
active_tcp_sessions: HashMap::new(), active_tcp_sessions: HashMap::new(),
active_udp_sessions: HashMap::new(), _active_udp_sessions: HashMap::new(),
proxy_ip: ip, proxy_ip: ip,
fake_ip_store: FakeIpStore::new(), fake_ip_store: FakeIpStore::new(),
failed_until: HashMap::new(), failed_until: HashMap::new(),
@@ -169,19 +166,6 @@ impl ConnectionManager {
} }
} }
fn create_tcp_socket<'a>() -> tcp::Socket<'a> {
const BUF_SIZE: usize = 512 * 1024;
let mut socket = tcp::Socket::new(
tcp::SocketBuffer::new(vec![0; BUF_SIZE]),
tcp::SocketBuffer::new(vec![0; BUF_SIZE]),
);
socket.set_nagle_enabled(false);
socket.set_ack_delay(None);
socket.set_keep_alive(Some(smoltcp::time::Duration::from_secs(30)));
socket.set_hop_limit(Some(64));
socket
}
fn create_dynamic_tcp_socket<'a>(port: u16) -> tcp::Socket<'a> { fn create_dynamic_tcp_socket<'a>(port: u16) -> tcp::Socket<'a> {
let buf_size = match port { let buf_size = match port {
443 | 80 => 2048 * 1024, 443 | 80 => 2048 * 1024,
+3 -3
View File
@@ -1,4 +1,4 @@
use netrunner_logger::{error, info, warn}; use netrunner_logger::{error, info};
use std::io; use std::io;
use std::process::Command; use std::process::Command;
@@ -150,7 +150,7 @@ pub fn setup_platform_routing(remote_address: &str) -> io::Result<()> {
Ok(()) Ok(())
} }
pub fn reset_platform_routing(proxy_ip: Option<&str>) -> io::Result<()> { pub fn reset_platform_routing(_proxy_ip: Option<&str>) -> io::Result<()> {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
let _ = run_cmd_ext("ip link delete netr0", true); let _ = run_cmd_ext("ip link delete netr0", true);
@@ -165,7 +165,7 @@ pub fn reset_platform_routing(proxy_ip: Option<&str>) -> io::Result<()> {
let _ = run_cmd_ext("route delete 0.0.0.0 mask 128.0.0.0", true); let _ = run_cmd_ext("route delete 0.0.0.0 mask 128.0.0.0", true);
let _ = run_cmd_ext("route delete 128.0.0.0 mask 128.0.0.0", true); let _ = run_cmd_ext("route delete 128.0.0.0 mask 128.0.0.0", true);
if let Some(ip) = proxy_ip { if let Some(ip) = _proxy_ip {
let _ = run_cmd_ext(&format!("route delete {}", ip), true); let _ = run_cmd_ext(&format!("route delete {}", ip), true);
} }
+1 -1
View File
@@ -1,4 +1,4 @@
use netrunner_logger::{error, info, warn}; use netrunner_logger::error;
use std::io; use std::io;
use tun::{AsyncDevice, Configuration, DeviceReader, DeviceWriter, create_as_async}; use tun::{AsyncDevice, Configuration, DeviceReader, DeviceWriter, create_as_async};
-2
View File
@@ -56,7 +56,6 @@ pub struct SessionKeys {
pub ecdh: ECDH, pub ecdh: ECDH,
pub auth_key: [u8; 32], pub auth_key: [u8; 32],
pub current_aead: Option<([u8; 32], [u8; 12], [u8; 32], [u8; 12])>, pub current_aead: Option<([u8; 32], [u8; 12], [u8; 32], [u8; 12])>,
is_initiator: bool,
} }
impl SessionKeys { impl SessionKeys {
@@ -66,7 +65,6 @@ impl SessionKeys {
ecdh: ECDH::new(), ecdh: ECDH::new(),
auth_key: [0u8; 32], auth_key: [0u8; 32],
current_aead: None, current_aead: None,
is_initiator,
} }
} }
+1 -1
View File
@@ -117,7 +117,7 @@ impl TlsInterceptor for ApplicationData {
)); ));
} }
Ok(Some(ApplicationData { Ok(Some(ApplicationData {
len: record.payload.len(), _len: record.payload.len(),
payload: record.payload, payload: record.payload,
})) }))
} }
+1 -1
View File
@@ -1,4 +1,4 @@
use bytes::{BufMut, Bytes, BytesMut}; use bytes::{BufMut, BytesMut};
use crate::protocol::parser::parser::Parser; use crate::protocol::parser::parser::Parser;
+7 -7
View File
@@ -71,12 +71,12 @@ impl Parser for ApplicationData {
} }
fn parse(bytes: &mut BytesMut) -> Result<Option<Self>, Self::Error> { fn parse(bytes: &mut BytesMut) -> Result<Option<Self>, Self::Error> {
let len = bytes.len(); let _len = bytes.len();
if len == 0 { if _len == 0 {
return Ok(None); return Ok(None);
} }
let payload = bytes.split_to(len).freeze(); let payload = bytes.split_to(_len).freeze();
Ok(Some(Self { len, payload })) Ok(Some(Self { _len, payload }))
} }
} }
@@ -104,7 +104,7 @@ impl Parser for HelloHeader {
Ok(Some(Self { Ok(Some(Self {
header_type, header_type,
len: U24::from_u32(len), _len: U24::from_u32(len),
})) }))
} }
} }
@@ -157,7 +157,7 @@ impl Parser for ClientHello {
return Ok(None); return Ok(None);
} }
let version = ProtocolVersion::try_from(bytes.get_u16()) let _version = ProtocolVersion::try_from(bytes.get_u16())
.map_err(|e| TlsError::new(ErrorStage::Tls(e), ErrorAction::Drop, Bytes::new()))?; .map_err(|e| TlsError::new(ErrorStage::Tls(e), ErrorAction::Drop, Bytes::new()))?;
let mut random = [0u8; 32]; let mut random = [0u8; 32];
@@ -184,7 +184,7 @@ impl Parser for ClientHello {
}; };
Ok(Some(Self { Ok(Some(Self {
version, _version,
random, random,
session_id, session_id,
cipher_suites, cipher_suites,
+3 -7
View File
@@ -16,9 +16,8 @@ use crate::{
}, },
tlseng::profile::BrowserProfile, tlseng::profile::BrowserProfile,
}; };
use bytes::{Bytes, BytesMut}; use bytes::BytesMut;
use netrunner_logger::{debug, error, info, trace, warn}; use netrunner_logger::info;
use std::net::SocketAddr;
use tokio::{ use tokio::{
io::{AsyncReadExt, AsyncWriteExt}, io::{AsyncReadExt, AsyncWriteExt},
net::{ net::{
@@ -43,7 +42,6 @@ pub trait TunnelHandler {
} }
pub struct Connection { pub struct Connection {
addr: SocketAddr,
pub inbound: OwnedReadHalf, pub inbound: OwnedReadHalf,
pub outbound: OwnedWriteHalf, pub outbound: OwnedWriteHalf,
pub read_buf: BytesMut, pub read_buf: BytesMut,
@@ -51,10 +49,9 @@ pub struct Connection {
} }
impl Connection { impl Connection {
pub fn new(stream: TcpStream, addr: SocketAddr, init: bool) -> Self { pub fn new(stream: TcpStream, init: bool) -> Self {
let (inbound, outbound) = stream.into_split(); let (inbound, outbound) = stream.into_split();
Self { Self {
addr,
inbound, inbound,
outbound, outbound,
read_buf: BytesMut::with_capacity(BUF_SIZE), read_buf: BytesMut::with_capacity(BUF_SIZE),
@@ -64,7 +61,6 @@ impl Connection {
pub fn new_raw(inbound: OwnedReadHalf, outbound: OwnedWriteHalf) -> Self { pub fn new_raw(inbound: OwnedReadHalf, outbound: OwnedWriteHalf) -> Self {
Self { Self {
addr: "0.0.0.0:0".parse().unwrap(),
inbound, inbound,
outbound, outbound,
read_buf: BytesMut::with_capacity(BUF_SIZE), read_buf: BytesMut::with_capacity(BUF_SIZE),
+3 -3
View File
@@ -62,8 +62,8 @@ impl Network {
tokio::select! { tokio::select! {
_ = token.cancelled() => break, _ = token.cancelled() => break,
res = listener.accept() => { res = listener.accept() => {
if let Ok((stream, client_addr)) = res { if let Ok((stream, _client_addr)) = res {
let conn = Connection::new(stream, client_addr, false); let conn = Connection::new(stream, false);
let handler = ClientHandler{ conn, muxer: muxer.clone() }; let handler = ClientHandler{ conn, muxer: muxer.clone() };
tokio::spawn(async move { tokio::spawn(async move {
if let Err(e) = handler.run().await { if let Err(e) = handler.run().await {
@@ -82,7 +82,7 @@ impl Network {
_ = token.cancelled() => break, _ = token.cancelled() => break,
res = listener.accept() => { res = listener.accept() => {
if let Ok((stream, client_addr)) = res { if let Ok((stream, client_addr)) = res {
let conn = Connection::new(stream, client_addr, true); let conn = Connection::new(stream, true);
let handler = ServerHandler { conn, token: token.clone() }; let handler = ServerHandler { conn, token: token.clone() };
tokio::spawn(async move { tokio::spawn(async move {
if let Err(e) = handler.run().await { if let Err(e) = handler.run().await {
-5
View File
@@ -8,8 +8,3 @@ pub const PSK_DHE_KE_MODE: u8 = 0x01;
pub const CERT_COMPRESSION_BROTLI: u16 = 0x0002; pub const CERT_COMPRESSION_BROTLI: u16 = 0x0002;
pub const OCSP_STATUS_TYPE: u8 = 0x01; pub const OCSP_STATUS_TYPE: u8 = 0x01;
pub const GREASE_IDENTIFIERS: [u16; 16] = [
0x0A0A, 0x1A1A, 0x2A2A, 0x3A3A, 0x4A4A, 0x5A5A, 0x6A6A, 0x7A7A, 0x8A8A, 0x9A9A, 0xAAAA, 0xBABA,
0xCACA, 0xDADA, 0xEAEA, 0xFAFA,
];
+2 -13
View File
@@ -1,11 +1,7 @@
use bytes::{BufMut, Bytes, BytesMut}; use bytes::{BufMut, Bytes, BytesMut};
use rand::RngExt;
use crate::tlseng::{ use crate::tlseng::{
consts::{ consts::{CERT_COMPRESSION_BROTLI, OCSP_STATUS_TYPE, PSK_DHE_KE_MODE, TYPE_HOST_NAME},
CERT_COMPRESSION_BROTLI, GREASE_IDENTIFIERS, OCSP_STATUS_TYPE, PSK_DHE_KE_MODE,
TYPE_HOST_NAME,
},
profile::BrowserProfile, profile::BrowserProfile,
types::{TlsExtensions, TlsGroups, TlsSignatures, TlsVersions}, types::{TlsExtensions, TlsGroups, TlsSignatures, TlsVersions},
}; };
@@ -58,18 +54,11 @@ impl ExtensionBuilder {
self.payload.put_slice(data); self.payload.put_slice(data);
} }
pub fn grease(&mut self) {
let mut rng = rand::rng();
let rnd = rng.random_range(0..GREASE_IDENTIFIERS.len());
let etype = GREASE_IDENTIFIERS[rnd];
self.add_extension(etype, &[]);
}
pub fn grease_with_id(&mut self, etype: u16) { pub fn grease_with_id(&mut self, etype: u16) {
self.add_extension(etype, &[]); self.add_extension(etype, &[]);
} }
pub fn apply_generic_extension(&mut self, etype: u16, profile: &BrowserProfile) { pub fn apply_generic_extension(&mut self, etype: u16, _profile: &BrowserProfile) {
match etype { match etype {
_ => { _ => {
netrunner_logger::trace!(etype, "Applying generic or unknown extension"); netrunner_logger::trace!(etype, "Applying generic or unknown extension");
+4 -4
View File
@@ -8,18 +8,18 @@ use crate::{
extension::ExtensionBuilder, extension::ExtensionBuilder,
profile::{BrowserProfile, ServerProfile}, profile::{BrowserProfile, ServerProfile},
tls_record::TlsRecord, tls_record::TlsRecord,
types::{ContentType, HelloType, ProtocolVersion, TlsVersions}, types::{ContentType, HelloType, ProtocolVersion},
}, },
utils::u24::U24, utils::u24::U24,
}; };
pub struct HelloHeader { pub struct HelloHeader {
pub header_type: HelloType, pub header_type: HelloType,
pub len: U24, pub _len: U24,
} }
pub struct ClientHello { pub struct ClientHello {
pub version: ProtocolVersion, pub _version: ProtocolVersion,
pub random: [u8; 32], pub random: [u8; 32],
@@ -88,7 +88,7 @@ impl ClientHello {
let extensions_bytes = ext_builder.build(); let extensions_bytes = ext_builder.build();
let client_hello = ClientHello { let client_hello = ClientHello {
version: ProtocolVersion::Tls12, _version: ProtocolVersion::Tls12,
random: tls_random, random: tls_random,
session_id: Bytes::copy_from_slice(&session_id_bytes), session_id: Bytes::copy_from_slice(&session_id_bytes),
cipher_suites: profile.cipher_suites.to_vec(), cipher_suites: profile.cipher_suites.to_vec(),
+1 -1
View File
@@ -1,7 +1,7 @@
use bytes::Bytes; use bytes::Bytes;
pub struct ApplicationData { pub struct ApplicationData {
pub len: usize, pub _len: usize,
pub payload: Bytes, pub payload: Bytes,
} }
+8 -12
View File
@@ -64,31 +64,27 @@ impl BrowserProfile {
} }
pub struct ServerProfile { pub struct ServerProfile {
pub name: &'static str,
pub versions: TlsVersions, pub versions: TlsVersions,
pub record_layer_version: ProtocolVersion, pub record_layer_version: ProtocolVersion,
pub cipher_suites: &'static [u16], pub cipher_suites: &'static [u16],
pub groups: TlsGroups, pub _groups: TlsGroups,
pub signatures: TlsSignatures, pub _signatures: TlsSignatures,
pub alpn: &'static [&'static str], pub _alpn: &'static [&'static str],
pub session_tickets: bool, pub _session_tickets: bool,
pub honor_cipher_order: bool, pub honor_cipher_order: bool,
} }
impl ServerProfile { impl ServerProfile {
pub const MODERN: Self = Self { pub const MODERN: Self = Self {
name: "Modern-Secure",
versions: TlsVersions::MODERN, versions: TlsVersions::MODERN,
record_layer_version: ProtocolVersion::Tls12, record_layer_version: ProtocolVersion::Tls12,
cipher_suites: &[0x1301, 0x1302, 0x1303], cipher_suites: &[0x1301, 0x1302, 0x1303],
groups: TlsGroups::MODERN, _groups: TlsGroups::MODERN,
signatures: TlsSignatures::BROWSER_STANDARD, _signatures: TlsSignatures::BROWSER_STANDARD,
alpn: &["h2", "http/1.1"], _alpn: &["h2", "http/1.1"],
session_tickets: true, _session_tickets: true,
honor_cipher_order: true, honor_cipher_order: true,
}; };
} }
+2 -2
View File
@@ -8,7 +8,7 @@ pub struct TlsRecord {
pub version: ProtocolVersion, pub version: ProtocolVersion,
pub len: u16, pub _len: u16,
pub payload: Bytes, pub payload: Bytes,
} }
@@ -18,7 +18,7 @@ impl TlsRecord {
Self { Self {
content_type, content_type,
version, version,
len: payload.len() as u16, _len: payload.len() as u16,
payload, payload,
} }
} }
+2 -2
View File
@@ -9,11 +9,11 @@ impl U24 {
U24([b[1], b[2], b[3]]) U24([b[1], b[2], b[3]])
} }
pub fn to_u32(&self) -> u32 { pub fn _to_u32(&self) -> u32 {
u32::from_be_bytes([0, self.0[0], self.0[1], self.0[2]]) u32::from_be_bytes([0, self.0[0], self.0[1], self.0[2]])
} }
pub fn from_slice(slice: &[u8]) -> u32 { pub fn _from_slice(slice: &[u8]) -> u32 {
u32::from_be_bytes([0, slice[0], slice[1], slice[2]]) u32::from_be_bytes([0, slice[0], slice[1], slice[2]])
} }
} }