2 * Copyright (C) 2003 Werner Koch <wk@gnupg.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
20 This file dispatches the generic crytpo functions to the implemented
21 backend or provides dummy stubs. Note, that some generic functions are
26 #include "mutt_crypt.h"
28 /* Make sure those macros are not defined. */
29 #undef BFNC_PGP_VOID_PASSPHRASE
30 #undef BFNC_PGP_DECRYPT_MIME
31 #undef BFNC_PGP_APPLICATION_PGP_HANDLER
32 #undef BFNC_PGP_ENCRYPTED_HANDLER
33 #undef BFNC_PGP_INVOKE_GETKEYS
34 #undef BFNC_PGP_ASK_FOR_KEY
35 #undef BNFC_PGP_CHECK_TRADITIONAL
36 #undef BFNC_PGP_TRADITIONAL_ENCRYPTSIGN
37 #undef BFNC_PGP_FREE_KEY
38 #undef BFNC_PGP_MAKE_KEY_ATTACHMENT
39 #undef BFNC_PGP_FINDKEYS
40 #undef BFNC_PGP_SIGN_MESSAGE
41 #undef BFNC_PGP_ENCRYPT_MESSAGE
42 #undef BFNC_PGP_INVOKE_IMPORT
43 #undef BFNC_PGP_VERIFY_ONE
45 #undef BFNC_PGP_EXTRACT_KEYS_FROM_ATTACHMENT_LIST
47 #undef BFNC_SMIME_VOID_PASSPHRASE
48 #undef BFNC_SMIME_DECRYPT_MIME
49 #undef BFNC_SMIME_APPLICATION_SMIME_HANDLER
50 #undef BFNC_SMIME_GETKEYS
51 #undef BFNC_SMIME_VERIFY_SENDER
52 #undef BFNC_SMIME_ASK_FOR_KEY
53 #undef BFNC_SMIME_FINDKEYS
54 #undef BFNC_SMIME_SIGN_MESSAGE
55 #undef BFNC_SMIME_BUILD_SMIME_ENTITY
56 #undef BFNC_SMIME_INVOKE_IMPORT
57 #undef BFNC_SMIME_VERIFY_ONE
61 #if defined (CRYPT_BACKEND_CLASSIC_PGP)
63 # define BFNC_PGP_VOID_PASSPHRASE pgp_void_passphrase
64 # define BFNC_PGP_DECRYPT_MIME pgp_decrypt_mime
65 # define BFNC_PGP_APPLICATION_PGP_HANDLER pgp_application_pgp_handler
66 # define BFNC_PGP_ENCRYPTED_HANDLER pgp_encrypted_handler
67 # define BFNC_PGP_INVOKE_GETKEYS pgp_invoke_getkeys
68 # define BFNC_PGP_ASK_FOR_KEY pgp_ask_for_key
69 # define BNFC_PGP_CHECK_TRADITIONAL pgp_check_traditional
70 # define BFNC_PGP_TRADITIONAL_ENCRYPTSIGN pgp_traditional_encryptsign
71 # define BFNC_PGP_FREE_KEY pgp_free_key
72 # define BFNC_PGP_MAKE_KEY_ATTACHMENT pgp_make_key_attachment
73 # define BFNC_PGP_FINDKEYS pgp_findKeys
74 # define BFNC_PGP_SIGN_MESSAGE pgp_sign_message
75 # define BFNC_PGP_ENCRYPT_MESSAGE pgp_encrypt_message
76 # define BFNC_PGP_INVOKE_IMPORT pgp_invoke_import
77 # define BFNC_PGP_VERIFY_ONE pgp_verify_one
78 # define BFNC_PGP_KEYID pgp_keyid
79 # define BFNC_PGP_EXTRACT_KEYS_FROM_ATTACHMENT_LIST \
80 pgp_extract_keys_from_attachment_list
83 #elif defined (CRYPT_BACKEND_GPGME)
84 # include "crypt-gpgme.h"
85 # define BFNC_PGP_VOID_PASSPHRASE NULL /* not required */
86 # define BFNC_PGP_DECRYPT_MIME gpg_pgp_decrypt_mime
88 #endif /* PGP backend */
91 /* The SMIME backend */
92 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
94 # define BFNC_SMIME_VOID_PASSPHRASE smime_void_passphrase
95 # define BFNC_SMIME_DECRYPT_MIME smime_decrypt_mime
96 # define BFNC_SMIME_APPLICATION_SMIME_HANDLER smime_application_smime_handler
97 # define BFNC_SMIME_GETKEYS smime_getkeys
98 # define BFNC_SMIME_VERIFY_SENDER smime_verify_sender
99 # define BFNC_SMIME_ASK_FOR_KEY smime_ask_for_key
100 # define BFNC_SMIME_FINDKEYS smime_findKeys
101 # define BFNC_SMIME_SIGN_MESSAGE smime_sign_message
102 # define BFNC_SMIME_BUILD_SMIME_ENTITY smime_build_smime_entity
103 # define BFNC_SMIME_INVOKE_IMPORT smime_invoke_import
104 # define BFNC_SMIME_VERIFY_ONE smime_verify_one
106 #elif defined (CRYPT_BACKEND_GPGME)
107 /* Already included above (gpgme supports both). */
108 # define BFNC_SMIME_VOID_PASSPHRASE NULL /* not required */
110 #endif /* SMIME backend */
119 /* Show a message that a backend will be invoked. */
120 void crypt_invoke_message (int type)
122 #if defined (CRYPT_BACKEND_CLASSIC_PGP) || defined(CRYPT_BACKEND_CLASSIC_SMIME)
123 if ((type & APPLICATION_PGP))
124 mutt_message _("Invoking PGP...");
125 if ((type & APPLICATION_SMIME))
126 mutt_message _("Invoking OpenSSL...");
127 #elif defined (CRYPT_BACKEND_GPGME)
128 if ((type & APPLICATION_PGP) || (type & APPLICATION_SMIME) )
129 mutt_message _("Invoking GnuPG...");
142 /* Reset a PGP passphrase */
143 void crypt_pgp_void_passphrase (void)
145 #ifdef BFNC_PGP_VOID_PASSPHRASE
146 BFNC_PGP_VOID_PASSPHRASE ();
150 /* Decrypt a PGP/MIME message. */
151 int crypt_pgp_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d)
153 #ifdef BFNC_PGP_DECRYPT_MIME
154 return BFNC_PGP_DECRYPT_MIME (a, b, c, d);
156 return -1; /* error */
160 /* MIME handler for the application/pgp content-type. */
161 void crypt_pgp_application_pgp_handler (BODY *m, STATE *s)
163 #ifdef BFNC_PGP_APPLICATION_PGP_HANDLER
164 BFNC_PGP_APPLICATION_PGP_HANDLER (m, s);
168 /* MIME handler for an PGP/MIME encrypted message. */
169 void crypt_pgp_encrypted_handler (BODY *a, STATE *s)
171 #ifdef BFNC_PGP_ENCRYPTED_HANDLER
172 BFNC_PGP_ENCRYPTED_HANDLER (a, s);
176 /* fixme: needs documentation. */
177 void crypt_pgp_invoke_getkeys (ADDRESS *addr)
179 #ifdef BFNC_PGP_INVOKE_GETKEYS
180 BFNC_PGP_INVOKE_GETKEYS (addr);
184 /* Ask for a PGP key. */
185 pgp_key_t crypt_pgp_ask_for_key (char *tag, char *whatfor,
186 short abilities, pgp_ring_t keyring)
188 #ifdef BFNC_PGP_ASK_FOR_KEY
189 return BFNC_PGP_ASK_FOR_KEY (tag, whatfor, abilities, keyring);
196 /* Check for a traditional PGP message in body B. */
197 int crypt_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only)
199 #ifdef BNFC_PGP_CHECK_TRADITIONAL
200 return BNFC_PGP_CHECK_TRADITIONAL (fp, b, tagged_only);
206 /* fixme: needs documentation. */
207 BODY *crypt_pgp_traditional_encryptsign (BODY *a, int flags, char *keylist)
209 #ifdef BFNC_PGP_TRADITIONAL_ENCRYPTSIGN
210 return BFNC_PGP_TRADITIONAL_ENCRYPTSIGN (a, flags, keylist);
216 /* Release pgp key KPP. */
217 void crypt_pgp_free_key (pgp_key_t *kpp)
219 #ifdef BFNC_PGP_FREE_KEY
220 BFNC_PGP_FREE_KEY (kpp);
225 /* Generate a PGP public key attachment. */
226 BODY *crypt_pgp_make_key_attachment (char *tempf)
228 #ifdef BFNC_PGP_MAKE_KEY_ATTACHMENT
229 return BFNC_PGP_MAKE_KEY_ATTACHMENT (tempf);
231 return NULL; /* error */
235 /* This routine attempts to find the keyids of the recipients of a
236 message. It returns NULL if any of the keys can not be found. */
237 char *crypt_pgp_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc)
239 #ifdef BFNC_PGP_FINDKEYS
240 return BFNC_PGP_FINDKEYS (to, cc, bcc);
246 /* Create a new body with a PGP signed message from A. */
247 BODY *crypt_pgp_sign_message (BODY *a)
249 #ifdef BFNC_PGP_SIGN_MESSAGE
250 return BFNC_PGP_SIGN_MESSAGE (a);
256 /* Warning: A is no longer freed in this routine, you need to free it
257 later. This is necessary for $fcc_attach. */
258 BODY *crypt_pgp_encrypt_message (BODY *a, char *keylist, int sign)
260 #ifdef BFNC_PGP_ENCRYPT_MESSAGE
261 return BFNC_PGP_ENCRYPT_MESSAGE (a, keylist, sign);
267 /* Invoke the PGP command to import a key. */
268 void crypt_pgp_invoke_import (const char *fname)
270 #ifdef BFNC_PGP_INVOKE_IMPORT
271 BFNC_PGP_INVOKE_IMPORT (fname);
275 /* fixme: needs documentation */
276 int crypt_pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempf)
278 #ifdef BFNC_PGP_VERIFY_ONE
279 return BFNC_PGP_VERIFY_ONE (sigbdy, s, tempf);
286 /* Access the keyID in K. */
287 char *crypt_pgp_keyid (pgp_key_t k)
289 #ifdef BFNC_PGP_KEYID
290 return pgp_keyid (k);
296 /* fixme: needs documentation */
297 void crypt_pgp_extract_keys_from_attachment_list (FILE *fp, int tag, BODY *top)
299 #ifdef BFNC_PGP_EXTRACT_KEYS_FROM_ATTACHMENT_LIST
300 BFNC_PGP_EXTRACT_KEYS_FROM_ATTACHMENT_LIST (fp, tag, top);
313 /* Reset an SMIME passphrase */
314 void crypt_smime_void_passphrase (void)
316 #ifdef BFNC_SMIME_VOID_PASSPHRASE
317 BFNC_SMIME_VOID_PASSPHRASE ();
322 /* Decrypt am S/MIME message. */
323 int crypt_smime_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d)
325 #ifdef BFNC_SMIME_DECRYPT_MIME
326 return BFNC_SMIME_DECRYPT_MIME (a, b, c, d);
328 return -1; /* error */
332 /* MIME handler for the application/smime content-type. */
333 void crypt_smime_application_smime_handler (BODY *m, STATE *s)
335 #ifdef BFNC_SMIME_APPLICATION_SMIME_HANDLER
336 BFNC_SMIME_APPLICATION_SMIME_HANDLER (m, s);
340 /* fixme: Needs documentation. */
341 void crypt_smime_getkeys (ENVELOPE *env)
343 #ifdef BFNC_SMIME_GETKEYS
344 BFNC_SMIME_GETKEYS (env);
348 /* Check that the sender matches. */
349 int crypt_smime_verify_sender(HEADER *h)
351 #ifdef BFNC_SMIME_VERIFY_SENDER
352 return BFNC_SMIME_VERIFY_SENDER (h);
358 /* Ask for an SMIME key. */
359 char *crypt_smime_ask_for_key (char *prompt, char *mailbox, short public)
361 #ifdef BFNC_SMIME_ASK_FOR_KEY
362 return BFNC_SMIME_ASK_FOR_KEY (prompt, mailbox, public);
364 return NULL; /* error */
369 /* This routine attempts to find the keyids of the recipients of a
370 message. It returns NULL if any of the keys can not be found. */
371 char *crypt_smime_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc)
373 #ifdef BFNC_SMIME_FINDKEYS
374 return BFNC_SMIME_FINDKEYS (to, cc, bcc);
380 /* fixme: Needs documentation. */
381 BODY *crypt_smime_sign_message (BODY *a)
383 #ifdef BFNC_SMIME_SIGN_MESSAGE
384 return BFNC_SMIME_SIGN_MESSAGE (a);
390 /* fixme: needs documentation. */
391 BODY *crypt_smime_build_smime_entity (BODY *a, char *certlist)
393 #ifdef BFNC_SMIME_BUILD_SMIME_ENTITY
394 return BFNC_SMIME_BUILD_SMIME_ENTITY (a, certlist);
400 /* Add a certificate and update index file (externally). */
401 void crypt_smime_invoke_import (char *infile, char *mailbox)
403 #ifdef BFNC_SMIME_INVOKE_IMPORT
404 BFNC_SMIME_INVOKE_IMPORT (infile, mailbox);
408 /* fixme: needs documentation */
409 int crypt_smime_verify_one (BODY *sigbdy, STATE *s, const char *tempf)
411 #ifdef BFNC_SMIME_VERIFY_ONE
412 return BFNC_SMIME_VERIFY_ONE (sigbdy, s, tempf);