TLS certificate hash is not reported

This commit is contained in:
Luca Deri
2019-09-14 15:00:52 +02:00
parent 659f75138c
commit 00e639d513
6 changed files with 35 additions and 7 deletions
+17
View File
@@ -1024,6 +1024,8 @@ static void printFlow(u_int16_t id, struct ndpi_flow_info *flow, u_int16_t threa
return; return;
if(!json_flag) { if(!json_flag) {
u_int i;
fprintf(out, "\t%u", id); fprintf(out, "\t%u", id);
fprintf(out, "\t%s ", ipProto2Name(flow->protocol)); fprintf(out, "\t%s ", ipProto2Name(flow->protocol));
@@ -1101,6 +1103,7 @@ static void printFlow(u_int16_t id, struct ndpi_flow_info *flow, u_int16_t threa
if(flow->ssh_tls.ja3_client[0] != '\0') fprintf(out, "[JA3C: %s%s]", flow->ssh_tls.ja3_client, if(flow->ssh_tls.ja3_client[0] != '\0') fprintf(out, "[JA3C: %s%s]", flow->ssh_tls.ja3_client,
print_cipher(flow->ssh_tls.client_unsafe_cipher)); print_cipher(flow->ssh_tls.client_unsafe_cipher));
if(flow->ssh_tls.server_info[0] != '\0') fprintf(out, "[Server: %s]", flow->ssh_tls.server_info); if(flow->ssh_tls.server_info[0] != '\0') fprintf(out, "[Server: %s]", flow->ssh_tls.server_info);
if(flow->ssh_tls.server_hassh[0] != '\0') fprintf(out, "[HASSH-S: %s]", flow->ssh_tls.server_hassh); if(flow->ssh_tls.server_hassh[0] != '\0') fprintf(out, "[HASSH-S: %s]", flow->ssh_tls.server_hassh);
@@ -1108,6 +1111,20 @@ static void printFlow(u_int16_t id, struct ndpi_flow_info *flow, u_int16_t threa
print_cipher(flow->ssh_tls.server_unsafe_cipher)); print_cipher(flow->ssh_tls.server_unsafe_cipher));
if(flow->ssh_tls.server_organization[0] != '\0') fprintf(out, "[Organization: %s]", flow->ssh_tls.server_organization); if(flow->ssh_tls.server_organization[0] != '\0') fprintf(out, "[Organization: %s]", flow->ssh_tls.server_organization);
if(flow->detected_protocol.master_protocol == NDPI_PROTOCOL_TLS) {
if((flow->ssh_tls.sha1_cert_fingerprint[0] == 0)
&& (flow->ssh_tls.sha1_cert_fingerprint[1] == 0)
&& (flow->ssh_tls.sha1_cert_fingerprint[2] == 0))
; /* Looks empty */
else {
fprintf(out, "[Certificate SHA-1: ");
for(i=0; i<20; i++)
fprintf(out, "%s%02X", (i > 0) ? ":" : "",
flow->ssh_tls.sha1_cert_fingerprint[i] & 0xFF);
fprintf(out, "]");
}
}
if(flow->ssh_tls.notBefore && flow->ssh_tls.notAfter) { if(flow->ssh_tls.notBefore && flow->ssh_tls.notAfter) {
char notBefore[32], notAfter[32]; char notBefore[32], notAfter[32];
struct tm a, b; struct tm a, b;
+2
View File
@@ -985,6 +985,8 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
flow->ndpi_flow->protos.stun_ssl.ssl.ja3_server); flow->ndpi_flow->protos.stun_ssl.ssl.ja3_server);
flow->ssh_tls.server_unsafe_cipher = flow->ndpi_flow->protos.stun_ssl.ssl.server_unsafe_cipher; flow->ssh_tls.server_unsafe_cipher = flow->ndpi_flow->protos.stun_ssl.ssl.server_unsafe_cipher;
flow->ssh_tls.server_cipher = flow->ndpi_flow->protos.stun_ssl.ssl.server_cipher; flow->ssh_tls.server_cipher = flow->ndpi_flow->protos.stun_ssl.ssl.server_cipher;
memcpy(flow->ssh_tls.sha1_cert_fingerprint,
flow->ndpi_flow->l4.tcp.tls_sha1_certificate_fingerprint, 20);
} }
} }
+2 -1
View File
@@ -161,7 +161,8 @@ typedef struct ndpi_flow_info {
char client_info[64], server_info[64], char client_info[64], server_info[64],
client_hassh[33], server_hassh[33], client_hassh[33], server_hassh[33],
server_organization[64], server_organization[64],
ja3_client[33], ja3_server[33]; ja3_client[33], ja3_server[33],
sha1_cert_fingerprint[20];
time_t notBefore, notAfter; time_t notBefore, notAfter;
u_int16_t server_cipher; u_int16_t server_cipher;
ndpi_cipher_weakness client_unsafe_cipher, server_unsafe_cipher; ndpi_cipher_weakness client_unsafe_cipher, server_unsafe_cipher;
+1
View File
@@ -612,6 +612,7 @@ struct ndpi_flow_tcp_struct {
tls_srv_cert_fingerprint_processed:1, tls_srv_cert_fingerprint_processed:1,
tls_stage:2, _pad:1; // 0 - 5 tls_stage:2, _pad:1; // 0 - 5
int16_t tls_record_offset, tls_fingerprint_len; /* Need to be signed */ int16_t tls_record_offset, tls_fingerprint_len; /* Need to be signed */
u_int8_t tls_sha1_certificate_fingerprint[20];
/* NDPI_PROTOCOL_POSTGRES */ /* NDPI_PROTOCOL_POSTGRES */
u_int32_t postgres_stage:3; u_int32_t postgres_stage:3;
+4
View File
@@ -6119,6 +6119,10 @@ void ndpi_free_flow(struct ndpi_flow_struct *flow) {
if(flow) { if(flow) {
if(flow->http.url) ndpi_free(flow->http.url); if(flow->http.url) ndpi_free(flow->http.url);
if(flow->http.content_type) ndpi_free(flow->http.content_type); if(flow->http.content_type) ndpi_free(flow->http.content_type);
if(flow->l4.tcp.tls_srv_cert_fingerprint_ctx)
ndpi_free(flow->l4.tcp.tls_srv_cert_fingerprint_ctx);
ndpi_free(flow); ndpi_free(flow);
} }
} }
+7 -4
View File
@@ -710,7 +710,6 @@ int getSSCertificateFingerprint(struct ndpi_detection_module_struct *ndpi_struct
return(0); /* We're good */ return(0); /* We're good */
if(flow->l4.tcp.tls_fingerprint_len > 0) { if(flow->l4.tcp.tls_fingerprint_len > 0) {
unsigned char sha1[20];
unsigned int i, avail = packet->payload_packet_len - flow->l4.tcp.tls_record_offset; unsigned int i, avail = packet->payload_packet_len - flow->l4.tcp.tls_record_offset;
if(avail > flow->l4.tcp.tls_fingerprint_len) if(avail > flow->l4.tcp.tls_fingerprint_len)
@@ -738,12 +737,12 @@ int getSSCertificateFingerprint(struct ndpi_detection_module_struct *ndpi_struct
flow->l4.tcp.tls_fingerprint_len -= avail; flow->l4.tcp.tls_fingerprint_len -= avail;
if(flow->l4.tcp.tls_fingerprint_len == 0) { if(flow->l4.tcp.tls_fingerprint_len == 0) {
SHA1Final(sha1, flow->l4.tcp.tls_srv_cert_fingerprint_ctx); SHA1Final(flow->l4.tcp.tls_sha1_certificate_fingerprint, flow->l4.tcp.tls_srv_cert_fingerprint_ctx);
#ifdef DEBUG_TLS #ifdef DEBUG_TLS
printf("=>> [TLS] SHA-1: "); printf("=>> [TLS] SHA-1: ");
for(i=0;i<20;i++) for(i=0;i<20;i++)
printf("%s%02X", (i > 0) ? ":" : "", sha1[i]); printf("%s%02X", (i > 0) ? ":" : "", flow->l4.tcp.tls_sha1_certificate_fingerprint[i]);
printf("\n"); printf("\n");
#endif #endif
@@ -772,7 +771,11 @@ int getSSCertificateFingerprint(struct ndpi_detection_module_struct *ndpi_struct
#ifdef DEBUG_TLS #ifdef DEBUG_TLS
printf("=>> [TLS] Certificate found\n"); printf("=>> [TLS] Certificate found\n");
#endif #endif
flow->l4.tcp.tls_srv_cert_fingerprint_ctx = (void*)ndpi_malloc(sizeof(SHA1_CTX));
if(flow->l4.tcp.tls_srv_cert_fingerprint_ctx == NULL)
flow->l4.tcp.tls_srv_cert_fingerprint_ctx = (void*)ndpi_malloc(sizeof(SHA1_CTX));
else
printf("[TLS] Internal error: double allocation\n:");
if(flow->l4.tcp.tls_srv_cert_fingerprint_ctx) { if(flow->l4.tcp.tls_srv_cert_fingerprint_ctx) {
SHA1Init(flow->l4.tcp.tls_srv_cert_fingerprint_ctx); SHA1Init(flow->l4.tcp.tls_srv_cert_fingerprint_ctx);