Added dkim detection

Signed-off-by: tyrolyean <tyrolyean@tyrolyean.net>
This commit is contained in:
tyrolyean 2020-04-28 23:43:09 +02:00
parent 80a42e7896
commit 1312510074
No known key found for this signature in database
GPG key ID: EDD105663B707C62
5 changed files with 31 additions and 6 deletions

View file

@ -23,6 +23,7 @@
#include "attach.h" #include "attach.h"
bool detect_pgp(struct email_t* mail); bool detect_pgp(struct email_t* mail);
bool detect_dkim(struct email_t* mail);
char* detect_start_of_body(char* message); char* detect_start_of_body(char* message);
char* detect_end_of_body(char* message); char* detect_end_of_body(char* message);
#endif /* DETECT_H */ #endif /* DETECT_H */

View file

@ -23,4 +23,5 @@
const char* insert_string(char * destination, const char* source, const char* insert_string(char * destination, const char* source,
size_t dest_orig_len, size_t offset); size_t dest_orig_len, size_t offset);
#endif /* TOOLS_H */ #endif /* TOOLS_H */

View file

@ -83,17 +83,16 @@ char* attach_files(char* message, size_t len){
struct email_t email = mail_from_text(message,len); struct email_t email = mail_from_text(message,len);
printf("Received message header: [%.*s]\n", email.header_len,
email.message);
printf("Received message body: [%.*s]\n",
email.message_length-email.body_offset,
email.message + email.body_offset);
/* Check if mails are signed/encrypted, and abort if nescessary */ /* Check if mails are signed/encrypted, and abort if nescessary */
if(abort_on_pgp && detect_pgp(&email)){ if(abort_on_pgp && detect_pgp(&email)){
printf("PGP detected, aborting..."); printf("PGP detected, aborting...");
return email.message; return email.message;
} }
/* Check if mails are signed/encrypted, and abort if nescessary */
if(abort_on_dkim && detect_dkim(&email)){
printf("DKIM signature detected, aborting...");
return email.message;
}
return email.message; return email.message;
} }

View file

@ -29,6 +29,11 @@ char* pgp_signatures[] =
"-----BEGIN PGP MESSAGE-----" "-----BEGIN PGP MESSAGE-----"
}; };
char* dkim_signatures[] =
{
"DKIM-Signature:"
};
bool detect_pgp(struct email_t* mail){ bool detect_pgp(struct email_t* mail){
size_t points = 0; size_t points = 0;
@ -45,6 +50,23 @@ bool detect_pgp(struct email_t* mail){
return points >= 2; return points >= 2;
} }
bool detect_dkim(struct email_t* mail){
size_t points = 0;
for(size_t i = 0; i < (sizeof(dkim_signatures)/sizeof(char*));i++){
if(strcasestr(mail->message, dkim_signatures[i]) != NULL
&& strcasestr(mail->message, dkim_signatures[i])
<= (mail->message+mail->header_len)){
points++;
}
}
return points >= 1;
}
/* If body hasn't started yet, it returns NULL, if it has started, it returns /* If body hasn't started yet, it returns NULL, if it has started, it returns
* the pointer to the beginning of the newline. * the pointer to the beginning of the newline.
*/ */

View file

@ -63,8 +63,10 @@ int main(int argc, char* argv[]){
printf("Incoming port: %u outgoing port: %u on loopback interface\n", printf("Incoming port: %u outgoing port: %u on loopback interface\n",
listen_port, forward_port); listen_port, forward_port);
printf("Ignoring PGP signed/encrypted messages: %s\n", printf("Ignoring PGP signed/encrypted messages: %s\n",
abort_on_pgp ? "true":false); abort_on_pgp ? "true":false);
printf("Ignoring DKIM signed messages: %s\n", printf("Ignoring DKIM signed messages: %s\n",
abort_on_dkim ? "true" : "false"); abort_on_dkim ? "true" : "false");