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
27 #include "mutt_crypt.h"
29 #include "crypt-mod.h"
37 #ifdef CRYPT_BACKEND_CLASSIC_PGP
38 extern struct crypt_module_specs crypt_mod_pgp_classic;
41 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
42 extern struct crypt_module_specs crypt_mod_smime_classic;
45 #ifdef CRYPT_BACKEND_GPGME
46 extern struct crypt_module_specs crypt_mod_pgp_gpgme;
47 extern struct crypt_module_specs crypt_mod_smime_gpgme;
50 void crypt_init (void)
52 #ifdef CRYPT_BACKEND_CLASSIC_PGP
54 #ifdef CRYPT_BACKEND_GPGME
55 (!option (OPTCRYPTUSEGPGME))
60 crypto_module_register (&crypt_mod_pgp_classic);
63 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
65 #ifdef CRYPT_BACKEND_GPGME
66 (!option (OPTCRYPTUSEGPGME))
71 crypto_module_register (&crypt_mod_smime_classic);
74 if (option (OPTCRYPTUSEGPGME)) {
75 #ifdef CRYPT_BACKEND_GPGME
76 crypto_module_register (&crypt_mod_pgp_gpgme);
77 crypto_module_register (&crypt_mod_smime_gpgme);
79 mutt_message (_("\"crypt_use_gpgme\" set"
80 " but not build with GPGME support."));
81 if (mutt_any_key_to_continue (NULL) == -1)
86 #if defined CRYPT_BACKEND_CLASSIG_PGP || defined CRYPT_BACKEND_CLASSIG_SMIME || defined CRYPT_BACKEND_GPGME
87 if (CRYPT_MOD_CALL_CHECK (PGP, init))
88 (CRYPT_MOD_CALL (PGP, init)) ();
90 if (CRYPT_MOD_CALL_CHECK (SMIME, init))
91 (CRYPT_MOD_CALL (SMIME, init)) ();
96 /* Show a message that a backend will be invoked. */
97 void crypt_invoke_message (int type)
99 if ((WithCrypto & APPLICATION_PGP) && (type & APPLICATION_PGP)) {
100 mutt_message _("Invoking PGP...");
102 else if ((WithCrypto & APPLICATION_SMIME) && (type & APPLICATION_SMIME)) {
103 mutt_message _("Invoking SMIME...");
116 /* Reset a PGP passphrase */
117 void crypt_pgp_void_passphrase (void)
119 if (CRYPT_MOD_CALL_CHECK (PGP, void_passphrase))
120 (CRYPT_MOD_CALL (PGP, void_passphrase)) ();
123 int crypt_pgp_valid_passphrase (void)
125 if (CRYPT_MOD_CALL_CHECK (PGP, valid_passphrase))
126 return (CRYPT_MOD_CALL (PGP, valid_passphrase)) ();
132 /* Decrypt a PGP/MIME message. */
133 int crypt_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
135 if (CRYPT_MOD_CALL_CHECK (PGP, decrypt_mime))
136 return (CRYPT_MOD_CALL (PGP, decrypt_mime)) (a, b, c, d);
141 /* MIME handler for the application/pgp content-type. */
142 void crypt_pgp_application_pgp_handler (BODY * m, STATE * s)
144 if (CRYPT_MOD_CALL_CHECK (PGP, application_handler))
145 (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
148 /* MIME handler for an PGP/MIME encrypted message. */
149 void crypt_pgp_encrypted_handler (BODY * a, STATE * s)
151 if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
152 (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
155 /* fixme: needs documentation. */
156 void crypt_pgp_invoke_getkeys (ADDRESS * addr)
158 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys))
159 (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr);
162 /* Check for a traditional PGP message in body B. */
163 int crypt_pgp_check_traditional (FILE * fp, BODY * b, int tagged_only)
165 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_check_traditional))
166 return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, tagged_only);
171 /* fixme: needs documentation. */
172 BODY *crypt_pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
174 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_traditional_encryptsign))
175 return (CRYPT_MOD_CALL (PGP, pgp_traditional_encryptsign)) (a, flags,
181 /* Generate a PGP public key attachment. */
182 BODY *crypt_pgp_make_key_attachment (char *tempf)
184 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment))
185 return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf);
190 /* This routine attempts to find the keyids of the recipients of a
191 message. It returns NULL if any of the keys can not be found. */
192 char *crypt_pgp_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc)
194 if (CRYPT_MOD_CALL_CHECK (PGP, findkeys))
195 return (CRYPT_MOD_CALL (PGP, findkeys)) (to, cc, bcc);
200 /* Create a new body with a PGP signed message from A. */
201 BODY *crypt_pgp_sign_message (BODY * a)
203 if (CRYPT_MOD_CALL_CHECK (PGP, sign_message))
204 return (CRYPT_MOD_CALL (PGP, sign_message)) (a);
209 /* Warning: A is no longer freed in this routine, you need to free it
210 later. This is necessary for $fcc_attach. */
211 BODY *crypt_pgp_encrypt_message (BODY * a, char *keylist, int sign)
213 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_encrypt_message))
214 return (CRYPT_MOD_CALL (PGP, pgp_encrypt_message)) (a, keylist, sign);
219 /* Invoke the PGP command to import a key. */
220 void crypt_pgp_invoke_import (const char *fname)
222 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_import))
223 (CRYPT_MOD_CALL (PGP, pgp_invoke_import)) (fname);
226 /* fixme: needs documentation */
227 int crypt_pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
229 if (CRYPT_MOD_CALL_CHECK (PGP, verify_one))
230 return (CRYPT_MOD_CALL (PGP, verify_one)) (sigbdy, s, tempf);
236 int crypt_pgp_send_menu (HEADER * msg, int *redraw)
238 if (CRYPT_MOD_CALL_CHECK (PGP, send_menu))
239 return (CRYPT_MOD_CALL (PGP, send_menu)) (msg, redraw);
245 /* fixme: needs documentation */
246 void crypt_pgp_extract_keys_from_attachment_list (FILE * fp, int tag,
249 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_extract_keys_from_attachment_list))
250 (CRYPT_MOD_CALL (PGP, pgp_extract_keys_from_attachment_list)) (fp, tag,
263 /* Reset an SMIME passphrase */
264 void crypt_smime_void_passphrase (void)
266 if (CRYPT_MOD_CALL_CHECK (SMIME, void_passphrase))
267 (CRYPT_MOD_CALL (SMIME, void_passphrase)) ();
270 int crypt_smime_valid_passphrase (void)
272 if (CRYPT_MOD_CALL_CHECK (SMIME, valid_passphrase))
273 return (CRYPT_MOD_CALL (SMIME, valid_passphrase)) ();
278 /* Decrypt am S/MIME message. */
279 int crypt_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
281 if (CRYPT_MOD_CALL_CHECK (SMIME, decrypt_mime))
282 return (CRYPT_MOD_CALL (SMIME, decrypt_mime)) (a, b, c, d);
287 /* MIME handler for the application/smime content-type. */
288 void crypt_smime_application_smime_handler (BODY * m, STATE * s)
290 if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler))
291 (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
294 /* MIME handler for an PGP/MIME encrypted message. */
295 void crypt_smime_encrypted_handler (BODY * a, STATE * s)
297 if (CRYPT_MOD_CALL_CHECK (SMIME, encrypted_handler))
298 (CRYPT_MOD_CALL (SMIME, encrypted_handler)) (a, s);
301 /* fixme: Needs documentation. */
302 void crypt_smime_getkeys (ENVELOPE * env)
304 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys))
305 (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env);
308 /* Check that the sender matches. */
309 int crypt_smime_verify_sender (HEADER * h)
311 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_verify_sender))
312 return (CRYPT_MOD_CALL (SMIME, smime_verify_sender)) (h);
317 /* This routine attempts to find the keyids of the recipients of a
318 message. It returns NULL if any of the keys can not be found. */
319 char *crypt_smime_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc)
321 if (CRYPT_MOD_CALL_CHECK (SMIME, findkeys))
322 return (CRYPT_MOD_CALL (SMIME, findkeys)) (to, cc, bcc);
327 /* fixme: Needs documentation. */
328 BODY *crypt_smime_sign_message (BODY * a)
330 if (CRYPT_MOD_CALL_CHECK (SMIME, sign_message))
331 return (CRYPT_MOD_CALL (SMIME, sign_message)) (a);
336 /* fixme: needs documentation. */
337 BODY *crypt_smime_build_smime_entity (BODY * a, char *certlist)
339 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity))
340 return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist);
345 /* Add a certificate and update index file (externally). */
346 void crypt_smime_invoke_import (char *infile, char *mailbox)
348 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_invoke_import))
349 (CRYPT_MOD_CALL (SMIME, smime_invoke_import)) (infile, mailbox);
352 /* fixme: needs documentation */
353 int crypt_smime_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
355 if (CRYPT_MOD_CALL_CHECK (SMIME, verify_one))
356 return (CRYPT_MOD_CALL (SMIME, verify_one)) (sigbdy, s, tempf);
361 int crypt_smime_send_menu (HEADER * msg, int *redraw)
363 if (CRYPT_MOD_CALL_CHECK (SMIME, send_menu))
364 return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg, redraw);