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 /* Decrypt a PGP/MIME message. */
64 int crypt_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
66 if (CRYPT_MOD_CALL_CHECK (PGP, decrypt_mime))
67 return (CRYPT_MOD_CALL (PGP, decrypt_mime)) (a, b, c, d);
72 /* MIME handler for the application/pgp content-type. */
73 int crypt_pgp_application_pgp_handler (BODY * m, STATE * s)
75 if (CRYPT_MOD_CALL_CHECK (PGP, application_handler))
76 return (CRYPT_MOD_CALL (PGP, application_handler)) (m, s);
80 /* MIME handler for an PGP/MIME encrypted message. */
81 int crypt_pgp_encrypted_handler (BODY * a, STATE * s)
83 if (CRYPT_MOD_CALL_CHECK (PGP, encrypted_handler))
84 return (CRYPT_MOD_CALL (PGP, encrypted_handler)) (a, s);
88 /* fixme: needs documentation. */
89 void crypt_pgp_invoke_getkeys (address_t * addr)
91 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_getkeys))
92 (CRYPT_MOD_CALL (PGP, pgp_invoke_getkeys)) (addr);
95 /* Check for a traditional PGP message in body B. */
96 int crypt_pgp_check_traditional (FILE * fp, BODY * b, int tagged_only)
98 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_check_traditional))
99 return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, tagged_only);
104 /* fixme: needs documentation. */
105 BODY *crypt_pgp_traditional_encryptsign (BODY * a, int flags, char *keylist)
107 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_traditional_encryptsign))
108 return (CRYPT_MOD_CALL (PGP, pgp_traditional_encryptsign)) (a, flags,
114 /* Generate a PGP public key attachment. */
115 BODY *crypt_pgp_make_key_attachment (char *tempf)
117 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment))
118 return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf);
123 /* This routine attempts to find the keyids of the recipients of a
124 message. It returns NULL if any of the keys can not be found. */
125 char *crypt_pgp_findkeys (address_t * to, address_t * cc, address_t * bcc)
127 if (CRYPT_MOD_CALL_CHECK (PGP, findkeys))
128 return (CRYPT_MOD_CALL (PGP, findkeys)) (to, cc, bcc);
133 /* Create a new body with a PGP signed message from A. */
134 BODY *crypt_pgp_sign_message (BODY * a)
136 if (CRYPT_MOD_CALL_CHECK (PGP, sign_message))
137 return (CRYPT_MOD_CALL (PGP, sign_message)) (a);
142 /* Warning: A is no longer freed in this routine, you need to free it
143 later. This is necessary for $fcc_attach. */
144 BODY *crypt_pgp_encrypt_message (BODY * a, char *keylist, int sign)
146 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_encrypt_message))
147 return (CRYPT_MOD_CALL (PGP, pgp_encrypt_message)) (a, keylist, sign);
152 /* Invoke the PGP command to import a key. */
153 void crypt_pgp_invoke_import (const char *fname)
155 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_invoke_import))
156 (CRYPT_MOD_CALL (PGP, pgp_invoke_import)) (fname);
159 /* fixme: needs documentation */
160 int crypt_pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
162 if (CRYPT_MOD_CALL_CHECK (PGP, verify_one))
163 return (CRYPT_MOD_CALL (PGP, verify_one)) (sigbdy, s, tempf);
169 int crypt_pgp_send_menu (HEADER * msg, int *redraw)
171 if (CRYPT_MOD_CALL_CHECK (PGP, send_menu))
172 return (CRYPT_MOD_CALL (PGP, send_menu)) (msg, redraw);
178 /* fixme: needs documentation */
179 void crypt_pgp_extract_keys_from_attachment_list (FILE * fp, int tag,
182 if (CRYPT_MOD_CALL_CHECK (PGP, pgp_extract_keys_from_attachment_list))
183 (CRYPT_MOD_CALL (PGP, pgp_extract_keys_from_attachment_list)) (fp, tag,
196 /* Decrypt am S/MIME message. */
197 int crypt_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d)
199 if (CRYPT_MOD_CALL_CHECK (SMIME, decrypt_mime))
200 return (CRYPT_MOD_CALL (SMIME, decrypt_mime)) (a, b, c, d);
205 /* MIME handler for the application/smime content-type. */
206 int crypt_smime_application_smime_handler (BODY * m, STATE * s)
208 if (CRYPT_MOD_CALL_CHECK (SMIME, application_handler))
209 return (CRYPT_MOD_CALL (SMIME, application_handler)) (m, s);
213 /* fixme: Needs documentation. */
214 void crypt_smime_getkeys (ENVELOPE * env)
216 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_getkeys))
217 (CRYPT_MOD_CALL (SMIME, smime_getkeys)) (env);
220 /* Check that the sender matches. */
221 int crypt_smime_verify_sender (HEADER * h)
223 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_verify_sender))
224 return (CRYPT_MOD_CALL (SMIME, smime_verify_sender)) (h);
229 /* This routine attempts to find the keyids of the recipients of a
230 message. It returns NULL if any of the keys can not be found. */
231 char *crypt_smime_findkeys (address_t * to, address_t * cc, address_t * bcc)
233 if (CRYPT_MOD_CALL_CHECK (SMIME, findkeys))
234 return (CRYPT_MOD_CALL (SMIME, findkeys)) (to, cc, bcc);
239 /* fixme: Needs documentation. */
240 BODY *crypt_smime_sign_message (BODY * a)
242 if (CRYPT_MOD_CALL_CHECK (SMIME, sign_message))
243 return (CRYPT_MOD_CALL (SMIME, sign_message)) (a);
248 /* fixme: needs documentation. */
249 BODY *crypt_smime_build_smime_entity (BODY * a, char *certlist)
251 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_build_smime_entity))
252 return (CRYPT_MOD_CALL (SMIME, smime_build_smime_entity)) (a, certlist);
257 /* Add a certificate and update index file (externally). */
258 void crypt_smime_invoke_import (char *infile, char *mailbox)
260 if (CRYPT_MOD_CALL_CHECK (SMIME, smime_invoke_import))
261 (CRYPT_MOD_CALL (SMIME, smime_invoke_import)) (infile, mailbox);
264 /* fixme: needs documentation */
265 int crypt_smime_verify_one (BODY * sigbdy, STATE * s, const char *tempf)
267 if (CRYPT_MOD_CALL_CHECK (SMIME, verify_one))
268 return (CRYPT_MOD_CALL (SMIME, verify_one)) (sigbdy, s, tempf);
273 int crypt_smime_send_menu (HEADER * msg, int *redraw)
275 if (CRYPT_MOD_CALL_CHECK (SMIME, send_menu))
276 return (CRYPT_MOD_CALL (SMIME, send_menu)) (msg, redraw);