Imported Upstream version 2.1.7
[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, 2010 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 "keydb.h"
26 #include "util.h"
27
28 /* It could be argued that the default cipher should be 3DES rather
29    than AES128, and the default compression should be 0
30    (i.e. uncompressed) rather than 1 (zip).  However, the real world
31    issues of speed and size come into play here. */
32
33 #if GPG_USE_AES128
34 # define DEFAULT_CIPHER_ALGO     CIPHER_ALGO_AES
35 #elif GPG_USE_CAST5
36 # define DEFAULT_CIPHER_ALGO     CIPHER_ALGO_CAST5
37 #else
38 # define DEFAULT_CIPHER_ALGO     CIPHER_ALGO_3DES
39 #endif
40
41 #define DEFAULT_DIGEST_ALGO     ((GNUPG)? DIGEST_ALGO_SHA256:DIGEST_ALGO_SHA1)
42 #define DEFAULT_S2K_DIGEST_ALGO DIGEST_ALGO_SHA1
43 #ifdef HAVE_ZIP
44 # define DEFAULT_COMPRESS_ALGO   COMPRESS_ALGO_ZIP
45 #else
46 # define DEFAULT_COMPRESS_ALGO   COMPRESS_ALGO_NONE
47 #endif
48
49
50 #define S2K_DIGEST_ALGO (opt.s2k_digest_algo?opt.s2k_digest_algo:DEFAULT_S2K_DIGEST_ALGO)
51
52
53 /* Various data objects.  */
54
55 typedef struct
56 {
57   int header_okay;
58   PK_LIST pk_list;
59   DEK *symkey_dek;
60   STRING2KEY *symkey_s2k;
61   cipher_filter_context_t cfx;
62 } encrypt_filter_context_t;
63
64
65 struct groupitem
66 {
67   char *name;
68   strlist_t values;
69   struct groupitem *next;
70 };
71
72
73 /*-- gpg.c --*/
74 extern int g10_errors_seen;
75
76 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
77   void g10_exit(int rc) __attribute__ ((noreturn));
78 #else
79   void g10_exit(int rc);
80 #endif
81 void print_pubkey_algo_note (pubkey_algo_t algo);
82 void print_cipher_algo_note (cipher_algo_t algo);
83 void print_digest_algo_note (digest_algo_t algo);
84 void print_md5_rejected_note (void);
85
86 /*-- armor.c --*/
87 char *make_radix64_string( const byte *data, size_t len );
88
89 /*-- misc.c --*/
90 void trap_unaligned(void);
91 int disable_core_dumps(void);
92 void register_secured_file (const char *fname);
93 void unregister_secured_file (const char *fname);
94 int  is_secured_file (int fd);
95 int  is_secured_filename (const char *fname);
96 u16 checksum_u16( unsigned n );
97 u16 checksum( byte *p, unsigned n );
98 u16 checksum_mpi( gcry_mpi_t a );
99 u32 buffer_to_u32( const byte *buffer );
100 const byte *get_session_marker( size_t *rlen );
101
102 enum gcry_cipher_algos map_cipher_openpgp_to_gcry (cipher_algo_t algo);
103 #define openpgp_cipher_open(_a,_b,_c,_d) \
104   gcry_cipher_open((_a),map_cipher_openpgp_to_gcry((_b)),(_c),(_d))
105 #define openpgp_cipher_get_algo_keylen(_a) \
106   gcry_cipher_get_algo_keylen(map_cipher_openpgp_to_gcry((_a)))
107 #define openpgp_cipher_get_algo_blklen(_a) \
108   gcry_cipher_get_algo_blklen(map_cipher_openpgp_to_gcry((_a)))
109 int openpgp_cipher_blocklen (cipher_algo_t algo);
110 int openpgp_cipher_test_algo(cipher_algo_t algo);
111 const char *openpgp_cipher_algo_name (cipher_algo_t algo);
112
113 pubkey_algo_t map_pk_gcry_to_openpgp (enum gcry_pk_algos algo);
114 int openpgp_pk_test_algo (pubkey_algo_t algo);
115 int openpgp_pk_test_algo2 (pubkey_algo_t algo, unsigned int use);
116 int openpgp_pk_algo_usage ( int algo );
117 const char *openpgp_pk_algo_name (pubkey_algo_t algo);
118
119 enum gcry_md_algos map_md_openpgp_to_gcry (digest_algo_t algo);
120 int openpgp_md_test_algo (digest_algo_t algo);
121 const char *openpgp_md_algo_name (int algo);
122
123 struct expando_args
124 {
125   PKT_public_key *pk;
126   PKT_public_key *pksk;
127   byte imagetype;
128   int validity_info;
129   const char *validity_string;
130   const byte *namehash;
131 };
132
133 char *pct_expando(const char *string,struct expando_args *args);
134 void deprecated_warning(const char *configname,unsigned int configlineno,
135                         const char *option,const char *repl1,const char *repl2);
136 void deprecated_command (const char *name);
137 void obsolete_scdaemon_option (const char *configname,
138                                unsigned int configlineno, const char *name);
139
140 int string_to_cipher_algo (const char *string);
141 int string_to_digest_algo (const char *string);
142
143 const char *compress_algo_to_string(int algo);
144 int string_to_compress_algo(const char *string);
145 int check_compress_algo(int algo);
146 int default_cipher_algo(void);
147 int default_compress_algo(void);
148 const char *compliance_option_string(void);
149 void compliance_failure(void);
150
151 struct parse_options
152 {
153   char *name;
154   unsigned int bit;
155   char **value;
156   char *help;
157 };
158
159 char *optsep(char **stringp);
160 char *argsplit(char *string);
161 int parse_options(char *str,unsigned int *options,
162                   struct parse_options *opts,int noisy);
163 const char *get_libexecdir (void);
164 int path_access(const char *file,int mode);
165
166 int pubkey_get_npkey (pubkey_algo_t algo);
167 int pubkey_get_nskey (pubkey_algo_t algo);
168 int pubkey_get_nsig (pubkey_algo_t algo);
169 int pubkey_get_nenc (pubkey_algo_t algo);
170
171 /* Temporary helpers. */
172 unsigned int pubkey_nbits( int algo, gcry_mpi_t *pkey );
173 int mpi_print (estream_t stream, gcry_mpi_t a, int mode);
174 unsigned int ecdsa_qbits_from_Q (unsigned int qbits);
175
176
177 /*-- status.c --*/
178 void set_status_fd ( int fd );
179 int  is_status_enabled ( void );
180 void write_status ( int no );
181 void write_status_error (const char *where, gpg_error_t err);
182 void write_status_errcode (const char *where, int errcode);
183 void write_status_text ( int no, const char *text );
184 void write_status_strings (int no, const char *text,
185                            ...) GPGRT_ATTR_SENTINEL(0);
186 void write_status_buffer ( int no,
187                            const char *buffer, size_t len, int wrap );
188 void write_status_text_and_buffer ( int no, const char *text,
189                                     const char *buffer, size_t len, int wrap );
190
191 void write_status_begin_signing (gcry_md_hd_t md);
192
193
194 int cpr_enabled(void);
195 char *cpr_get( const char *keyword, const char *prompt );
196 char *cpr_get_no_help( const char *keyword, const char *prompt );
197 char *cpr_get_utf8( const char *keyword, const char *prompt );
198 char *cpr_get_hidden( const char *keyword, const char *prompt );
199 void cpr_kill_prompt(void);
200 int  cpr_get_answer_is_yes_def (const char *keyword, const char *prompt,
201                                 int def_yes);
202 int  cpr_get_answer_is_yes( const char *keyword, const char *prompt );
203 int  cpr_get_answer_yes_no_quit( const char *keyword, const char *prompt );
204 int  cpr_get_answer_okay_cancel (const char *keyword,
205                                  const char *prompt,
206                                  int def_answer);
207
208 /*-- helptext.c --*/
209 void display_online_help( const char *keyword );
210
211 /*-- encode.c --*/
212 int setup_symkey (STRING2KEY **symkey_s2k,DEK **symkey_dek);
213 int encrypt_symmetric (const char *filename );
214 int encrypt_store (const char *filename );
215 int encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename,
216                    strlist_t remusr, int use_symkey, pk_list_t provided_keys,
217                    int outputfd);
218 void encrypt_crypt_files (ctrl_t ctrl,
219                           int nfiles, char **files, strlist_t remusr);
220 int encrypt_filter (void *opaque, int control,
221                     iobuf_t a, byte *buf, size_t *ret_len);
222
223
224 /*-- sign.c --*/
225 int complete_sig (PKT_signature *sig, PKT_public_key *pksk, gcry_md_hd_t md,
226                   const char *cache_nonce);
227 int sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
228                int do_encrypt, strlist_t remusr, const char *outfile );
229 int clearsign_file( const char *fname, strlist_t locusr, const char *outfile );
230 int sign_symencrypt_file (const char *fname, strlist_t locusr);
231
232 /*-- sig-check.c --*/
233 int check_revocation_keys (PKT_public_key *pk, PKT_signature *sig);
234 int check_backsig(PKT_public_key *main_pk,PKT_public_key *sub_pk,
235                   PKT_signature *backsig);
236 int check_key_signature( KBNODE root, KBNODE node, int *is_selfsig );
237 int check_key_signature2( KBNODE root, KBNODE node, PKT_public_key *check_pk,
238                           PKT_public_key *ret_pk, int *is_selfsig,
239                           u32 *r_expiredate, int *r_expired );
240
241 /*-- delkey.c --*/
242 gpg_error_t delete_keys (strlist_t names, int secret, int allow_both);
243
244 /*-- keyedit.c --*/
245 void keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
246                    strlist_t commands, int quiet, int seckey_check );
247 void keyedit_passwd (ctrl_t ctrl, const char *username);
248 void keyedit_quick_adduid (ctrl_t ctrl, const char *username,
249                            const char *newuid);
250 void keyedit_quick_sign (ctrl_t ctrl, const char *fpr,
251                          strlist_t uids, strlist_t locusr, int local);
252 void show_basic_key_info (KBNODE keyblock);
253
254 /*-- keygen.c --*/
255 u32 parse_expire_string(const char *string);
256 u32 ask_expire_interval(int object,const char *def_expire);
257 u32 ask_expiredate(void);
258 void quick_generate_keypair (const char *uid);
259 void generate_keypair (ctrl_t ctrl, int full, const char *fname,
260                        const char *card_serialno, int card_backup_key);
261 int keygen_set_std_prefs (const char *string,int personal);
262 PKT_user_id *keygen_get_std_prefs (void);
263 int keygen_add_key_expire( PKT_signature *sig, void *opaque );
264 int keygen_add_std_prefs( PKT_signature *sig, void *opaque );
265 int keygen_upd_std_prefs( PKT_signature *sig, void *opaque );
266 int keygen_add_keyserver_url(PKT_signature *sig, void *opaque);
267 int keygen_add_notations(PKT_signature *sig,void *opaque);
268 int keygen_add_revkey(PKT_signature *sig, void *opaque);
269 gpg_error_t make_backsig (PKT_signature *sig, PKT_public_key *pk,
270                           PKT_public_key *sub_pk, PKT_public_key *sub_psk,
271                           u32 timestamp, const char *cache_nonce);
272 gpg_error_t generate_subkeypair (ctrl_t ctrl, kbnode_t pub_keyblock);
273 #ifdef ENABLE_CARD_SUPPORT
274 gpg_error_t generate_card_subkeypair (kbnode_t pub_keyblock,
275                                       int keyno, const char *serialno);
276 int save_unprotected_key_to_card (PKT_public_key *sk, int keyno);
277 #endif
278
279
280 /*-- openfile.c --*/
281 int overwrite_filep( const char *fname );
282 char *make_outfile_name( const char *iname );
283 char *ask_outfile_name( const char *name, size_t namelen );
284 int open_outfile (int inp_fd, const char *iname, int mode,
285                   int restrictedperm, iobuf_t *a);
286 char *get_matching_datafile (const char *sigfilename);
287 iobuf_t open_sigfile (const char *sigfilename, progress_filter_context_t *pfx);
288 void try_make_homedir( const char *fname );
289 char *get_openpgp_revocdir (const char *home);
290
291 /*-- seskey.c --*/
292 void make_session_key( DEK *dek );
293 gcry_mpi_t encode_session_key( int openpgp_pk_algo, DEK *dek, unsigned nbits );
294 gcry_mpi_t encode_md_value (PKT_public_key *pk,
295                             gcry_md_hd_t md, int hash_algo );
296
297 /*-- import.c --*/
298 typedef gpg_error_t (*import_screener_t)(kbnode_t keyblock, void *arg);
299
300 int parse_import_options(char *str,unsigned int *options,int noisy);
301 void import_keys (ctrl_t ctrl, char **fnames, int nnames,
302                   void *stats_hd, unsigned int options);
303 int import_keys_stream (ctrl_t ctrl, iobuf_t inp, void *stats_hd,
304                         unsigned char **fpr,
305                         size_t *fpr_len, unsigned int options);
306 int import_keys_es_stream (ctrl_t ctrl, estream_t fp, void *stats_handle,
307                            unsigned char **fpr, size_t *fpr_len,
308                            unsigned int options,
309                            import_screener_t screener, void *screener_arg);
310 gpg_error_t import_old_secring (ctrl_t ctrl, const char *fname);
311 void *import_new_stats_handle (void);
312 void import_release_stats_handle (void *p);
313 void import_print_stats (void *hd);
314
315 int collapse_uids( KBNODE *keyblock );
316
317
318 /*-- export.c --*/
319 int parse_export_options(char *str,unsigned int *options,int noisy);
320 int export_pubkeys (ctrl_t ctrl, strlist_t users, unsigned int options );
321 int export_pubkeys_stream (ctrl_t ctrl, iobuf_t out, strlist_t users,
322                            kbnode_t *keyblock_out, unsigned int options );
323 gpg_error_t export_pubkey_buffer (ctrl_t ctrl, const char *keyspec,
324                                   unsigned int options,
325                                   kbnode_t *r_keyblock,
326                                   void **r_data, size_t *r_datalen);
327 int export_seckeys (ctrl_t ctrl, strlist_t users);
328 int export_secsubkeys (ctrl_t ctrl, strlist_t users);
329
330 /*-- dearmor.c --*/
331 int dearmor_file( const char *fname );
332 int enarmor_file( const char *fname );
333
334 /*-- revoke.c --*/
335 struct revocation_reason_info;
336 int gen_standard_revoke (PKT_public_key *psk, const char *cache_nonce);
337 int gen_revoke( const char *uname );
338 int gen_desig_revoke( const char *uname, strlist_t locusr);
339 int revocation_reason_build_cb( PKT_signature *sig, void *opaque );
340 struct revocation_reason_info *
341                 ask_revocation_reason( int key_rev, int cert_rev, int hint );
342 void release_revocation_reason_info( struct revocation_reason_info *reason );
343
344 /*-- keylist.c --*/
345 void public_key_list (ctrl_t ctrl, strlist_t list, int locate_mode );
346 void secret_key_list (ctrl_t ctrl, strlist_t list );
347 void print_subpackets_colon(PKT_signature *sig);
348 void reorder_keyblock (KBNODE keyblock);
349 void list_keyblock_direct (kbnode_t keyblock, int secret, int has_secret,
350                            int fpr);
351 void print_fingerprint (estream_t fp, PKT_public_key *pk, int mode);
352 void print_revokers (estream_t fp, PKT_public_key *pk);
353 void show_policy_url(PKT_signature *sig,int indent,int mode);
354 void show_keyserver_url(PKT_signature *sig,int indent,int mode);
355 void show_notation(PKT_signature *sig,int indent,int mode,int which);
356 void dump_attribs (const PKT_user_id *uid, PKT_public_key *pk);
357 void set_attrib_fd(int fd);
358 void print_seckey_info (PKT_public_key *pk);
359 void print_pubkey_info (estream_t fp, PKT_public_key *pk);
360 void print_card_key_info (estream_t fp, KBNODE keyblock);
361
362 /*-- verify.c --*/
363 void print_file_status( int status, const char *name, int what );
364 int verify_signatures (ctrl_t ctrl, int nfiles, char **files );
365 int verify_files (ctrl_t ctrl, int nfiles, char **files );
366 int gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, estream_t out_fp);
367
368 /*-- decrypt.c --*/
369 int decrypt_message (ctrl_t ctrl, const char *filename );
370 gpg_error_t decrypt_message_fd (ctrl_t ctrl, int input_fd, int output_fd);
371 void decrypt_messages (ctrl_t ctrl, int nfiles, char *files[]);
372
373 /*-- plaintext.c --*/
374 int hash_datafiles( gcry_md_hd_t md, gcry_md_hd_t md2,
375                     strlist_t files, const char *sigfilename, int textmode);
376 int hash_datafile_by_fd ( gcry_md_hd_t md, gcry_md_hd_t md2, int data_fd,
377                           int textmode );
378 PKT_plaintext *setup_plaintext_name(const char *filename,IOBUF iobuf);
379
380 /*-- server.c --*/
381 int gpg_server (ctrl_t);
382 gpg_error_t gpg_proxy_pinentry_notify (ctrl_t ctrl,
383                                        const unsigned char *line);
384
385 #ifdef ENABLE_CARD_SUPPORT
386 /*-- card-util.c --*/
387 void change_pin (int no, int allow_admin);
388 void card_status (estream_t fp, char *serialno, size_t serialnobuflen);
389 void card_edit (ctrl_t ctrl, strlist_t commands);
390 gpg_error_t  card_generate_subkey (KBNODE pub_keyblock);
391 int  card_store_subkey (KBNODE node, int use);
392 #endif
393
394 #define S2K_DECODE_COUNT(_val) ((16ul + ((_val) & 15)) << (((_val) >> 4) + 6))
395
396 /*-- migrate.c --*/
397 void migrate_secring (ctrl_t ctrl);
398
399
400 #endif /*G10_MAIN_H*/