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"
31 #include "crypt-mod.h"
39 #ifdef CRYPT_BACKEND_CLASSIC_PGP
40 extern struct crypt_module_specs crypt_mod_pgp_classic;
43 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
44 extern struct crypt_module_specs crypt_mod_smime_classic;
47 #ifdef CRYPT_BACKEND_GPGME
48 extern struct crypt_module_specs crypt_mod_pgp_gpgme;
49 extern struct crypt_module_specs crypt_mod_smime_gpgme;
52 void crypt_init (void)
54 #ifdef CRYPT_BACKEND_CLASSIC_PGP
56 #ifdef CRYPT_BACKEND_GPGME
57 (!option (OPTCRYPTUSEGPGME))
62 crypto_module_register (&crypt_mod_pgp_classic);
65 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
67 #ifdef CRYPT_BACKEND_GPGME
68 (!option (OPTCRYPTUSEGPGME))
73 crypto_module_register (&crypt_mod_smime_classic);
76 if (option (OPTCRYPTUSEGPGME)) {
77 #ifdef CRYPT_BACKEND_GPGME
78 crypto_module_register (&crypt_mod_pgp_gpgme);
79 crypto_module_register (&crypt_mod_smime_gpgme);
81 mutt_message (_("\"crypt_use_gpgme\" set"
82 " but not build with GPGME support."));
83 if (mutt_any_key_to_continue (NULL) == -1)
88 #if defined CRYPT_BACKEND_CLASSIG_PGP || defined CRYPT_BACKEND_CLASSIG_SMIME || defined CRYPT_BACKEND_GPGME
89 if (CRYPT_MOD_CALL_CHECK (PGP, init))
90 (CRYPT_MOD_CALL (PGP, init)) ();
92 if (CRYPT_MOD_CALL_CHECK (SMIME, init))
93 (CRYPT_MOD_CALL (SMIME, init)) ();
98 /* Show a message that a backend will be invoked. */
99 void crypt_invoke_message (int type)
101 if ((WithCrypto & APPLICATION_PGP) && (type & APPLICATION_PGP)) {
102 mutt_message _("Invoking PGP...");
104 else if ((WithCrypto & APPLICATION_SMIME) && (type & APPLICATION_SMIME)) {
105 mutt_message _("Invoking S/MIME...");
118 /* Reset a PGP passphrase */
119 void crypt_pgp_void_passphrase (void)
121 if (CRYPT_MOD_CALL_CHECK (PGP, void_passphrase))
122 (CRYPT_MOD_CALL (PGP, void_passphrase)) ();
125 int crypt_pgp_valid_passphrase (void)
127 if (CRYPT_MOD_CALL_CHECK (PGP, valid_passphrase))
128 return (CRYPT_MOD_CALL (PGP, valid_passphrase)) ();
134 /* Decrypt a PGP/MIME message. */
135 int crypt_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
137 if (CRYPT_MOD_CALL_CHECK (PGP, decrypt_mime))
138 return (CRYPT_MOD_CALL (PGP, decrypt_mime)) (a, b, c, d);
143 /* MIME handler for the application/pgp content-type. */
144 int crypt_pgp_application_pgp_handler (BODY * m, STATE * s)
146 if (CRYPT_MOD_CALL_CHECK (PGP, application_handler))
147 return (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
151 /* MIME handler for an PGP/MIME encrypted message. */
152 int crypt_pgp_encrypted_handler (BODY * a, STATE * s)
154 if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
155 return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
159 /* fixme: needs documentation. */
160 void crypt_pgp_invoke_getkeys (ADDRESS * addr)
162 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys))
163 (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr);
166 /* Check for a traditional PGP message in body B. */
167 int crypt_pgp_check_traditional (FILE * fp, BODY * b, int tagged_only)
169 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_check_traditional))
170 return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, tagged_only);
175 /* fixme: needs documentation. */
176 BODY *crypt_pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
178 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_traditional_encryptsign))
179 return (CRYPT_MOD_CALL (PGP, pgp_traditional_encryptsign)) (a, flags,
185 /* Generate a PGP public key attachment. */
186 BODY *crypt_pgp_make_key_attachment (char *tempf)
188 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment))
189 return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf);
194 /* This routine attempts to find the keyids of the recipients of a
195 message. It returns NULL if any of the keys can not be found. */
196 char *crypt_pgp_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc)
198 if (CRYPT_MOD_CALL_CHECK (PGP, findkeys))
199 return (CRYPT_MOD_CALL (PGP, findkeys)) (to, cc, bcc);
204 /* Create a new body with a PGP signed message from A. */
205 BODY *crypt_pgp_sign_message (BODY * a)
207 if (CRYPT_MOD_CALL_CHECK (PGP, sign_message))
208 return (CRYPT_MOD_CALL (PGP, sign_message)) (a);
213 /* Warning: A is no longer freed in this routine, you need to free it
214 later. This is necessary for $fcc_attach. */
215 BODY *crypt_pgp_encrypt_message (BODY * a, char *keylist, int sign)
217 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_encrypt_message))
218 return (CRYPT_MOD_CALL (PGP, pgp_encrypt_message)) (a, keylist, sign);
223 /* Invoke the PGP command to import a key. */
224 void crypt_pgp_invoke_import (const char *fname)
226 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_import))
227 (CRYPT_MOD_CALL (PGP, pgp_invoke_import)) (fname);
230 /* fixme: needs documentation */
231 int crypt_pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
233 if (CRYPT_MOD_CALL_CHECK (PGP, verify_one))
234 return (CRYPT_MOD_CALL (PGP, verify_one)) (sigbdy, s, tempf);
240 int crypt_pgp_send_menu (HEADER * msg, int *redraw)
242 if (CRYPT_MOD_CALL_CHECK (PGP, send_menu))
243 return (CRYPT_MOD_CALL (PGP, send_menu)) (msg, redraw);
249 /* fixme: needs documentation */
250 void crypt_pgp_extract_keys_from_attachment_list (FILE * fp, int tag,
253 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_extract_keys_from_attachment_list))
254 (CRYPT_MOD_CALL (PGP, pgp_extract_keys_from_attachment_list)) (fp, tag,
267 /* Reset an SMIME passphrase */
268 void crypt_smime_void_passphrase (void)
270 if (CRYPT_MOD_CALL_CHECK (SMIME, void_passphrase))
271 (CRYPT_MOD_CALL (SMIME, void_passphrase)) ();
274 int crypt_smime_valid_passphrase (void)
276 if (CRYPT_MOD_CALL_CHECK (SMIME, valid_passphrase))
277 return (CRYPT_MOD_CALL (SMIME, valid_passphrase)) ();
282 /* Decrypt am S/MIME message. */
283 int crypt_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
285 if (CRYPT_MOD_CALL_CHECK (SMIME, decrypt_mime))
286 return (CRYPT_MOD_CALL (SMIME, decrypt_mime)) (a, b, c, d);
291 /* MIME handler for the application/smime content-type. */
292 int crypt_smime_application_smime_handler (BODY * m, STATE * s)
294 if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler))
295 return (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
299 /* MIME handler for an PGP/MIME encrypted message. */
300 int crypt_smime_encrypted_handler (BODY * a, STATE * s)
302 if (CRYPT_MOD_CALL_CHECK (SMIME, encrypted_handler))
303 return (CRYPT_MOD_CALL (SMIME, encrypted_handler)) (a, s);
307 /* fixme: Needs documentation. */
308 void crypt_smime_getkeys (ENVELOPE * env)
310 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys))
311 (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env);
314 /* Check that the sender matches. */
315 int crypt_smime_verify_sender (HEADER * h)
317 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_verify_sender))
318 return (CRYPT_MOD_CALL (SMIME, smime_verify_sender)) (h);
323 /* This routine attempts to find the keyids of the recipients of a
324 message. It returns NULL if any of the keys can not be found. */
325 char *crypt_smime_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc)
327 if (CRYPT_MOD_CALL_CHECK (SMIME, findkeys))
328 return (CRYPT_MOD_CALL (SMIME, findkeys)) (to, cc, bcc);
333 /* fixme: Needs documentation. */
334 BODY *crypt_smime_sign_message (BODY * a)
336 if (CRYPT_MOD_CALL_CHECK (SMIME, sign_message))
337 return (CRYPT_MOD_CALL (SMIME, sign_message)) (a);
342 /* fixme: needs documentation. */
343 BODY *crypt_smime_build_smime_entity (BODY * a, char *certlist)
345 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity))
346 return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist);
351 /* Add a certificate and update index file (externally). */
352 void crypt_smime_invoke_import (char *infile, char *mailbox)
354 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_invoke_import))
355 (CRYPT_MOD_CALL (SMIME, smime_invoke_import)) (infile, mailbox);
358 /* fixme: needs documentation */
359 int crypt_smime_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
361 if (CRYPT_MOD_CALL_CHECK (SMIME, verify_one))
362 return (CRYPT_MOD_CALL (SMIME, verify_one)) (sigbdy, s, tempf);
367 int crypt_smime_send_menu (HEADER * msg, int *redraw)
369 if (CRYPT_MOD_CALL_CHECK (SMIME, send_menu))
370 return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg, redraw);