Skip to content

Commit 681049e

Browse files
committed
FIXED TLS plugin variable-length IE IPFIX export
1 parent 4e0cf0a commit 681049e

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

process/tls.hpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* \file tls.hpp
33
* \brief Plugin for parsing https traffic.
44
* \author Jiri Havranek <[email protected]>
5-
* \date 2018
5+
* \author Karel Hynek <[email protected]>
6+
* \date 2021
67
*/
78
/*
89
* Copyright (C) 2018 CESNET
@@ -47,6 +48,7 @@
4748
#include <string>
4849
#include <cstring>
4950
#include <arpa/inet.h>
51+
5052
#include <sstream>
5153
#include <iomanip>
5254

@@ -58,6 +60,7 @@
5860
#include <ipfixprobe/flowifc.hpp>
5961
#include <ipfixprobe/packet.hpp>
6062
#include <ipfixprobe/ipfix-elements.hpp>
63+
#include <ipfixprobe/utils.hpp>
6164

6265
namespace ipxp {
6366

@@ -109,24 +112,20 @@ struct RecordExtTLS : public RecordExt {
109112

110113
virtual int fill_ipfix(uint8_t *buffer, int size)
111114
{
112-
int sni_len = strlen(sni);
113-
int alpn_len = strlen(alpn);
114-
int pos = 0;
115+
uint16_t sni_len = strlen(sni);
116+
uint16_t alpn_len = strlen(alpn);
115117

116-
if (sni_len + alpn_len + 2 + 16 + 3 > size) {
118+
uint32_t pos = 0;
119+
uint32_t req_buff_len = (sni_len + 3) + (alpn_len + 3) + (2) + (16 + 3); // (SNI) + (ALPN) + (VERSION) + (JA3)
120+
if (req_buff_len > size) {
117121
return -1;
118122
}
119123

120124
*(uint16_t *) buffer = ntohs(version);
121125
pos += 2;
122126

123-
buffer[pos++] = sni_len;
124-
memcpy(buffer + pos, sni, sni_len);
125-
pos += sni_len;
126-
127-
buffer[pos++] = alpn_len;
128-
memcpy(buffer + pos, alpn, alpn_len);
129-
pos += alpn_len;
127+
pos += variable2ipfix_buffer(buffer + pos, (uint8_t*) sni, sni_len);
128+
pos += variable2ipfix_buffer(buffer + pos, (uint8_t*) alpn, alpn_len);
130129

131130
buffer[pos++] = 16;
132131
memcpy(buffer + pos, ja3_hash_bin, 16);

0 commit comments

Comments
 (0)