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