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