aboutsummaryrefslogtreecommitdiff
path: root/src/lib/protocols/mail_imap.c
diff options
context:
space:
mode:
authoremanuele-f <black.silver@hotmail.it>2016-08-12 13:19:42 +0200
committeremanuele-f <black.silver@hotmail.it>2016-08-12 13:19:42 +0200
commit6e1341c148195420ffa0faf7c130a4cbcb44ca1f (patch)
treef0a45fcbedf8bed197f1ef7beb79b74625066c24 /src/lib/protocols/mail_imap.c
parent5e1e6a48a4211d1a7a92fb06a193dc7c368e9118 (diff)
Add STARTTLS detection
Diffstat (limited to 'src/lib/protocols/mail_imap.c')
-rw-r--r--src/lib/protocols/mail_imap.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/lib/protocols/mail_imap.c b/src/lib/protocols/mail_imap.c
index c62c1d366..a5c9c55be 100644
--- a/src/lib/protocols/mail_imap.c
+++ b/src/lib/protocols/mail_imap.c
@@ -42,6 +42,15 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
/* const u_int8_t *command = 0; */
NDPI_LOG(NDPI_PROTOCOL_MAIL_IMAP, ndpi_struct, NDPI_LOG_DEBUG, "search IMAP.\n");
+
+ if (flow->l4.tcp.mail_imap_starttls == 2) {
+#ifdef NDPI_PROTOCOL_SSL
+ NDPI_LOG(NDPI_PROTOCOL_MAIL_IMAP, ndpi_struct, NDPI_LOG_DEBUG, "starttls detected\n");
+ NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MAIL_IMAP);
+ NDPI_DEL_PROTOCOL_FROM_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SSL);
+ return;
+#endif
+ }
if (packet->payload_packet_len >= 4 && ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a) {
// the DONE command appears without a tag
@@ -62,7 +71,7 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
}
if (!((packet->payload[i] >= 'a' && packet->payload[i] <= 'z') ||
(packet->payload[i] >= 'A' && packet->payload[i] <= 'Z') ||
- (packet->payload[i] >= '0' && packet->payload[i] <= '9') || packet->payload[i] == '*')) {
+ (packet->payload[i] >= '0' && packet->payload[i] <= '9') || packet->payload[i] == '*' || packet->payload[i] == '.')) {
goto imap_excluded;
}
i++;
@@ -99,6 +108,8 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
&& (packet->payload[command_start + 1] == 'K' || packet->payload[command_start + 1] == 'k')
&& packet->payload[command_start + 2] == ' ') {
flow->l4.tcp.mail_imap_stage += 1;
+ if (flow->l4.tcp.mail_imap_starttls == 1)
+ flow->l4.tcp.mail_imap_starttls = 2;
saw_command = 1;
} else if ((packet->payload[command_start] == 'U' || packet->payload[command_start] == 'u')
&& (packet->payload[command_start + 1] == 'I' || packet->payload[command_start + 1] == 'i')
@@ -131,8 +142,8 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
&& (packet->payload[command_start + 5] == 'T' || packet->payload[command_start + 5] == 't')
&& (packet->payload[command_start + 6] == 'L' || packet->payload[command_start + 6] == 'l')
&& (packet->payload[command_start + 7] == 'S' || packet->payload[command_start + 7] == 's')) {
- flow->l4.tcp.mail_imap_stage += 1;
- saw_command = 1;
+ flow->l4.tcp.mail_imap_starttls = 1;
+ saw_command = 1;
}
}
if ((command_start + 5) < packet->payload_packet_len) {