feat: add extra logging
This commit is contained in:
@@ -126,16 +126,35 @@ bool TinyMITMProxy::init()
|
|||||||
{
|
{
|
||||||
_running = true;
|
_running = true;
|
||||||
|
|
||||||
// wolfssl setup
|
TINYMITM_WRITELOG(info, "proxy init");
|
||||||
if (wolfSSL_Init() != WOLFSSL_SUCCESS) return false;
|
|
||||||
|
|
||||||
|
TINYMITM_WRITELOG(verbose, "wolfssl init");
|
||||||
|
|
||||||
|
// wolfssl setup
|
||||||
|
if (wolfSSL_Init() != WOLFSSL_SUCCESS)
|
||||||
|
{
|
||||||
|
TINYMITM_WRITELOG(error, "wolfssl failed to initialize");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
TINYMITM_WRITELOG(verbose, "wolfssl context creation");
|
||||||
_clientCtx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
|
_clientCtx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
|
||||||
if (!_clientCtx) return false;
|
if (!_clientCtx)
|
||||||
|
{
|
||||||
|
TINYMITM_WRITELOG(error, "failed to create wolfssl context");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
wolfSSL_CTX_set_verify(_clientCtx, WOLFSSL_VERIFY_NONE, nullptr);
|
wolfSSL_CTX_set_verify(_clientCtx, WOLFSSL_VERIFY_NONE, nullptr);
|
||||||
|
|
||||||
// cert setup
|
// cert setup
|
||||||
if (!_certManager.init()) return false;
|
TINYMITM_WRITELOG(verbose, "certmanager init");
|
||||||
|
if (!_certManager.init())
|
||||||
|
{
|
||||||
|
TINYMITM_WRITELOG(error, "certmanager failed to initialize");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TINYMITM_WRITELOG(verbose, "loading / generating CA");
|
||||||
bool hasCA = false;
|
bool hasCA = false;
|
||||||
if (_config.autoGenerateCA)
|
if (_config.autoGenerateCA)
|
||||||
{
|
{
|
||||||
@@ -148,28 +167,51 @@ bool TinyMITMProxy::init()
|
|||||||
else
|
else
|
||||||
hasCA = _certManager.loadCA(_config.customCaCertDer.c_str(), _config.customCaKeyDer.c_str());
|
hasCA = _certManager.loadCA(_config.customCaCertDer.c_str(), _config.customCaKeyDer.c_str());
|
||||||
|
|
||||||
if (!hasCA) return false;
|
if (!hasCA)
|
||||||
|
{
|
||||||
|
TINYMITM_WRITELOG(error, "certManager was unable to obtain a certificate");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (_config.installToSystemStore) _certManager.installCertificate();
|
TINYMITM_WRITELOG(verbose, "installing CA");
|
||||||
|
if (_config.installToSystemStore)
|
||||||
|
{
|
||||||
|
if (!_certManager.installCertificate())
|
||||||
|
{
|
||||||
|
TINYMITM_WRITELOG(error, "failed to install CA");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// socket setup
|
// socket setup
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
TINYMITM_WRITELOG(verbose, "starting winsock");
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) return false;
|
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
|
||||||
|
{
|
||||||
|
TINYMITM_WRITELOG(error, "failed to start winsock");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
TINYMITM_WRITELOG(verbose, "setting up listen socket");
|
||||||
_listenSocket = socket(AF_INET, SOCK_STREAM, 0);
|
_listenSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
sockaddr_in addr{};
|
sockaddr_in addr{};
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(_config.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)
|
||||||
|
{
|
||||||
|
TINYMITM_WRITELOG(error, "failed to bind listensocket");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
listen(_listenSocket, SOMAXCONN);
|
listen(_listenSocket, SOMAXCONN);
|
||||||
|
|
||||||
// handler threads
|
// handler threads
|
||||||
|
TINYMITM_WRITELOG(verbose, "starting handler threads");
|
||||||
for (unsigned char i = 0; i < _config.threadCount; i++)
|
for (unsigned char i = 0; i < _config.threadCount; i++)
|
||||||
{
|
{
|
||||||
_poolThreads.emplace_back([this]() {
|
_poolThreads.emplace_back([this]() {
|
||||||
@@ -187,6 +229,7 @@ bool TinyMITMProxy::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dispatcher thread
|
// dispatcher thread
|
||||||
|
TINYMITM_WRITELOG(verbose, "starting handler thread");
|
||||||
_dispatchThread = std::thread([this] {
|
_dispatchThread = std::thread([this] {
|
||||||
while (_running)
|
while (_running)
|
||||||
{
|
{
|
||||||
@@ -200,6 +243,8 @@ bool TinyMITMProxy::init()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
TINYMITM_WRITELOG(info, "proxy started successfully");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user