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