diff --git a/include/config.h b/include/config.h index a5f5a0f..b1aa220 100644 --- a/include/config.h +++ b/include/config.h @@ -18,7 +18,10 @@ #define CONFIG_H #include +#include extern uint16_t listen_port, forward_port; +extern bool abort_on_pgp, abort_on_dkim; + #endif /* CONFIG_H */ diff --git a/include/detect.h b/include/detect.h index 4d25556..c9b9f2b 100644 --- a/include/detect.h +++ b/include/detect.h @@ -20,8 +20,9 @@ #include #include +#include "attach.h" -bool detect_pgp(const char* message); +bool detect_pgp(struct email_t* mail); char* detect_start_of_body(char* message); char* detect_end_of_body(char* message); #endif /* DETECT_H */ diff --git a/src/attach.c b/src/attach.c index 144d7b0..4feedde 100644 --- a/src/attach.c +++ b/src/attach.c @@ -17,6 +17,9 @@ */ #include "attach.h" +#include "detect.h" +#include "config.h" + #include #include #include @@ -59,7 +62,7 @@ void redetect_body_head(struct email_t* mail){ */ if(body_start == NULL) { - fprintf(stderr, "Received message without header!"); + fprintf(stderr, "Received message without header!\n"); mail->header_len = 0; mail->body_offset = 0; return; @@ -72,6 +75,10 @@ void redetect_body_head(struct email_t* mail){ } +/* Message is required to be a null terminated string, length is the mail body. + * One may leave something behind the body. len is without the '\0' + * Attempts to replace files inside the email with links to it on a webserver + */ char* attach_files(char* message, size_t len){ struct email_t email = mail_from_text(message,len); @@ -82,7 +89,11 @@ char* attach_files(char* message, size_t len){ email.message_length-email.body_offset, email.message + email.body_offset); - /* Now we have a null terminated body which we can edit! */ + /* Check if mails are signed/encrypted, and abort if nescessary */ + if(abort_on_pgp && detect_pgp(&email)){ + printf("PGP detected, aborting..."); + return email.message; + } return email.message; } diff --git a/src/config.c b/src/config.c index fc16d3c..9056020 100644 --- a/src/config.c +++ b/src/config.c @@ -17,3 +17,4 @@ #include "config.h" uint16_t listen_port = 4269, forward_port = 4270; +bool abort_on_pgp = true, abort_on_dkim = true; diff --git a/src/detect.c b/src/detect.c index 59c585a..e32322a 100644 --- a/src/detect.c +++ b/src/detect.c @@ -15,14 +15,34 @@ * under the License. */ -#include "detect.h" #include #define _GNU_SOURCE #include -bool detect_pgp(const char* message){ +#include "detect.h" - return false; +char* pgp_signatures[] = +{ + "application/pgp-encrypted", + "application/pgp-signature", + "-----BEGIN PGP SIGNATURE-----", + "-----BEGIN PGP MESSAGE-----" +}; + +bool detect_pgp(struct email_t* mail){ + + size_t points = 0; + + for(size_t i = 0; i < (sizeof(pgp_signatures)/sizeof(char*));i++){ + if(strcasestr(mail->message, + pgp_signatures[i]) != NULL){ + points++; + } + + } + + + return points >= 2; } /* If body hasn't started yet, it returns NULL, if it has started, it returns