aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/dkim.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-07 13:36:07 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-07 13:36:07 +0100
commit67bca2f59cb0afeaf212fb82289f2b482f72a756 (patch)
tree1d9ae781e47a8182ced3accccdfaa063751761fd /src/libserver/dkim.c
parent362019a45e6f94756b6c40e9a336a7db88336c88 (diff)
downloadrspamd-67bca2f59cb0afeaf212fb82289f2b482f72a756.tar.gz
rspamd-67bca2f59cb0afeaf212fb82289f2b482f72a756.zip
[Fix] Fix start of body detection in DKIM
Diffstat (limited to 'src/libserver/dkim.c')
-rw-r--r--src/libserver/dkim.c52
1 files changed, 44 insertions, 8 deletions
diff --git a/src/libserver/dkim.c b/src/libserver/dkim.c
index cdad6365c..4d6fc6940 100644
--- a/src/libserver/dkim.c
+++ b/src/libserver/dkim.c
@@ -1878,6 +1878,44 @@ rspamd_dkim_canonize_header (struct rspamd_dkim_common_ctx *ctx,
return FALSE;
}
+static inline const gchar *
+rspamd_dkim_body_start (const gchar *headers_end, const gchar *body_end)
+{
+ const gchar *p = headers_end;
+ enum {
+ st_start = 0,
+ st_cr,
+ st_lf,
+ } state = st_start;
+
+ if (headers_end + 1 >= body_end) {
+ return headers_end;
+ }
+
+ switch (state) {
+ case st_start:
+ if (*p == '\r') {
+ p ++;
+ state = st_cr;
+ }
+ else if (*p == '\n') {
+ p ++;
+ state = st_lf;
+ }
+ break;
+ case st_cr:
+ if (*p == '\n' && p < body_end) {
+ /* CRLF */
+ p ++;
+ }
+ break;
+ case st_lf:
+ break;
+ }
+
+ return p;
+}
+
/**
* Check task for dkim context using dkim key
* @param ctx dkim verify context
@@ -1890,7 +1928,7 @@ rspamd_dkim_check (rspamd_dkim_context_t *ctx,
rspamd_dkim_key_t *key,
struct rspamd_task *task)
{
- const gchar *p, *headers_end = NULL, *body_end;
+ const gchar *p, *headers_end = NULL, *body_end, *body_start;
guchar raw_digest[EVP_MAX_MD_SIZE];
gsize dlen;
gint res = DKIM_CONTINUE;
@@ -1907,13 +1945,10 @@ rspamd_dkim_check (rspamd_dkim_context_t *ctx,
body_end = task->msg.begin + task->msg.len;
headers_end = task->msg.begin + task->raw_headers_content.len;
- while ((*headers_end == '\r' || *headers_end == '\n') &&
- headers_end < body_end) {
- headers_end ++;
- }
+ body_start = rspamd_dkim_body_start (headers_end, body_end);
/* Start canonization of body part */
- if (!rspamd_dkim_canonize_body (&ctx->common, headers_end, body_end)) {
+ if (!rspamd_dkim_canonize_body (&ctx->common, body_start, body_end)) {
return DKIM_RECORD_ERROR;
}
/* Now canonize headers */
@@ -2153,7 +2188,7 @@ rspamd_dkim_sign (struct rspamd_task *task,
{
GString *hdr;
struct rspamd_dkim_header *dh;
- const gchar *p, *headers_end = NULL, *body_end;
+ const gchar *p, *headers_end = NULL, *body_end, *body_start;
guchar raw_digest[EVP_MAX_MD_SIZE];
gsize dlen;
guint i, j;
@@ -2167,13 +2202,14 @@ rspamd_dkim_sign (struct rspamd_task *task,
p = task->msg.begin;
body_end = task->msg.begin + task->msg.len;
headers_end = task->msg.begin + task->raw_headers_content.len;
+ body_start = rspamd_dkim_body_start (headers_end, body_end);
if (len > 0) {
ctx->common.len = len;
}
/* Start canonization of body part */
- if (!rspamd_dkim_canonize_body (&ctx->common, headers_end, body_end)) {
+ if (!rspamd_dkim_canonize_body (&ctx->common, body_start, body_end)) {
return NULL;
}