Expansions: new ${authresults {mch}} for an Authentication-Results header
[exim.git] / src / src / pdkim / pdkim.h
index 067c574f2b0d67be307934400c970bb1210ffbd0..775581be75f3e5173da49dfb40c7c6f1d9ca87e3 100644 (file)
@@ -2,7 +2,7 @@
  *  PDKIM - a RFC4871 (DKIM) implementation
  *
  *  Copyright (C) 2009 - 2012  Tom Kistner <tom@duncanthrax.net>
- *  Copyright (c) 2016 - 2017  Jeremy Harris
+ *  Copyright (c) 2016 - 2018  Jeremy Harris
  *
  *  http://duncanthrax.net/pdkim/
  *
@@ -57,6 +57,7 @@
 #define PDKIM_VERIFY_INVALID   1
 #define PDKIM_VERIFY_FAIL      2
 #define PDKIM_VERIFY_PASS      3
+#define PDKIM_VERIFY_POLICY    BIT(31)
 
 #define PDKIM_VERIFY_FAIL_BODY                    1
 #define PDKIM_VERIFY_FAIL_MESSAGE                 2
 /* Some parameter values */
 #define PDKIM_QUERYMETHOD_DNS_TXT 0
 
+/*#define PDKIM_ALGO_RSA_SHA256     0 */
+/*#define PDKIM_ALGO_RSA_SHA1       1 */
+
 #define PDKIM_CANON_SIMPLE        0
 #define PDKIM_CANON_RELAXED       1
 
-/*XXX change to enums */
-#define PDKIM_HASH_SHA256         1
-
-#define PDKIM_KEYTYPE_RSA         0
-
 /* -------------------------------------------------------------------------- */
 /* Some required forward declarations, please ignore */
 typedef struct pdkim_stringlist pdkim_stringlist;
@@ -108,10 +107,8 @@ typedef struct pdkim_pubkey {
   const uschar *granularity;      /* g=  */
 
   const uschar * hashes;          /* h=  */
-#ifdef notdef
-  uschar *keytype;                /* k=  */
-#endif
-  const uschar *srvtype;          /* s=  */
+  const uschar * keytype;         /* k=  */
+  const uschar * srvtype;         /* s=  */
   uschar *notes;                  /* n=  */
 
   blob  key;                      /* p=  */
@@ -119,6 +116,21 @@ typedef struct pdkim_pubkey {
   int   no_subdomaining;          /* t=s */
 } pdkim_pubkey;
 
+/* -------------------------------------------------------------------------- */
+/* Body-hash to be calculated */
+typedef struct pdkim_bodyhash {
+  struct pdkim_bodyhash *      next;
+  int                          hashtype;
+  int                          canon_method;
+  long                         bodylength;
+
+  hctx                                 body_hash_ctx;
+  unsigned long                        signed_body_bytes;      /* done so far */
+  int                          num_buffered_blanklines;
+
+  blob                         bh;                     /* completed hash */
+} pdkim_bodyhash;
+
 /* -------------------------------------------------------------------------- */
 /* Signature as it appears in a DKIM-Signature header */
 typedef struct pdkim_signature {
@@ -129,7 +141,8 @@ typedef struct pdkim_signature {
   /* (v=) The version, as an integer. Currently, always "1" */
   int version;
 
-  int keytype; /* PDKIM_KEYTYPE_RSA */
+  /* (a=) The signature algorithm. Either PDKIM_ALGO_RSA_SHA256 */
+  int keytype; /* pdkim_keytypes index */
   int hashtype;        /* pdkim_hashes index */
 
   /* (c=x/) Header canonicalization method. Either PDKIM_CANON_SIMPLE
@@ -236,11 +249,9 @@ typedef struct pdkim_signature {
   /* Properties below this point are used internally only ------------- */
 
   /* Per-signature helper variables ----------------------------------- */
-  hctx         body_hash_ctx;
+  pdkim_bodyhash *calc_body_hash;      /* hash to be / being calculated */
 
-  unsigned long signed_body_bytes; /* How many body bytes we hashed     */
-  int num_buffered_blanklines;
-  pdkim_stringlist *headers; /* Raw headers included in the sig         */
+  pdkim_stringlist *headers;           /* Raw headers included in the sig */
 
   /* Signing specific ------------------------------------------------- */
   uschar * privkey;         /* Private key                                 */
@@ -264,8 +275,11 @@ typedef struct pdkim_ctx {
   /* One (signing) or several chained (verification) signatures */
   pdkim_signature *sig;
 
+  /* One (signing) or several chained (verification) bodyhashes */
+  pdkim_bodyhash *bodyhash;
+
   /* Callback for dns/txt query method (verification only) */
-  int(*dns_txt_callback)(char *, char *);
+  uschar * (*dns_txt_callback)(char *);
 
   /* Coder's little helpers */
   gstring   *cur_header;
@@ -287,7 +301,7 @@ extern "C" {
 
 void      pdkim_init         (void);
 
-void      pdkim_init_context (pdkim_ctx *, BOOL, int(*)(char *, char *));
+void      pdkim_init_context (pdkim_ctx *, BOOL, uschar * (*)(char *));
 
 DLLEXPORT
 pdkim_signature *pdkim_init_sign    (pdkim_ctx *,
@@ -295,7 +309,7 @@ pdkim_signature *pdkim_init_sign    (pdkim_ctx *,
                               const uschar **);
 
 DLLEXPORT
-pdkim_ctx *pdkim_init_verify  (int(*)(char *, char *), BOOL);
+pdkim_ctx *pdkim_init_verify  (uschar * (*)(char *), BOOL);
 
 DLLEXPORT
 void       pdkim_set_optional (pdkim_signature *, char *, char *,int, int,
@@ -303,6 +317,8 @@ void       pdkim_set_optional (pdkim_signature *, char *, char *,int, int,
                                unsigned long,
                                unsigned long);
 
+pdkim_bodyhash *pdkim_set_bodyhash(pdkim_ctx *, pdkim_signature *);
+
 DLLEXPORT
 int        pdkim_feed         (pdkim_ctx *, uschar *, int);
 DLLEXPORT