feat: add TinyMITMConfig
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -26,17 +26,38 @@ struct WOLFSSL;
|
||||
#define TINYMTM_HANDSHAKE_TIMEOUT 5
|
||||
#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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user