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
22 #include <lib-lib/lib-lib.h>
26 #include "crypt-mod.h"
32 extern struct crypt_module_specs crypt_mod_pgp_classic;
33 extern struct crypt_module_specs crypt_mod_smime_classic;
35 #ifdef CRYPT_BACKEND_GPGME
36 extern struct crypt_module_specs crypt_mod_pgp_gpgme;
37 extern struct crypt_module_specs crypt_mod_smime_gpgme;
40 void crypt_init (void)
43 #ifdef CRYPT_BACKEND_GPGME
44 (!option (OPTCRYPTUSEGPGME))
49 crypto_module_register (&crypt_mod_pgp_classic);
52 #ifdef CRYPT_BACKEND_GPGME
53 (!option (OPTCRYPTUSEGPGME))
58 crypto_module_register (&crypt_mod_smime_classic);
60 if (option (OPTCRYPTUSEGPGME)) {
61 #ifdef CRYPT_BACKEND_GPGME
62 crypto_module_register (&crypt_mod_pgp_gpgme);
63 crypto_module_register (&crypt_mod_smime_gpgme);
65 mutt_message (_("\"crypt_use_gpgme\" set"
66 " but not build with GPGME support."));
67 if (mutt_any_key_to_continue (NULL) == -1)
72 #if defined CRYPT_BACKEND_CLASSIG_PGP || defined CRYPT_BACKEND_CLASSIG_SMIME || defined CRYPT_BACKEND_GPGME
73 if (CRYPT_MOD_CALL_CHECK (PGP, init))
74 (CRYPT_MOD_CALL (PGP, init)) ();
76 if (CRYPT_MOD_CALL_CHECK (SMIME, init))
77 (CRYPT_MOD_CALL (SMIME, init)) ();
82 /* Show a message that a backend will be invoked. */
83 void crypt_invoke_message (int type)
85 if (type & APPLICATION_PGP) {
86 mutt_message _("Invoking PGP...");
88 else if (type & APPLICATION_SMIME) {
89 mutt_message _("Invoking S/MIME...");
102 /* Reset a PGP passphrase */
103 void crypt_pgp_void_passphrase (void)
105 if (CRYPT_MOD_CALL_CHECK (PGP, void_passphrase))
106 (CRYPT_MOD_CALL (PGP, void_passphrase)) ();
109 int crypt_pgp_valid_passphrase (void)
111 if (CRYPT_MOD_CALL_CHECK (PGP, valid_passphrase))
112 return (CRYPT_MOD_CALL (PGP, valid_passphrase)) ();
118 /* Decrypt a PGP/MIME message. */
119 int crypt_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
121 if (CRYPT_MOD_CALL_CHECK (PGP, decrypt_mime))
122 return (CRYPT_MOD_CALL (PGP, decrypt_mime)) (a, b, c, d);
127 /* MIME handler for the application/pgp content-type. */
128 int crypt_pgp_application_pgp_handler (BODY * m, STATE * s)
130 if (CRYPT_MOD_CALL_CHECK (PGP, application_handler))
131 return (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
135 /* MIME handler for an PGP/MIME encrypted message. */
136 int crypt_pgp_encrypted_handler (BODY * a, STATE * s)
138 if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
139 return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
143 /* fixme: needs documentation. */
144 void crypt_pgp_invoke_getkeys (address_t * addr)
146 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys))
147 (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr);
150 /* Check for a traditional PGP message in body B. */
151 int crypt_pgp_check_traditional (FILE * fp, BODY * b, int tagged_only)
153 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_check_traditional))
154 return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, tagged_only);
159 /* fixme: needs documentation. */
160 BODY *crypt_pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
162 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_traditional_encryptsign))
163 return (CRYPT_MOD_CALL (PGP, pgp_traditional_encryptsign)) (a, flags,
169 /* Generate a PGP public key attachment. */
170 BODY *crypt_pgp_make_key_attachment (char *tempf)
172 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment))
173 return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf);
178 /* This routine attempts to find the keyids of the recipients of a
179 message. It returns NULL if any of the keys can not be found. */
180 char *crypt_pgp_findkeys (address_t * to, address_t * cc, address_t * bcc)
182 if (CRYPT_MOD_CALL_CHECK (PGP, findkeys))
183 return (CRYPT_MOD_CALL (PGP, findkeys)) (to, cc, bcc);
188 /* Create a new body with a PGP signed message from A. */
189 BODY *crypt_pgp_sign_message (BODY * a)
191 if (CRYPT_MOD_CALL_CHECK (PGP, sign_message))
192 return (CRYPT_MOD_CALL (PGP, sign_message)) (a);
197 /* Warning: A is no longer freed in this routine, you need to free it
198 later. This is necessary for $fcc_attach. */
199 BODY *crypt_pgp_encrypt_message (BODY * a, char *keylist, int sign)
201 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_encrypt_message))
202 return (CRYPT_MOD_CALL (PGP, pgp_encrypt_message)) (a, keylist, sign);
207 /* Invoke the PGP command to import a key. */
208 void crypt_pgp_invoke_import (const char *fname)
210 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_import))
211 (CRYPT_MOD_CALL (PGP, pgp_invoke_import)) (fname);
214 /* fixme: needs documentation */
215 int crypt_pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
217 if (CRYPT_MOD_CALL_CHECK (PGP, verify_one))
218 return (CRYPT_MOD_CALL (PGP, verify_one)) (sigbdy, s, tempf);
224 int crypt_pgp_send_menu (HEADER * msg, int *redraw)
226 if (CRYPT_MOD_CALL_CHECK (PGP, send_menu))
227 return (CRYPT_MOD_CALL (PGP, send_menu)) (msg, redraw);
233 /* fixme: needs documentation */
234 void crypt_pgp_extract_keys_from_attachment_list (FILE * fp, int tag,
237 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_extract_keys_from_attachment_list))
238 (CRYPT_MOD_CALL (PGP, pgp_extract_keys_from_attachment_list)) (fp, tag,
251 /* Reset an SMIME passphrase */
252 void crypt_smime_void_passphrase (void)
254 if (CRYPT_MOD_CALL_CHECK (SMIME, void_passphrase))
255 (CRYPT_MOD_CALL (SMIME, void_passphrase)) ();
258 int crypt_smime_valid_passphrase (void)
260 if (CRYPT_MOD_CALL_CHECK (SMIME, valid_passphrase))
261 return (CRYPT_MOD_CALL (SMIME, valid_passphrase)) ();
266 /* Decrypt am S/MIME message. */
267 int crypt_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
269 if (CRYPT_MOD_CALL_CHECK (SMIME, decrypt_mime))
270 return (CRYPT_MOD_CALL (SMIME, decrypt_mime)) (a, b, c, d);
275 /* MIME handler for the application/smime content-type. */
276 int crypt_smime_application_smime_handler (BODY * m, STATE * s)
278 if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler))
279 return (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
283 /* fixme: Needs documentation. */
284 void crypt_smime_getkeys (ENVELOPE * env)
286 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys))
287 (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env);
290 /* Check that the sender matches. */
291 int crypt_smime_verify_sender (HEADER * h)
293 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_verify_sender))
294 return (CRYPT_MOD_CALL (SMIME, smime_verify_sender)) (h);
299 /* This routine attempts to find the keyids of the recipients of a
300 message. It returns NULL if any of the keys can not be found. */
301 char *crypt_smime_findkeys (address_t * to, address_t * cc, address_t * bcc)
303 if (CRYPT_MOD_CALL_CHECK (SMIME, findkeys))
304 return (CRYPT_MOD_CALL (SMIME, findkeys)) (to, cc, bcc);
309 /* fixme: Needs documentation. */
310 BODY *crypt_smime_sign_message (BODY * a)
312 if (CRYPT_MOD_CALL_CHECK (SMIME, sign_message))
313 return (CRYPT_MOD_CALL (SMIME, sign_message)) (a);
318 /* fixme: needs documentation. */
319 BODY *crypt_smime_build_smime_entity (BODY * a, char *certlist)
321 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity))
322 return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist);
327 /* Add a certificate and update index file (externally). */
328 void crypt_smime_invoke_import (char *infile, char *mailbox)
330 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_invoke_import))
331 (CRYPT_MOD_CALL (SMIME, smime_invoke_import)) (infile, mailbox);
334 /* fixme: needs documentation */
335 int crypt_smime_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
337 if (CRYPT_MOD_CALL_CHECK (SMIME, verify_one))
338 return (CRYPT_MOD_CALL (SMIME, verify_one)) (sigbdy, s, tempf);
343 int crypt_smime_send_menu (HEADER * msg, int *redraw)
345 if (CRYPT_MOD_CALL_CHECK (SMIME, send_menu))
346 return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg, redraw);