/*
* PDKIM - a RFC4871 (DKIM) implementation
*
- * Copyright (C) 2009 - 2012 Tom Kistner <tom@duncanthrax.net>
+ * Copyright (C) 2009 - 2015 Tom Kistner <tom@duncanthrax.net>
*
* http://duncanthrax.net/pdkim/
*
#include <ctype.h>
#include "pdkim.h"
+#include "pdkim-rsa.h"
-#include "sha1.h"
-#include "sha2.h"
-#include "rsa.h"
-#include "base64.h"
+#include "polarssl/sha1.h"
+#include "polarssl/sha2.h"
+#include "polarssl/rsa.h"
+#include "polarssl/base64.h"
#define PDKIM_SIGNATURE_VERSION "1"
#define PDKIM_PUB_RECORD_VERSION "DKIM1"
pdkim_strtrim(cur_val);
#ifdef PDKIM_DEBUG
if (ctx->debug_stream)
- fprintf(ctx->debug_stream, "%s=%s\n", cur_tag->str, cur_val->str);
+ fprintf(ctx->debug_stream, " %s=%s\n", cur_tag->str, cur_val->str);
#endif
switch (cur_tag->str[0]) {
case 'b':
default:
#ifdef PDKIM_DEBUG
if (ctx->debug_stream)
- fprintf(ctx->debug_stream, "Unknown tag encountered\n");
+ fprintf(ctx->debug_stream, " Unknown tag encountered\n");
#endif
break;
}
pdkim_strtrim(cur_val);
#ifdef PDKIM_DEBUG
if (ctx->debug_stream)
- fprintf(ctx->debug_stream, "%s=%s\n", cur_tag->str, cur_val->str);
+ fprintf(ctx->debug_stream, " %s=%s\n", cur_tag->str, cur_val->str);
#endif
switch (cur_tag->str[0]) {
case 'v':
default:
#ifdef PDKIM_DEBUG
if (ctx->debug_stream)
- fprintf(ctx->debug_stream, "Unknown tag encountered\n");
+ fprintf(ctx->debug_stream, " Unknown tag encountered\n");
#endif
break;
}
sig->signed_body_bytes += canon_len;
#ifdef PDKIM_DEBUG
if (ctx->debug_stream!=NULL)
- pdkim_quoteprint(ctx->debug_stream,canon_data,canon_len,0);
+ pdkim_quoteprint(ctx->debug_stream,canon_data,canon_len,1);
#endif
}
goto BAIL;
}
+ if ( ctx->sig
+ && ctx->sig->canon_body == PDKIM_CANON_RELAXED) {
+ /* Lines with just spaces need to be buffered too */
+ char *check = p;
+ while(memcmp(check,"\r\n",2) != 0) {
+ char c = *check;
+
+ if (c != '\t' && c != ' ')
+ goto PROCESS;
+ check++;
+ }
+
+ ctx->num_buffered_crlf++;
+ goto BAIL;
+ }
+
+ PROCESS:
/* At this point, we have a non-empty line, so release the buffered ones. */
while (ctx->num_buffered_crlf) {
pdkim_update_bodyhash(ctx,"\r\n",2);
ctx->cur_header->str);
if (list == NULL) return PDKIM_ERR_OOM;
sig->headers = list;
-
+
NEXT_SIG:
sig = sig->next;
}
*
* col: this int holds and receives column number (octets since last '\n')
* str: partial string to append to
- * pad: padding, split line or space after before or after eg: ";"
+ * pad: padding, split line or space after before or after eg: ";"
* intro: - must join to payload eg "h=", usually the tag name
* payload: eg base64 data - long data can be split arbitrarily.
*
* this code doesn't fold the header in some of the places that RFC4871
* allows: As per RFC5322(2.2.3) it only folds before or after tag-value
* pairs and inside long values. it also always spaces or breaks after the
- * "pad"
+ * "pad"
*
* no guarantees are made for output given out-of range input. like tag
* names loinger than 78, or bogus col. Input is assumed to be free of line breaks.
if (ctx->debug_stream) {
fprintf(ctx->debug_stream,
"PDKIM >> Parsing public key record >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
- fprintf(ctx->debug_stream,"Raw record: ");
+ fprintf(ctx->debug_stream," Raw record: ");
pdkim_quoteprint(ctx->debug_stream, dns_txt_reply, strlen(dns_txt_reply), 1);
}
#endif
sig->verify_ext_status = PDKIM_VERIFY_INVALID_PUBKEY_PARSING;
#ifdef PDKIM_DEBUG
if (ctx->debug_stream) {
- fprintf(ctx->debug_stream,"Error while parsing public key record\n");
+ fprintf(ctx->debug_stream," Error while parsing public key record\n");
fprintf(ctx->debug_stream,
"PDKIM <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
}