SSL cleanup
This commit is contained in:
@@ -541,7 +541,10 @@ struct ndpi_flow_tcp_struct {
|
||||
u_int32_t telnet_stage:2; // 0 - 2
|
||||
|
||||
/* NDPI_PROTOCOL_SSL */
|
||||
u_int8_t ssl_seen_client_cert:1, ssl_seen_server_cert:1, ssl_stage:2; // 0 - 5
|
||||
u_int8_t ssl_seen_client_cert:1,
|
||||
ssl_seen_server_cert:1,
|
||||
ssl_seen_certificate:1,
|
||||
ssl_stage:2; // 0 - 5
|
||||
|
||||
/* NDPI_PROTOCOL_POSTGRES */
|
||||
u_int32_t postgres_stage:3;
|
||||
|
||||
+20
-11
@@ -152,8 +152,9 @@ int getSSLcertificate(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
#ifdef CERTIFICATE_DEBUG
|
||||
{
|
||||
u_int16_t ssl_version = (packet->payload[1] << 8) + packet->payload[2];
|
||||
u_int16_t ssl_len = (packet->payload[3] << 8) + packet->payload[4];
|
||||
|
||||
printf("SSL [version: %u]\n", ssl_version);
|
||||
printf("SSL Record [version: 0x%02X][len: %u]\n", ssl_version, ssl_len);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -175,10 +176,18 @@ int getSSLcertificate(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
if(total_len > 4) {
|
||||
int i;
|
||||
|
||||
if(handshake_protocol == 0x02 || handshake_protocol == 0xb /* Server Hello and Certificate message types are interesting for us */) {
|
||||
#ifdef CERTIFICATE_DEBUG
|
||||
printf("SSL [len: %u][handshake_protocol: %02X]\n", packet->payload_packet_len, handshake_protocol);
|
||||
#endif
|
||||
|
||||
if((handshake_protocol == 0x02)
|
||||
|| (handshake_protocol == 0xb) /* Server Hello and Certificate message types are interesting for us */) {
|
||||
u_int num_found = 0;
|
||||
|
||||
if(handshake_protocol == 0x02)
|
||||
flow->l4.tcp.ssl_seen_server_cert = 1;
|
||||
else
|
||||
flow->l4.tcp.ssl_seen_certificate = 1;
|
||||
|
||||
/* Check after handshake protocol header (5 bytes) and message header (4 bytes) */
|
||||
for(i = 9; i < packet->payload_packet_len-3; i++) {
|
||||
@@ -474,7 +483,8 @@ int sslDetectProtocolFromCertificate(struct ndpi_detection_module_struct *ndpi_s
|
||||
/* If we've detected the subprotocol from client certificate but haven't had a chance
|
||||
* to see the server certificate yet, set up extra packet processing to wait
|
||||
* a few more packets. */
|
||||
if(((flow->l4.tcp.ssl_seen_client_cert == 1) && (flow->protos.stun_ssl.ssl.client_certificate[0] != '\0')) && ((flow->l4.tcp.ssl_seen_server_cert != 1) && (flow->protos.stun_ssl.ssl.server_certificate[0] == '\0'))) {
|
||||
if(((flow->l4.tcp.ssl_seen_client_cert == 1) && (flow->protos.stun_ssl.ssl.client_certificate[0] != '\0'))
|
||||
&& ((flow->l4.tcp.ssl_seen_server_cert != 1) && (flow->protos.stun_ssl.ssl.server_certificate[0] == '\0'))) {
|
||||
sslInitExtraPacketProcessing(0, flow);
|
||||
}
|
||||
|
||||
@@ -487,11 +497,13 @@ int sslDetectProtocolFromCertificate(struct ndpi_detection_module_struct *ndpi_s
|
||||
return(rc);
|
||||
}
|
||||
|
||||
if(((packet->ssl_certificate_num_checks >= 2)
|
||||
if(((packet->ssl_certificate_num_checks >= 3)
|
||||
&& flow->l4.tcp.seen_syn
|
||||
&& flow->l4.tcp.seen_syn_ack
|
||||
&& flow->l4.tcp.seen_ack /* We have seen the 3-way handshake */)
|
||||
|| ((flow->l4.tcp.ssl_seen_server_cert == 1) && (flow->protos.stun_ssl.ssl.server_certificate[0] != '\0'))
|
||||
|| ((flow->l4.tcp.ssl_seen_certificate == 1)
|
||||
&& (flow->l4.tcp.ssl_seen_server_cert == 1)
|
||||
&& (flow->protos.stun_ssl.ssl.server_certificate[0] != '\0'))
|
||||
/* || ((flow->l4.tcp.ssl_seen_client_cert == 1) && (flow->protos.stun_ssl.ssl.client_certificate[0] != '\0')) */
|
||||
) {
|
||||
ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL);
|
||||
@@ -501,8 +513,7 @@ int sslDetectProtocolFromCertificate(struct ndpi_detection_module_struct *ndpi_s
|
||||
return(0);
|
||||
}
|
||||
|
||||
static void ssl_mark_and_payload_search_for_other_protocols(struct
|
||||
ndpi_detection_module_struct
|
||||
static void ssl_mark_and_payload_search_for_other_protocols(struct ndpi_detection_module_struct
|
||||
*ndpi_struct, struct ndpi_flow_struct *flow)
|
||||
{
|
||||
struct ndpi_packet_struct *packet = &flow->packet;
|
||||
@@ -579,16 +590,16 @@ static void ssl_mark_and_payload_search_for_other_protocols(struct
|
||||
/* SSL without certificate (Skype, Ultrasurf?) */
|
||||
NDPI_LOG_INFO(ndpi_struct, "found ssl NO_CERT\n");
|
||||
ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL_NO_CERT);
|
||||
} else
|
||||
} else if(packet->ssl_certificate_num_checks >= 3) {
|
||||
NDPI_LOG_INFO(ndpi_struct, "found ssl\n");
|
||||
ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static u_int8_t ndpi_search_sslv3_direction1(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow) {
|
||||
|
||||
struct ndpi_packet_struct *packet = &flow->packet;
|
||||
|
||||
if((packet->payload_packet_len >= 5)
|
||||
@@ -716,7 +727,6 @@ void ndpi_search_ssl_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
|
||||
|
||||
NDPI_LOG_DBG(ndpi_struct, "search ssl\n");
|
||||
|
||||
{
|
||||
/* Check if this is whatsapp first (this proto runs over port 443) */
|
||||
if((packet->payload_packet_len > 5)
|
||||
&& ((packet->payload[0] == 'W')
|
||||
@@ -736,7 +746,6 @@ void ndpi_search_ssl_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
|
||||
if(sslDetectProtocolFromCertificate(ndpi_struct, flow) > 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(packet->payload_packet_len > 40 && flow->l4.tcp.ssl_stage == 0) {
|
||||
NDPI_LOG_DBG2(ndpi_struct, "first ssl packet\n");
|
||||
|
||||
Reference in New Issue
Block a user