diff --git a/src/proxy/tinymitm/proxy.cpp b/src/proxy/tinymitm/proxy.cpp index b334c90..18c9a6f 100644 --- a/src/proxy/tinymitm/proxy.cpp +++ b/src/proxy/tinymitm/proxy.cpp @@ -126,16 +126,35 @@ bool TinyMITMProxy::init() { _running = true; - // wolfssl setup - if (wolfSSL_Init() != WOLFSSL_SUCCESS) return false; + TINYMITM_WRITELOG(info, "proxy init"); + 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()); - 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); // 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; if (_config.autoGenerateCA) { @@ -148,28 +167,51 @@ bool TinyMITMProxy::init() else 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 - 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 // socket setup #ifdef _WIN32 + TINYMITM_WRITELOG(verbose, "starting winsock"); 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 + TINYMITM_WRITELOG(verbose, "setting up listen socket"); _listenSocket = socket(AF_INET, SOCK_STREAM, 0); sockaddr_in addr{}; addr.sin_family = AF_INET; addr.sin_port = htons(_config.port); 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); // handler threads + TINYMITM_WRITELOG(verbose, "starting handler threads"); for (unsigned char i = 0; i < _config.threadCount; i++) { _poolThreads.emplace_back([this]() { @@ -187,6 +229,7 @@ bool TinyMITMProxy::init() } // dispatcher thread + TINYMITM_WRITELOG(verbose, "starting handler thread"); _dispatchThread = std::thread([this] { while (_running) { @@ -200,6 +243,8 @@ bool TinyMITMProxy::init() } }); + TINYMITM_WRITELOG(info, "proxy started successfully"); + return true; }