Imported Upstream version 2.1.5
[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_option (const char *configname, unsigned int configlineno,
138                       const char *name);
139 void obsolete_scdaemon_option (const char *configname,
140                                unsigned int configlineno, const char *name);
141
142 int string_to_cipher_algo (const char *string);
143 int string_to_digest_algo (const char *string);
144
145 const char *compress_algo_to_string(int algo);
146 int string_to_compress_algo(const char *string);
147 int check_compress_algo(int algo);
148 int default_cipher_algo(void);
149 int default_compress_algo(void);
150 const char *compliance_option_string(void);
151 void compliance_failure(void);
152
153 struct parse_options
154 {
155   char *name;
156   unsigned int bit;
157   char **value;
158   char *help;
159 };
160
161 char *optsep(char **stringp);
162 char *argsplit(char *string);
163 int parse_options(char *str,unsigned int *options,
164                   struct parse_options *opts,int noisy);
165 const char *get_libexecdir (void);
166 int path_access(const char *file,int mode);
167
168 int pubkey_get_npkey (pubkey_algo_t algo);
169 int pubkey_get_nskey (pubkey_algo_t algo);
170 int pubkey_get_nsig (pubkey_algo_t algo);
171 int pubkey_get_nenc (pubkey_algo_t algo);
172
173 /* Temporary helpers. */
174 unsigned int pubkey_nbits( int algo, gcry_mpi_t *pkey );
175 int mpi_print (estream_t stream, gcry_mpi_t a, int mode);
176 unsigned int ecdsa_qbits_from_Q (unsigned int qbits);
177
178
179 /*-- status.c --*/
180 void set_status_fd ( int fd );
181 int  is_status_enabled ( void );
182 void write_status ( int no );
183 void write_status_error (const char *where, gpg_error_t err);
184 void write_status_errcode (const char *where, int errcode);
185 void write_status_text ( int no, const char *text );
186 void write_status_strings (int no, const char *text,
187                            ...) GNUPG_GCC_A_SENTINEL(0);
188 void write_status_buffer ( int no,
189                            const char *buffer, size_t len, int wrap );
190 void write_status_text_and_buffer ( int no, const char *text,
191                                     const char *buffer, size_t len, int wrap );
192
193 void write_status_begin_signing (gcry_md_hd_t md);
194
195
196 int cpr_enabled(void);
197 char *cpr_get( const char *keyword, const char *prompt );
198 char *cpr_get_no_help( const char *keyword, const char *prompt );
199 char *cpr_get_utf8( const char *keyword, const char *prompt );
200 char *cpr_get_hidden( const char *keyword, const char *prompt );
201 void cpr_kill_prompt(void);
202 int  cpr_get_answer_is_yes_def (const char *keyword, const char *prompt,
203                                 int def_yes);
204 int  cpr_get_answer_is_yes( const char *keyword, const char *prompt );
205 int  cpr_get_answer_yes_no_quit( const char *keyword, const char *prompt );
206 int  cpr_get_answer_okay_cancel (const char *keyword,
207                                  const char *prompt,
208                                  int def_answer);
209
210 /*-- helptext.c --*/
211 void display_online_help( const char *keyword );
212
213 /*-- encode.c --*/
214 int setup_symkey (STRING2KEY **symkey_s2k,DEK **symkey_dek);
215 int encrypt_symmetric (const char *filename );
216 int encrypt_store (const char *filename );
217 int encrypt_crypt (ctrl_t ctrl, int filefd, const char *filename,
218                    strlist_t remusr, int use_symkey, pk_list_t provided_keys,
219                    int outputfd);
220 void encrypt_crypt_files (ctrl_t ctrl,
221                           int nfiles, char **files, strlist_t remusr);
222 int encrypt_filter (void *opaque, int control,
223                     iobuf_t a, byte *buf, size_t *ret_len);
224
225
226 /*-- sign.c --*/
227 int complete_sig (PKT_signature *sig, PKT_public_key *pksk, gcry_md_hd_t md,
228                   const char *cache_nonce);
229 int sign_file (ctrl_t ctrl, strlist_t filenames, int detached, strlist_t locusr,
230                int do_encrypt, strlist_t remusr, const char *outfile );
231 int clearsign_file( const char *fname, strlist_t locusr, const char *outfile );
232 int sign_symencrypt_file (const char *fname, strlist_t locusr);
233
234 /*-- sig-check.c --*/
235 int check_revocation_keys (PKT_public_key *pk, PKT_signature *sig);
236 int check_backsig(PKT_public_key *main_pk,PKT_public_key *sub_pk,
237                   PKT_signature *backsig);
238 int check_key_signature( KBNODE root, KBNODE node, int *is_selfsig );
239 int check_key_signature2( KBNODE root, KBNODE node, PKT_public_key *check_pk,
240                           PKT_public_key *ret_pk, int *is_selfsig,
241                           u32 *r_expiredate, int *r_expired );
242
243 /*-- delkey.c --*/
244 gpg_error_t delete_keys (strlist_t names, int secret, int allow_both);
245
246 /*-- keyedit.c --*/
247 void keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
248                    strlist_t commands, int quiet, int seckey_check );
249 void keyedit_passwd (ctrl_t ctrl, const char *username);
250 void keyedit_quick_adduid (ctrl_t ctrl, const char *username,
251                            const char *newuid);
252 void keyedit_quick_sign (ctrl_t ctrl, const char *fpr,
253                          strlist_t uids, strlist_t locusr, int local);
254 void show_basic_key_info (KBNODE keyblock);
255
256 /*-- keygen.c --*/
257 u32 parse_expire_string(const char *string);
258 u32 ask_expire_interval(int object,const char *def_expire);
259 u32 ask_expiredate(void);
260 void quick_generate_keypair (const char *uid);
261 void generate_keypair (ctrl_t ctrl, int full, const char *fname,
262                        const char *card_serialno, int card_backup_key);
263 int keygen_set_std_prefs (const char *string,int personal);
264 PKT_user_id *keygen_get_std_prefs (void);
265 int keygen_add_key_expire( PKT_signature *sig, void *opaque );
266 int keygen_add_std_prefs( PKT_signature *sig, void *opaque );
267 int keygen_upd_std_prefs( PKT_signature *sig, void *opaque );
268 int keygen_add_keyserver_url(PKT_signature *sig, void *opaque);
269 int keygen_add_notations(PKT_signature *sig,void *opaque);
270 int keygen_add_revkey(PKT_signature *sig, void *opaque);
271 gpg_error_t make_backsig (PKT_signature *sig, PKT_public_key *pk,
272                           PKT_public_key *sub_pk, PKT_public_key *sub_psk,
273                           u32 timestamp, const char *cache_nonce);
274 gpg_error_t generate_subkeypair (ctrl_t ctrl, kbnode_t pub_keyblock);
275 #ifdef ENABLE_CARD_SUPPORT
276 gpg_error_t generate_card_subkeypair (kbnode_t pub_keyblock,
277                                       int keyno, const char *serialno);
278 int save_unprotected_key_to_card (PKT_public_key *sk, int keyno);
279 #endif
280
281
282 /*-- openfile.c --*/
283 int overwrite_filep( const char *fname );
284 char *make_outfile_name( const char *iname );
285 char *ask_outfile_name( const char *name, size_t namelen );
286 int open_outfile (int inp_fd, const char *iname, int mode,
287                   int restrictedperm, iobuf_t *a);
288 char *get_matching_datafile (const char *sigfilename);
289 iobuf_t open_sigfile (const char *sigfilename, progress_filter_context_t *pfx);
290 void try_make_homedir( const char *fname );
291 char *get_openpgp_revocdir (const char *home);
292
293 /*-- seskey.c --*/
294 void make_session_key( DEK *dek );
295 gcry_mpi_t encode_session_key( int openpgp_pk_algo, DEK *dek, unsigned nbits );
296 gcry_mpi_t encode_md_value (PKT_public_key *pk,
297                             gcry_md_hd_t md, int hash_algo );
298
299 /*-- import.c --*/
300 typedef gpg_error_t (*import_screener_t)(kbnode_t keyblock, void *arg);
301
302 int parse_import_options(char *str,unsigned int *options,int noisy);
303 void import_keys (ctrl_t ctrl, char **fnames, int nnames,
304                   void *stats_hd, unsigned int options);
305 int import_keys_stream (ctrl_t ctrl, iobuf_t inp, void *stats_hd,
306                         unsigned char **fpr,
307                         size_t *fpr_len, unsigned int options);
308 int import_keys_es_stream (ctrl_t ctrl, estream_t fp, void *stats_handle,
309                            unsigned char **fpr, size_t *fpr_len,
310                            unsigned int options,
311                            import_screener_t screener, void *screener_arg);
312 gpg_error_t import_old_secring (ctrl_t ctrl, const char *fname);
313 void *import_new_stats_handle (void);
314 void import_release_stats_handle (void *p);
315 void import_print_stats (void *hd);
316
317 int collapse_uids( KBNODE *keyblock );
318
319
320 /*-- export.c --*/
321 int parse_export_options(char *str,unsigned int *options,int noisy);
322 int export_pubkeys (ctrl_t ctrl, strlist_t users, unsigned int options );
323 int export_pubkeys_stream (ctrl_t ctrl, iobuf_t out, strlist_t users,
324                            kbnode_t *keyblock_out, unsigned int options );
325 gpg_error_t export_pubkey_buffer (ctrl_t ctrl, const char *keyspec,
326                                   unsigned int options,
327                                   kbnode_t *r_keyblock,
328                                   void **r_data, size_t *r_datalen);
329 int export_seckeys (ctrl_t ctrl, strlist_t users);
330 int export_secsubkeys (ctrl_t ctrl, strlist_t users);
331
332 /*-- dearmor.c --*/
333 int dearmor_file( const char *fname );
334 int enarmor_file( const char *fname );
335
336 /*-- revoke.c --*/
337 struct revocation_reason_info;
338 int gen_standard_revoke (PKT_public_key *psk, const char *cache_nonce);
339 int gen_revoke( const char *uname );
340 int gen_desig_revoke( const char *uname, strlist_t locusr);
341 int revocation_reason_build_cb( PKT_signature *sig, void *opaque );
342 struct revocation_reason_info *
343                 ask_revocation_reason( int key_rev, int cert_rev, int hint );
344 void release_revocation_reason_info( struct revocation_reason_info *reason );
345
346 /*-- keylist.c --*/
347 void public_key_list (ctrl_t ctrl, strlist_t list, int locate_mode );
348 void secret_key_list (ctrl_t ctrl, strlist_t list );
349 void print_subpackets_colon(PKT_signature *sig);
350 void reorder_keyblock (KBNODE keyblock);
351 void list_keyblock_direct (kbnode_t keyblock, int secret, int has_secret,
352                            int fpr);
353 void print_fingerprint (estream_t fp, PKT_public_key *pk, int mode);
354 void print_revokers (estream_t fp, PKT_public_key *pk);
355 void show_policy_url(PKT_signature *sig,int indent,int mode);
356 void show_keyserver_url(PKT_signature *sig,int indent,int mode);
357 void show_notation(PKT_signature *sig,int indent,int mode,int which);
358 void dump_attribs (const PKT_user_id *uid, PKT_public_key *pk);
359 void set_attrib_fd(int fd);
360 void print_seckey_info (PKT_public_key *pk);
361 void print_pubkey_info (estream_t fp, PKT_public_key *pk);
362 void print_card_key_info (estream_t fp, KBNODE keyblock);
363
364 /*-- verify.c --*/
365 void print_file_status( int status, const char *name, int what );
366 int verify_signatures (ctrl_t ctrl, int nfiles, char **files );
367 int verify_files (ctrl_t ctrl, int nfiles, char **files );
368 int gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, estream_t out_fp);
369
370 /*-- decrypt.c --*/
371 int decrypt_message (ctrl_t ctrl, const char *filename );
372 gpg_error_t decrypt_message_fd (ctrl_t ctrl, int input_fd, int output_fd);
373 void decrypt_messages (ctrl_t ctrl, int nfiles, char *files[]);
374
375 /*-- plaintext.c --*/
376 int hash_datafiles( gcry_md_hd_t md, gcry_md_hd_t md2,
377                     strlist_t files, const char *sigfilename, int textmode);
378 int hash_datafile_by_fd ( gcry_md_hd_t md, gcry_md_hd_t md2, int data_fd,
379                           int textmode );
380 PKT_plaintext *setup_plaintext_name(const char *filename,IOBUF iobuf);
381
382 /*-- server.c --*/
383 int gpg_server (ctrl_t);
384 gpg_error_t gpg_proxy_pinentry_notify (ctrl_t ctrl,
385                                        const unsigned char *line);
386
387 #ifdef ENABLE_CARD_SUPPORT
388 /*-- card-util.c --*/
389 void change_pin (int no, int allow_admin);
390 void card_status (estream_t fp, char *serialno, size_t serialnobuflen);
391 void card_edit (ctrl_t ctrl, strlist_t commands);
392 gpg_error_t  card_generate_subkey (KBNODE pub_keyblock);
393 int  card_store_subkey (KBNODE node, int use);
394 #endif
395
396 #define S2K_DECODE_COUNT(_val) ((16ul + ((_val) & 15)) << (((_val) >> 4) + 6))
397
398 /*-- migrate.c --*/
399 void migrate_secring (ctrl_t ctrl);
400
401
402 #endif /*G10_MAIN_H*/