Skip to content

Commit 6863357

Browse files
lukacanhynekkar
authored andcommitted
Support of extracting TLS version from handshake extension
1 parent cf5adcb commit 6863357

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

pcaps/tls_ver_ext.pcapng

23.9 KB
Binary file not shown.

process/tls.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ bool TLSPlugin::obtain_tls_data(TLSData &payload, RecordExtTLS *rec, std::string
121121
} else if (hs_type == TLS_HANDSHAKE_SERVER_HELLO) {
122122
if (type == TLS_EXT_ALPN) {
123123
tls_parser.tls_get_alpn(payload, rec->alpn, BUFF_SIZE);
124-
return true;
124+
// not sure, but probably don`t return yet, as
125+
// this is not only field we want to parse
126+
//return true;
127+
} else if (type == TLS_EXT_SUPPORTED_VER){
128+
tls_parser.tls_get_supp_ver(payload, rec->version);
125129
}
126130
}
127131
payload.start += length;
@@ -159,7 +163,7 @@ bool TLSPlugin::parse_tls(const uint8_t *data, uint16_t payload_len, RecordExtTL
159163
}
160164
tls_handshake tls_hs = tls_parser.tls_get_handshake();
161165

162-
rec->version = ((uint16_t) tls_hs.version.major << 8) | tls_hs.version.minor;
166+
rec->version = (rec->version == 0)?(((uint16_t) tls_hs.version.major << 8) | tls_hs.version.minor) : rec->version;
163167
ja3 += std::to_string((uint16_t) tls_hs.version.version) + ',';
164168

165169
if (!tls_parser.tls_skip_random(payload)) {

process/tls.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ struct RecordExtTLS : public RecordExt {
144144
#define TLS_EXT_ECLIPTIC_CURVES 10 // AKA supported_groups
145145
#define TLS_EXT_EC_POINT_FORMATS 11
146146
#define TLS_EXT_ALPN 16
147+
#define TLS_EXT_SUPPORTED_VER 43
147148

148149

149150
/**

process/tls_parser.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ void TLSParser::tls_get_server_name(TLSData &data, char *buffer, size_t buffer_s
126126
return;
127127
}
128128

129+
void TLSParser::tls_get_supp_ver(TLSData &data, uint16_t &version)
130+
{
131+
tls_version* ext_ver = (tls_version *) data.start;
132+
version = ((uint16_t) ext_ver->major << 8) | ext_ver->minor;
133+
return;
134+
}
135+
129136
void TLSParser::tls_get_alpn(TLSData &data, char *buffer, size_t buffer_size)
130137
{
131138
uint16_t list_len = ntohs(*(uint16_t *) data.start);

process/tls_parser.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class TLSParser
8686
bool tls_check_rec(TLSData&);
8787
void tls_get_server_name(TLSData &, char *, size_t);
8888
void tls_get_alpn(TLSData &, char *, size_t);
89+
void tls_get_supp_ver(TLSData &, uint16_t &);
8990

9091
void tls_get_quic_user_agent(TLSData &, char *, size_t);
9192
bool tls_check_handshake(TLSData&);

0 commit comments

Comments
 (0)