mutt stable branch with some hacks
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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#define OPPENCRYPT (1 << 8) /* Opportunistic encrypt mode */
43
44#define APPLICATION_PGP (1 << 9)
45#define APPLICATION_SMIME (1 << 10)
46
47#define PGP_TRADITIONAL_CHECKED (1 << 11)
48
49#define PGPENCRYPT (APPLICATION_PGP | ENCRYPT)
50#define PGPSIGN (APPLICATION_PGP | SIGN)
51#define PGPGOODSIGN (APPLICATION_PGP | GOODSIGN)
52#define PGPKEY (APPLICATION_PGP | KEYBLOCK)
53#define PGPINLINE (APPLICATION_PGP | INLINE)
54
55#define SMIMEENCRYPT (APPLICATION_SMIME | ENCRYPT)
56#define SMIMESIGN (APPLICATION_SMIME | SIGN)
57#define SMIMEGOODSIGN (APPLICATION_SMIME | GOODSIGN)
58#define SMIMEBADSIGN (APPLICATION_SMIME | BADSIGN)
59#define SMIMEOPAQUE (APPLICATION_SMIME | SIGNOPAQUE)
60
61
62/* WITHCRYPTO actually replaces ifdefs so make the code more readable.
63 Because it is defined as a constant and known at compile time, the
64 compiler can do dead code elimination and thus it behaves
65 effectively as a conditional compile directive. It is set to false
66 if no crypto backend is configures or to a bit vector denoting the
67 configured backends. */
68#if (defined(CRYPT_BACKEND_CLASSIC_PGP) && defined(CRYPT_BACKEND_CLASSIC_SMIME)) || defined (CRYPT_BACKEND_GPGME)
69# define WithCrypto (APPLICATION_PGP | APPLICATION_SMIME)
70#elif defined(CRYPT_BACKEND_CLASSIC_PGP)
71# define WithCrypto APPLICATION_PGP
72#elif defined(CRYPT_BACKEND_CLASSIC_SMIME)
73# define WithCrypto APPLICATION_SMIME
74#else
75# define WithCrypto 0
76#endif
77
78
79#define KEYFLAG_CANSIGN (1 << 0)
80#define KEYFLAG_CANENCRYPT (1 << 1)
81#define KEYFLAG_ISX509 (1 << 2)
82#define KEYFLAG_SECRET (1 << 7)
83#define KEYFLAG_EXPIRED (1 << 8)
84#define KEYFLAG_REVOKED (1 << 9)
85#define KEYFLAG_DISABLED (1 << 10)
86#define KEYFLAG_SUBKEY (1 << 11)
87#define KEYFLAG_CRITICAL (1 << 12)
88#define KEYFLAG_PREFER_ENCRYPTION (1 << 13)
89#define KEYFLAG_PREFER_SIGNING (1 << 14)
90
91#define KEYFLAG_CANTUSE (KEYFLAG_DISABLED|KEYFLAG_REVOKED|KEYFLAG_EXPIRED)
92#define KEYFLAG_RESTRICTIONS (KEYFLAG_CANTUSE|KEYFLAG_CRITICAL)
93
94#define KEYFLAG_ABILITIES (KEYFLAG_CANSIGN|KEYFLAG_CANENCRYPT|KEYFLAG_PREFER_ENCRYPTION|KEYFLAG_PREFER_SIGNING)
95
96enum pgp_ring
97{
98 PGP_PUBRING,
99 PGP_SECRING
100};
101typedef enum pgp_ring pgp_ring_t;
102
103
104struct pgp_keyinfo;
105typedef struct pgp_keyinfo *pgp_key_t;
106
107
108
109/* Some prototypes -- old crypt.h. */
110
111int mutt_protect (HEADER *, char *);
112
113int mutt_is_multipart_encrypted (BODY *);
114
115int mutt_is_valid_multipart_pgp_encrypted (BODY *b);
116
117int mutt_is_malformed_multipart_pgp_encrypted (BODY *b);
118
119int mutt_is_multipart_signed (BODY *);
120
121int mutt_is_application_pgp (BODY *);
122
123int mutt_is_application_smime (BODY *);
124
125int mutt_signed_handler (BODY *, STATE *);
126
127int mutt_parse_crypt_hdr (const char *, int, int);
128
129
130void convert_to_7bit (BODY *);
131
132
133
134/*-- crypt.c --*/
135
136/* Print the current time. */
137void crypt_current_time(STATE *s, char *app_name);
138
139/* Check out the type of encryption used and set the cached status
140 values if there are any. */
141int crypt_query (BODY *m);
142
143/* Fixme: To be documented. */
144void crypt_extract_keys_from_messages (HEADER *h);
145
146/* Do a quick check to make sure that we can find all of the
147 encryption keys if the user has requested this service.
148 Return the list of keys in KEYLIST.
149 If oppenc_mode is true, only keys that can be determined without
150 prompting will be used. */
151int crypt_get_keys (HEADER *msg, char **keylist, int oppenc_mode);
152
153/* Check if all recipients keys can be automatically determined.
154 * Enable encryption if they can, otherwise disable encryption. */
155void crypt_opportunistic_encrypt(HEADER *msg);
156
157/* Forget a passphrase and display a message. */
158void crypt_forget_passphrase (void);
159
160/* Check that we have a usable passphrase, ask if not. */
161int crypt_valid_passphrase (int);
162
163/* Write the message body/part A described by state S to a the given
164 TEMPFILE. */
165int crypt_write_signed(BODY *a, STATE *s, const char *tempf);
166
167/* Obtain pointers to fingerprint or short or long key ID, if any.
168
169 Upon return, at most one of return, *ppl and *pps pointers is non-NULL,
170 indicating the longest fingerprint or ID found, if any.
171
172 Return: Copy of fingerprint, if any, stripped of all spaces, else NULL.
173 Must be FREE'd by caller.
174 *pphint Start of string to be passed to pgp_add_string_to_hints() or
175 crypt_add_string_to_hints().
176 *ppl Start of long key ID if detected, else NULL.
177 *pps Start of short key ID if detected, else NULL. */
178const char* crypt_get_fingerprint_or_id (char *p, const char **pphint,
179 const char **ppl, const char **pps);
180
181/* Check if a string contains a numerical key */
182short crypt_is_numerical_keyid (const char *s);
183
184
185
186/*-- cryptglue.c --*/
187
188/* Show a message that a backend will be invoked. */
189void crypt_invoke_message (int type);
190
191
192/* Silently forget about a passphrase. */
193void crypt_pgp_void_passphrase (void);
194
195int crypt_pgp_valid_passphrase (void);
196
197
198/* Decrypt a PGP/MIME message. */
199int crypt_pgp_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d);
200
201/* MIME handler for the application/pgp content-type. */
202int crypt_pgp_application_pgp_handler (BODY *m, STATE *s);
203
204/* MIME handler for an PGP/MIME encrypted message. */
205int crypt_pgp_encrypted_handler (BODY *a, STATE *s);
206
207/* fixme: needs documentation. */
208void crypt_pgp_invoke_getkeys (ADDRESS *addr);
209
210/* Ask for a PGP key. */
211pgp_key_t crypt_pgp_ask_for_key (char *tag, char *whatfor,
212 short abilities, pgp_ring_t keyring);
213
214/* Check for a traditional PGP message in body B. */
215int crypt_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only);
216
217/* fixme: needs documentation. */
218BODY *crypt_pgp_traditional_encryptsign (BODY *a, int flags, char *keylist);
219
220/* Release the PGP key KPP (note, that we pass a pointer to it). */
221void crypt_pgp_free_key (pgp_key_t *kpp);
222
223/* Generate a PGP public key attachment. */
224BODY *crypt_pgp_make_key_attachment (char *tempf);
225
226/* This routine attempts to find the keyids of the recipients of a
227 message. It returns NULL if any of the keys can not be found.
228 If oppenc_mode is true, only keys that can be determined without
229 prompting will be used. */
230char *crypt_pgp_findkeys (ADDRESS *adrlist, int oppenc_mode);
231
232/* Create a new body with a PGP signed message from A. */
233BODY *crypt_pgp_sign_message (BODY *a);
234
235/* Warning: A is no longer freed in this routine, you need to free it
236 later. This is necessary for $fcc_attach. */
237BODY *crypt_pgp_encrypt_message (BODY *a, char *keylist, int sign);
238
239/* Invoke the PGP command to import a key. */
240void crypt_pgp_invoke_import (const char *fname);
241
242int crypt_pgp_send_menu (HEADER *msg, int *redraw);
243
244/* fixme: needs documentation */
245int crypt_pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempf);
246
247/* Access the keyID in K. */
248char *crypt_pgp_keyid (pgp_key_t k);
249
250/* fixme: needs documentation */
251void crypt_pgp_extract_keys_from_attachment_list (FILE *fp, int tag,BODY *top);
252
253void crypt_pgp_set_sender (const char *sender);
254
255
256
257/* Silently forget about a passphrase. */
258void crypt_smime_void_passphrase (void);
259
260int crypt_smime_valid_passphrase (void);
261
262/* Decrypt an S/MIME message. */
263int crypt_smime_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d);
264
265/* MIME handler for the application/smime content-type. */
266int crypt_smime_application_smime_handler (BODY *m, STATE *s);
267
268/* fixme: Needs documentation. */
269void crypt_smime_getkeys (ENVELOPE *env);
270
271/* Check that the sender matches. */
272int crypt_smime_verify_sender(HEADER *h);
273
274/* Ask for an SMIME key. */
275char *crypt_smime_ask_for_key (char *prompt, char *mailbox, short public);
276
277/* This routine attempts to find the keyids of the recipients of a
278 message. It returns NULL if any of the keys can not be found.
279 If oppenc_mode is true, only keys that can be determined without
280 prompting will be used. */
281char *crypt_smime_findkeys (ADDRESS *adrlist, int oppenc_mode);
282
283/* fixme: Needs documentation. */
284BODY *crypt_smime_sign_message (BODY *a);
285
286/* fixme: needs documentation. */
287BODY *crypt_smime_build_smime_entity (BODY *a, char *certlist);
288
289/* Add a certificate and update index file (externally). */
290void crypt_smime_invoke_import (char *infile, char *mailbox);
291
292int crypt_smime_send_menu (HEADER *msg, int *redraw);
293
294void crypt_smime_set_sender (const char *sender);
295
296/* fixme: needs documentation */
297int crypt_smime_verify_one (BODY *sigbdy, STATE *s, const char *tempf);
298
299void crypt_init (void);
300
301#endif /*MUTT_CRYPT_H*/