feat: add sslWriteAll (for tunnel)

This commit is contained in:
2026-05-13 11:38:12 -03:00
parent d8ddcd83ee
commit facee79998
+32 -1
View File
@@ -100,6 +100,37 @@ struct HttpStream
} }
}; };
/*
misc helpers
*/
bool sslWriteAll(WOLFSSL* ssl, const void* data, int len, SOCKET s)
{
int sent = 0;
while (sent < len)
{
int ret = wolfSSL_write(ssl, (const char*)data + sent, len - sent);
if (ret > 0)
{
sent += ret;
continue;
}
int err = wolfSSL_get_error(ssl, ret);
if (err == WOLFSSL_ERROR_WANT_READ || err == WOLFSSL_ERROR_WANT_WRITE)
{
fd_set fds;
FD_ZERO(&fds);
FD_SET(s, &fds);
struct timeval tv{0, 10000}; // 10ms wait
select(0, (err == WOLFSSL_ERROR_WANT_READ) ? &fds : nullptr,
(err == WOLFSSL_ERROR_WANT_WRITE) ? &fds : nullptr, nullptr, &tv);
continue;
}
return false;
}
return true;
}
/* /*
platform specific stuff platform specific stuff
*/ */
@@ -393,7 +424,7 @@ void TinyMITMProxy::handleClient(SOCKET clientSocket)
{ {
if (tunnelMode) if (tunnelMode)
{ {
wolfSSL_write(remoteSSL.get(), buf, rd); if (!sslWriteAll(remoteSSL.get(), buf, rd, remoteGuard)) break;
} }
else else
{ {