Add ssl_RemoveSession API

pull/8768/head
Lealem Amedie 2025-05-14 11:47:33 -06:00
parent 5a4c1d99a3
commit 4af0e14e7b
2 changed files with 105 additions and 0 deletions

View File

@ -7626,6 +7626,106 @@ int ssl_LoadSecretsFromKeyLogFile(const char* keylogfile, char* error)
#endif /* WOLFSSL_SNIFFER_KEYLOGFILE */
/*
* Removes a session from the SessionTable based on client/server IP & ports
* Returns 0 if a session was found and freed, -1 otherwise
*/
int ssl_RemoveSession(const char* clientIp, int clientPort,
const char* serverIp, int serverPort,
char* error)
{
IpAddrInfo clientAddr;
IpAddrInfo serverAddr;
IpInfo ipInfo;
TcpInfo tcpInfo;
SnifferSession* session;
int ret = -1; /* Default to not found */
word32 row;
if (clientIp == NULL || serverIp == NULL) {
SetError(BAD_IPVER_STR, error, NULL, 0);
return ret;
}
/* Set up client IP address */
clientAddr.version = IPV4;
clientAddr.ip4 = XINET_ADDR(clientIp);
if (clientAddr.ip4 == XINADDR_NONE) {
#ifdef FUSION_RTOS
if (XINET_PTON(AF_INET6, clientIp, clientAddr.ip6,
sizeof(clientAddr.ip4)) == 1)
#else
if (XINET_PTON(AF_INET6, clientIp, clientAddr.ip6) == 1)
#endif
{
clientAddr.version = IPV6;
}
else {
SetError(BAD_IPVER_STR, error, NULL, 0);
return ret;
}
}
/* Set up server IP address */
serverAddr.version = IPV4;
serverAddr.ip4 = XINET_ADDR(serverIp);
if (serverAddr.ip4 == XINADDR_NONE) {
#ifdef FUSION_RTOS
if (XINET_PTON(AF_INET6, serverIp, serverAddr.ip6,
sizeof(serverAddr.ip4)) == 1)
#else
if (XINET_PTON(AF_INET6, serverIp, serverAddr.ip6) == 1)
#endif
{
serverAddr.version = IPV6;
}
else {
SetError(BAD_IPVER_STR, error, NULL, 0);
return ret;
}
}
XMEMSET(&ipInfo, 0, sizeof(ipInfo));
XMEMSET(&tcpInfo, 0, sizeof(tcpInfo));
/* Set up client->server direction */
ipInfo.src = clientAddr;
ipInfo.dst = serverAddr;
tcpInfo.srcPort = clientPort;
tcpInfo.dstPort = serverPort;
/* Calculate the hash row for this session */
row = SessionHash(&ipInfo, &tcpInfo);
LOCK_SESSION();
/* Search only the specific row in the session table */
session = SessionTable[row];
while (session) {
SnifferSession* next = session->next;
/* Check if this session matches the specified client/server IP/port */
if (MatchAddr(session->client, clientAddr) &&
MatchAddr(session->server, serverAddr) &&
session->cliPort == clientPort &&
session->srvPort == serverPort) {
/* Use RemoveSession to remove and free the session */
RemoveSession(session, NULL, NULL, row);
ret = 0; /* Session found and freed */
break;
}
session = next;
}
UNLOCK_SESSION();
return ret;
}
#undef ERROR_OUT
#endif /* WOLFSSL_SNIFFER */

View File

@ -345,6 +345,11 @@ typedef int (*SSLSnifferSecretCb)(unsigned char* client_random,
#endif /* WOLFSSL_SNIFFER_KEYLOGFILE */
WOLFSSL_API
SSL_SNIFFER_API int ssl_RemoveSession(const char* clientIp, int clientPort,
const char* serverIp, int serverPort,
char* error);
#ifdef __cplusplus
} /* extern "C" */