X-Git-Url: https://git.r.bdr.sh/rbdr/olden-mail/blobdiff_plain/14c2e8bcb8c84ae5861b82045c60e49625d27299..a8a71b1901784f672f6b778464506463c4ecb286:/src/proxy.rs diff --git a/src/proxy.rs b/src/proxy.rs index 2551015..befb35b 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -42,6 +42,7 @@ use std::thread::{sleep, spawn, JoinHandle}; use std::time::Duration; use crate::configuration::Proxy; +use crate::middleware::{SERVER_MIDDLEWARE, CLIENT_MIDDLEWARE}; /// A proxy server that listens for plaintext connections and forwards them /// via TLS. @@ -226,7 +227,13 @@ 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 CLIENT_MIDDLEWARE { + command = middleware(&command); + } + + let debug_str = String::from_utf8_lossy(&command) .replace('\n', "\\n") .replace('\r', "\\r") .replace('\t', "\\t"); @@ -235,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; } @@ -279,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; }