1 /* $Cambridge: exim/src/src/pdkim/pdkim.h,v 1.1.2.4 2009/02/27 17:04:20 tom Exp $ */
9 #define PDKIM_SIGNATURE_VERSION "1"
10 #define PDKIM_MAX_BODY_LINE_LEN 1024
12 #define PDKIM_DEFAULT_SIGN_HEADERS "From:Sender:Reply-To:Subject:Date:"\
13 "Message-ID:To:Cc:MIME-Version:Content-Type:"\
14 "Content-Transfer-Encoding:Content-ID:"\
15 "Content-Description:Resent-Date:Resent-From:"\
16 "Resent-Sender:Resent-To:Resent-Cc:"\
17 "Resent-Message-ID:In-Reply-To:References:"\
18 "List-Id:List-Help:List-Unsubscribe:"\
19 "List-Subscribe:List-Post:List-Owner:List-Archive"
22 /* Function success / error codes */
25 #define PDKIM_ERR_OOM -100
26 #define PDKIM_ERR_RSA_PRIVKEY -101
27 #define PDKIM_ERR_RSA_SIGNING -102
28 #define PDKIM_ERR_LONG_LINE -103
30 /* Main verification status */
31 #define PDKIM_VERIFY_NONE 0
32 #define PDKIM_VERIFY_INVALID 1
33 #define PDKIM_VERIFY_FAIL 2
34 #define PDKIM_VERIFY_PASS 3
36 /* Extended verification status */
37 #define PDKIM_VERIFY_FAIL_NONE 0
38 #define PDKIM_VERIFY_FAIL_BODY 1
39 #define PDKIM_VERIFY_FAIL_MESSAGE 2
48 void pdkim_quoteprint(FILE *, char *, int, int);
51 typedef struct pdkim_stringlist {
55 pdkim_stringlist *pdkim_append_stringlist(pdkim_stringlist *, char *);
58 #define PDKIM_STR_ALLOC_FRAG 256
59 typedef struct pdkim_str {
62 unsigned int allocated;
64 pdkim_str *pdkim_strnew (char *);
65 char *pdkim_strcat (pdkim_str *, char *);
66 char *pdkim_strncat(pdkim_str *, char *, int);
67 void pdkim_strfree(pdkim_str *);
69 #define PDKIM_QUERYMETHOD_DNS_TXT 0
70 /* extern char *pdkim_querymethods[]; */
72 #define PDKIM_ALGO_RSA_SHA256 0
73 #define PDKIM_ALGO_RSA_SHA1 1
74 /* extern char *pdkim_algos[]; */
76 #define PDKIM_CANON_SIMPLE 0
77 #define PDKIM_CANON_RELAXED 1
78 /* extern char *pdkim_canons[]; */
81 /* -------------------------------------------------------------------------- */
82 /* Public key as (usually) fetched from DNS */
83 typedef struct pdkim_pubkey {
84 char *version; /* v= */
85 char *granularity; /* g= */
88 int **hash_algos; /* h= */
96 int testing; /* t=y */
97 int no_subdomaining; /* t=s */
100 /* -------------------------------------------------------------------------- */
101 /* Signature as it appears in a DKIM-Signature header */
102 typedef struct pdkim_signature {
104 /* Bits stored in a DKIM signature header ------ */
105 int version; /* v= */
107 int canon_headers; /* c=x/ */
108 int canon_body; /* c=/x */
109 int querymethod; /* q= */
111 char *selector; /* s= */
112 char *domain; /* d= */
113 char *identity; /* i= */
115 unsigned long created; /* t= */
116 unsigned long expires; /* x= */
117 unsigned long bodylength; /* l= */
119 char *headernames; /* h= */
120 char *copiedheaders; /* z= */
122 char *sigdata; /* b= */
123 char *bodyhash; /* bh= */
128 /* Signing specific ---------------------------- */
129 char *rsa_privkey; /* Private RSA key */
130 char *sign_headers; /* To-be-signed header names */
132 /* Verification specific ----------------------- */
133 pdkim_pubkey pubkey; /* Public key used to verify this signature. */
134 int headernames_pos; /* Current position in header name list */
135 char *rawsig_no_b_val; /* Original signature header w/o b= tag value. */
136 void *next; /* Pointer to next signature in list. */
137 int verify_status; /* Verification result */
138 int verify_ext_status; /* Extended verification result */
140 /* Per-signature helper variables -------------- */
141 sha1_context sha1_body;
142 sha2_context sha2_body;
143 unsigned long signed_body_bytes;
144 pdkim_stringlist *headers;
148 /* -------------------------------------------------------------------------- */
149 /* Context to keep state between all operations */
151 #define PDKIM_MODE_SIGN 0
152 #define PDKIM_MODE_VERIFY 1
153 #define PDKIM_INPUT_NORMAL 0
154 #define PDKIM_INPUT_SMTP 1
156 typedef struct pdkim_ctx {
158 /* PDKIM_MODE_VERIFY or PDKIM_MODE_SIGN */
161 /* PDKIM_INPUT_SMTP or PDKIM_INPUT_NORMAL */
164 /* One (signing) or several chained (verification) signatures */
165 pdkim_signature *sig;
167 /* Coder's little helpers */
168 pdkim_str *cur_header;
169 char linebuf[PDKIM_MAX_BODY_LINE_LEN];
174 int num_buffered_crlf;
177 /* A FILE pointer. When not NULL, debug output will be generated
178 and sent to this stream */
185 int header_name_match (char *, char *, int);
186 char *pdkim_relax_header (char *, int);
188 int pdkim_update_bodyhash (pdkim_ctx *, char *, int);
189 int pdkim_finish_bodyhash (pdkim_ctx *);
191 int pdkim_bodyline_complete (pdkim_ctx *);
192 int pdkim_header_complete (pdkim_ctx *);
194 int pdkim_feed (pdkim_ctx *, char *, int);
195 int pdkim_feed_finish (pdkim_ctx *, char **);
197 char *pdkim_create_header (pdkim_signature *, int);
200 *pdkim_init_sign (char *, char *, char *);
203 *pdkim_init_verify (void);
205 int pdkim_set_optional (pdkim_ctx *,
213 void pdkim_free_sig (pdkim_signature *);
214 void pdkim_free_ctx (pdkim_ctx *);
218 void pdkim_set_debug_stream (pdkim_ctx *, FILE *);