Skip to content

Commit 23e9000

Browse files
debug: Added print statements from debugging
1 parent 17a2ab3 commit 23e9000

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

server/src/handlers/client.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ pub async fn handle_client(
1515
stream: Box<dyn AsyncStream>,
1616
tx: Arc<AsyncMutex<UnboundedSender<Packet>>>,
1717
) {
18+
println!("🔗 New client connection established");
1819
let (rd, wt) = tokio::io::split(stream);
1920
let rd: StreamReader = Arc::new(AsyncMutex::new(rd));
2021
let wt: StreamWriter = Arc::new(AsyncMutex::new(wt));
2122

23+
println!("🔗 Starting handshake...");
2224
let (name, session_key, public_key) = match perform_handshake(rd.clone(), wt.clone()).await {
2325
Ok(data) => data,
24-
Err(_) => return,
26+
Err(e) => {
27+
eprintln!("❗️ Handshake failed: {:?}", e);
28+
return;
29+
}
2530
};
2631

2732
let client_id = public_key_to_user_id(&public_key);

server/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ async fn main() {
4444
loop {
4545
match listener.accept().await {
4646
Ok((stream, _)) => {
47+
println!("🔒 New TLS connection from {}", stream.peer_addr().unwrap());
4748
let acceptor = acceptor.clone();
4849
let sd_clone = sender.clone();
4950

51+
println!("🔒 Spawning new task for TLS connection");
5052
tokio::spawn(async move {
5153
match acceptor.accept(stream).await {
5254
Ok(tls_stream) => handle_client(Box::new(tls_stream), sd_clone).await,

server/src/net.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ pub async fn perform_handshake(
1717
rd: StreamReader,
1818
wt: StreamWriter,
1919
) -> Result<(String, Vec<u8>, RsaPublicKey), Box<dyn std::error::Error + Send + Sync>> {
20+
println!("Trying to receive handshake packet...");
2021
// Step: 0
2122
// Receive handshake packet from client with username and public_key
2223
let packet: HandshakePacket = read_packet(rd.clone()).await?;
24+
println!("\nReceived handshake packet: {:?}\n", packet);
2325
if packet.step != 0 {
26+
eprintln!("❗️ Invalid handshake step: expected 0, got {}", packet.step);
2427
let _ = close_connection(wt.clone(), "Invalid handshake step").await;
2528
return Err("Invalid handshake step".into());
2629
}
@@ -33,6 +36,7 @@ pub async fn perform_handshake(
3336
None => return Err("❗️Missing Public Key".into()),
3437
};
3538

39+
println!("Received handshake packet from client: {}", user_name);
3640
// Step: 1
3741
// Generate session data (nonce & session_key)
3842
// Send handshake packet from server with nonce
@@ -46,12 +50,14 @@ pub async fn perform_handshake(
4650
signature: None,
4751
session_key: None,
4852
};
53+
println!("\nSending handshake packet with nonce: {:?}\n", nonce);
4954
write_packet(wt.clone(), packet).await?;
5055

5156
// Step: 2
5257
// Receive signature and verify it
5358
let packet: HandshakePacket = read_packet(rd.clone()).await?;
5459
if packet.step != 2 {
60+
eprintln!("❗️ Invalid handshake step: expected 2, got {}", packet.step);
5561
let _ = close_connection(wt.clone(), "Invalid handshake step").await;
5662
return Err("Invalid handshake step".into());
5763
}
@@ -61,6 +67,7 @@ pub async fn perform_handshake(
6167
};
6268

6369
if !verify_nonce_signature(&public_key, &nonce, &signature) {
70+
eprintln!("❗️ Invalid signature!");
6471
let _ = close_connection(wt.clone(), "Invalid signature!").await;
6572
return Err("Invalid signature!".into());
6673
}

0 commit comments

Comments
 (0)