mirror of https://github.com/wolfSSL/wolfssl.git
Sniffer Update
1. Collect the SSL Info capture into its own function. 2. Add a Trace function for the SSL Info. 3. When copying the IANA name for the cipher suite, use a strncpy instead of a memcpy and cap the copy at the length of the destination. Force a null terminator at the end of the destination, just in case. 4. Modify the snifftest to collect the SSL Info.pull/1929/head
parent
3599798aac
commit
96b4ddad82
|
@ -1017,6 +1017,23 @@ static void TraceRemovedSession(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Show SSLInfo if provided and is valid. */
|
||||||
|
static void TraceSessionInfo(SSLInfo* sslInfo)
|
||||||
|
{
|
||||||
|
if (TraceOn) {
|
||||||
|
if (sslInfo != NULL && sslInfo->isValid) {
|
||||||
|
fprintf(TraceFile,
|
||||||
|
"\tver:(%u %u) suiteId:(%02x %02x) suiteName:(%s)\n",
|
||||||
|
sslInfo->protocolVersionMajor,
|
||||||
|
sslInfo->protocolVersionMinor,
|
||||||
|
sslInfo->serverCipherSuite0,
|
||||||
|
sslInfo->serverCipherSuite,
|
||||||
|
sslInfo->serverCipherSuiteName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Set user error string */
|
/* Set user error string */
|
||||||
static void SetError(int idx, char* error, SnifferSession* session, int fatal)
|
static void SetError(int idx, char* error, SnifferSession* session, int fatal)
|
||||||
{
|
{
|
||||||
|
@ -3465,6 +3482,38 @@ static int RemoveFatalSession(IpInfo* ipInfo, TcpInfo* tcpInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Copies the session's infomation to the provided sslInfo. Skip copy if
|
||||||
|
* SSLInfo is not provided. */
|
||||||
|
static void CopySessionInfo(SnifferSession* session, SSLInfo* sslInfo)
|
||||||
|
{
|
||||||
|
if (NULL != sslInfo) {
|
||||||
|
XMEMSET(sslInfo, 0, sizeof(SSLInfo));
|
||||||
|
|
||||||
|
/* Pass back Session Info after we have processed the Server Hello. */
|
||||||
|
if (0 != session->sslServer->options.cipherSuite) {
|
||||||
|
const char* pCipher;
|
||||||
|
|
||||||
|
sslInfo->isValid = 1;
|
||||||
|
sslInfo->protocolVersionMajor = session->sslServer->version.major;
|
||||||
|
sslInfo->protocolVersionMinor = session->sslServer->version.minor;
|
||||||
|
sslInfo->serverCipherSuite0 =
|
||||||
|
session->sslServer->options.cipherSuite0;
|
||||||
|
sslInfo->serverCipherSuite =
|
||||||
|
session->sslServer->options.cipherSuite;
|
||||||
|
|
||||||
|
pCipher = wolfSSL_get_cipher(session->sslServer);
|
||||||
|
if (NULL != pCipher) {
|
||||||
|
XSTRNCPY((char*)sslInfo->serverCipherSuiteName, pCipher,
|
||||||
|
sizeof(sslInfo->serverCipherSuiteName));
|
||||||
|
sslInfo->serverCipherSuiteName
|
||||||
|
[sizeof(sslInfo->serverCipherSuiteName) - 1] = '\0';
|
||||||
|
}
|
||||||
|
TraceSessionInfo(sslInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Passes in an IP/TCP packet for decoding (ethernet/localhost frame) removed */
|
/* Passes in an IP/TCP packet for decoding (ethernet/localhost frame) removed */
|
||||||
/* returns Number of bytes on success, 0 for no data yet, and -1 on error */
|
/* returns Number of bytes on success, 0 for no data yet, and -1 on error */
|
||||||
static int ssl_DecodePacketInternal(const byte* packet, int length,
|
static int ssl_DecodePacketInternal(const byte* packet, int length,
|
||||||
|
@ -3478,9 +3527,6 @@ static int ssl_DecodePacketInternal(const byte* packet, int length,
|
||||||
int ret;
|
int ret;
|
||||||
SnifferSession* session = 0;
|
SnifferSession* session = 0;
|
||||||
|
|
||||||
if (NULL != sslInfo)
|
|
||||||
XMEMSET(sslInfo, 0, sizeof(SSLInfo));
|
|
||||||
|
|
||||||
if (CheckHeaders(&ipInfo, &tcpInfo, packet, length, &sslFrame, &sslBytes,
|
if (CheckHeaders(&ipInfo, &tcpInfo, packet, length, &sslFrame, &sslBytes,
|
||||||
error) != 0)
|
error) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -3505,21 +3551,8 @@ static int ssl_DecodePacketInternal(const byte* packet, int length,
|
||||||
if (RemoveFatalSession(&ipInfo, &tcpInfo, session, error)) return -1;
|
if (RemoveFatalSession(&ipInfo, &tcpInfo, session, error)) return -1;
|
||||||
CheckFinCapture(&ipInfo, &tcpInfo, session);
|
CheckFinCapture(&ipInfo, &tcpInfo, session);
|
||||||
|
|
||||||
/* Pass back Session Info after we have processed the Server Hello. */
|
CopySessionInfo(session, sslInfo);
|
||||||
if ((NULL != sslInfo) && (0 != session->sslServer->options.cipherSuite)) {
|
|
||||||
const char* pCipher;
|
|
||||||
|
|
||||||
sslInfo->isValid = 1;
|
|
||||||
sslInfo->protocolVersionMajor = session->sslServer->version.major;
|
|
||||||
sslInfo->protocolVersionMinor = session->sslServer->version.minor;
|
|
||||||
sslInfo->serverCipherSuite0 = session->sslServer->options.cipherSuite0;
|
|
||||||
sslInfo->serverCipherSuite = session->sslServer->options.cipherSuite;
|
|
||||||
|
|
||||||
pCipher = wolfSSL_get_cipher(session->sslServer);
|
|
||||||
if (NULL != pCipher)
|
|
||||||
XMEMCPY(sslInfo->serverCipherSuiteName, pCipher,
|
|
||||||
sizeof(sslInfo->serverCipherSuiteName) - 1);
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -295,6 +295,7 @@ int main(int argc, char** argv)
|
||||||
static int packetNumber = 0;
|
static int packetNumber = 0;
|
||||||
struct pcap_pkthdr header;
|
struct pcap_pkthdr header;
|
||||||
const unsigned char* packet = pcap_next(pcap, &header);
|
const unsigned char* packet = pcap_next(pcap, &header);
|
||||||
|
SSLInfo sslInfo;
|
||||||
packetNumber++;
|
packetNumber++;
|
||||||
if (packet) {
|
if (packet) {
|
||||||
|
|
||||||
|
@ -307,7 +308,8 @@ int main(int argc, char** argv)
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ret = ssl_DecodePacket(packet, header.caplen, &data, err);
|
ret = ssl_DecodePacketWithSessionInfo(packet, header.caplen, &data,
|
||||||
|
&sslInfo, err);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
printf("ssl_Decode ret = %d, %s\n", ret, err);
|
printf("ssl_Decode ret = %d, %s\n", ret, err);
|
||||||
hadBadPacket = 1;
|
hadBadPacket = 1;
|
||||||
|
|
Loading…
Reference in New Issue