2 * Copyright (C) 2003 Werner Koch <wk@gnupg.org>
3 * Copyright (C) 2004 g10 Code GmbH
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.
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.
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.
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.
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
36 #include "mutt_crypt.h"
38 #include "crypt-mod.h"
46 #ifdef CRYPT_BACKEND_CLASSIC_PGP
47 extern struct crypt_module_specs crypt_mod_pgp_classic;
50 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
51 extern struct crypt_module_specs crypt_mod_smime_classic;
54 #ifdef CRYPT_BACKEND_GPGME
55 extern struct crypt_module_specs crypt_mod_pgp_gpgme;
56 extern struct crypt_module_specs crypt_mod_smime_gpgme;
59 void crypt_init (void)
61 #ifdef CRYPT_BACKEND_CLASSIC_PGP
63 #ifdef CRYPT_BACKEND_GPGME
64 (! option (OPTCRYPTUSEGPGME))
69 crypto_module_register (&crypt_mod_pgp_classic);
72 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
74 #ifdef CRYPT_BACKEND_GPGME
75 (! option (OPTCRYPTUSEGPGME))
80 crypto_module_register (&crypt_mod_smime_classic);
83 if (option (OPTCRYPTUSEGPGME))
85 #ifdef CRYPT_BACKEND_GPGME
86 crypto_module_register (&crypt_mod_pgp_gpgme);
87 crypto_module_register (&crypt_mod_smime_gpgme);
89 mutt_message (_("\"crypt_use_gpgme\" set"
90 " but not built with GPGME support."));
91 if (mutt_any_key_to_continue (NULL) == -1)
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)) ();
100 if (CRYPT_MOD_CALL_CHECK (SMIME, init))
101 (CRYPT_MOD_CALL (SMIME, init)) ();
106 /* Show a message that a backend will be invoked. */
107 void crypt_invoke_message (int type)
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...");
124 /* Reset a PGP passphrase */
125 void crypt_pgp_void_passphrase (void)
127 if (CRYPT_MOD_CALL_CHECK (PGP, void_passphrase))
128 (CRYPT_MOD_CALL (PGP, void_passphrase)) ();
131 int crypt_pgp_valid_passphrase (void)
133 if (CRYPT_MOD_CALL_CHECK (PGP, valid_passphrase))
134 return (CRYPT_MOD_CALL (PGP, valid_passphrase)) ();
140 /* Decrypt a PGP/MIME message. */
141 int crypt_pgp_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d)
143 if (CRYPT_MOD_CALL_CHECK (PGP, decrypt_mime))
144 return (CRYPT_MOD_CALL (PGP, decrypt_mime)) (a, b, c, d);
149 /* MIME handler for the application/pgp content-type. */
150 int crypt_pgp_application_pgp_handler (BODY *m, STATE *s)
152 if (CRYPT_MOD_CALL_CHECK (PGP, application_handler))
153 return (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
158 /* MIME handler for an PGP/MIME encrypted message. */
159 int crypt_pgp_encrypted_handler (BODY *a, STATE *s)
161 if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
162 return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
167 /* fixme: needs documentation. */
168 void crypt_pgp_invoke_getkeys (ADDRESS *addr)
170 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys))
171 (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr);
174 /* Check for a traditional PGP message in body B. */
175 int crypt_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only)
177 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_check_traditional))
178 return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, tagged_only);
183 /* fixme: needs documentation. */
184 BODY *crypt_pgp_traditional_encryptsign (BODY *a, int flags, char *keylist)
186 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_traditional_encryptsign))
187 return (CRYPT_MOD_CALL (PGP, pgp_traditional_encryptsign)) (a, flags, keylist);
192 /* Generate a PGP public key attachment. */
193 BODY *crypt_pgp_make_key_attachment (char *tempf)
195 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment))
196 return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf);
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 char *crypt_pgp_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc)
205 if (CRYPT_MOD_CALL_CHECK (PGP, findkeys))
206 return (CRYPT_MOD_CALL (PGP, findkeys)) (to, cc, bcc);
211 /* Create a new body with a PGP signed message from A. */
212 BODY *crypt_pgp_sign_message (BODY *a)
214 if (CRYPT_MOD_CALL_CHECK (PGP, sign_message))
215 return (CRYPT_MOD_CALL (PGP, sign_message)) (a);
220 /* Warning: A is no longer freed in this routine, you need to free it
221 later. This is necessary for $fcc_attach. */
222 BODY *crypt_pgp_encrypt_message (BODY *a, char *keylist, int sign)
224 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_encrypt_message))
225 return (CRYPT_MOD_CALL (PGP, pgp_encrypt_message)) (a, keylist, sign);
230 /* Invoke the PGP command to import a key. */
231 void crypt_pgp_invoke_import (const char *fname)
233 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_import))
234 (CRYPT_MOD_CALL (PGP, pgp_invoke_import)) (fname);
237 /* fixme: needs documentation */
238 int crypt_pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempf)
240 if (CRYPT_MOD_CALL_CHECK (PGP, verify_one))
241 return (CRYPT_MOD_CALL (PGP, verify_one)) (sigbdy, s, tempf);
247 int crypt_pgp_send_menu (HEADER *msg, int *redraw)
249 if (CRYPT_MOD_CALL_CHECK (PGP, send_menu))
250 return (CRYPT_MOD_CALL (PGP, send_menu)) (msg, redraw);
256 /* fixme: needs documentation */
257 void crypt_pgp_extract_keys_from_attachment_list (FILE *fp, int tag, BODY *top)
259 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_extract_keys_from_attachment_list))
260 (CRYPT_MOD_CALL (PGP, pgp_extract_keys_from_attachment_list)) (fp, tag, top);
263 void crypt_pgp_set_sender (const char *sender)
265 if (CRYPT_MOD_CALL_CHECK (PGP, set_sender))
266 (CRYPT_MOD_CALL (PGP, set_sender)) (sender);
279 /* Reset an SMIME passphrase */
280 void crypt_smime_void_passphrase (void)
282 if (CRYPT_MOD_CALL_CHECK (SMIME, void_passphrase))
283 (CRYPT_MOD_CALL (SMIME, void_passphrase)) ();
286 int crypt_smime_valid_passphrase (void)
288 if (CRYPT_MOD_CALL_CHECK (SMIME, valid_passphrase))
289 return (CRYPT_MOD_CALL (SMIME, valid_passphrase)) ();
294 /* Decrypt am S/MIME message. */
295 int crypt_smime_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d)
297 if (CRYPT_MOD_CALL_CHECK (SMIME, decrypt_mime))
298 return (CRYPT_MOD_CALL (SMIME, decrypt_mime)) (a, b, c, d);
303 /* MIME handler for the application/smime content-type. */
304 int crypt_smime_application_smime_handler (BODY *m, STATE *s)
306 if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler))
307 return (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
312 /* MIME handler for an PGP/MIME encrypted message. */
313 void crypt_smime_encrypted_handler (BODY *a, STATE *s)
315 if (CRYPT_MOD_CALL_CHECK (SMIME, encrypted_handler))
316 (CRYPT_MOD_CALL (SMIME, encrypted_handler)) (a, s);
319 /* fixme: Needs documentation. */
320 void crypt_smime_getkeys (ENVELOPE *env)
322 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys))
323 (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env);
326 /* Check that the sender matches. */
327 int crypt_smime_verify_sender(HEADER *h)
329 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_verify_sender))
330 return (CRYPT_MOD_CALL (SMIME, smime_verify_sender)) (h);
335 /* This routine attempts to find the keyids of the recipients of a
336 message. It returns NULL if any of the keys can not be found. */
337 char *crypt_smime_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc)
339 if (CRYPT_MOD_CALL_CHECK (SMIME, findkeys))
340 return (CRYPT_MOD_CALL (SMIME, findkeys)) (to, cc, bcc);
345 /* fixme: Needs documentation. */
346 BODY *crypt_smime_sign_message (BODY *a)
348 if (CRYPT_MOD_CALL_CHECK (SMIME, sign_message))
349 return (CRYPT_MOD_CALL (SMIME, sign_message)) (a);
354 /* fixme: needs documentation. */
355 BODY *crypt_smime_build_smime_entity (BODY *a, char *certlist)
357 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity))
358 return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist);
363 /* Add a certificate and update index file (externally). */
364 void crypt_smime_invoke_import (char *infile, char *mailbox)
366 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_invoke_import))
367 (CRYPT_MOD_CALL (SMIME, smime_invoke_import)) (infile, mailbox);
370 /* fixme: needs documentation */
371 int crypt_smime_verify_one (BODY *sigbdy, STATE *s, const char *tempf)
373 if (CRYPT_MOD_CALL_CHECK (SMIME, verify_one))
374 return (CRYPT_MOD_CALL (SMIME, verify_one)) (sigbdy, s, tempf);
379 int crypt_smime_send_menu (HEADER *msg, int *redraw)
381 if (CRYPT_MOD_CALL_CHECK (SMIME, send_menu))
382 return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg, redraw);
387 void crypt_smime_set_sender (const char *sender)
389 if (CRYPT_MOD_CALL_CHECK (SMIME, set_sender))
390 (CRYPT_MOD_CALL (SMIME, set_sender)) (sender);