aboutsummaryrefslogtreecommitdiff
path: root/src/lib/protocols
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2018-08-16 14:57:44 +0200
committerLuca Deri <deri@ntop.org>2018-08-16 14:57:44 +0200
commit01bf295a19c19dc4f521ee40f0c478c794e1b5e4 (patch)
tree7666d50e4e4407d82a05e7d9beb067ec4045ab3d /src/lib/protocols
parentf88648fbc845eaf75a74f1c45a9483d144993e29 (diff)
Completed custom category implementation
Diffstat (limited to 'src/lib/protocols')
-rw-r--r--src/lib/protocols/dns.c8
-rw-r--r--src/lib/protocols/fbzero.c4
-rw-r--r--src/lib/protocols/http.c27
-rw-r--r--src/lib/protocols/quic.c2
-rw-r--r--src/lib/protocols/ssl.c67
5 files changed, 67 insertions, 41 deletions
diff --git a/src/lib/protocols/dns.c b/src/lib/protocols/dns.c
index 6ffa74a27..90be9544c 100644
--- a/src/lib/protocols/dns.c
+++ b/src/lib/protocols/dns.c
@@ -207,12 +207,16 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
flow->protos.dns.num_queries = (u_int8_t)dns_header.num_queries,
flow->protos.dns.num_answers = (u_int8_t) (dns_header.num_answers + dns_header.authority_rrs + dns_header.additional_rrs);
- if(j > 0)
+ if(j > 0) {
+ ndpi_protocol_match_result ret_match;
+
ndpi_match_host_subprotocol(ndpi_struct, flow,
(char *)flow->host_server_name,
strlen((const char*)flow->host_server_name),
+ &ret_match,
NDPI_PROTOCOL_DNS);
-
+ }
+
#ifdef DNS_DEBUG
NDPI_LOG_DBG2(ndpi_struct, "[num_queries=%d][num_answers=%d][reply_code=%u][rsp_type=%u][host_server_name=%s]\n",
flow->protos.dns.num_queries, flow->protos.dns.num_answers,
diff --git a/src/lib/protocols/fbzero.c b/src/lib/protocols/fbzero.c
index 3048bff79..6c818e3c7 100644
--- a/src/lib/protocols/fbzero.c
+++ b/src/lib/protocols/fbzero.c
@@ -84,7 +84,8 @@ void ndpi_search_fbzero(struct ndpi_detection_module_struct *ndpi_struct,
&& (t->tag[2] == 'I') && (t->tag[3] == '\0')) {
char *value = (char*)&packet->payload[data_offset + data_prev_offset];
u_int tag_len = t->tag_offset_len-data_prev_offset, max_len;
-
+ ndpi_protocol_match_result ret_match;
+
max_len = ndpi_min(tag_len, sizeof(flow->host_server_name)-1);
strncpy((char*)flow->host_server_name, value, max_len);
@@ -99,6 +100,7 @@ void ndpi_search_fbzero(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_match_host_subprotocol(ndpi_struct, flow, (char *)flow->host_server_name,
strlen((const char *)flow->host_server_name),
+ &ret_match,
NDPI_PROTOCOL_FBZERO);
return;
}
diff --git a/src/lib/protocols/http.c b/src/lib/protocols/http.c
index e03b48710..94d918e76 100644
--- a/src/lib/protocols/http.c
+++ b/src/lib/protocols/http.c
@@ -172,7 +172,8 @@ static void setHttpUserAgent(struct ndpi_detection_module_struct *ndpi_struct,
static void parseHttpSubprotocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
if((flow->l4.tcp.http_stage == 0) || (flow->http.url && flow->http_detected)) {
char *double_col = strchr((char*)flow->host_server_name, ':');
-
+ ndpi_protocol_match_result ret_match;
+
if(double_col) double_col[0] = '\0';
/**
@@ -182,6 +183,7 @@ static void parseHttpSubprotocol(struct ndpi_detection_module_struct *ndpi_struc
*/
ndpi_match_host_subprotocol(ndpi_struct, flow, (char *)flow->host_server_name,
strlen((const char *)flow->host_server_name),
+ &ret_match,
NDPI_PROTOCOL_HTTP);
}
}
@@ -349,12 +351,16 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
packet->host_line.len, packet->host_line.ptr);
/* call ndpi_match_host_subprotocol to see if there is a match with known-host HTTP subprotocol */
- if((ndpi_struct->http_dont_dissect_response) || flow->http_detected)
+ if((ndpi_struct->http_dont_dissect_response) || flow->http_detected) {
+ ndpi_protocol_match_result ret_match;
+
ndpi_match_host_subprotocol(ndpi_struct, flow,
(char*)packet->host_line.ptr,
packet->host_line.len,
+ &ret_match,
NDPI_PROTOCOL_HTTP);
-
+ }
+
/* Copy result for nDPI apps */
if(!ndpi_struct->disable_metadata_export) {
len = ndpi_min(packet->host_line.len, sizeof(flow->host_server_name)-1);
@@ -395,12 +401,16 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
if((flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN)
&& ((ndpi_struct->http_dont_dissect_response) || flow->http_detected)
- && (packet->http_origin.len > 0))
+ && (packet->http_origin.len > 0)) {
+ ndpi_protocol_match_result ret_match;
+
ndpi_match_host_subprotocol(ndpi_struct, flow,
(char *)packet->http_origin.ptr,
packet->http_origin.len,
+ &ret_match,
NDPI_PROTOCOL_HTTP);
-
+ }
+
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN) {
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_HTTP) {
NDPI_LOG_INFO(ndpi_struct, "found HTTP/%s\n",
@@ -440,10 +450,13 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
NDPI_LOG_DBG2(ndpi_struct, "Content Type line found %.*s\n",
packet->content_line.len, packet->content_line.ptr);
- if((ndpi_struct->http_dont_dissect_response) || flow->http_detected)
+ if((ndpi_struct->http_dont_dissect_response) || flow->http_detected) {
+ ndpi_protocol_match_result ret_match;
+
ndpi_match_content_subprotocol(ndpi_struct, flow,
(char*)packet->content_line.ptr, packet->content_line.len,
- NDPI_PROTOCOL_HTTP);
+ &ret_match, NDPI_PROTOCOL_HTTP);
+ }
}
}
diff --git a/src/lib/protocols/quic.c b/src/lib/protocols/quic.c
index 4c838f41f..e28db634a 100644
--- a/src/lib/protocols/quic.c
+++ b/src/lib/protocols/quic.c
@@ -107,6 +107,7 @@ void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct,
if((sni_offset+len) < udp_len) {
if(!ndpi_struct->disable_metadata_export) {
int max_len = sizeof(flow->host_server_name)-1, j = 0;
+ ndpi_protocol_match_result ret_match;
if(len > max_len) len = max_len;
@@ -118,6 +119,7 @@ void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_match_host_subprotocol(ndpi_struct, flow,
(char *)flow->host_server_name,
strlen((const char*)flow->host_server_name),
+ &ret_match,
NDPI_PROTOCOL_QUIC);
}
}
diff --git a/src/lib/protocols/ssl.c b/src/lib/protocols/ssl.c
index a277f8120..b8c36976b 100644
--- a/src/lib/protocols/ssl.c
+++ b/src/lib/protocols/ssl.c
@@ -327,13 +327,13 @@ int sslTryAndRetrieveServerCertificate(struct ndpi_detection_module_struct *ndpi
}
/* Client hello, Server Hello, and certificate packets probably all checked in this case */
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 */)
- {
- /* We're done processing extra packets since we've probably checked all possible cert packets */
- return 0;
- }
+ && (flow->l4.tcp.seen_syn)
+ && (flow->l4.tcp.seen_syn_ack)
+ && (flow->l4.tcp.seen_ack) /* We have seen the 3-way handshake */)
+ {
+ /* We're done processing extra packets since we've probably checked all possible cert packets */
+ return 0;
+ }
}
/* 1 means keep looking for more packets */
return 1;
@@ -368,22 +368,27 @@ int sslDetectProtocolFromCertificate(struct ndpi_detection_module_struct *ndpi_s
#ifdef CERTIFICATE_DEBUG
NDPI_LOG_DBG2(ndpi_struct, "***** [SSL] %s\n", certificate);
#endif
+ ndpi_protocol_match_result ret_match;
u_int32_t subproto = ndpi_match_host_subprotocol(ndpi_struct, flow, certificate,
- strlen(certificate), NDPI_PROTOCOL_SSL);
+ strlen(certificate),
+ &ret_match,
+ NDPI_PROTOCOL_SSL);
+
if(subproto != NDPI_PROTOCOL_UNKNOWN) {
- /* 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->protos.stun_ssl.ssl.client_certificate[0] != '\0') && (flow->protos.stun_ssl.ssl.server_certificate[0] == '\0')) {
- sslInitExtraPacketProcessing(0, flow);
- }
- ndpi_set_detected_protocol(ndpi_struct, flow, subproto,
- ndpi_ssl_refine_master_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SSL));
- return(rc); /* Fix courtesy of Gianluca Costa <g.costa@xplico.org> */
- }
+ /* 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->protos.stun_ssl.ssl.client_certificate[0] != '\0') && (flow->protos.stun_ssl.ssl.server_certificate[0] == '\0')) {
+ sslInitExtraPacketProcessing(0, flow);
+ }
+
+ ndpi_set_detected_protocol(ndpi_struct, flow, subproto,
+ ndpi_ssl_refine_master_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SSL));
+ return(rc); /* Fix courtesy of Gianluca Costa <g.costa@xplico.org> */
+ }
- if(ndpi_is_ssl_tor(ndpi_struct, flow, certificate) != 0)
- return(rc);
+ if(ndpi_is_ssl_tor(ndpi_struct, flow, certificate) != 0)
+ return(rc);
}
if(((packet->ssl_certificate_num_checks >= 2)
@@ -394,9 +399,9 @@ int sslDetectProtocolFromCertificate(struct ndpi_detection_module_struct *ndpi_s
/* || (flow->protos.stun_ssl.ssl.client_certificate[0] != '\0') */
) {
ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL);
- }
+ }
+ }
}
- }
return(0);
}
@@ -480,7 +485,7 @@ static void ssl_mark_and_payload_search_for_other_protocols(struct
ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL_NO_CERT);
} else
NDPI_LOG_INFO(ndpi_struct, "found ssl\n");
- ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL);
+ ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL);
}
}
@@ -516,16 +521,16 @@ static u_int8_t ndpi_search_sslv3_direction1(struct ndpi_detection_module_struct
u_int32_t cert_start;
NDPI_LOG_DBG2(ndpi_struct,
- "maybe SSLv3 server hello split into smaller packets\n");
+ "maybe SSLv3 server hello split into smaller packets\n");
/* lets hope at least the server hello and the start of the certificate block are in the first packet */
cert_start = ntohs(get_u_int16_t(packet->payload, 7)) + 5 + 4;
NDPI_LOG_DBG2(ndpi_struct, "suspected start of certificate: %u\n",
- cert_start);
+ cert_start);
if(cert_start < packet->payload_packet_len && packet->payload[cert_start] == 0x0b) {
NDPI_LOG_DBG2(ndpi_struct,
- "found 0x0b at suspected start of certificate block\n");
+ "found 0x0b at suspected start of certificate block\n");
return 2;
}
}
@@ -536,16 +541,16 @@ static u_int8_t ndpi_search_sslv3_direction1(struct ndpi_detection_module_struct
u_int32_t cert_start;
NDPI_LOG_DBG2(ndpi_struct,
- "maybe SSLv3 server hello split into smaller packets but with seperate record for the certificate\n");
+ "maybe SSLv3 server hello split into smaller packets but with seperate record for the certificate\n");
/* lets hope at least the server hello record and the start of the certificate record are in the first packet */
cert_start = ntohs(get_u_int16_t(packet->payload, 7)) + 5 + 5 + 4;
NDPI_LOG_DBG2(ndpi_struct, "suspected start of certificate: %u\n",
- cert_start);
+ cert_start);
if(cert_start < packet->payload_packet_len && packet->payload[cert_start] == 0x0b) {
NDPI_LOG_DBG2(ndpi_struct,
- "found 0x0b at suspected start of certificate block\n");
+ "found 0x0b at suspected start of certificate block\n");
return 2;
}
}
@@ -603,7 +608,7 @@ void ndpi_search_ssl_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
* so go on checking for certificate patterns for a couple more packets
*/
NDPI_LOG_DBG2(ndpi_struct,
- "ssl flow but check another packet for patterns\n");
+ "ssl flow but check another packet for patterns\n");
ssl_mark_and_payload_search_for_other_protocols(ndpi_struct, flow);
if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_SSL) {
/* still ssl so check another packet */
@@ -685,7 +690,7 @@ void ndpi_search_ssl_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
return;
} else if(ret == 2) {
NDPI_LOG_DBG2(ndpi_struct,
- "sslv3 server len match with split packet -> check some more packets for SSL patterns\n");
+ "sslv3 server len match with split packet -> check some more packets for SSL patterns\n");
ssl_mark_and_payload_search_for_other_protocols(ndpi_struct, flow);
if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_SSL) {
flow->l4.tcp.ssl_stage = 3;