@@ -123,8 +123,10 @@ static bool str_contains_digit(char *str) {
123123
124124/* TODO: rename */
125125static int keep_extra_dissection_tcp (struct ndpi_detection_module_struct * ndpi_struct ,
126- struct ndpi_flow_struct * flow )
127- {
126+ struct ndpi_flow_struct * flow ) {
127+ if (ndpi_struct -> cfg .tls_blocks_analysis_enabled )
128+ return (1 ); /* Process as much TLS blocks as the max packet number */
129+
128130 /* Common path: found handshake on both directions */
129131 if (
130132 (flow -> tls_quic .certificate_processed == 1 && flow -> protos .tls_quic .client_hello_processed )
@@ -1245,7 +1247,7 @@ int processCertificate(struct ndpi_detection_module_struct *ndpi_struct,
12451247 }
12461248
12471249 if ((ndpi_struct -> num_tls_blocks_to_follow != 0 )
1248- && (flow -> l4 .tcp .tls .num_tls_blocks >= ndpi_struct -> num_tls_blocks_to_follow )) {
1250+ && (flow -> l4 .tcp .tls .num_processed_tls_blocks >= ndpi_struct -> num_tls_blocks_to_follow )) {
12491251#ifdef DEBUG_TLS_BLOCKS
12501252 printf ("*** [TLS Block] Enough blocks dissected\n" );
12511253#endif
@@ -1412,6 +1414,23 @@ int ndpi_search_tls_tcp(struct ndpi_detection_module_struct *ndpi_struct,
14121414
14131415 content_type = message -> buffer [0 ];
14141416
1417+ if (ndpi_struct -> cfg .tls_blocks_analysis_enabled ) {
1418+ if (flow -> l4 .tcp .tls .num_tls_blocks < NDPI_MAX_NUM_TLS_APPL_BLOCKS ) {
1419+ int16_t blen = len - 5 ;
1420+
1421+ /* Use positive values for c->s and negative for s->c */
1422+ if (packet -> packet_direction != 0 ) blen = - blen ;
1423+
1424+ flow -> l4 .tcp .tls .tls_blocks [flow -> l4 .tcp .tls .num_tls_blocks ].len = blen ;
1425+ flow -> l4 .tcp .tls .tls_blocks [flow -> l4 .tcp .tls .num_tls_blocks ++ ].block_type = content_type ;
1426+
1427+ #ifdef DEBUG_TLS_BLOCKS
1428+ printf ("*** [TLS Block] [len: %u][num_tls_blocks: %u/%u]\n" ,
1429+ len - 5 , flow -> l4 .tcp .tls .num_tls_blocks , ndpi_struct -> num_tls_blocks_to_follow );
1430+ #endif
1431+ }
1432+ }
1433+
14151434 /* Overwriting packet payload */
14161435 p = packet -> payload ;
14171436 p_len = packet -> payload_packet_len ; /* Backup */
@@ -1423,7 +1442,7 @@ int ndpi_search_tls_tcp(struct ndpi_detection_module_struct *ndpi_struct,
14231442 so in this case we reset the number of observed
14241443 TLS blocks
14251444 */
1426- flow -> l4 .tcp .tls .num_tls_blocks = 0 ;
1445+ flow -> l4 .tcp .tls .num_processed_tls_blocks = 0 ;
14271446 }
14281447 if (len == 6 &&
14291448 message -> buffer [1 ] == 0x03 && /* TLS >= 1.0 */
@@ -1439,8 +1458,15 @@ int ndpi_search_tls_tcp(struct ndpi_detection_module_struct *ndpi_struct,
14391458 ndpi_int_tls_add_connection (ndpi_struct , flow );
14401459 flow -> l4 .tcp .tls .app_data_seen [packet -> packet_direction ] = 1 ;
14411460 /* Further data is encrypted so we are not able to parse it without
1442- erros and without setting `something_went_wrong` variable */
1443- break ;
1461+ errors and without setting `something_went_wrong` variable */
1462+
1463+ if (!ndpi_struct -> cfg .tls_blocks_analysis_enabled ) {
1464+ /*
1465+ In case of TLS blocks analysis we want to analize all the blocks
1466+ whereas in "standard" mode we can use this shortcut and break
1467+ */
1468+ break ;
1469+ }
14441470 }
14451471 } else if (content_type == 0x15 /* Alert */ ) {
14461472 /* https://techcommunity.microsoft.com/t5/iis-support-blog/ssl-tls-alert-protocol-and-the-alert-codes/ba-p/377132 */
@@ -1513,22 +1539,6 @@ int ndpi_search_tls_tcp(struct ndpi_detection_module_struct *ndpi_struct,
15131539 flow -> l4 .tcp .tls .app_data_seen [packet -> packet_direction ] = 1 ;
15141540 if (flow -> l4 .tcp .tls .app_data_seen [!packet -> packet_direction ] == 1 )
15151541 flow -> tls_quic .certificate_processed = 1 ;
1516-
1517- if (flow -> tls_quic .certificate_processed ) {
1518- if (flow -> l4 .tcp .tls .num_tls_blocks < ndpi_struct -> num_tls_blocks_to_follow ) {
1519- int16_t blen = len - 5 ;
1520-
1521- /* Use positive values for c->s e negative for s->c */
1522- if (packet -> packet_direction != 0 ) blen = - blen ;
1523-
1524- flow -> l4 .tcp .tls .tls_application_blocks_len [flow -> l4 .tcp .tls .num_tls_blocks ++ ] = blen ;
1525- }
1526-
1527- #ifdef DEBUG_TLS_BLOCKS
1528- printf ("*** [TLS Block] [len: %u][num_tls_blocks: %u/%u]\n" ,
1529- len - 5 , flow -> l4 .tcp .tls .num_tls_blocks , ndpi_struct -> num_tls_blocks_to_follow );
1530- #endif
1531- }
15321542 }
15331543 }
15341544
@@ -1552,7 +1562,7 @@ int ndpi_search_tls_tcp(struct ndpi_detection_module_struct *ndpi_struct,
15521562
15531563 if (something_went_wrong
15541564 || ((ndpi_struct -> num_tls_blocks_to_follow > 0 )
1555- && (flow -> l4 .tcp .tls .num_tls_blocks == ndpi_struct -> num_tls_blocks_to_follow ))
1565+ && (flow -> l4 .tcp .tls .num_processed_tls_blocks == ndpi_struct -> num_tls_blocks_to_follow ))
15561566 || ((ndpi_struct -> num_tls_blocks_to_follow == 0 )
15571567 && (!keep_extra_dissection_tcp (ndpi_struct , flow )))
15581568 ) {
0 commit comments