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 struct crypt_module_specs crypt_mod_SMIME_gpgme = {
31 smime_gpgme_decrypt_mime,
32 smime_gpgme_application_handler,
33 NULL, /* encrypted_handler */
35 smime_gpgme_sign_message,
36 smime_gpgme_verify_one,
37 smime_gpgme_send_menu,
39 NULL, /* pgp_encrypt_message */
40 NULL, /* pgp_make_key_attachment */
41 NULL, /* pgp_check_traditional */
42 NULL, /* pgp_traditional_encryptsign */
43 NULL, /* pgp_invoke_getkeys */
44 NULL, /* pgp_invoke_import */
45 NULL, /* pgp_extract_keys_from_attachment_list */
47 NULL, /* smime_getkeys */
48 smime_gpgme_verify_sender,
49 smime_gpgme_build_smime_entity,
50 NULL, /* smime_invoke_import */
53 struct crypt_module_specs crypt_mod_PGP_gpgme = {
55 pgp_gpgme_decrypt_mime,
56 pgp_gpgme_application_handler,
57 pgp_gpgme_encrypted_handler,
59 pgp_gpgme_sign_message,
64 pgp_gpgme_encrypt_message,
65 NULL, /* pgp_make_key_attachment, */
66 pgp_gpgme_check_traditional,
67 NULL, /* pgp_traditional_encryptsign */
68 NULL, /* pgp_invoke_getkeys */
69 pgp_gpgme_invoke_import, /* pgp_invoke_import */
70 pgp_gpgme_from_attachment_list,
71 /* pgp_extract_keys_from_attachment_list */
73 NULL, /* smime_getkeys */
74 NULL, /* smime_verify_sender */
75 NULL, /* smime_build_smime_entity */
76 NULL, /* smime_invoke_import */
79 void crypt_init (void)
81 (CRYPT_MOD_CALL(PGP, init))();
82 (CRYPT_MOD_CALL(SMIME, init))();
85 /* Show a message that a backend will be invoked. */
86 void crypt_invoke_message (int type)
88 if (type & APPLICATION_PGP) {
89 mutt_message _("Invoking PGP...");
91 else if (type & APPLICATION_SMIME) {
92 mutt_message _("Invoking S/MIME...");
99 /* Decrypt a PGP/MIME message. */
100 int crypt_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
102 if (CRYPT_MOD_CALL_CHECK (PGP, decrypt_mime))
103 return (CRYPT_MOD_CALL (PGP, decrypt_mime)) (a, b, c, d);
108 /* MIME handler for the application/pgp content-type. */
109 int crypt_pgp_application_pgp_handler (BODY * m, STATE * s)
111 if (CRYPT_MOD_CALL_CHECK (PGP, application_handler))
112 return (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
116 /* MIME handler for an PGP/MIME encrypted message. */
117 int crypt_pgp_encrypted_handler (BODY * a, STATE * s)
119 if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
120 return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
124 /* fixme: needs documentation. */
125 void crypt_pgp_invoke_getkeys (address_t * addr)
127 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys))
128 (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr);
131 /* Check for a traditional PGP message in body B. */
132 int crypt_pgp_check_traditional (FILE * fp, BODY * b, int tagged_only)
134 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_check_traditional))
135 return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, tagged_only);
140 /* fixme: needs documentation. */
141 BODY *crypt_pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
143 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_traditional_encryptsign))
144 return (CRYPT_MOD_CALL (PGP, pgp_traditional_encryptsign)) (a, flags,
150 /* Generate a PGP public key attachment. */
151 BODY *crypt_pgp_make_key_attachment (char *tempf)
153 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment))
154 return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf);
159 /* This routine attempts to find the keyids of the recipients of a
160 message. It returns NULL if any of the keys can not be found. */
161 char *crypt_pgp_findkeys (address_t * to, address_t * cc, address_t * bcc)
163 if (CRYPT_MOD_CALL_CHECK (PGP, findkeys))
164 return (CRYPT_MOD_CALL (PGP, findkeys)) (to, cc, bcc);
169 /* Create a new body with a PGP signed message from A. */
170 BODY *crypt_pgp_sign_message (BODY * a)
172 if (CRYPT_MOD_CALL_CHECK (PGP, sign_message))
173 return (CRYPT_MOD_CALL (PGP, sign_message)) (a);
178 /* Warning: A is no longer freed in this routine, you need to free it
179 later. This is necessary for $fcc_attach. */
180 BODY *crypt_pgp_encrypt_message (BODY * a, char *keylist, int sign)
182 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_encrypt_message))
183 return (CRYPT_MOD_CALL (PGP, pgp_encrypt_message)) (a, keylist, sign);
188 /* Invoke the PGP command to import a key. */
189 void crypt_pgp_invoke_import (const char *fname)
191 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_import))
192 (CRYPT_MOD_CALL (PGP, pgp_invoke_import)) (fname);
195 /* fixme: needs documentation */
196 int crypt_pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
198 if (CRYPT_MOD_CALL_CHECK (PGP, verify_one))
199 return (CRYPT_MOD_CALL (PGP, verify_one)) (sigbdy, s, tempf);
205 int crypt_pgp_send_menu (HEADER * msg, int *redraw)
207 if (CRYPT_MOD_CALL_CHECK (PGP, send_menu))
208 return (CRYPT_MOD_CALL (PGP, send_menu)) (msg, redraw);
214 /* fixme: needs documentation */
215 void crypt_pgp_extract_keys_from_attachment_list (FILE * fp, int tag,
218 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_extract_keys_from_attachment_list))
219 (CRYPT_MOD_CALL (PGP, pgp_extract_keys_from_attachment_list)) (fp, tag,
232 /* Decrypt am S/MIME message. */
233 int crypt_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
235 if (CRYPT_MOD_CALL_CHECK (SMIME, decrypt_mime))
236 return (CRYPT_MOD_CALL (SMIME, decrypt_mime)) (a, b, c, d);
241 /* MIME handler for the application/smime content-type. */
242 int crypt_smime_application_smime_handler (BODY * m, STATE * s)
244 if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler))
245 return (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
249 /* fixme: Needs documentation. */
250 void crypt_smime_getkeys (ENVELOPE * env)
252 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys))
253 (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env);
256 /* Check that the sender matches. */
257 int crypt_smime_verify_sender (HEADER * h)
259 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_verify_sender))
260 return (CRYPT_MOD_CALL (SMIME, smime_verify_sender)) (h);
265 /* This routine attempts to find the keyids of the recipients of a
266 message. It returns NULL if any of the keys can not be found. */
267 char *crypt_smime_findkeys (address_t * to, address_t * cc, address_t * bcc)
269 if (CRYPT_MOD_CALL_CHECK (SMIME, findkeys))
270 return (CRYPT_MOD_CALL (SMIME, findkeys)) (to, cc, bcc);
275 /* fixme: Needs documentation. */
276 BODY *crypt_smime_sign_message (BODY * a)
278 if (CRYPT_MOD_CALL_CHECK (SMIME, sign_message))
279 return (CRYPT_MOD_CALL (SMIME, sign_message)) (a);
284 /* fixme: needs documentation. */
285 BODY *crypt_smime_build_smime_entity (BODY * a, char *certlist)
287 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity))
288 return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist);
293 /* Add a certificate and update index file (externally). */
294 void crypt_smime_invoke_import (char *infile, char *mailbox)
296 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_invoke_import))
297 (CRYPT_MOD_CALL (SMIME, smime_invoke_import)) (infile, mailbox);
300 /* fixme: needs documentation */
301 int crypt_smime_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
303 if (CRYPT_MOD_CALL_CHECK (SMIME, verify_one))
304 return (CRYPT_MOD_CALL (SMIME, verify_one)) (sigbdy, s, tempf);
309 int crypt_smime_send_menu (HEADER * msg, int *redraw)
311 if (CRYPT_MOD_CALL_CHECK (SMIME, send_menu))
312 return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg, redraw);