Andreas Krennmair:
[apps/madmutt.git] / mutt_crypt.h
1 /*
2  * Copyright (C) 2003 Werner Koch <wk@gnupg.org>
3  * Copyright (C) 2004 g10code GmbH
4  * 
5  *     This program is free software; you can redistribute it and/or modify
6  *     it under the terms of the GNU General Public License as published by
7  *     the Free Software Foundation; either version 2 of the License, or
8  *     (at your option) any later version.
9  * 
10  *     This program is distributed in the hope that it will be useful,
11  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *     GNU General Public License for more details.
14  * 
15  *     You should have received a copy of the GNU General Public License
16  *     along with this program; if not, write to the Free Software
17  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
18  */
19
20 /*
21    Common definitions and prototypes for the crypt functions. They are
22    all defined in crypt.c and cryptglue.c
23 */
24
25 #ifndef MUTT_CRYPT_H
26 #define MUTT_CRYPT_H
27
28 #include "mutt.h"               /* Need this to declare BODY, ADDRESS. STATE etc. */
29 /* FIXME: They should be pointer to anonymous structures for better
30    information hiding. */
31
32
33
34 #define ENCRYPT    (1 << 0)
35 #define SIGN       (1 << 1)
36 #define GOODSIGN   (1 << 2)
37 #define BADSIGN    (1 << 3)
38 #define PARTSIGN   (1 << 4)
39 #define SIGNOPAQUE (1 << 5)
40 #define KEYBLOCK   (1 << 6)     /* KEY too generic? */
41 #define INLINE     (1 << 7)
42
43 #define APPLICATION_PGP    (1 << 8)
44 #define APPLICATION_SMIME  (1 << 9)
45
46 #define PGP_TRADITIONAL_CHECKED (1 << 10)
47
48 #define PGPENCRYPT  (APPLICATION_PGP | ENCRYPT)
49 #define PGPSIGN     (APPLICATION_PGP | SIGN)
50 #define PGPGOODSIGN (APPLICATION_PGP | GOODSIGN)
51 #define PGPKEY      (APPLICATION_PGP | KEYBLOCK)
52 #define PGPINLINE   (APPLICATION_PGP | INLINE)
53
54 #define SMIMEENCRYPT  (APPLICATION_SMIME | ENCRYPT)
55 #define SMIMESIGN     (APPLICATION_SMIME | SIGN)
56 #define SMIMEGOODSIGN (APPLICATION_SMIME | GOODSIGN)
57 #define SMIMEBADSIGN  (APPLICATION_SMIME | BADSIGN)
58 #define SMIMEOPAQUE   (APPLICATION_SMIME | SIGNOPAQUE)
59
60
61 /* WITHCRYPTO actually replaces ifdefs so make the code more readable.
62    Because it is defined as a constant and known at compile time, the
63    compiler can do dead code elimination and thus it behaves
64    effectively as a conditional compile directive. It is set to false
65    if no crypto backend is configures or to a bit vector denoting the
66    configured backends. */
67 #if (defined(CRYPT_BACKEND_CLASSIC_PGP) && defined(CRYPT_BACKEND_CLASSIC_SMIME)) || defined (CRYPT_BACKEND_GPGME)
68 # define WithCrypto (APPLICATION_PGP | APPLICATION_SMIME)
69 #elif defined(CRYPT_BACKEND_CLASSIC_PGP)
70 # define WithCrypto  APPLICATION_PGP
71 #elif defined(CRYPT_BACKEND_CLASSIC_SMIME)
72 # define WithCrypto  APPLICATION_SMIME
73 #else
74 # define WithCrypto 0
75 #endif
76
77
78 #define KEYFLAG_CANSIGN                 (1 <<  0)
79 #define KEYFLAG_CANENCRYPT              (1 <<  1)
80 #define KEYFLAG_ISX509                  (1 <<  2)
81 #define KEYFLAG_SECRET                  (1 <<  7)
82 #define KEYFLAG_EXPIRED                 (1 <<  8)
83 #define KEYFLAG_REVOKED                 (1 <<  9)
84 #define KEYFLAG_DISABLED                (1 << 10)
85 #define KEYFLAG_SUBKEY                  (1 << 11)
86 #define KEYFLAG_CRITICAL                (1 << 12)
87 #define KEYFLAG_PREFER_ENCRYPTION       (1 << 13)
88 #define KEYFLAG_PREFER_SIGNING          (1 << 14)
89
90 #define KEYFLAG_CANTUSE (KEYFLAG_DISABLED|KEYFLAG_REVOKED|KEYFLAG_EXPIRED)
91 #define KEYFLAG_RESTRICTIONS (KEYFLAG_CANTUSE|KEYFLAG_CRITICAL)
92
93 #define KEYFLAG_ABILITIES (KEYFLAG_CANSIGN|KEYFLAG_CANENCRYPT|KEYFLAG_PREFER_ENCRYPTION|KEYFLAG_PREFER_SIGNING)
94
95 enum pgp_ring {
96   PGP_PUBRING,
97   PGP_SECRING
98 };
99 typedef enum pgp_ring pgp_ring_t;
100
101
102 struct pgp_keyinfo;
103 typedef struct pgp_keyinfo *pgp_key_t;
104
105
106
107 /* Some prototypes -- old crypt.h. */
108
109 int mutt_protect (HEADER *, char *);
110
111 int mutt_is_multipart_encrypted (BODY *);
112
113 int mutt_is_multipart_signed (BODY *);
114
115 int mutt_is_application_pgp (BODY *);
116
117 int mutt_is_application_smime (BODY *);
118
119 void mutt_signed_handler (BODY *, STATE *);
120
121 int mutt_parse_crypt_hdr (char *, int);
122
123
124 void convert_to_7bit (BODY *);
125
126
127
128 /*-- crypt.c --*/
129
130 /* Print the current time. */
131 void crypt_current_time (STATE * s, char *app_name);
132
133 /* Check out the type of encryption used and set the cached status
134    values if there are any. */
135 int crypt_query (BODY * m);
136
137 /* Fixme: To be documented. */
138 void crypt_extract_keys_from_messages (HEADER * h);
139
140 /* Do a quick check to make sure that we can find all of the
141    encryption keys if the user has requested this service. 
142    Return the list of keys in KEYLIST. */
143 int crypt_get_keys (HEADER * msg, char **keylist);
144
145 /* Forget a passphrase and display a message. */
146 void crypt_forget_passphrase (void);
147
148 /* Check that we have a usable passphrase, ask if not. */
149 int crypt_valid_passphrase (int);
150
151 /* Write the message body/part A described by state S to a the given
152    TEMPFILE.  */
153 int crypt_write_signed (BODY * a, STATE * s, const char *tempf);
154
155
156
157 /*-- cryptglue.c --*/
158
159 /* Show a message that a backend will be invoked. */
160 void crypt_invoke_message (int type);
161
162
163 /* Silently forget about a passphrase. */
164 void crypt_pgp_void_passphrase (void);
165
166 int crypt_pgp_valid_passphrase (void);
167
168
169 /* Decrypt a PGP/MIME message. */
170 int crypt_pgp_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d);
171
172 /* MIME handler for the application/pgp content-type. */
173 void crypt_pgp_application_pgp_handler (BODY * m, STATE * s);
174
175 /* MIME handler for an PGP/MIME encrypted message. */
176 void crypt_pgp_encrypted_handler (BODY * a, STATE * s);
177
178 /* fixme: needs documentation. */
179 void crypt_pgp_invoke_getkeys (ADDRESS * addr);
180
181 /* Ask for a PGP key. */
182 pgp_key_t crypt_pgp_ask_for_key (char *tag, char *whatfor,
183                                  short abilities, pgp_ring_t keyring);
184
185 /* Check for a traditional PGP message in body B. */
186 int crypt_pgp_check_traditional (FILE * fp, BODY * b, int tagged_only);
187
188 /* fixme: needs documentation. */
189 BODY *crypt_pgp_traditional_encryptsign (BODY * a, int flags, char *keylist);
190
191 /* Release the PGP key KPP (note, that we pass a pointer to it). */
192 void crypt_pgp_free_key (pgp_key_t * kpp);
193
194 /* Generate a PGP public key attachment. */
195 BODY *crypt_pgp_make_key_attachment (char *tempf);
196
197 /* This routine attempts to find the keyids of the recipients of a
198    message.  It returns NULL if any of the keys can not be found.  */
199 char *crypt_pgp_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc);
200
201 /* Create a new body with a PGP signed message from A. */
202 BODY *crypt_pgp_sign_message (BODY * a);
203
204 /* Warning: A is no longer freed in this routine, you need to free it
205    later.  This is necessary for $fcc_attach. */
206 BODY *crypt_pgp_encrypt_message (BODY * a, char *keylist, int sign);
207
208 /* Invoke the PGP command to import a key. */
209 void crypt_pgp_invoke_import (const char *fname);
210
211 int crypt_pgp_send_menu (HEADER * msg, int *redraw);
212
213 /* fixme: needs documentation */
214 int crypt_pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempf);
215
216 /* Access the keyID in K. */
217 char *crypt_pgp_keyid (pgp_key_t k);
218
219 /* fixme: needs documentation */
220 void crypt_pgp_extract_keys_from_attachment_list (FILE * fp, int tag,
221                                                   BODY * top);
222
223
224
225
226
227 /* Silently forget about a passphrase. */
228 void crypt_smime_void_passphrase (void);
229
230 int crypt_smime_valid_passphrase (void);
231
232 /* Decrypt an S/MIME message. */
233 int crypt_smime_decrypt_mime (FILE * a, FILE ** b, BODY * c, BODY ** d);
234
235 /* MIME handler for the application/smime content-type. */
236 void crypt_smime_application_smime_handler (BODY * m, STATE * s);
237
238 /* fixme: Needs documentation. */
239 void crypt_smime_getkeys (ENVELOPE * env);
240
241 /* Check that the sender matches. */
242 int crypt_smime_verify_sender (HEADER * h);
243
244 /* Ask for an SMIME key. */
245 char *crypt_smime_ask_for_key (char *prompt, char *mailbox, short public);
246
247 /* This routine attempts to find the keyids of the recipients of a
248    message.  It returns NULL if any of the keys can not be found.  */
249 char *crypt_smime_findkeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc);
250
251 /* fixme: Needs documentation. */
252 BODY *crypt_smime_sign_message (BODY * a);
253
254 /* fixme: needs documentation. */
255 BODY *crypt_smime_build_smime_entity (BODY * a, char *certlist);
256
257 /* Add a certificate and update index file (externally). */
258 void crypt_smime_invoke_import (char *infile, char *mailbox);
259
260 int crypt_smime_send_menu (HEADER * msg, int *redraw);
261
262 /* fixme: needs documentation */
263 int crypt_smime_verify_one (BODY * sigbdy, STATE * s, const char *tempf);
264
265 void crypt_init (void);
266
267 #endif /*MUTT_CRYPT_H */