Added pgp detection
Signed-off-by: Tyrolyean <tyrolyean@tyrolyean.net>
This commit is contained in:
parent
b6a46d7378
commit
2a6e7c9e5c
5 changed files with 42 additions and 6 deletions
|
@ -18,7 +18,10 @@
|
|||
#define CONFIG_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
extern uint16_t listen_port, forward_port;
|
||||
|
||||
extern bool abort_on_pgp, abort_on_dkim;
|
||||
|
||||
#endif /* CONFIG_H */
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#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 */
|
||||
|
|
15
src/attach.c
15
src/attach.c
|
@ -17,6 +17,9 @@
|
|||
*/
|
||||
|
||||
#include "attach.h"
|
||||
#include "detect.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -17,3 +17,4 @@
|
|||
#include "config.h"
|
||||
|
||||
uint16_t listen_port = 4269, forward_port = 4270;
|
||||
bool abort_on_pgp = true, abort_on_dkim = true;
|
||||
|
|
26
src/detect.c
26
src/detect.c
|
@ -15,14 +15,34 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
#include "detect.h"
|
||||
#include <stddef.h>
|
||||
#define _GNU_SOURCE
|
||||
#include <string.h>
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue