From: Vsevolod Stakhov Date: Thu, 21 Mar 2019 13:47:28 +0000 (+0000) Subject: [Fix] Try to fix double signing in the milter X-Git-Tag: 1.9.1~68 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a22e432387c6d62c41228eccac67e1085d5dee31;p=rspamd.git [Fix] Try to fix double signing in the milter Issue: #2810 --- diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index 23690f45a..34eaabe89 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -1233,38 +1233,56 @@ rspamd_protocol_write_ucl (struct rspamd_task *task, dkim_sigs = rspamd_mempool_get_variable (task->task_pool, RSPAMD_MEMPOOL_DKIM_SIGNATURE); - for (; dkim_sigs != NULL; dkim_sigs = dkim_sigs->next) { - GString *folded_header; - dkim_sig = (GString *) dkim_sigs->data; - if (task->flags & RSPAMD_TASK_FLAG_MILTER) { - folded_header = rspamd_header_value_fold ("DKIM-Signature", - dkim_sig->str, 80, RSPAMD_TASK_NEWLINES_LF, NULL); + if (dkim_sigs) { + if (dkim_sigs->next) { + /* Multiple DKIM signatures */ + ucl_object_t *ar = ucl_object_typed_new (UCL_ARRAY); + + for (; dkim_sigs != NULL; dkim_sigs = dkim_sigs->next) { + GString *folded_header; + dkim_sig = (GString *) dkim_sigs->data; + + if (task->flags & RSPAMD_TASK_FLAG_MILTER) { + folded_header = rspamd_header_value_fold ("DKIM-Signature", + dkim_sig->str, 80, RSPAMD_TASK_NEWLINES_LF, NULL); + } + else { + folded_header = rspamd_header_value_fold ("DKIM-Signature", + dkim_sig->str, 80, task->nlines_type, NULL); + } + + ucl_array_append (ar, + ucl_object_fromstring_common (folded_header->str, + folded_header->len, UCL_STRING_RAW)); + g_string_free (folded_header, TRUE); + } + + ucl_object_insert_key (top, + ar, + "dkim-signature", 0, + false); } else { - folded_header = rspamd_header_value_fold ("DKIM-Signature", - dkim_sig->str, 80, task->nlines_type, NULL); + /* Single DKIM signature */ + GString *folded_header; + dkim_sig = (GString *) dkim_sigs->data; + + if (task->flags & RSPAMD_TASK_FLAG_MILTER) { + folded_header = rspamd_header_value_fold ("DKIM-Signature", + dkim_sig->str, 80, RSPAMD_TASK_NEWLINES_LF, NULL); + } + else { + folded_header = rspamd_header_value_fold ("DKIM-Signature", + dkim_sig->str, 80, task->nlines_type, NULL); + } + + ucl_object_insert_key (top, + ucl_object_fromstring_common (folded_header->str, + folded_header->len, UCL_STRING_RAW), + "dkim-signature", 0, false); + g_string_free (folded_header, TRUE); } - /* - * According to milter docs, we need to be extra careful - * when folding headers: - * Neither the name nor the value of the header is checked for standards - * compliance. However, each line of the header must be under 2048 - * characters and should be under 998 characters. - * If longer headers are needed, make them multi-line. - * To make a multi-line header, insert a line feed (ASCII 0x0a, or \n - * in C) followed by at least one whitespace character such as a - * space (ASCII 0x20) or tab (ASCII 0x09, or \t in C). - * The line feed should NOT be preceded by a carriage return (ASCII 0x0d); - * the MTA will add this automatically. - * It is the filter writer's responsibility to ensure that no - * standards are violated. - */ - ucl_object_insert_key (top, - ucl_object_fromstring_common (folded_header->str, - folded_header->len, UCL_STRING_RAW), - "dkim-signature", 0, false); - g_string_free (folded_header, TRUE); } }