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