]> git.r.bdr.sh - rbdr/olden-mail/commitdiff
Separate client and server middleware
authorRuben Beltran del Rio <redacted>
Mon, 27 Jan 2025 16:00:32 +0000 (17:00 +0100)
committerRuben Beltran del Rio <redacted>
Mon, 27 Jan 2025 16:00:32 +0000 (17:00 +0100)
src/middleware/mod.rs
src/proxy.rs

index a1070f4840082d288014d58b509ff6ae5cba3818..da7e64ad7b774e6e6ec7b707c0e6a6d698dd0bb7 100644 (file)
@@ -4,4 +4,5 @@ use find_mailboxes_compatibility::middleware as find_mailboxes_compatibility_mid
 
 type Middleware = fn(&[u8]) -> Vec<u8>;
 
 
 type Middleware = fn(&[u8]) -> Vec<u8>;
 
-pub const MIDDLEWARE: [Middleware; 1] = [find_mailboxes_compatibility_middleware];
+pub const CLIENT_MIDDLEWARE: [Middleware; 1] = [find_mailboxes_compatibility_middleware];
+pub const SERVER_MIDDLEWARE: [Middleware; 0] = [];
index 2798df372642f4abf497706ab8ad9cbe8624489a..befb35b59c39effc2e8e00de81c3f943c84775b1 100644 (file)
@@ -42,7 +42,7 @@ use std::thread::{sleep, spawn, JoinHandle};
 use std::time::Duration;
 
 use crate::configuration::Proxy;
 use std::time::Duration;
 
 use crate::configuration::Proxy;
-use crate::middleware::MIDDLEWARE;
+use crate::middleware::{SERVER_MIDDLEWARE, CLIENT_MIDDLEWARE};
 
 /// A proxy server that listens for plaintext connections and forwards them
 /// via TLS.
 
 /// 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<Proxy>) {
 
             let mut command = buffer[..bytes_read].to_vec();
 
 
             let mut command = buffer[..bytes_read].to_vec();
 
-            for middleware in MIDDLEWARE {
+            for middleware in CLIENT_MIDDLEWARE {
                 command = middleware(&command);
             }
 
                 command = middleware(&command);
             }
 
@@ -242,7 +242,7 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc<Proxy>) {
             // Lock the TLS stream and write the data to server
             match tls_stream_clone.lock() {
                 Ok(mut tls_guard) => {
             // 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;
                     }
                         debug!(">>> Error writing to server: {error}");
                         break;
                     }
@@ -286,14 +286,20 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc<Proxy>) {
                 }
             };
 
                 }
             };
 
-            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
                 .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;
             }
                 debug!("<<< ERR");
                 break;
             }