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"
27 #include "crypt-gpgme.h"
29 static struct crypt_module_specs crypt_mod_smime_gpgme = { APPLICATION_SMIME,
32 smime_gpgme_decrypt_mime,
33 smime_gpgme_application_handler,
34 NULL, /* encrypted_handler */
36 smime_gpgme_sign_message,
37 smime_gpgme_verify_one,
38 smime_gpgme_send_menu,
40 NULL, /* pgp_encrypt_message */
41 NULL, /* pgp_make_key_attachment */
42 NULL, /* pgp_check_traditional */
43 NULL, /* pgp_traditional_encryptsign */
44 NULL, /* pgp_invoke_getkeys */
45 NULL, /* pgp_invoke_import */
46 NULL, /* pgp_extract_keys_from_attachment_list */
48 NULL, /* smime_getkeys */
49 smime_gpgme_verify_sender,
50 smime_gpgme_build_smime_entity,
51 NULL, /* smime_invoke_import */
55 static struct crypt_module_specs crypt_mod_pgp_gpgme = { APPLICATION_PGP,
58 pgp_gpgme_decrypt_mime,
59 pgp_gpgme_application_handler,
60 pgp_gpgme_encrypted_handler,
62 pgp_gpgme_sign_message,
67 pgp_gpgme_encrypt_message,
68 NULL, /* pgp_make_key_attachment, */
69 pgp_gpgme_check_traditional,
70 NULL, /* pgp_traditional_encryptsign */
71 NULL, /* pgp_invoke_getkeys */
72 pgp_gpgme_invoke_import, /* pgp_invoke_import */
73 pgp_gpgme_from_attachment_list,
74 /* pgp_extract_keys_from_attachment_list */
76 NULL, /* smime_getkeys */
77 NULL, /* smime_verify_sender */
78 NULL, /* smime_build_smime_entity */
79 NULL, /* smime_invoke_import */
83 void crypt_init (void)
85 crypto_module_register (&crypt_mod_pgp_gpgme);
86 crypto_module_register (&crypt_mod_smime_gpgme);
88 (CRYPT_MOD_CALL(PGP, init))();
89 (CRYPT_MOD_CALL (SMIME, init)) ();
92 /* Show a message that a backend will be invoked. */
93 void crypt_invoke_message (int type)
95 if (type & APPLICATION_PGP) {
96 mutt_message _("Invoking PGP...");
98 else if (type & APPLICATION_SMIME) {
99 mutt_message _("Invoking S/MIME...");
111 /* Decrypt a PGP/MIME message. */
112 int crypt_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
114 if (CRYPT_MOD_CALL_CHECK (PGP, decrypt_mime))
115 return (CRYPT_MOD_CALL (PGP, decrypt_mime)) (a, b, c, d);
120 /* MIME handler for the application/pgp content-type. */
121 int crypt_pgp_application_pgp_handler (BODY * m, STATE * s)
123 if (CRYPT_MOD_CALL_CHECK (PGP, application_handler))
124 return (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
128 /* MIME handler for an PGP/MIME encrypted message. */
129 int crypt_pgp_encrypted_handler (BODY * a, STATE * s)
131 if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
132 return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
136 /* fixme: needs documentation. */
137 void crypt_pgp_invoke_getkeys (address_t * addr)
139 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys))
140 (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr);
143 /* Check for a traditional PGP message in body B. */
144 int crypt_pgp_check_traditional (FILE * fp, BODY * b, int tagged_only)
146 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_check_traditional))
147 return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, tagged_only);
152 /* fixme: needs documentation. */
153 BODY *crypt_pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
155 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_traditional_encryptsign))
156 return (CRYPT_MOD_CALL (PGP, pgp_traditional_encryptsign)) (a, flags,
162 /* Generate a PGP public key attachment. */
163 BODY *crypt_pgp_make_key_attachment (char *tempf)
165 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment))
166 return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf);
171 /* This routine attempts to find the keyids of the recipients of a
172 message. It returns NULL if any of the keys can not be found. */
173 char *crypt_pgp_findkeys (address_t * to, address_t * cc, address_t * bcc)
175 if (CRYPT_MOD_CALL_CHECK (PGP, findkeys))
176 return (CRYPT_MOD_CALL (PGP, findkeys)) (to, cc, bcc);
181 /* Create a new body with a PGP signed message from A. */
182 BODY *crypt_pgp_sign_message (BODY * a)
184 if (CRYPT_MOD_CALL_CHECK (PGP, sign_message))
185 return (CRYPT_MOD_CALL (PGP, sign_message)) (a);
190 /* Warning: A is no longer freed in this routine, you need to free it
191 later. This is necessary for $fcc_attach. */
192 BODY *crypt_pgp_encrypt_message (BODY * a, char *keylist, int sign)
194 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_encrypt_message))
195 return (CRYPT_MOD_CALL (PGP, pgp_encrypt_message)) (a, keylist, sign);
200 /* Invoke the PGP command to import a key. */
201 void crypt_pgp_invoke_import (const char *fname)
203 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_import))
204 (CRYPT_MOD_CALL (PGP, pgp_invoke_import)) (fname);
207 /* fixme: needs documentation */
208 int crypt_pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
210 if (CRYPT_MOD_CALL_CHECK (PGP, verify_one))
211 return (CRYPT_MOD_CALL (PGP, verify_one)) (sigbdy, s, tempf);
217 int crypt_pgp_send_menu (HEADER * msg, int *redraw)
219 if (CRYPT_MOD_CALL_CHECK (PGP, send_menu))
220 return (CRYPT_MOD_CALL (PGP, send_menu)) (msg, redraw);
226 /* fixme: needs documentation */
227 void crypt_pgp_extract_keys_from_attachment_list (FILE * fp, int tag,
230 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_extract_keys_from_attachment_list))
231 (CRYPT_MOD_CALL (PGP, pgp_extract_keys_from_attachment_list)) (fp, tag,
244 /* Decrypt am S/MIME message. */
245 int crypt_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
247 if (CRYPT_MOD_CALL_CHECK (SMIME, decrypt_mime))
248 return (CRYPT_MOD_CALL (SMIME, decrypt_mime)) (a, b, c, d);
253 /* MIME handler for the application/smime content-type. */
254 int crypt_smime_application_smime_handler (BODY * m, STATE * s)
256 if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler))
257 return (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
261 /* fixme: Needs documentation. */
262 void crypt_smime_getkeys (ENVELOPE * env)
264 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys))
265 (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env);
268 /* Check that the sender matches. */
269 int crypt_smime_verify_sender (HEADER * h)
271 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_verify_sender))
272 return (CRYPT_MOD_CALL (SMIME, smime_verify_sender)) (h);
277 /* This routine attempts to find the keyids of the recipients of a
278 message. It returns NULL if any of the keys can not be found. */
279 char *crypt_smime_findkeys (address_t * to, address_t * cc, address_t * bcc)
281 if (CRYPT_MOD_CALL_CHECK (SMIME, findkeys))
282 return (CRYPT_MOD_CALL (SMIME, findkeys)) (to, cc, bcc);
287 /* fixme: Needs documentation. */
288 BODY *crypt_smime_sign_message (BODY * a)
290 if (CRYPT_MOD_CALL_CHECK (SMIME, sign_message))
291 return (CRYPT_MOD_CALL (SMIME, sign_message)) (a);
296 /* fixme: needs documentation. */
297 BODY *crypt_smime_build_smime_entity (BODY * a, char *certlist)
299 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity))
300 return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist);
305 /* Add a certificate and update index file (externally). */
306 void crypt_smime_invoke_import (char *infile, char *mailbox)
308 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_invoke_import))
309 (CRYPT_MOD_CALL (SMIME, smime_invoke_import)) (infile, mailbox);
312 /* fixme: needs documentation */
313 int crypt_smime_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
315 if (CRYPT_MOD_CALL_CHECK (SMIME, verify_one))
316 return (CRYPT_MOD_CALL (SMIME, verify_one)) (sigbdy, s, tempf);
321 int crypt_smime_send_menu (HEADER * msg, int *redraw)
323 if (CRYPT_MOD_CALL_CHECK (SMIME, send_menu))
324 return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg, redraw);