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-gpgme.h"
28 struct crypt_module_specs crypt_mod_SMIME_gpgme = {
30 smime_gpgme_decrypt_mime,
31 smime_gpgme_application_handler,
32 NULL, /* encrypted_handler */
34 smime_gpgme_sign_message,
35 smime_gpgme_verify_one,
36 smime_gpgme_send_menu,
38 NULL, /* pgp_encrypt_message */
39 NULL, /* pgp_make_key_attachment */
40 NULL, /* pgp_check_traditional */
41 NULL, /* pgp_traditional_encryptsign */
42 NULL, /* pgp_invoke_getkeys */
43 NULL, /* pgp_invoke_import */
44 NULL, /* pgp_extract_keys_from_attachment_list */
46 NULL, /* smime_getkeys */
47 smime_gpgme_verify_sender,
48 smime_gpgme_build_smime_entity,
49 NULL, /* smime_invoke_import */
52 struct crypt_module_specs crypt_mod_PGP_gpgme = {
54 pgp_gpgme_decrypt_mime,
55 pgp_gpgme_application_handler,
56 pgp_gpgme_encrypted_handler,
58 pgp_gpgme_sign_message,
63 pgp_gpgme_encrypt_message,
64 NULL, /* pgp_make_key_attachment, */
65 pgp_gpgme_check_traditional,
66 NULL, /* pgp_traditional_encryptsign */
67 NULL, /* pgp_invoke_getkeys */
68 pgp_gpgme_invoke_import, /* pgp_invoke_import */
69 pgp_gpgme_from_attachment_list,
70 /* pgp_extract_keys_from_attachment_list */
72 NULL, /* smime_getkeys */
73 NULL, /* smime_verify_sender */
74 NULL, /* smime_build_smime_entity */
75 NULL, /* smime_invoke_import */
78 void crypt_init (void)
80 (CRYPT_MOD_CALL(PGP, init))();
81 (CRYPT_MOD_CALL(SMIME, init))();
84 /* Show a message that a backend will be invoked. */
85 void crypt_invoke_message (int type)
87 if (type & APPLICATION_PGP) {
88 mutt_message _("Invoking PGP...");
90 else if (type & APPLICATION_SMIME) {
91 mutt_message _("Invoking S/MIME...");
98 /* Decrypt a PGP/MIME message. */
99 int crypt_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
101 if (CRYPT_MOD_CALL_CHECK (PGP, decrypt_mime))
102 return (CRYPT_MOD_CALL (PGP, decrypt_mime)) (a, b, c, d);
107 /* MIME handler for the application/pgp content-type. */
108 int crypt_pgp_application_pgp_handler (BODY * m, STATE * s)
110 if (CRYPT_MOD_CALL_CHECK (PGP, application_handler))
111 return (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
115 /* MIME handler for an PGP/MIME encrypted message. */
116 int crypt_pgp_encrypted_handler (BODY * a, STATE * s)
118 if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
119 return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
123 /* fixme: needs documentation. */
124 void crypt_pgp_invoke_getkeys (address_t * addr)
126 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys))
127 (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr);
130 /* Check for a traditional PGP message in body B. */
131 int crypt_pgp_check_traditional (FILE * fp, BODY * b, int tagged_only)
133 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_check_traditional))
134 return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, tagged_only);
139 /* fixme: needs documentation. */
140 BODY *crypt_pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
142 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_traditional_encryptsign))
143 return (CRYPT_MOD_CALL (PGP, pgp_traditional_encryptsign)) (a, flags,
149 /* Generate a PGP public key attachment. */
150 BODY *crypt_pgp_make_key_attachment (char *tempf)
152 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment))
153 return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf);
158 /* This routine attempts to find the keyids of the recipients of a
159 message. It returns NULL if any of the keys can not be found. */
160 char *crypt_pgp_findkeys (address_t * to, address_t * cc, address_t * bcc)
162 if (CRYPT_MOD_CALL_CHECK (PGP, findkeys))
163 return (CRYPT_MOD_CALL (PGP, findkeys)) (to, cc, bcc);
168 /* Create a new body with a PGP signed message from A. */
169 BODY *crypt_pgp_sign_message (BODY * a)
171 if (CRYPT_MOD_CALL_CHECK (PGP, sign_message))
172 return (CRYPT_MOD_CALL (PGP, sign_message)) (a);
177 /* Warning: A is no longer freed in this routine, you need to free it
178 later. This is necessary for $fcc_attach. */
179 BODY *crypt_pgp_encrypt_message (BODY * a, char *keylist, int sign)
181 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_encrypt_message))
182 return (CRYPT_MOD_CALL (PGP, pgp_encrypt_message)) (a, keylist, sign);
187 /* Invoke the PGP command to import a key. */
188 void crypt_pgp_invoke_import (const char *fname)
190 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_import))
191 (CRYPT_MOD_CALL (PGP, pgp_invoke_import)) (fname);
194 /* fixme: needs documentation */
195 int crypt_pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
197 if (CRYPT_MOD_CALL_CHECK (PGP, verify_one))
198 return (CRYPT_MOD_CALL (PGP, verify_one)) (sigbdy, s, tempf);
204 int crypt_pgp_send_menu (HEADER * msg, int *redraw)
206 if (CRYPT_MOD_CALL_CHECK (PGP, send_menu))
207 return (CRYPT_MOD_CALL (PGP, send_menu)) (msg, redraw);
213 /* fixme: needs documentation */
214 void crypt_pgp_extract_keys_from_attachment_list (FILE * fp, int tag,
217 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_extract_keys_from_attachment_list))
218 (CRYPT_MOD_CALL (PGP, pgp_extract_keys_from_attachment_list)) (fp, tag,
231 /* Decrypt am S/MIME message. */
232 int crypt_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
234 if (CRYPT_MOD_CALL_CHECK (SMIME, decrypt_mime))
235 return (CRYPT_MOD_CALL (SMIME, decrypt_mime)) (a, b, c, d);
240 /* MIME handler for the application/smime content-type. */
241 int crypt_smime_application_smime_handler (BODY * m, STATE * s)
243 if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler))
244 return (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
248 /* fixme: Needs documentation. */
249 void crypt_smime_getkeys (ENVELOPE * env)
251 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys))
252 (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env);
255 /* Check that the sender matches. */
256 int crypt_smime_verify_sender (HEADER * h)
258 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_verify_sender))
259 return (CRYPT_MOD_CALL (SMIME, smime_verify_sender)) (h);
264 /* This routine attempts to find the keyids of the recipients of a
265 message. It returns NULL if any of the keys can not be found. */
266 char *crypt_smime_findkeys (address_t * to, address_t * cc, address_t * bcc)
268 if (CRYPT_MOD_CALL_CHECK (SMIME, findkeys))
269 return (CRYPT_MOD_CALL (SMIME, findkeys)) (to, cc, bcc);
274 /* fixme: Needs documentation. */
275 BODY *crypt_smime_sign_message (BODY * a)
277 if (CRYPT_MOD_CALL_CHECK (SMIME, sign_message))
278 return (CRYPT_MOD_CALL (SMIME, sign_message)) (a);
283 /* fixme: needs documentation. */
284 BODY *crypt_smime_build_smime_entity (BODY * a, char *certlist)
286 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity))
287 return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist);
292 /* Add a certificate and update index file (externally). */
293 void crypt_smime_invoke_import (char *infile, char *mailbox)
295 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_invoke_import))
296 (CRYPT_MOD_CALL (SMIME, smime_invoke_import)) (infile, mailbox);
299 /* fixme: needs documentation */
300 int crypt_smime_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
302 if (CRYPT_MOD_CALL_CHECK (SMIME, verify_one))
303 return (CRYPT_MOD_CALL (SMIME, verify_one)) (sigbdy, s, tempf);
308 int crypt_smime_send_menu (HEADER * msg, int *redraw)
310 if (CRYPT_MOD_CALL_CHECK (SMIME, send_menu))
311 return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg, redraw);