mutt stable branch with some hacks
1/*
2 * Copyright (C) 2003 Werner Koch <wk@gnupg.org>
3 * Copyright (C) 2004 g10 Code GmbH
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20/*
21 This file dispatches the generic crypto functions to the
22 implemented backend or provides dummy stubs. Note, that some
23 generic functions are handled in crypt.c.
24*/
25
26/* Note: This file has been changed to make use of the new module
27 system. Consequently there's a 1:1 mapping between the functions
28 contained in this file and the functions implemented by the crypto
29 modules. */
30
31#if HAVE_CONFIG_H
32# include "config.h"
33#endif
34
35#include "mutt.h"
36#include "mutt_crypt.h"
37
38#include "crypt-mod.h"
39
40/*
41
42 Generic
43
44*/
45
46#ifdef CRYPT_BACKEND_CLASSIC_PGP
47extern struct crypt_module_specs crypt_mod_pgp_classic;
48#endif
49
50#ifdef CRYPT_BACKEND_CLASSIC_SMIME
51extern struct crypt_module_specs crypt_mod_smime_classic;
52#endif
53
54#ifdef CRYPT_BACKEND_GPGME
55extern struct crypt_module_specs crypt_mod_pgp_gpgme;
56extern struct crypt_module_specs crypt_mod_smime_gpgme;
57#endif
58
59void crypt_init (void)
60{
61#ifdef CRYPT_BACKEND_CLASSIC_PGP
62 if (
63#ifdef CRYPT_BACKEND_GPGME
64 (! option (OPTCRYPTUSEGPGME))
65#else
66 1
67#endif
68 )
69 crypto_module_register (&crypt_mod_pgp_classic);
70#endif
71
72#ifdef CRYPT_BACKEND_CLASSIC_SMIME
73 if (
74#ifdef CRYPT_BACKEND_GPGME
75 (! option (OPTCRYPTUSEGPGME))
76#else
77 1
78#endif
79 )
80 crypto_module_register (&crypt_mod_smime_classic);
81#endif
82
83 if (option (OPTCRYPTUSEGPGME))
84 {
85#ifdef CRYPT_BACKEND_GPGME
86 crypto_module_register (&crypt_mod_pgp_gpgme);
87 crypto_module_register (&crypt_mod_smime_gpgme);
88#else
89 mutt_message (_("\"crypt_use_gpgme\" set"
90 " but not built with GPGME support."));
91 if (mutt_any_key_to_continue (NULL) == -1)
92 mutt_exit(1);
93#endif
94 }
95
96#if defined CRYPT_BACKEND_CLASSIC_PGP || defined CRYPT_BACKEND_CLASSIC_SMIME || defined CRYPT_BACKEND_GPGME
97 if (CRYPT_MOD_CALL_CHECK (PGP, init))
98 (CRYPT_MOD_CALL (PGP, init)) ();
99
100 if (CRYPT_MOD_CALL_CHECK (SMIME, init))
101 (CRYPT_MOD_CALL (SMIME, init)) ();
102#endif
103}
104
105
106/* Show a message that a backend will be invoked. */
107void crypt_invoke_message (int type)
108{
109 if ((WithCrypto & APPLICATION_PGP) && (type & APPLICATION_PGP))
110 mutt_message _("Invoking PGP...");
111 else if ((WithCrypto & APPLICATION_SMIME) && (type & APPLICATION_SMIME))
112 mutt_message _("Invoking S/MIME...");
113}
114
115
116
117/*
118
119 PGP
120
121*/
122
123
124/* Reset a PGP passphrase */
125void crypt_pgp_void_passphrase (void)
126{
127 if (CRYPT_MOD_CALL_CHECK (PGP, void_passphrase))
128 (CRYPT_MOD_CALL (PGP, void_passphrase)) ();
129}
130
131int crypt_pgp_valid_passphrase (void)
132{
133 if (CRYPT_MOD_CALL_CHECK (PGP, valid_passphrase))
134 return (CRYPT_MOD_CALL (PGP, valid_passphrase)) ();
135
136 return 0;
137}
138
139
140/* Decrypt a PGP/MIME message. */
141int crypt_pgp_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d)
142{
143 if (CRYPT_MOD_CALL_CHECK (PGP, decrypt_mime))
144 return (CRYPT_MOD_CALL (PGP, decrypt_mime)) (a, b, c, d);
145
146 return -1;
147}
148
149/* MIME handler for the application/pgp content-type. */
150int crypt_pgp_application_pgp_handler (BODY *m, STATE *s)
151{
152 if (CRYPT_MOD_CALL_CHECK (PGP, application_handler))
153 return (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
154
155 return -1;
156}
157
158/* MIME handler for an PGP/MIME encrypted message. */
159int crypt_pgp_encrypted_handler (BODY *a, STATE *s)
160{
161 if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
162 return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
163
164 return -1;
165}
166
167/* fixme: needs documentation. */
168void crypt_pgp_invoke_getkeys (ADDRESS *addr)
169{
170 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys))
171 (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr);
172}
173
174/* Check for a traditional PGP message in body B. */
175int crypt_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only)
176{
177 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_check_traditional))
178 return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, tagged_only);
179
180 return 0;
181}
182
183/* fixme: needs documentation. */
184BODY *crypt_pgp_traditional_encryptsign (BODY *a, int flags, char *keylist)
185{
186 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_traditional_encryptsign))
187 return (CRYPT_MOD_CALL (PGP, pgp_traditional_encryptsign)) (a, flags, keylist);
188
189 return NULL;
190}
191
192/* Generate a PGP public key attachment. */
193BODY *crypt_pgp_make_key_attachment (char *tempf)
194{
195 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment))
196 return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf);
197
198 return NULL;
199}
200
201/* This routine attempts to find the keyids of the recipients of a
202 message. It returns NULL if any of the keys can not be found.
203 If oppenc_mode is true, only keys that can be determined without
204 prompting will be used. */
205char *crypt_pgp_findkeys (ADDRESS *adrlist, int oppenc_mode)
206{
207 if (CRYPT_MOD_CALL_CHECK (PGP, findkeys))
208 return (CRYPT_MOD_CALL (PGP, findkeys)) (adrlist, oppenc_mode);
209
210 return NULL;
211}
212
213/* Create a new body with a PGP signed message from A. */
214BODY *crypt_pgp_sign_message (BODY *a)
215{
216 if (CRYPT_MOD_CALL_CHECK (PGP, sign_message))
217 return (CRYPT_MOD_CALL (PGP, sign_message)) (a);
218
219 return NULL;
220}
221
222/* Warning: A is no longer freed in this routine, you need to free it
223 later. This is necessary for $fcc_attach. */
224BODY *crypt_pgp_encrypt_message (BODY *a, char *keylist, int sign)
225{
226 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_encrypt_message))
227 return (CRYPT_MOD_CALL (PGP, pgp_encrypt_message)) (a, keylist, sign);
228
229 return NULL;
230}
231
232/* Invoke the PGP command to import a key. */
233void crypt_pgp_invoke_import (const char *fname)
234{
235 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_import))
236 (CRYPT_MOD_CALL (PGP, pgp_invoke_import)) (fname);
237}
238
239/* fixme: needs documentation */
240int crypt_pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempf)
241{
242 if (CRYPT_MOD_CALL_CHECK (PGP, verify_one))
243 return (CRYPT_MOD_CALL (PGP, verify_one)) (sigbdy, s, tempf);
244
245 return -1;
246}
247
248
249int crypt_pgp_send_menu (HEADER *msg, int *redraw)
250{
251 if (CRYPT_MOD_CALL_CHECK (PGP, send_menu))
252 return (CRYPT_MOD_CALL (PGP, send_menu)) (msg, redraw);
253
254 return 0;
255}
256
257
258/* fixme: needs documentation */
259void crypt_pgp_extract_keys_from_attachment_list (FILE *fp, int tag, BODY *top)
260{
261 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_extract_keys_from_attachment_list))
262 (CRYPT_MOD_CALL (PGP, pgp_extract_keys_from_attachment_list)) (fp, tag, top);
263}
264
265void crypt_pgp_set_sender (const char *sender)
266{
267 if (CRYPT_MOD_CALL_CHECK (PGP, set_sender))
268 (CRYPT_MOD_CALL (PGP, set_sender)) (sender);
269}
270
271
272
273
274/*
275
276 S/MIME
277
278*/
279
280
281/* Reset an SMIME passphrase */
282void crypt_smime_void_passphrase (void)
283{
284 if (CRYPT_MOD_CALL_CHECK (SMIME, void_passphrase))
285 (CRYPT_MOD_CALL (SMIME, void_passphrase)) ();
286}
287
288int crypt_smime_valid_passphrase (void)
289{
290 if (CRYPT_MOD_CALL_CHECK (SMIME, valid_passphrase))
291 return (CRYPT_MOD_CALL (SMIME, valid_passphrase)) ();
292
293 return 0;
294}
295
296/* Decrypt am S/MIME message. */
297int crypt_smime_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d)
298{
299 if (CRYPT_MOD_CALL_CHECK (SMIME, decrypt_mime))
300 return (CRYPT_MOD_CALL (SMIME, decrypt_mime)) (a, b, c, d);
301
302 return -1;
303}
304
305/* MIME handler for the application/smime content-type. */
306int crypt_smime_application_smime_handler (BODY *m, STATE *s)
307{
308 if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler))
309 return (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
310
311 return -1;
312}
313
314/* MIME handler for an PGP/MIME encrypted message. */
315void crypt_smime_encrypted_handler (BODY *a, STATE *s)
316{
317 if (CRYPT_MOD_CALL_CHECK (SMIME, encrypted_handler))
318 (CRYPT_MOD_CALL (SMIME, encrypted_handler)) (a, s);
319}
320
321/* fixme: Needs documentation. */
322void crypt_smime_getkeys (ENVELOPE *env)
323{
324 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys))
325 (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env);
326}
327
328/* Check that the sender matches. */
329int crypt_smime_verify_sender(HEADER *h)
330{
331 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_verify_sender))
332 return (CRYPT_MOD_CALL (SMIME, smime_verify_sender)) (h);
333
334 return 1;
335}
336
337/* This routine attempts to find the keyids of the recipients of a
338 message. It returns NULL if any of the keys can not be found.
339 If oppenc_mode is true, only keys that can be determined without
340 prompting will be used. */
341char *crypt_smime_findkeys (ADDRESS *adrlist, int oppenc_mode)
342{
343 if (CRYPT_MOD_CALL_CHECK (SMIME, findkeys))
344 return (CRYPT_MOD_CALL (SMIME, findkeys)) (adrlist, oppenc_mode);
345
346 return NULL;
347}
348
349/* fixme: Needs documentation. */
350BODY *crypt_smime_sign_message (BODY *a)
351{
352 if (CRYPT_MOD_CALL_CHECK (SMIME, sign_message))
353 return (CRYPT_MOD_CALL (SMIME, sign_message)) (a);
354
355 return NULL;
356}
357
358/* fixme: needs documentation. */
359BODY *crypt_smime_build_smime_entity (BODY *a, char *certlist)
360{
361 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity))
362 return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist);
363
364 return NULL;
365}
366
367/* Add a certificate and update index file (externally). */
368void crypt_smime_invoke_import (char *infile, char *mailbox)
369{
370 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_invoke_import))
371 (CRYPT_MOD_CALL (SMIME, smime_invoke_import)) (infile, mailbox);
372}
373
374/* fixme: needs documentation */
375int crypt_smime_verify_one (BODY *sigbdy, STATE *s, const char *tempf)
376{
377 if (CRYPT_MOD_CALL_CHECK (SMIME, verify_one))
378 return (CRYPT_MOD_CALL (SMIME, verify_one)) (sigbdy, s, tempf);
379
380 return -1;
381}
382
383int crypt_smime_send_menu (HEADER *msg, int *redraw)
384{
385 if (CRYPT_MOD_CALL_CHECK (SMIME, send_menu))
386 return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg, redraw);
387
388 return 0;
389}
390
391void crypt_smime_set_sender (const char *sender)
392{
393 if (CRYPT_MOD_CALL_CHECK (SMIME, set_sender))
394 (CRYPT_MOD_CALL (SMIME, set_sender)) (sender);
395}