X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/a7bac71d85c678c2459d4ae27f25d10b8d898c34..184e88237dea64ce48076cdd0184612d057cbafd:/src/src/dk.c diff --git a/src/src/dk.c b/src/src/dk.c index dcaf58052..713684b2a 100644 --- a/src/src/dk.c +++ b/src/src/dk.c @@ -1,10 +1,10 @@ -/* $Cambridge: exim/src/src/dk.c,v 1.8 2005/09/01 08:39:03 tom Exp $ */ +/* $Cambridge: exim/src/src/dk.c,v 1.12 2007/01/08 10:50:18 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2005 */ +/* Copyright (c) University of Cambridge 1995 - 2007 */ /* See the file NOTICE for conditions of use and distribution. */ /* Code for DomainKeys support. Other DK relevant code is in @@ -239,8 +239,10 @@ uschar *dk_exim_sign(int dk_fd, uschar *dk_selector, uschar *dk_canon) { uschar *rc = NULL; + uschar *headers = NULL; + int headers_len; int dk_canon_int = DK_CANON_SIMPLE; - char c; + char buf[4096]; int seen_lf = 0; int seen_lfdot = 0; uschar sig[1024]; @@ -269,40 +271,46 @@ uschar *dk_exim_sign(int dk_fd, goto CLEANUP; } - while((sread = read(dk_fd,&c,1)) > 0) { + while((sread = read(dk_fd,&buf,4096)) > 0) { + int pos = 0; + char c; - if ((c == '.') && seen_lfdot) { - /* escaped dot, write "\n.", continue */ - dk_message(dk_context, CUS "\n.", 2); - seen_lf = 0; - seen_lfdot = 0; - continue; - } + while (pos < sread) { + c = buf[pos++]; - if (seen_lfdot) { - /* EOM, write "\n" and break */ - dk_message(dk_context, CUS "\n", 1); - break; - } + if ((c == '.') && seen_lfdot) { + /* escaped dot, write "\n.", continue */ + dk_message(dk_context, CUS "\n.", 2); + seen_lf = 0; + seen_lfdot = 0; + continue; + } - if ((c == '.') && seen_lf) { - seen_lfdot = 1; - continue; - } + if (seen_lfdot) { + /* EOM, write "\n" and break */ + dk_message(dk_context, CUS "\n", 1); + break; + } - if (seen_lf) { - /* normal lf, just send it */ - dk_message(dk_context, CUS "\n", 1); - seen_lf = 0; - } + if ((c == '.') && seen_lf) { + seen_lfdot = 1; + continue; + } - if (c == '\n') { - seen_lf = 1; - continue; - } + if (seen_lf) { + /* normal lf, just send it */ + dk_message(dk_context, CUS "\n", 1); + seen_lf = 0; + } - /* write the char */ - dk_message(dk_context, CUS &c, 1); + if (c == '\n') { + seen_lf = 1; + continue; + } + + /* write the char */ + dk_message(dk_context, CUS &c, 1); + } } /* Handle failed read above. */ @@ -398,7 +406,7 @@ uschar *dk_exim_sign(int dk_fd, } /* Get the signature. */ - dk_internal_status = dk_getsig(dk_context, dk_private_key, sig, 8192); + dk_internal_status = dk_getsig(dk_context, dk_private_key, sig, 1024); /* Check for unuseable key */ if (dk_internal_status != DK_STAT_OK) { @@ -407,13 +415,17 @@ uschar *dk_exim_sign(int dk_fd, goto CLEANUP; } - rc = store_get(1024); + headers_len = dk_headers(dk_context, NULL); + rc = store_get(1024+256+headers_len); + headers = store_malloc(headers_len); + dk_headers(dk_context, CS headers); /* Build DomainKey-Signature header to return. */ - (void)string_format(rc, 1024, "DomainKey-Signature: a=rsa-sha1; q=dns; c=%s;\r\n" - "\ts=%s; d=%s;\r\n" - "\tb=%s;\r\n", dk_canon, dk_selector, dk_domain, sig); + (void)string_format(rc, 1024+256+headers_len, "DomainKey-Signature: a=rsa-sha1; q=dns; c=%s; s=%s; d=%s;\r\n" + "\th=%s;\r\n" + "\tb=%s;\r\n", dk_canon, dk_selector, dk_domain, headers, sig); - log_write(0, LOG_MAIN, "DK: message signed using a=rsa-sha1; q=dns; c=%s; s=%s; d=%s;", dk_canon, dk_selector, dk_domain); + log_write(0, LOG_MAIN, "DK: message signed using a=rsa-sha1; q=dns; c=%s; s=%s; d=%s; h=%s;", dk_canon, dk_selector, dk_domain, headers); + store_free(headers); CLEANUP: if (dk_context != NULL) {