2 * Copyright notice from original mutt:
3 * Copyright (C) 2003 Werner Koch <wk@gnupg.org>
4 * Copyright (C) 2004 g10 Code GmbH
6 * This file is part of mutt-ng, see http://www.muttng.org/.
7 * It's licensed under the GNU General Public License,
8 * please see the file GPL in the top level source directory.
12 This file dispatches the generic crypto functions to the
13 implemented backend or provides dummy stubs. Note, that some
14 generic functions are handled in crypt.c.
17 /* Note: This file has been changed to make use of the new module
18 system. Consequently there's a 1:1 mapping between the functions
19 contained in this file and the functions implemented by the crypto
26 #include <lib-lib/macros.h>
29 #include "mutt_crypt.h"
32 #include "crypt-mod.h"
40 #ifdef CRYPT_BACKEND_CLASSIC_PGP
41 extern struct crypt_module_specs crypt_mod_pgp_classic;
44 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
45 extern struct crypt_module_specs crypt_mod_smime_classic;
48 #ifdef CRYPT_BACKEND_GPGME
49 extern struct crypt_module_specs crypt_mod_pgp_gpgme;
50 extern struct crypt_module_specs crypt_mod_smime_gpgme;
53 void crypt_init (void)
55 #ifdef CRYPT_BACKEND_CLASSIC_PGP
57 #ifdef CRYPT_BACKEND_GPGME
58 (!option (OPTCRYPTUSEGPGME))
63 crypto_module_register (&crypt_mod_pgp_classic);
66 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
68 #ifdef CRYPT_BACKEND_GPGME
69 (!option (OPTCRYPTUSEGPGME))
74 crypto_module_register (&crypt_mod_smime_classic);
77 if (option (OPTCRYPTUSEGPGME)) {
78 #ifdef CRYPT_BACKEND_GPGME
79 crypto_module_register (&crypt_mod_pgp_gpgme);
80 crypto_module_register (&crypt_mod_smime_gpgme);
82 mutt_message (_("\"crypt_use_gpgme\" set"
83 " but not build with GPGME support."));
84 if (mutt_any_key_to_continue (NULL) == -1)
89 #if defined CRYPT_BACKEND_CLASSIG_PGP || defined CRYPT_BACKEND_CLASSIG_SMIME || defined CRYPT_BACKEND_GPGME
90 if (CRYPT_MOD_CALL_CHECK (PGP, init))
91 (CRYPT_MOD_CALL (PGP, init)) ();
93 if (CRYPT_MOD_CALL_CHECK (SMIME, init))
94 (CRYPT_MOD_CALL (SMIME, init)) ();
99 /* Show a message that a backend will be invoked. */
100 void crypt_invoke_message (int type)
102 if ((WithCrypto & APPLICATION_PGP) && (type & APPLICATION_PGP)) {
103 mutt_message _("Invoking PGP...");
105 else if ((WithCrypto & APPLICATION_SMIME) && (type & APPLICATION_SMIME)) {
106 mutt_message _("Invoking S/MIME...");
119 /* Reset a PGP passphrase */
120 void crypt_pgp_void_passphrase (void)
122 if (CRYPT_MOD_CALL_CHECK (PGP, void_passphrase))
123 (CRYPT_MOD_CALL (PGP, void_passphrase)) ();
126 int crypt_pgp_valid_passphrase (void)
128 if (CRYPT_MOD_CALL_CHECK (PGP, valid_passphrase))
129 return (CRYPT_MOD_CALL (PGP, valid_passphrase)) ();
135 /* Decrypt a PGP/MIME message. */
136 int crypt_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
138 if (CRYPT_MOD_CALL_CHECK (PGP, decrypt_mime))
139 return (CRYPT_MOD_CALL (PGP, decrypt_mime)) (a, b, c, d);
144 /* MIME handler for the application/pgp content-type. */
145 int crypt_pgp_application_pgp_handler (BODY * m, STATE * s)
147 if (CRYPT_MOD_CALL_CHECK (PGP, application_handler))
148 return (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
152 /* MIME handler for an PGP/MIME encrypted message. */
153 int crypt_pgp_encrypted_handler (BODY * a, STATE * s)
155 if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
156 return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
160 /* fixme: needs documentation. */
161 void crypt_pgp_invoke_getkeys (ADDRESS * addr)
163 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys))
164 (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr);
167 /* Check for a traditional PGP message in body B. */
168 int crypt_pgp_check_traditional (FILE * fp, BODY * b, int tagged_only)
170 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_check_traditional))
171 return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, tagged_only);
176 /* fixme: needs documentation. */
177 BODY *crypt_pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
179 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_traditional_encryptsign))
180 return (CRYPT_MOD_CALL (PGP, pgp_traditional_encryptsign)) (a, flags,
186 /* Generate a PGP public key attachment. */
187 BODY *crypt_pgp_make_key_attachment (char *tempf)
189 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment))
190 return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf);
195 /* This routine attempts to find the keyids of the recipients of a
196 message. It returns NULL if any of the keys can not be found. */
197 char *crypt_pgp_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc)
199 if (CRYPT_MOD_CALL_CHECK (PGP, findkeys))
200 return (CRYPT_MOD_CALL (PGP, findkeys)) (to, cc, bcc);
205 /* Create a new body with a PGP signed message from A. */
206 BODY *crypt_pgp_sign_message (BODY * a)
208 if (CRYPT_MOD_CALL_CHECK (PGP, sign_message))
209 return (CRYPT_MOD_CALL (PGP, sign_message)) (a);
214 /* Warning: A is no longer freed in this routine, you need to free it
215 later. This is necessary for $fcc_attach. */
216 BODY *crypt_pgp_encrypt_message (BODY * a, char *keylist, int sign)
218 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_encrypt_message))
219 return (CRYPT_MOD_CALL (PGP, pgp_encrypt_message)) (a, keylist, sign);
224 /* Invoke the PGP command to import a key. */
225 void crypt_pgp_invoke_import (const char *fname)
227 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_import))
228 (CRYPT_MOD_CALL (PGP, pgp_invoke_import)) (fname);
231 /* fixme: needs documentation */
232 int crypt_pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
234 if (CRYPT_MOD_CALL_CHECK (PGP, verify_one))
235 return (CRYPT_MOD_CALL (PGP, verify_one)) (sigbdy, s, tempf);
241 int crypt_pgp_send_menu (HEADER * msg, int *redraw)
243 if (CRYPT_MOD_CALL_CHECK (PGP, send_menu))
244 return (CRYPT_MOD_CALL (PGP, send_menu)) (msg, redraw);
250 /* fixme: needs documentation */
251 void crypt_pgp_extract_keys_from_attachment_list (FILE * fp, int tag,
254 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_extract_keys_from_attachment_list))
255 (CRYPT_MOD_CALL (PGP, pgp_extract_keys_from_attachment_list)) (fp, tag,
268 /* Reset an SMIME passphrase */
269 void crypt_smime_void_passphrase (void)
271 if (CRYPT_MOD_CALL_CHECK (SMIME, void_passphrase))
272 (CRYPT_MOD_CALL (SMIME, void_passphrase)) ();
275 int crypt_smime_valid_passphrase (void)
277 if (CRYPT_MOD_CALL_CHECK (SMIME, valid_passphrase))
278 return (CRYPT_MOD_CALL (SMIME, valid_passphrase)) ();
283 /* Decrypt am S/MIME message. */
284 int crypt_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
286 if (CRYPT_MOD_CALL_CHECK (SMIME, decrypt_mime))
287 return (CRYPT_MOD_CALL (SMIME, decrypt_mime)) (a, b, c, d);
292 /* MIME handler for the application/smime content-type. */
293 int crypt_smime_application_smime_handler (BODY * m, STATE * s)
295 if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler))
296 return (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
300 /* MIME handler for an PGP/MIME encrypted message. */
301 int crypt_smime_encrypted_handler (BODY * a, STATE * s)
303 if (CRYPT_MOD_CALL_CHECK (SMIME, encrypted_handler))
304 return (CRYPT_MOD_CALL (SMIME, encrypted_handler)) (a, s);
308 /* fixme: Needs documentation. */
309 void crypt_smime_getkeys (ENVELOPE * env)
311 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys))
312 (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env);
315 /* Check that the sender matches. */
316 int crypt_smime_verify_sender (HEADER * h)
318 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_verify_sender))
319 return (CRYPT_MOD_CALL (SMIME, smime_verify_sender)) (h);
324 /* This routine attempts to find the keyids of the recipients of a
325 message. It returns NULL if any of the keys can not be found. */
326 char *crypt_smime_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc)
328 if (CRYPT_MOD_CALL_CHECK (SMIME, findkeys))
329 return (CRYPT_MOD_CALL (SMIME, findkeys)) (to, cc, bcc);
334 /* fixme: Needs documentation. */
335 BODY *crypt_smime_sign_message (BODY * a)
337 if (CRYPT_MOD_CALL_CHECK (SMIME, sign_message))
338 return (CRYPT_MOD_CALL (SMIME, sign_message)) (a);
343 /* fixme: needs documentation. */
344 BODY *crypt_smime_build_smime_entity (BODY * a, char *certlist)
346 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity))
347 return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist);
352 /* Add a certificate and update index file (externally). */
353 void crypt_smime_invoke_import (char *infile, char *mailbox)
355 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_invoke_import))
356 (CRYPT_MOD_CALL (SMIME, smime_invoke_import)) (infile, mailbox);
359 /* fixme: needs documentation */
360 int crypt_smime_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
362 if (CRYPT_MOD_CALL_CHECK (SMIME, verify_one))
363 return (CRYPT_MOD_CALL (SMIME, verify_one)) (sigbdy, s, tempf);
368 int crypt_smime_send_menu (HEADER * msg, int *redraw)
370 if (CRYPT_MOD_CALL_CHECK (SMIME, send_menu))
371 return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg, redraw);