From cde3ca15c21e8c44c82d3759b3b44a2283d3ca9c Mon Sep 17 00:00:00 2001 From: bol-van Date: Thu, 14 Nov 2024 14:03:37 +0300 Subject: [PATCH] tpws: debug log data before and after 2nd TLS record --- tpws/tamper.c | 13 +++++++++++++ tpws/tamper.h | 2 ++ tpws/tpws_conn.c | 7 ------- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tpws/tamper.c b/tpws/tamper.c index b380902..553488e 100644 --- a/tpws/tamper.c +++ b/tpws/tamper.c @@ -8,6 +8,13 @@ #include "protocol.h" #include "helpers.h" +#define PKTDATA_MAXDUMP 32 + +void packet_debug(const uint8_t *data, size_t sz) +{ + hexdump_limited_dlog(data, sz, PKTDATA_MAXDUMP); VPRINT("\n"); +} + static bool dp_match(struct desync_profile *dp, const struct sockaddr *dest, const char *hostname, t_l7proto l7proto) { bool bHostlistsEmpty; @@ -327,6 +334,7 @@ void tamper_out(t_ctrack *ctrack, const struct sockaddr *dest, uint8_t *segment, if (l>=2) { int i; + size_t dlen; // length is checked in IsTLSClientHello and cannot exceed buffer size if ((tpos-5)>=l) tpos=5+1; VPRINT("making 2 TLS records at pos %zu\n",tpos); @@ -337,6 +345,11 @@ void tamper_out(t_ctrack *ctrack, const struct sockaddr *dest, uint8_t *segment, phton16(segment+tpos+3,l-(tpos-5)); phton16(segment+3,tpos-5); *size += 5; + VPRINT("-2nd TLS record: "); + dlen = tpos<16 ? tpos : 16; + packet_debug(segment+tpos-dlen,dlen); + VPRINT("+2nd TLS record: "); + packet_debug(segment+tpos,*size-tpos); // fix split positions after tlsrec. increase split pos by tlsrec header size (5 bytes) if (multisplit_pos) for(i=0;i<*multisplit_count;i++) diff --git a/tpws/tamper.h b/tpws/tamper.h index b34fbf6..65eed6f 100644 --- a/tpws/tamper.h +++ b/tpws/tamper.h @@ -28,3 +28,5 @@ void tamper_in(t_ctrack *ctrack, const struct sockaddr *client, uint8_t *segment void rst_in(t_ctrack *ctrack, const struct sockaddr *client); // local leg closed connection (timeout waiting response ?) void hup_out(t_ctrack *ctrack, const struct sockaddr *client); + +void packet_debug(const uint8_t *data, size_t sz); diff --git a/tpws/tpws_conn.c b/tpws/tpws_conn.c index b9f7ac3..a979bf0 100644 --- a/tpws/tpws_conn.c +++ b/tpws/tpws_conn.c @@ -24,8 +24,6 @@ #include "helpers.h" #include "hostlist.h" -#define PKTDATA_MAXDUMP 32 - // keep separate legs counter. counting every time thousands of legs can consume cpu static int legs_local, legs_remote; /* @@ -93,11 +91,6 @@ static bool socks_send_rep_errno(uint8_t ver, int fd, int errn) return ver==5 ? socks5_send_rep_errno(fd,errn) : socks4_send_rep_errno(fd, errn); } -static void packet_debug(const uint8_t *data, size_t sz) -{ - hexdump_limited_dlog(data, sz, PKTDATA_MAXDUMP); VPRINT("\n"); -} - static bool cork(int fd, int enable) {