From 8ee416294c9cbd5a0c453574b8f4d590596072f2 Mon Sep 17 00:00:00 2001 From: neru Date: Tue, 12 May 2026 18:13:58 -0300 Subject: [PATCH] feat: add TinyMITMConfig --- src/proxy/tinymitm/proxy.cpp | 3 ++- src/proxy/tinymitm/proxy.h | 33 +++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/proxy/tinymitm/proxy.cpp b/src/proxy/tinymitm/proxy.cpp index dc51660..2253788 100644 --- a/src/proxy/tinymitm/proxy.cpp +++ b/src/proxy/tinymitm/proxy.cpp @@ -150,13 +150,14 @@ bool TinyMITMProxy::init() sockaddr_in addr{}; addr.sin_family = AF_INET; addr.sin_port = htons(_port); + addr.sin_port = htons(_config.port); addr.sin_addr.s_addr = INADDR_ANY; if (bind(_listenSocket, (sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR) return false; listen(_listenSocket, SOMAXCONN); // handler threads - for (unsigned char i = 0; i < _threadCount; i++) + for (unsigned char i = 0; i < _config.threadCount; i++) { _poolThreads.emplace_back([this]() { while (_running) diff --git a/src/proxy/tinymitm/proxy.h b/src/proxy/tinymitm/proxy.h index a55fe2c..6100b4a 100644 --- a/src/proxy/tinymitm/proxy.h +++ b/src/proxy/tinymitm/proxy.h @@ -24,19 +24,40 @@ struct WOLFSSL; #ifndef TINYMTM_HANDSHAKE_TIMEOUT #define TINYMTM_HANDSHAKE_TIMEOUT 5 -#endif +#endif + +struct TinyMITMConfig +{ + unsigned short port = 44444; + + unsigned char threadCount = 255; + + std::string caCertPath = "ca.pem"; + std::string caKeyPath = "ca.key"; + + std::string caName = "TinyMITM-CA"; + int certDays = 365; + + bool autoGenerateCA = true; + +#ifdef _WIN32 + bool installToSystemStore = false; +#endif + + std::vector customCaCertDer; + std::vector customCaKeyDer; +}; class TinyMITMProxy { public: - TinyMITMProxy(unsigned short port = 44444, unsigned char threadCount = 255) - : _port(port), _threadCount(threadCount) {}; + TinyMITMProxy(TinyMITMConfig config) : _config(std::move(config)) {} ~TinyMITMProxy(); bool init(); void shutdown(); - inline unsigned short getPort() { return _port; } + inline unsigned short getPort() { return _config.port; } inline bool getRunning() { return _running; } /* @@ -79,8 +100,6 @@ class TinyMITMProxy static bool doHandshake(WOLFSSL* ssl, SOCKET socket, bool isAccept); - unsigned short _port; - unsigned char _threadCount; SOCKET _listenSocket = 0; @@ -97,4 +116,6 @@ class TinyMITMProxy WOLFSSL_CTX* _clientCtx = nullptr; CertificateManager _certManager; + + TinyMITMConfig _config; };