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