1 /* $Cambridge: exim/src/src/pdkim/pdkim.h,v 1.1.2.1 2009/02/24 13:13:47 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= */
110 /* Public key used to verify this signature.
111 (Verification only) */
114 /* Private RSA key used to create this signature */
117 /* Header field names to include in the signature,
118 colon separated. When NULL, the recommended defaults
119 from RFC 4871 are used. */
122 /* Per-signature helper variables */
123 sha1_context sha1_body;
124 sha2_context sha2_body;
125 unsigned long signed_body_bytes;
126 pdkim_stringlist *headers;
128 /* Verification specific */
131 /* Pointer to next signature in list.
132 (Always NULL for signing) */
138 /* -------------------------------------------------------------------------- */
139 /* Context to keep state between all operations */
141 #define PDKIM_MODE_SIGN 0
142 #define PDKIM_MODE_VERIFY 1
143 #define PDKIM_INPUT_NORMAL 0
144 #define PDKIM_INPUT_SMTP 1
146 typedef struct pdkim_ctx {
148 /* PDKIM_MODE_VERIFY or PDKIM_MODE_SIGN */
151 /* PDKIM_INPUT_SMTP or PDKIM_INPUT_NORMAL */
154 /* One (signing) or several chained (verification) signatures */
155 pdkim_signature *sig;
157 /* Coder's little helpers */
158 pdkim_str *cur_header;
159 char linebuf[PDKIM_MAX_BODY_LINE_LEN];
164 int num_buffered_crlf;
167 /* A FILE pointer. When not NULL, debug output will be generated
168 and sent to this stream */
175 int header_name_match (char *, char *);
176 char *pdkim_relax_header (char *, int);
178 int pdkim_update_bodyhash (pdkim_ctx *, char *, int);
179 int pdkim_finish_bodyhash (pdkim_ctx *);
181 int pdkim_bodyline_complete (pdkim_ctx *);
182 int pdkim_header_complete (pdkim_ctx *);
184 int pdkim_feed (pdkim_ctx *, char *data, int len);
185 int pdkim_feed_finish (pdkim_ctx *);
188 *pdkim_create_header (pdkim_ctx *, int);
191 *pdkim_init_sign (char *, char *, char *);
193 int pdkim_set_optional (pdkim_ctx *, char *, char *,
199 void pdkim_free_sig (pdkim_signature *);
200 void pdkim_free_ctx (pdkim_ctx *);
204 void pdkim_set_debug_stream (pdkim_ctx *, FILE *);