X-Git-Url: https://git.r.bdr.sh/rbdr/olden-mail/blobdiff_plain/573aaf2a8ccdb6c8c917b2d88a39c9c8103f64ef..8ef3566a8961e2305ab701fce160de0dba1d050c:/src/proxy.rs?ds=sidebyside diff --git a/src/proxy.rs b/src/proxy.rs index 2798df3..33de440 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -42,7 +42,7 @@ use std::thread::{sleep, spawn, JoinHandle}; use std::time::Duration; use crate::configuration::Proxy; -use crate::middleware::MIDDLEWARE; +use crate::middleware::{CLIENT_MIDDLEWARE, SERVER_MIDDLEWARE}; /// A proxy server that listens for plaintext connections and forwards them /// via TLS. @@ -229,7 +229,7 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc) { let mut command = buffer[..bytes_read].to_vec(); - for middleware in MIDDLEWARE { + for middleware in CLIENT_MIDDLEWARE { command = middleware(&command); } @@ -242,7 +242,7 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc) { // Lock the TLS stream and write the data to server match tls_stream_clone.lock() { Ok(mut tls_guard) => { - if let Err(error) = tls_guard.write_all(&buffer[..bytes_read]) { + if let Err(error) = tls_guard.write_all(&command) { debug!(">>> Error writing to server: {error}"); break; } @@ -286,14 +286,20 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc) { } }; - let debug_str = String::from_utf8_lossy(&buffer[..bytes_read]) + let mut command = buffer[..bytes_read].to_vec(); + + for middleware in SERVER_MIDDLEWARE { + command = middleware(&command); + } + + let debug_str = String::from_utf8_lossy(&command) .replace('\n', "\\n") .replace('\r', "\\r") .replace('\t', "\\t"); debug!("<<< {}", debug_str); // Write decrypted data to client - if client_writer.write_all(&buffer[..bytes_read]).is_err() { + if client_writer.write_all(&command).is_err() { debug!("<<< ERR"); break; }