feat: add TinyMITMConfig

This commit is contained in:
2026-05-12 18:13:58 -03:00
parent 0507c68a0b
commit 8ee416294c
2 changed files with 29 additions and 7 deletions
+2 -1
View File
@@ -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)
+27 -6
View File
@@ -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<unsigned char> customCaCertDer;
std::vector<unsigned char> 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;
};