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_gpgme;
33 extern struct crypt_module_specs crypt_mod_smime_gpgme;
35 void crypt_init (void)
37 crypto_module_register (&crypt_mod_pgp_gpgme);
38 crypto_module_register (&crypt_mod_smime_gpgme);
40 (CRYPT_MOD_CALL(PGP, init))();
41 (CRYPT_MOD_CALL (SMIME, init)) ();
44 /* Show a message that a backend will be invoked. */
45 void crypt_invoke_message (int type)
47 if (type & APPLICATION_PGP) {
48 mutt_message _("Invoking PGP...");
50 else if (type & APPLICATION_SMIME) {
51 mutt_message _("Invoking S/MIME...");
63 /* Reset a PGP passphrase */
64 void crypt_pgp_void_passphrase (void)
66 if (CRYPT_MOD_CALL_CHECK (PGP, void_passphrase))
67 (CRYPT_MOD_CALL (PGP, void_passphrase)) ();
70 int crypt_pgp_valid_passphrase (void)
72 if (CRYPT_MOD_CALL_CHECK (PGP, valid_passphrase))
73 return (CRYPT_MOD_CALL (PGP, valid_passphrase)) ();
79 /* Decrypt a PGP/MIME message. */
80 int crypt_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
82 if (CRYPT_MOD_CALL_CHECK (PGP, decrypt_mime))
83 return (CRYPT_MOD_CALL (PGP, decrypt_mime)) (a, b, c, d);
88 /* MIME handler for the application/pgp content-type. */
89 int crypt_pgp_application_pgp_handler (BODY * m, STATE * s)
91 if (CRYPT_MOD_CALL_CHECK (PGP, application_handler))
92 return (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
96 /* MIME handler for an PGP/MIME encrypted message. */
97 int crypt_pgp_encrypted_handler (BODY * a, STATE * s)
99 if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
100 return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
104 /* fixme: needs documentation. */
105 void crypt_pgp_invoke_getkeys (address_t * addr)
107 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys))
108 (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr);
111 /* Check for a traditional PGP message in body B. */
112 int crypt_pgp_check_traditional (FILE * fp, BODY * b, int tagged_only)
114 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_check_traditional))
115 return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, tagged_only);
120 /* fixme: needs documentation. */
121 BODY *crypt_pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
123 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_traditional_encryptsign))
124 return (CRYPT_MOD_CALL (PGP, pgp_traditional_encryptsign)) (a, flags,
130 /* Generate a PGP public key attachment. */
131 BODY *crypt_pgp_make_key_attachment (char *tempf)
133 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment))
134 return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf);
139 /* This routine attempts to find the keyids of the recipients of a
140 message. It returns NULL if any of the keys can not be found. */
141 char *crypt_pgp_findkeys (address_t * to, address_t * cc, address_t * bcc)
143 if (CRYPT_MOD_CALL_CHECK (PGP, findkeys))
144 return (CRYPT_MOD_CALL (PGP, findkeys)) (to, cc, bcc);
149 /* Create a new body with a PGP signed message from A. */
150 BODY *crypt_pgp_sign_message (BODY * a)
152 if (CRYPT_MOD_CALL_CHECK (PGP, sign_message))
153 return (CRYPT_MOD_CALL (PGP, sign_message)) (a);
158 /* Warning: A is no longer freed in this routine, you need to free it
159 later. This is necessary for $fcc_attach. */
160 BODY *crypt_pgp_encrypt_message (BODY * a, char *keylist, int sign)
162 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_encrypt_message))
163 return (CRYPT_MOD_CALL (PGP, pgp_encrypt_message)) (a, keylist, sign);
168 /* Invoke the PGP command to import a key. */
169 void crypt_pgp_invoke_import (const char *fname)
171 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_import))
172 (CRYPT_MOD_CALL (PGP, pgp_invoke_import)) (fname);
175 /* fixme: needs documentation */
176 int crypt_pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
178 if (CRYPT_MOD_CALL_CHECK (PGP, verify_one))
179 return (CRYPT_MOD_CALL (PGP, verify_one)) (sigbdy, s, tempf);
185 int crypt_pgp_send_menu (HEADER * msg, int *redraw)
187 if (CRYPT_MOD_CALL_CHECK (PGP, send_menu))
188 return (CRYPT_MOD_CALL (PGP, send_menu)) (msg, redraw);
194 /* fixme: needs documentation */
195 void crypt_pgp_extract_keys_from_attachment_list (FILE * fp, int tag,
198 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_extract_keys_from_attachment_list))
199 (CRYPT_MOD_CALL (PGP, pgp_extract_keys_from_attachment_list)) (fp, tag,
212 /* Reset an SMIME passphrase */
213 void crypt_smime_void_passphrase (void)
215 if (CRYPT_MOD_CALL_CHECK (SMIME, void_passphrase))
216 (CRYPT_MOD_CALL (SMIME, void_passphrase)) ();
219 int crypt_smime_valid_passphrase (void)
221 if (CRYPT_MOD_CALL_CHECK (SMIME, valid_passphrase))
222 return (CRYPT_MOD_CALL (SMIME, valid_passphrase)) ();
227 /* Decrypt am S/MIME message. */
228 int crypt_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
230 if (CRYPT_MOD_CALL_CHECK (SMIME, decrypt_mime))
231 return (CRYPT_MOD_CALL (SMIME, decrypt_mime)) (a, b, c, d);
236 /* MIME handler for the application/smime content-type. */
237 int crypt_smime_application_smime_handler (BODY * m, STATE * s)
239 if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler))
240 return (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
244 /* fixme: Needs documentation. */
245 void crypt_smime_getkeys (ENVELOPE * env)
247 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys))
248 (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env);
251 /* Check that the sender matches. */
252 int crypt_smime_verify_sender (HEADER * h)
254 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_verify_sender))
255 return (CRYPT_MOD_CALL (SMIME, smime_verify_sender)) (h);
260 /* This routine attempts to find the keyids of the recipients of a
261 message. It returns NULL if any of the keys can not be found. */
262 char *crypt_smime_findkeys (address_t * to, address_t * cc, address_t * bcc)
264 if (CRYPT_MOD_CALL_CHECK (SMIME, findkeys))
265 return (CRYPT_MOD_CALL (SMIME, findkeys)) (to, cc, bcc);
270 /* fixme: Needs documentation. */
271 BODY *crypt_smime_sign_message (BODY * a)
273 if (CRYPT_MOD_CALL_CHECK (SMIME, sign_message))
274 return (CRYPT_MOD_CALL (SMIME, sign_message)) (a);
279 /* fixme: needs documentation. */
280 BODY *crypt_smime_build_smime_entity (BODY * a, char *certlist)
282 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity))
283 return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist);
288 /* Add a certificate and update index file (externally). */
289 void crypt_smime_invoke_import (char *infile, char *mailbox)
291 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_invoke_import))
292 (CRYPT_MOD_CALL (SMIME, smime_invoke_import)) (infile, mailbox);
295 /* fixme: needs documentation */
296 int crypt_smime_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
298 if (CRYPT_MOD_CALL_CHECK (SMIME, verify_one))
299 return (CRYPT_MOD_CALL (SMIME, verify_one)) (sigbdy, s, tempf);
304 int crypt_smime_send_menu (HEADER * msg, int *redraw)
306 if (CRYPT_MOD_CALL_CHECK (SMIME, send_menu))
307 return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg, redraw);