Imported Upstream version 2.0.19
[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     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 void print_pubkey_algo_note( int algo );
67 void print_cipher_algo_note( int algo );
68 void print_digest_algo_note( int algo );
69
70 /*-- armor.c --*/
71 char *make_radix64_string( const byte *data, size_t len );
72
73 /*-- misc.c --*/
74 void trap_unaligned(void);
75 int disable_core_dumps(void);
76 void register_secured_file (const char *fname);
77 void unregister_secured_file (const char *fname);
78 int  is_secured_file (int fd);
79 int  is_secured_filename (const char *fname);
80 u16 checksum_u16( unsigned n );
81 u16 checksum( byte *p, unsigned n );
82 u16 checksum_mpi( gcry_mpi_t a );
83 u32 buffer_to_u32( const byte *buffer );
84 const byte *get_session_marker( size_t *rlen );
85 int map_cipher_openpgp_to_gcry (int algo);
86 #define openpgp_cipher_open(_a,_b,_c,_d) gcry_cipher_open((_a),map_cipher_openpgp_to_gcry((_b)),(_c),(_d))
87 #define openpgp_cipher_get_algo_keylen(_a) gcry_cipher_get_algo_keylen(map_cipher_openpgp_to_gcry((_a)))
88 #define openpgp_cipher_get_algo_blklen(_a) gcry_cipher_get_algo_blklen(map_cipher_openpgp_to_gcry((_a)))
89 int openpgp_cipher_blocklen (int algo);
90 int openpgp_cipher_test_algo( int algo );
91 const char *openpgp_cipher_algo_name (int algo);
92 int openpgp_pk_test_algo( int algo );
93 int openpgp_pk_test_algo2 ( int algo, unsigned int use );
94 int openpgp_pk_algo_usage ( int algo );
95 int openpgp_md_test_algo( int algo );
96
97 #ifdef USE_IDEA
98 void idea_cipher_warn( int show );
99 #else
100 #define idea_cipher_warn(a)  do { } while (0)
101 #endif
102
103 struct expando_args
104 {
105   PKT_public_key *pk;
106   PKT_secret_key *sk;
107   byte imagetype;
108   int validity_info;
109   const char *validity_string;
110 };
111
112 char *pct_expando(const char *string,struct expando_args *args);
113 void deprecated_warning(const char *configname,unsigned int configlineno,
114                         const char *option,const char *repl1,const char *repl2);
115 void deprecated_command (const char *name);
116 void obsolete_option (const char *configname, unsigned int configlineno, 
117                       const char *name);
118
119 int string_to_cipher_algo (const char *string);
120 int string_to_digest_algo (const char *string);
121
122 const char *compress_algo_to_string(int algo);
123 int string_to_compress_algo(const char *string);
124 int check_compress_algo(int algo);
125 int default_cipher_algo(void);
126 int default_compress_algo(void);
127 const char *compliance_option_string(void);
128 void compliance_failure(void);
129
130 struct parse_options
131 {
132   char *name;
133   unsigned int bit;
134   char **value;
135   char *help;
136 };
137
138 char *optsep(char **stringp);
139 char *argsplit(char *string);
140 int parse_options(char *str,unsigned int *options,
141                   struct parse_options *opts,int noisy);
142 int has_invalid_email_chars (const char *s);
143 int is_valid_mailbox (const char *name);
144 const char *get_libexecdir (void);
145 int path_access(const char *file,int mode);
146
147 /* Temporary helpers. */
148 int pubkey_get_npkey( int algo );
149 int pubkey_get_nskey( int algo );
150 int pubkey_get_nsig( int algo );
151 int pubkey_get_nenc( int algo );
152 unsigned int pubkey_nbits( int algo, gcry_mpi_t *pkey );
153 int mpi_print( FILE *fp, gcry_mpi_t a, int mode );
154
155 /*-- status.c --*/
156 void set_status_fd ( int fd );
157 int  is_status_enabled ( void );
158 void write_status ( int no );
159 void write_status_error (const char *where, int errcode);
160 void write_status_text ( int no, const char *text );
161 void write_status_buffer ( int no,
162                            const char *buffer, size_t len, int wrap );
163 void write_status_text_and_buffer ( int no, const char *text,
164                                     const char *buffer, size_t len, int wrap );
165
166 void write_status_begin_signing (gcry_md_hd_t md);
167
168
169 int cpr_enabled(void);
170 char *cpr_get( const char *keyword, const char *prompt );
171 char *cpr_get_no_help( const char *keyword, const char *prompt );
172 char *cpr_get_utf8( const char *keyword, const char *prompt );
173 char *cpr_get_hidden( const char *keyword, const char *prompt );
174 void cpr_kill_prompt(void);
175 int  cpr_get_answer_is_yes( const char *keyword, const char *prompt );
176 int  cpr_get_answer_yes_no_quit( const char *keyword, const char *prompt );
177 int  cpr_get_answer_okay_cancel (const char *keyword,
178                                  const char *prompt,
179                                  int def_answer);
180
181 /*-- helptext.c --*/
182 void display_online_help( const char *keyword );
183
184 /*-- encode.c --*/
185 int setup_symkey(STRING2KEY **symkey_s2k,DEK **symkey_dek);
186 int encode_symmetric( const char *filename );
187 int encode_store( const char *filename );
188 int encode_crypt( const char *filename, strlist_t remusr, int use_symkey );
189 void encode_crypt_files(int nfiles, char **files, strlist_t remusr);
190 int encrypt_filter( void *opaque, int control,
191                     iobuf_t a, byte *buf, size_t *ret_len);
192
193
194 /*-- sign.c --*/
195 int complete_sig( PKT_signature *sig, PKT_secret_key *sk, gcry_md_hd_t md );
196 int sign_file( strlist_t filenames, int detached, strlist_t locusr,
197                int do_encrypt, strlist_t remusr, const char *outfile );
198 int clearsign_file( const char *fname, strlist_t locusr, const char *outfile );
199 int sign_symencrypt_file (const char *fname, strlist_t locusr);
200
201 /*-- sig-check.c --*/
202 int check_revocation_keys (PKT_public_key *pk, PKT_signature *sig);
203 int check_backsig(PKT_public_key *main_pk,PKT_public_key *sub_pk,
204                   PKT_signature *backsig);
205 int check_key_signature( KBNODE root, KBNODE node, int *is_selfsig );
206 int check_key_signature2( KBNODE root, KBNODE node, PKT_public_key *check_pk,
207                           PKT_public_key *ret_pk, int *is_selfsig,
208                           u32 *r_expiredate, int *r_expired );
209
210 /*-- delkey.c --*/
211 int delete_keys( strlist_t names, int secret, int allow_both );
212
213 /*-- keyedit.c --*/
214 void keyedit_menu( const char *username, strlist_t locusr,
215                    strlist_t commands, int quiet, int seckey_check );
216 void keyedit_passwd (const char *username);
217 void show_basic_key_info (KBNODE keyblock);
218
219 /*-- keygen.c --*/
220 u32 parse_expire_string(const char *string);
221 u32 ask_expire_interval(int object,const char *def_expire);
222 u32 ask_expiredate(void);
223 void generate_keypair( const char *fname, const char *card_serialno,
224                        const char *backup_encryption_dir );
225 int keygen_set_std_prefs (const char *string,int personal);
226 PKT_user_id *keygen_get_std_prefs (void);
227 int keygen_add_key_expire( PKT_signature *sig, void *opaque );
228 int keygen_add_std_prefs( PKT_signature *sig, void *opaque );
229 int keygen_upd_std_prefs( PKT_signature *sig, void *opaque );
230 int keygen_add_keyserver_url(PKT_signature *sig, void *opaque);
231 int keygen_add_notations(PKT_signature *sig,void *opaque);
232 int keygen_add_revkey(PKT_signature *sig, void *opaque);
233 int make_backsig(PKT_signature *sig,PKT_public_key *pk,
234                  PKT_public_key *sub_pk,PKT_secret_key *sub_sk,
235                  u32 timestamp);
236 int generate_subkeypair( KBNODE pub_keyblock, KBNODE sec_keyblock );
237 #ifdef ENABLE_CARD_SUPPORT
238 int generate_card_subkeypair (KBNODE pub_keyblock, KBNODE sec_keyblock,
239                               int keyno, const char *serialno);
240 int save_unprotected_key_to_card (PKT_secret_key *sk, int keyno);
241 #endif
242
243 /*-- openfile.c --*/
244 int overwrite_filep( const char *fname );
245 char *make_outfile_name( const char *iname );
246 char *ask_outfile_name( const char *name, size_t namelen );
247 int   open_outfile( const char *iname, int mode, iobuf_t *a );
248 iobuf_t open_sigfile( const char *iname, progress_filter_context_t *pfx );
249 void try_make_homedir( const char *fname );
250
251 /*-- seskey.c --*/
252 void make_session_key( DEK *dek );
253 gcry_mpi_t encode_session_key( DEK *dek, unsigned nbits );
254 gcry_mpi_t encode_md_value( PKT_public_key *pk, PKT_secret_key *sk,
255                             gcry_md_hd_t md, int hash_algo );
256
257 /*-- import.c --*/
258 int parse_import_options(char *str,unsigned int *options,int noisy);
259 void import_keys( char **fnames, int nnames,
260                   void *stats_hd, unsigned int options );
261 int import_keys_stream( iobuf_t inp,void *stats_hd,unsigned char **fpr,
262                         size_t *fpr_len,unsigned int options );
263 void *import_new_stats_handle (void);
264 void import_release_stats_handle (void *p);
265 void import_print_stats (void *hd);
266
267 int collapse_uids( KBNODE *keyblock );
268
269 int auto_create_card_key_stub ( const char *serialnostr, 
270                                 const unsigned char *fpr1,
271                                 const unsigned char *fpr2,
272                                 const unsigned char *fpr3);
273
274 /*-- export.c --*/
275 int parse_export_options(char *str,unsigned int *options,int noisy);
276 int export_pubkeys( strlist_t users, unsigned int options );
277 int export_pubkeys_stream( iobuf_t out, strlist_t users,
278                            KBNODE *keyblock_out, unsigned int options );
279 int export_seckeys( strlist_t users );
280 int export_secsubkeys( strlist_t users );
281
282 /* dearmor.c --*/
283 int dearmor_file( const char *fname );
284 int enarmor_file( const char *fname );
285
286 /*-- revoke.c --*/
287 struct revocation_reason_info;
288 int gen_revoke( const char *uname );
289 int gen_desig_revoke( const char *uname, strlist_t locusr);
290 int revocation_reason_build_cb( PKT_signature *sig, void *opaque );
291 struct revocation_reason_info *
292                 ask_revocation_reason( int key_rev, int cert_rev, int hint );
293 void release_revocation_reason_info( struct revocation_reason_info *reason );
294
295 /*-- keylist.c --*/
296 void public_key_list( strlist_t list, int locate_mode );
297 void secret_key_list( strlist_t list );
298 void print_subpackets_colon(PKT_signature *sig);
299 void reorder_keyblock (KBNODE keyblock);
300 void list_keyblock( KBNODE keyblock, int secret, int fpr, void *opaque );
301 void print_fingerprint (PKT_public_key *pk, PKT_secret_key *sk, int mode);
302 void print_revokers(PKT_public_key *pk);
303 void show_policy_url(PKT_signature *sig,int indent,int mode);
304 void show_keyserver_url(PKT_signature *sig,int indent,int mode);
305 void show_notation(PKT_signature *sig,int indent,int mode,int which);
306 void dump_attribs(const PKT_user_id *uid,
307                   PKT_public_key *pk,PKT_secret_key *sk);
308 void set_attrib_fd(int fd);
309 void print_seckey_info (PKT_secret_key *sk);
310 void print_pubkey_info (FILE *fp, PKT_public_key *pk);
311 void print_card_key_info (FILE *fp, KBNODE keyblock);
312
313 /*-- verify.c --*/
314 void print_file_status( int status, const char *name, int what );
315 int verify_signatures( int nfiles, char **files );
316 int verify_files( int nfiles, char **files );
317 int gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, FILE *out_fp);
318
319 /*-- decrypt.c --*/
320 int decrypt_message( const char *filename );
321 void decrypt_messages(int nfiles, char *files[]);
322
323 /*-- plaintext.c --*/
324 int hash_datafiles( gcry_md_hd_t md, gcry_md_hd_t md2,
325                     strlist_t files, const char *sigfilename, int textmode );
326 int hash_datafile_by_fd ( gcry_md_hd_t md, gcry_md_hd_t md2, int data_fd,
327                           int textmode );
328 PKT_plaintext *setup_plaintext_name(const char *filename,IOBUF iobuf);
329
330 /*-- signal.c --*/
331 void init_signals(void);
332 void pause_on_sigusr( int which );
333 void block_all_signals(void);
334 void unblock_all_signals(void);
335
336 /*-- server.c --*/
337 int gpg_server (ctrl_t);
338
339 #ifdef ENABLE_CARD_SUPPORT
340 /*-- card-util.c --*/
341 void change_pin (int no, int allow_admin);
342 void card_status (FILE *fp, char *serialno, size_t serialnobuflen);
343 void card_edit (strlist_t commands);
344 int  card_generate_subkey (KBNODE pub_keyblock, KBNODE sec_keyblock);
345 int  card_store_subkey (KBNODE node, int use);
346 #endif
347
348 #define S2K_DECODE_COUNT(_val) ((16ul + ((_val) & 15)) << (((_val) >> 4) + 6))
349
350 #endif /*G10_MAIN_H*/