feat: add TinyMITMConfig
This commit is contained in:
@@ -150,13 +150,14 @@ bool TinyMITMProxy::init()
|
|||||||
sockaddr_in addr{};
|
sockaddr_in addr{};
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(_port);
|
addr.sin_port = htons(_port);
|
||||||
|
addr.sin_port = htons(_config.port);
|
||||||
addr.sin_addr.s_addr = INADDR_ANY;
|
addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
|
||||||
if (bind(_listenSocket, (sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR) return false;
|
if (bind(_listenSocket, (sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR) return false;
|
||||||
listen(_listenSocket, SOMAXCONN);
|
listen(_listenSocket, SOMAXCONN);
|
||||||
|
|
||||||
// handler threads
|
// handler threads
|
||||||
for (unsigned char i = 0; i < _threadCount; i++)
|
for (unsigned char i = 0; i < _config.threadCount; i++)
|
||||||
{
|
{
|
||||||
_poolThreads.emplace_back([this]() {
|
_poolThreads.emplace_back([this]() {
|
||||||
while (_running)
|
while (_running)
|
||||||
|
|||||||
@@ -24,19 +24,40 @@ struct WOLFSSL;
|
|||||||
|
|
||||||
#ifndef TINYMTM_HANDSHAKE_TIMEOUT
|
#ifndef TINYMTM_HANDSHAKE_TIMEOUT
|
||||||
#define TINYMTM_HANDSHAKE_TIMEOUT 5
|
#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
|
class TinyMITMProxy
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TinyMITMProxy(unsigned short port = 44444, unsigned char threadCount = 255)
|
TinyMITMProxy(TinyMITMConfig config) : _config(std::move(config)) {}
|
||||||
: _port(port), _threadCount(threadCount) {};
|
|
||||||
~TinyMITMProxy();
|
~TinyMITMProxy();
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
inline unsigned short getPort() { return _port; }
|
inline unsigned short getPort() { return _config.port; }
|
||||||
inline bool getRunning() { return _running; }
|
inline bool getRunning() { return _running; }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -79,8 +100,6 @@ class TinyMITMProxy
|
|||||||
|
|
||||||
static bool doHandshake(WOLFSSL* ssl, SOCKET socket, bool isAccept);
|
static bool doHandshake(WOLFSSL* ssl, SOCKET socket, bool isAccept);
|
||||||
|
|
||||||
unsigned short _port;
|
|
||||||
unsigned char _threadCount;
|
|
||||||
|
|
||||||
SOCKET _listenSocket = 0;
|
SOCKET _listenSocket = 0;
|
||||||
|
|
||||||
@@ -97,4 +116,6 @@ class TinyMITMProxy
|
|||||||
WOLFSSL_CTX* _clientCtx = nullptr;
|
WOLFSSL_CTX* _clientCtx = nullptr;
|
||||||
|
|
||||||
CertificateManager _certManager;
|
CertificateManager _certManager;
|
||||||
|
|
||||||
|
TinyMITMConfig _config;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user