Enable full master protocol detection for sub-protocols

This commit is contained in:
emanuele-f
2016-08-22 11:32:57 +02:00
parent 5f4bbe311e
commit 11ca0a01d3
+22 -12
View File
@@ -34,13 +34,9 @@
extern u_int8_t is_skype_flow(struct ndpi_detection_module_struct *ndpi_struct, extern u_int8_t is_skype_flow(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow); struct ndpi_flow_struct *flow);
static void ndpi_int_ssl_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static u_int32_t ndpi_ssl_refine_master_protocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, u_int32_t protocol) struct ndpi_flow_struct *flow, u_int32_t protocol)
{ {
if((protocol != NDPI_PROTOCOL_SSL)
&& (protocol != NDPI_PROTOCOL_SSL_NO_CERT)) {
ndpi_set_detected_protocol(ndpi_struct, flow, protocol, NDPI_PROTOCOL_UNKNOWN);
} else {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
if((flow->protos.ssl.client_certificate[0] != '\0') if((flow->protos.ssl.client_certificate[0] != '\0')
@@ -54,7 +50,7 @@ static void ndpi_int_ssl_add_connection(struct ndpi_detection_module_struct *ndp
switch(protocol) { switch(protocol) {
case NDPI_PROTOCOL_SSL: case NDPI_PROTOCOL_SSL:
case NDPI_PROTOCOL_SSL_NO_CERT: case NDPI_PROTOCOL_SSL_NO_CERT:
{ {
/* /*
In case of SSL there are probably sub-protocols In case of SSL there are probably sub-protocols
such as IMAPS that can be otherwise detected such as IMAPS that can be otherwise detected
@@ -69,16 +65,27 @@ static void ndpi_int_ssl_add_connection(struct ndpi_detection_module_struct *ndp
#endif #endif
) protocol = NDPI_PROTOCOL_MAIL_IMAPS; ) protocol = NDPI_PROTOCOL_MAIL_IMAPS;
else if((sport == 995) || (dport == 995)) protocol = NDPI_PROTOCOL_MAIL_POPS; else if((sport == 995) || (dport == 995)) protocol = NDPI_PROTOCOL_MAIL_POPS;
} }
break; break;
} }
if((protocol == NDPI_PROTOCOL_SSL_NO_CERT) if((protocol == NDPI_PROTOCOL_SSL_NO_CERT)
&& is_skype_flow(ndpi_struct, flow)) { && is_skype_flow(ndpi_struct, flow)) {
protocol = NDPI_PROTOCOL_SKYPE; protocol = NDPI_PROTOCOL_SKYPE;
} }
} }
return protocol;
}
static void ndpi_int_ssl_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, u_int32_t protocol)
{
if((protocol != NDPI_PROTOCOL_SSL)
&& (protocol != NDPI_PROTOCOL_SSL_NO_CERT)) {
ndpi_set_detected_protocol(ndpi_struct, flow, protocol, NDPI_PROTOCOL_UNKNOWN);
} else {
protocol = ndpi_ssl_refine_master_protocol(ndpi_struct, flow, protocol);
ndpi_set_detected_protocol(ndpi_struct, flow, protocol, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, protocol, NDPI_PROTOCOL_UNKNOWN);
} }
} }
@@ -320,11 +327,14 @@ int sslDetectProtocolFromCertificate(struct ndpi_detection_module_struct *ndpi_s
#ifdef CERTIFICATE_DEBUG #ifdef CERTIFICATE_DEBUG
printf("***** [SSL] %s\n", certificate); printf("***** [SSL] %s\n", certificate);
#endif #endif
u_int32_t subproto = ndpi_match_host_subprotocol(ndpi_struct, flow, certificate,
strlen(certificate), NDPI_PROTOCOL_SSL);
if(ndpi_match_host_subprotocol(ndpi_struct, flow, certificate, if(subproto != NDPI_PROTOCOL_UNKNOWN) {
strlen(certificate), ndpi_set_detected_protocol(ndpi_struct, flow, subproto,
NDPI_PROTOCOL_SSL) != NDPI_PROTOCOL_UNKNOWN) ndpi_ssl_refine_master_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SSL));
return(rc); /* Fix courtesy of Gianluca Costa <g.costa@xplico.org> */ return(rc); /* Fix courtesy of Gianluca Costa <g.costa@xplico.org> */
}
#ifdef NDPI_PROTOCOL_TOR #ifdef NDPI_PROTOCOL_TOR
if(ndpi_is_ssl_tor(ndpi_struct, flow, certificate) != 0) if(ndpi_is_ssl_tor(ndpi_struct, flow, certificate) != 0)