Imported Upstream version 2.0.27
[platform/upstream/gpg2.git] / g10 / main.h
1 /* main.h
2  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3  *               2008, 2009 Free Software Foundation, Inc.
4  *
5  * This file is part of GnuPG.
6  *
7  * GnuPG is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * GnuPG is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20 #ifndef G10_MAIN_H
21 #define G10_MAIN_H
22
23 #include "types.h"
24 #include "iobuf.h"
25 #include "cipher.h"
26 #include "keydb.h"
27 #include "util.h"
28
29
30 /* It could be argued that the default cipher should be 3DES rather
31    than CAST5, and the default compression should be 0
32    (i.e. uncompressed) rather than 1 (zip).  However, the real world
33    issues of speed and size come into play here. */
34
35 #define DEFAULT_CIPHER_ALGO     CIPHER_ALGO_CAST5
36 #define DEFAULT_DIGEST_ALGO     ((GNUPG)? DIGEST_ALGO_SHA256:DIGEST_ALGO_SHA1)
37 #define DEFAULT_COMPRESS_ALGO   COMPRESS_ALGO_ZIP
38 #define DEFAULT_S2K_DIGEST_ALGO DIGEST_ALGO_SHA1
39
40 #define S2K_DIGEST_ALGO (opt.s2k_digest_algo?opt.s2k_digest_algo:DEFAULT_S2K_DIGEST_ALGO)
41
42 typedef struct
43 {
44   int header_okay;
45   PK_LIST pk_list;
46   DEK *symkey_dek;
47   STRING2KEY *symkey_s2k;
48   cipher_filter_context_t cfx;
49 } encrypt_filter_context_t;
50
51 struct groupitem
52 {
53   char *name;
54   strlist_t values;
55   struct groupitem *next;
56 };
57
58 /*-- gpg.c --*/
59 extern int g10_errors_seen;
60
61 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
62   void g10_exit(int rc) __attribute__ ((noreturn));
63 #else
64   void g10_exit(int rc);
65 #endif
66
67 /*-- armor.c --*/
68 char *make_radix64_string( const byte *data, size_t len );
69 int parse_key_failed_line (const void *lineptr, unsigned int len);
70
71 /*-- misc.c --*/
72 void trap_unaligned(void);
73 int disable_core_dumps(void);
74 void register_secured_file (const char *fname);
75 void unregister_secured_file (const char *fname);
76 int  is_secured_file (int fd);
77 int  is_secured_filename (const char *fname);
78 u16 checksum_u16( unsigned n );
79 u16 checksum( byte *p, unsigned n );
80 u16 checksum_mpi( gcry_mpi_t a );
81 const byte *get_session_marker( size_t *rlen );
82 void print_pubkey_algo_note( int algo );
83 void print_cipher_algo_note( int algo );
84 void print_digest_algo_note( int algo );
85 void print_md5_rejected_note (void);
86 int map_cipher_openpgp_to_gcry (int algo);
87 #define openpgp_cipher_open(_a,_b,_c,_d) gcry_cipher_open((_a),map_cipher_openpgp_to_gcry((_b)),(_c),(_d))
88 #define openpgp_cipher_get_algo_keylen(_a) gcry_cipher_get_algo_keylen(map_cipher_openpgp_to_gcry((_a)))
89 #define openpgp_cipher_get_algo_blklen(_a) gcry_cipher_get_algo_blklen(map_cipher_openpgp_to_gcry((_a)))
90 int openpgp_cipher_blocklen (int algo);
91 int openpgp_cipher_test_algo( int algo );
92 const char *openpgp_cipher_algo_name (int algo);
93 int map_pk_openpgp_to_gcry (int algo);
94 int openpgp_pk_test_algo( int algo );
95 int openpgp_pk_test_algo2 ( int algo, unsigned int use );
96 int openpgp_pk_algo_usage ( int algo );
97 const char *openpgp_pk_algo_name (int algo);
98 int openpgp_md_test_algo( int algo );
99
100 #ifdef USE_IDEA
101 void idea_cipher_warn( int show );
102 #else
103 #define idea_cipher_warn(a)  do { } while (0)
104 #endif
105
106 struct expando_args
107 {
108   PKT_public_key *pk;
109   PKT_secret_key *sk;
110   byte imagetype;
111   int validity_info;
112   const char *validity_string;
113   const byte *namehash;
114 };
115
116 char *pct_expando(const char *string,struct expando_args *args);
117 void deprecated_warning(const char *configname,unsigned int configlineno,
118                         const char *option,const char *repl1,const char *repl2);
119 void deprecated_command (const char *name);
120 void obsolete_option (const char *configname, unsigned int configlineno,
121                       const char *name);
122 void obsolete_scdaemon_option (const char *configname,
123                                unsigned int configlineno, const char *name);
124
125 int string_to_cipher_algo (const char *string);
126 int string_to_digest_algo (const char *string);
127
128 const char *compress_algo_to_string(int algo);
129 int string_to_compress_algo(const char *string);
130 int check_compress_algo(int algo);
131 int default_cipher_algo(void);
132 int default_compress_algo(void);
133 const char *compliance_option_string(void);
134 void compliance_failure(void);
135
136 struct parse_options
137 {
138   char *name;
139   unsigned int bit;
140   char **value;
141   char *help;
142 };
143
144 char *optsep(char **stringp);
145 char *argsplit(char *string);
146 int parse_options(char *str,unsigned int *options,
147                   struct parse_options *opts,int noisy);
148 int has_invalid_email_chars (const char *s);
149 int is_valid_mailbox (const char *name);
150 const char *get_libexecdir (void);
151 int path_access(const char *file,int mode);
152
153 /* Temporary helpers. */
154 int pubkey_get_npkey( int algo );
155 int pubkey_get_nskey( int algo );
156 int pubkey_get_nsig( int algo );
157 int pubkey_get_nenc( int algo );
158 unsigned int pubkey_nbits( int algo, gcry_mpi_t *pkey );
159 int mpi_print( FILE *fp, gcry_mpi_t a, int mode );
160
161 /*-- status.c --*/
162 void set_status_fd ( int fd );
163 int  is_status_enabled ( void );
164 void write_status ( int no );
165 void write_status_error (const char *where, int errcode);
166 void write_status_text ( int no, const char *text );
167 void write_status_strings (int no, const char *text,
168                            ...) GNUPG_GCC_A_SENTINEL(0);
169 void write_status_buffer ( int no,
170                            const char *buffer, size_t len, int wrap );
171 void write_status_text_and_buffer ( int no, const char *text,
172                                     const char *buffer, size_t len, int wrap );
173
174 void write_status_begin_signing (gcry_md_hd_t md);
175
176
177 int cpr_enabled(void);
178 char *cpr_get( const char *keyword, const char *prompt );
179 char *cpr_get_no_help( const char *keyword, const char *prompt );
180 char *cpr_get_utf8( const char *keyword, const char *prompt );
181 char *cpr_get_hidden( const char *keyword, const char *prompt );
182 void cpr_kill_prompt(void);
183 int  cpr_get_answer_is_yes( const char *keyword, const char *prompt );
184 int  cpr_get_answer_yes_no_quit( const char *keyword, const char *prompt );
185 int  cpr_get_answer_okay_cancel (const char *keyword,
186                                  const char *prompt,
187                                  int def_answer);
188
189 /*-- helptext.c --*/
190 void display_online_help( const char *keyword );
191
192 /*-- encode.c --*/
193 int setup_symkey(STRING2KEY **symkey_s2k,DEK **symkey_dek);
194 int encode_symmetric( const char *filename );
195 int encode_store( const char *filename );
196 int encode_crypt( const char *filename, strlist_t remusr, int use_symkey );
197 void encode_crypt_files(int nfiles, char **files, strlist_t remusr);
198 int encrypt_filter( void *opaque, int control,
199                     iobuf_t a, byte *buf, size_t *ret_len);
200
201
202 /*-- sign.c --*/
203 int complete_sig( PKT_signature *sig, PKT_secret_key *sk, gcry_md_hd_t md );
204 int sign_file( strlist_t filenames, int detached, strlist_t locusr,
205                int do_encrypt, strlist_t remusr, const char *outfile );
206 int clearsign_file( const char *fname, strlist_t locusr, const char *outfile );
207 int sign_symencrypt_file (const char *fname, strlist_t locusr);
208
209 /*-- sig-check.c --*/
210 int check_revocation_keys (PKT_public_key *pk, PKT_signature *sig);
211 int check_backsig(PKT_public_key *main_pk,PKT_public_key *sub_pk,
212                   PKT_signature *backsig);
213 int check_key_signature( KBNODE root, KBNODE node, int *is_selfsig );
214 int check_key_signature2( KBNODE root, KBNODE node, PKT_public_key *check_pk,
215                           PKT_public_key *ret_pk, int *is_selfsig,
216                           u32 *r_expiredate, int *r_expired );
217
218 /*-- delkey.c --*/
219 int delete_keys( strlist_t names, int secret, int allow_both );
220
221 /*-- keyedit.c --*/
222 void keyedit_menu( const char *username, strlist_t locusr,
223                    strlist_t commands, int quiet, int seckey_check );
224 void keyedit_passwd (const char *username);
225 void show_basic_key_info (KBNODE keyblock);
226
227 /*-- keygen.c --*/
228 u32 parse_expire_string(const char *string);
229 u32 ask_expire_interval(int object,const char *def_expire);
230 u32 ask_expiredate(void);
231 void generate_keypair( const char *fname, const char *card_serialno,
232                        const char *backup_encryption_dir );
233 int keygen_set_std_prefs (const char *string,int personal);
234 PKT_user_id *keygen_get_std_prefs (void);
235 int keygen_add_key_expire( PKT_signature *sig, void *opaque );
236 int keygen_add_std_prefs( PKT_signature *sig, void *opaque );
237 int keygen_upd_std_prefs( PKT_signature *sig, void *opaque );
238 int keygen_add_keyserver_url(PKT_signature *sig, void *opaque);
239 int keygen_add_notations(PKT_signature *sig,void *opaque);
240 int keygen_add_revkey(PKT_signature *sig, void *opaque);
241 int make_backsig(PKT_signature *sig,PKT_public_key *pk,
242                  PKT_public_key *sub_pk,PKT_secret_key *sub_sk,
243                  u32 timestamp);
244 int generate_subkeypair( KBNODE pub_keyblock, KBNODE sec_keyblock );
245 #ifdef ENABLE_CARD_SUPPORT
246 int generate_card_subkeypair (KBNODE pub_keyblock, KBNODE sec_keyblock,
247                               int keyno, const char *serialno);
248 int save_unprotected_key_to_card (PKT_secret_key *sk, int keyno);
249 #endif
250
251 /*-- openfile.c --*/
252 int overwrite_filep( const char *fname );
253 char *make_outfile_name( const char *iname );
254 char *ask_outfile_name( const char *name, size_t namelen );
255 int   open_outfile( const char *iname, int mode, iobuf_t *a );
256 char *get_matching_datafile (const char *sigfilename);
257 iobuf_t open_sigfile (const char *sigfilename, progress_filter_context_t *pfx);
258 void try_make_homedir( const char *fname );
259
260 /*-- seskey.c --*/
261 void make_session_key( DEK *dek );
262 gcry_mpi_t encode_session_key( DEK *dek, unsigned nbits );
263 gcry_mpi_t encode_md_value( PKT_public_key *pk, PKT_secret_key *sk,
264                             gcry_md_hd_t md, int hash_algo );
265
266 /*-- import.c --*/
267
268 typedef int (*import_filter_t)(kbnode_t keyblock, void *arg);
269
270 int parse_import_options(char *str,unsigned int *options,int noisy);
271 void import_keys( char **fnames, int nnames,
272                   void *stats_hd, unsigned int options );
273 int import_keys_stream (iobuf_t inp, void *stats_hd, unsigned char **fpr,
274                         size_t *fpr_len, unsigned int options,
275                         import_filter_t filter, void *filter_arg,
276                         int *r_gpgkeys_err);
277 void *import_new_stats_handle (void);
278 void import_release_stats_handle (void *p);
279 void import_print_stats (void *hd);
280
281 int collapse_uids( KBNODE *keyblock );
282
283 int auto_create_card_key_stub ( const char *serialnostr,
284                                 const unsigned char *fpr1,
285                                 const unsigned char *fpr2,
286                                 const unsigned char *fpr3);
287
288 /*-- export.c --*/
289 int parse_export_options(char *str,unsigned int *options,int noisy);
290 int export_pubkeys( strlist_t users, unsigned int options );
291 int export_pubkeys_stream( iobuf_t out, strlist_t users,
292                            KBNODE *keyblock_out, unsigned int options );
293 int export_seckeys( strlist_t users );
294 int export_secsubkeys( strlist_t users );
295
296 /* dearmor.c --*/
297 int dearmor_file( const char *fname );
298 int enarmor_file( const char *fname );
299
300 /*-- revoke.c --*/
301 struct revocation_reason_info;
302 int gen_revoke( const char *uname );
303 int gen_desig_revoke( const char *uname, strlist_t locusr);
304 int revocation_reason_build_cb( PKT_signature *sig, void *opaque );
305 struct revocation_reason_info *
306                 ask_revocation_reason( int key_rev, int cert_rev, int hint );
307 void release_revocation_reason_info( struct revocation_reason_info *reason );
308
309 /*-- keylist.c --*/
310 void public_key_list( strlist_t list, int locate_mode );
311 void secret_key_list( strlist_t list );
312 void print_subpackets_colon(PKT_signature *sig);
313 void reorder_keyblock (KBNODE keyblock);
314 void list_keyblock( KBNODE keyblock, int secret, int fpr, void *opaque );
315 void print_fingerprint (PKT_public_key *pk, PKT_secret_key *sk, int mode);
316 void print_revokers(PKT_public_key *pk);
317 void show_policy_url(PKT_signature *sig,int indent,int mode);
318 void show_keyserver_url(PKT_signature *sig,int indent,int mode);
319 void show_notation(PKT_signature *sig,int indent,int mode,int which);
320 void dump_attribs(const PKT_user_id *uid,
321                   PKT_public_key *pk,PKT_secret_key *sk);
322 void set_attrib_fd(int fd);
323 void print_seckey_info (PKT_secret_key *sk);
324 void print_pubkey_info (FILE *fp, PKT_public_key *pk);
325 void print_card_key_info (FILE *fp, KBNODE keyblock);
326
327 /*-- verify.c --*/
328 void print_file_status( int status, const char *name, int what );
329 int verify_signatures( int nfiles, char **files );
330 int verify_files( int nfiles, char **files );
331 int gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, FILE *out_fp);
332
333 /*-- decrypt.c --*/
334 int decrypt_message( const char *filename );
335 void decrypt_messages(int nfiles, char *files[]);
336
337 /*-- plaintext.c --*/
338 int hash_datafiles( gcry_md_hd_t md, gcry_md_hd_t md2,
339                     strlist_t files, const char *sigfilename, int textmode );
340 int hash_datafile_by_fd ( gcry_md_hd_t md, gcry_md_hd_t md2, int data_fd,
341                           int textmode );
342 PKT_plaintext *setup_plaintext_name(const char *filename,IOBUF iobuf);
343
344 /*-- signal.c --*/
345 void init_signals(void);
346 void pause_on_sigusr( int which );
347 void block_all_signals(void);
348 void unblock_all_signals(void);
349
350 /*-- server.c --*/
351 int gpg_server (ctrl_t);
352
353 #ifdef ENABLE_CARD_SUPPORT
354 /*-- card-util.c --*/
355 void change_pin (int no, int allow_admin);
356 void card_status (FILE *fp, char *serialno, size_t serialnobuflen);
357 void card_edit (strlist_t commands);
358 int  card_generate_subkey (KBNODE pub_keyblock, KBNODE sec_keyblock);
359 int  card_store_subkey (KBNODE node, int use);
360 #endif
361
362 #define S2K_DECODE_COUNT(_val) ((16ul + ((_val) & 15)) << (((_val) >> 4) + 6))
363
364 #endif /*G10_MAIN_H*/