1 /* $Cambridge: exim/src/src/pdkim/pdkim.h,v 1.1.2.3 2009/02/26 16:07:36 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 /* 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
32 void pdkim_quoteprint(FILE *, char *, int, int);
36 typedef struct pdkim_stringlist {
40 pdkim_stringlist *pdkim_append_stringlist(pdkim_stringlist *, char *);
43 #define PDKIM_STR_ALLOC_FRAG 256
44 typedef struct pdkim_str {
47 unsigned int allocated;
49 pdkim_str *pdkim_strnew (char *);
50 char *pdkim_strcat (pdkim_str *, char *);
51 char *pdkim_strncat(pdkim_str *, char *, int);
52 void pdkim_strfree(pdkim_str *);
54 #define PDKIM_QUERYMETHOD_DNS_TXT 0
55 /* extern char *pdkim_querymethods[]; */
57 #define PDKIM_ALGO_RSA_SHA256 0
58 #define PDKIM_ALGO_RSA_SHA1 1
59 /* extern char *pdkim_algos[]; */
61 #define PDKIM_CANON_SIMPLE 0
62 #define PDKIM_CANON_RELAXED 1
63 /* extern char *pdkim_canons[]; */
66 /* -------------------------------------------------------------------------- */
67 /* Public key as (usually) fetched from DNS */
68 typedef struct pdkim_pubkey {
69 char *version; /* v= */
70 char *granularity; /* g= */
73 int **hash_algos; /* h= */
81 int testing; /* t=y */
82 int no_subdomaining; /* t=s */
85 /* -------------------------------------------------------------------------- */
86 /* Signature as it appears in a DKIM-Signature header */
87 typedef struct pdkim_signature {
89 /* Bits stored in a DKIM signature header ------ */
92 int canon_headers; /* c=x/ */
93 int canon_body; /* c=/x */
94 int querymethod; /* q= */
96 char *sigdata; /* b= */
97 char *bodyhash; /* bh= */
99 char *selector; /* s= */
100 char *domain; /* d= */
101 char *identity; /* i= */
103 unsigned long created; /* t= */
104 unsigned long expires; /* x= */
105 unsigned long bodylength; /* l= */
107 char *headernames; /* h= */
108 char *copiedheaders; /* z= */
111 /* Signing specific ---------------------------- */
112 char *rsa_privkey; /* Private RSA key */
113 char *sign_headers; /* To-be-signed header names */
115 /* Verification specific ----------------------- */
116 pdkim_pubkey pubkey; /* Public key used to verify this signature. */
117 int verify_result; /* Verification result */
118 char *rawsig_no_b_val; /* Original signature header w/o b= tag value. */
119 void *next; /* Pointer to next signature in list. */
121 /* Per-signature helper variables -------------- */
122 sha1_context sha1_body;
123 sha2_context sha2_body;
124 unsigned long signed_body_bytes;
125 pdkim_stringlist *headers;
129 /* -------------------------------------------------------------------------- */
130 /* Context to keep state between all operations */
132 #define PDKIM_MODE_SIGN 0
133 #define PDKIM_MODE_VERIFY 1
134 #define PDKIM_INPUT_NORMAL 0
135 #define PDKIM_INPUT_SMTP 1
137 typedef struct pdkim_ctx {
139 /* PDKIM_MODE_VERIFY or PDKIM_MODE_SIGN */
142 /* PDKIM_INPUT_SMTP or PDKIM_INPUT_NORMAL */
145 /* One (signing) or several chained (verification) signatures */
146 pdkim_signature *sig;
148 /* Coder's little helpers */
149 pdkim_str *cur_header;
150 char linebuf[PDKIM_MAX_BODY_LINE_LEN];
155 int num_buffered_crlf;
158 /* A FILE pointer. When not NULL, debug output will be generated
159 and sent to this stream */
166 int header_name_match (char *, char *);
167 char *pdkim_relax_header (char *, int);
169 int pdkim_update_bodyhash (pdkim_ctx *, char *, int);
170 int pdkim_finish_bodyhash (pdkim_ctx *);
172 int pdkim_bodyline_complete (pdkim_ctx *);
173 int pdkim_header_complete (pdkim_ctx *);
175 int pdkim_feed (pdkim_ctx *, char *, int);
176 int pdkim_feed_finish (pdkim_ctx *, char **);
179 *pdkim_create_header (pdkim_signature *, int);
182 *pdkim_init_sign (char *, char *, char *);
185 *pdkim_init_verify (void);
187 int pdkim_set_optional (pdkim_ctx *,
195 void pdkim_free_sig (pdkim_signature *);
196 void pdkim_free_ctx (pdkim_ctx *);
200 void pdkim_set_debug_stream (pdkim_ctx *, FILE *);