diff --git a/src/client/net.rs b/src/client/net.rs index a14a1c3..9aa6c24 100644 --- a/src/client/net.rs +++ b/src/client/net.rs @@ -8,6 +8,7 @@ use super::types; use colored::Colorize; use pea_2_pea::{shared::net::send_and_recv_with_retry, *}; use rand::{RngCore, rng}; +use sha2::Digest; pub fn query_request( buf: &mut [u8; UDP_BUFFER_SIZE], @@ -434,14 +435,28 @@ pub async fn handle_incoming_connection( ..P2PStandardDataPositions::IV as usize + BLOCK_SIZE], &buf[P2PStandardDataPositions::DATA as usize..data_lenght as usize], ) { - Ok(data) => match tun_iface.send(&data) { - Ok(_) => {} - Err(e) => eprintln!( - "{} failed to write packet to tun interface, Error: {}", - "[WARNING]".yellow(), - e - ), - }, + Ok(data) => { + #[cfg(debug_assertions)] + eprintln!( + "packet contets: {}\nhash: {:x}", + data.iter() + .map(|x| format!("{:02X} ", x)) + .collect::(), + { + let mut hasher = sha2::Sha256::new(); + hasher.update(&data); + hasher.finalize() + } + ); + match tun_iface.send(&data) { + Ok(_) => {} + Err(e) => eprintln!( + "{} failed to write packet to tun interface, Error: {}", + "[WARNING]".yellow(), + e + ), + } + } Err(e) => eprintln!( "{} failed to decrypt packet, Error: {}", "[WARNING]".yellow(), @@ -449,9 +464,15 @@ pub async fn handle_incoming_connection( ), } } else { - match tun_iface.send(&buf[P2PStandardDataPositions::DATA as usize..data_lenght as usize]) { - Ok(_) => {}, - Err(e) => eprintln!("{} failed to write packet to tun interface, Error: {}", "[WARNING]".yellow(), e), + match tun_iface + .send(&buf[P2PStandardDataPositions::DATA as usize..data_lenght as usize]) + { + Ok(_) => {} + Err(e) => eprintln!( + "{} failed to write packet to tun interface, Error: {}", + "[WARNING]".yellow(), + e + ), }; } } diff --git a/src/client/tun.rs b/src/client/tun.rs index 5000295..175e5d7 100644 --- a/src/client/tun.rs +++ b/src/client/tun.rs @@ -3,6 +3,7 @@ use std::sync::{Arc, RwLock}; use pea_2_pea::*; use rand::RngCore; use rayon::prelude::*; +use sha2::Digest; use crate::types::Network; @@ -30,10 +31,10 @@ pub fn read_tun_iface( ) { let mut buf: [u8; IP_BUFFER_SIZE] = [0u8; IP_BUFFER_SIZE]; - smol::block_on(async { + smol::block_on(async { + #[cfg(debug_assertions)] + eprintln!("Started listening for ip packets"); loop { - #[cfg(debug_assertions)] - eprintln!("Started listening for ip packets"); let data_lenght = tun_iface.recv(&mut buf).unwrap(); // build in auto termination, isn't it great smol::spawn(handle_ip_packet( buf[..data_lenght - 1].to_vec().into(), @@ -41,8 +42,8 @@ pub fn read_tun_iface( socket.clone(), )) .detach(); - }}); - + } + }); } pub async fn handle_ip_packet( @@ -51,7 +52,22 @@ pub async fn handle_ip_packet( socket: Arc, ) { #[cfg(debug_assertions)] - eprintln!("Processing IP packet"); + eprintln!("Processing IP packet"); + + #[cfg(debug_assertions)] + eprintln!( + "packet contets: {}\nhash: {:x}", + packet_data + .iter() + .map(|x| format!("{:02X} ", x)) + .collect::(), + { + let mut hasher = sha2::Sha256::new(); + hasher.update(&packet_data); + hasher.finalize() + } + ); + let dst_ip = std::net::Ipv4Addr::from( match <[u8; 4]>::try_from( &packet_data[DEST_IN_IPV4_OFFSET..DEST_IN_IPV4_OFFSET + IPV4_SIZE],