1 |
/* wptGPG.h - GnuPG interface |
2 |
* Copyright (C) 2000-2006 Timo Schulz |
3 |
* |
4 |
* This file is part of WinPT. |
5 |
* |
6 |
* WinPT is free software; you can redistribute it and/or |
7 |
* modify it under the terms of the GNU General Public License |
8 |
* as published by the Free Software Foundation; either version 2 |
9 |
* of the License, or (at your option) any later version. |
10 |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
* General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
20 |
|
21 |
#ifndef WPT_GPG_H |
22 |
#define WPT_GPG_H |
23 |
|
24 |
#include <gpgme.h> |
25 |
#include "wptKeyCache.h" |
26 |
#include "wptNLS.h" |
27 |
|
28 |
|
29 |
#define NO_STRICT 0 |
30 |
|
31 |
/* Macro to indicate if a key is useable or not. */ |
32 |
#define key_is_useable(key) (!(key)->revoked && \ |
33 |
!(key)->expired && \ |
34 |
!(key)->disabled) |
35 |
|
36 |
enum setup_t { |
37 |
SETUP_KEYGEN = 1, |
38 |
SETUP_IMPORT = 2, |
39 |
SETUP_EXISTING = 3, |
40 |
SETUP_CARDGEN = 4 |
41 |
}; |
42 |
|
43 |
enum gpg_cmd_t { |
44 |
GPG_CMD_DECRYPT = 0, |
45 |
GPG_CMD_SIGN = 1 |
46 |
}; |
47 |
|
48 |
enum keycache_t { |
49 |
KEYCACHE_PRV = 0, |
50 |
KEYCACHE_PUB = 1 |
51 |
}; |
52 |
|
53 |
|
54 |
struct gpg_card_s; |
55 |
typedef struct gpg_card_s *gpg_card_t; |
56 |
|
57 |
/* Keycache refresh context. */ |
58 |
struct refresh_cache_s { |
59 |
int kr_reload; |
60 |
int kr_update; |
61 |
int tr_update; |
62 |
}; |
63 |
|
64 |
|
65 |
/* Structure for the passphrase callback. */ |
66 |
struct passphrase_cb_s { |
67 |
int gpg_cmd; /* sign or decrypt. */ |
68 |
int pwd_init; /* 1 = passphrase request via dialog. */ |
69 |
char *pwd; /* actual passphrase. */ |
70 |
char info[1024]; /* hold up the info message */ |
71 |
char *title; /* dialog title. */ |
72 |
char keyid[16+1]; /* keyid of the secret key the pwd can be used for. */ |
73 |
HWND hwnd; /* handle of the dialog window. */ |
74 |
int cancel; /* 1 = user cancelled passphrase request. */ |
75 |
unsigned int is_card:1; /* 1 = key stored on a smart card. */ |
76 |
unsigned int bad_pwd:1; /* 1 = last passphrase was bad. */ |
77 |
gpgme_ctx_t gpg; |
78 |
gpgme_recipient_t recipients; |
79 |
struct { |
80 |
int sym_algo; |
81 |
int s2k_mode; |
82 |
int s2k_hash; |
83 |
} sym; |
84 |
}; |
85 |
|
86 |
|
87 |
/* This variable is 1 if IDEA is available. */ |
88 |
extern int idea_available; |
89 |
|
90 |
/*-- wptGPG.cpp --*/ |
91 |
char* get_gnupg_default_key (void); |
92 |
int set_gnupg_default_key (const char *key); |
93 |
char* get_gnupg_config (void); |
94 |
char* get_gnupg_keyring_from_options (const char *fname, int pub); |
95 |
int check_gnupg_config (const char *fname, int *secrings, int *pubrings); |
96 |
char* get_gnupg_path (void); |
97 |
int check_gnupg_prog (void); |
98 |
int gnupg_access_files (void); |
99 |
char* get_gnupg_prog (void); |
100 |
char* get_gnupg_keyring (int pub, int strict); |
101 |
char* get_gnupg_cfgfile (void); |
102 |
int set_gnupg_options( const char *buf, size_t buflen ); |
103 |
int gnupg_load_config (void); |
104 |
char* multi_gnupg_path (int strict); |
105 |
|
106 |
int check_gnupg_options (const char *buf, int showerr); |
107 |
void init_gnupg_table (void); |
108 |
void free_gnupg_table (void); |
109 |
int keyring_check_last_access (void); |
110 |
const char* gnupg_check_file_ext (const char *fname, int *r_type); |
111 |
int gpg_check_permissions (int showmsg); |
112 |
int gnupg_check_homedir (void); |
113 |
int gnupg_access_keyring (int _pub); |
114 |
void gnupg_backup_options (); |
115 |
void gnupg_backup_keyrings (int auto_backup, int backup_mode, |
116 |
int include_secr); |
117 |
int gnupg_copy_keyrings (void); |
118 |
int check_gnupg_engine (const char *need_gpg_ver, |
119 |
int *r_major, int *r_minor, int *r_patch); |
120 |
|
121 |
/*-- wptGPGME.cpp --*/ |
122 |
const char * get_signature_status( gpgme_sigsum_t sigstat ); |
123 |
|
124 |
gpgme_error_t get_pubkey (const char *keyid, gpgme_key_t *ret_key); |
125 |
gpgme_error_t winpt_get_pubkey (const char *keyid, struct winpt_key_s *k); |
126 |
void winpt_release_pubkey (winpt_key_s *k); |
127 |
gpgme_error_t get_seckey (const char *keyid, gpgme_key_t *ret_skey); |
128 |
gpgme_error_t winpt_get_seckey (const char *keyid, struct winpt_key_s *k); |
129 |
|
130 |
void keycache_release (int cleanup); |
131 |
gpgme_error_t keycache_update (int is_sec, const char *keyid); |
132 |
gpgme_error_t keycache_init (const char *pubring, const char * secring); |
133 |
gpg_keycache_t keycache_get_ctx (int _pub); |
134 |
|
135 |
gpgme_error_t gpg_clip_sym_encrypt (void); |
136 |
const char *get_gpg_sigstat (gpgme_sigsum_t sum); |
137 |
int check_ultimate_trusted_key (void); |
138 |
bool secret_key_available (void); |
139 |
|
140 |
/*-- wptGPGParser.cpp --*/ |
141 |
enum entry_t { |
142 |
ENTRY_OPAQUE = 1, |
143 |
ENTRY_SINGLE = 2, |
144 |
ENTRY_MULTI = 3, |
145 |
ENTRY_GROUP = 4, |
146 |
}; |
147 |
|
148 |
struct conf_option_s { |
149 |
struct conf_option_s *next; |
150 |
char *name; |
151 |
char *val; |
152 |
unsigned int used:1; |
153 |
int type; |
154 |
}; |
155 |
typedef struct conf_option_s *conf_option_t; |
156 |
|
157 |
struct conf_member_s { |
158 |
struct conf_member_s *next; |
159 |
char *name; |
160 |
unsigned int used:1; |
161 |
}; |
162 |
typedef struct conf_member_s *conf_member_t; |
163 |
|
164 |
struct conf_group_s { |
165 |
struct conf_group_s *next; |
166 |
struct conf_member_s *list; |
167 |
char *name; |
168 |
unsigned int used:1; |
169 |
}; |
170 |
typedef struct conf_group_s *conf_group_t; |
171 |
|
172 |
struct conf_file_s { |
173 |
struct conf_option_s *list; |
174 |
struct conf_group_s *grp; |
175 |
}; |
176 |
typedef struct conf_file_s *config_file_t; |
177 |
|
178 |
/* find */ |
179 |
conf_group_t conf_find_group( config_file_t opt, const char *str ); |
180 |
conf_option_t conf_find_option( config_file_t opt, const char *str ); |
181 |
conf_member_t conf_find_member( config_file_t opt, const char *grp, const char *str ); |
182 |
/* delete */ |
183 |
int conf_delete_group( config_file_t opt, const char *str ); |
184 |
int conf_delete_member( config_file_t opt, const char *grp, const char *str ); |
185 |
int conf_delete_option( config_file_t opt, const char *str ); |
186 |
/* add */ |
187 |
int conf_modify_entry( config_file_t opt, int type, const char *name, const char *val ); |
188 |
int conf_add_entry( config_file_t opt, int type, const char *name, const char *val ); |
189 |
int conf_add_entry_int (config_file_t opt, int type, const char *name, int val); |
190 |
int conf_add_member( config_file_t opt, const char *grp, const char *str ); |
191 |
int conf_add_group( config_file_t opt, const char *str ); |
192 |
/* high-level */ |
193 |
void new_config (config_file_t *r_opt); |
194 |
int parse_config (const char *file, config_file_t *r_opt); |
195 |
int commit_config (const char *file, config_file_t opt); |
196 |
void release_config (config_file_t opt); |
197 |
/* memory */ |
198 |
void release_group( conf_group_t grp ); |
199 |
|
200 |
/*-- wptPassphraseCB.cpp --*/ |
201 |
enum passdlg_t { |
202 |
PASSDLG_REPEAT = 0, |
203 |
PASSDLG_INIT = 1, |
204 |
PASSDLG_STRICT = 2, |
205 |
PASSDLG_NOTEMPTY= 4, |
206 |
PASSDLG_WARN_UTF8=8, |
207 |
}; |
208 |
|
209 |
void set_gpg_passphrase_cb (passphrase_cb_s *cb, gpgme_ctx_t ctx, |
210 |
int cmd, HWND hwnd, const char *title); |
211 |
void release_gpg_passphrase_cb (passphrase_cb_s *cb); |
212 |
void release_gpg_recipients (gpgme_recipient_t *recipients); |
213 |
|
214 |
char *request_passphrase (const char *title, int flags, int *ret_cancel); |
215 |
char *request_passphrase2 (const char *title, int flags, int *ret_cancel); |
216 |
char *request_key_passphrase (gpgme_key_t key, const char *title, |
217 |
int *ret_cancel); |
218 |
const char * passphrase_cb (void *opaque, const char * desc, void *r_hd); |
219 |
char * get_key_userid (const char *keyid); |
220 |
int check_passwd_quality (const char *pass, int strict); |
221 |
|
222 |
/*-- wptClipboard.cpp --*/ |
223 |
gpgme_error_t gpg_clip_istext_avail (int *r_val); |
224 |
gpgme_error_t gpg_clip_is_secured (int *r_type, int *r_val); |
225 |
gpgme_error_t gpg_clip_get_pgptype (int *r_type); |
226 |
gpgme_error_t gpg_clip_parse_pgpid (const char *data, int *r_type); |
227 |
|
228 |
/* wptGPGMEData.cpp --*/ |
229 |
gpgme_error_t gpg_data_new_from_clipboard (gpgme_data_t *r_dh, int wraplen); |
230 |
void gpg_data_release_and_set_clipboard (gpgme_data_t dh, int chg_ver); |
231 |
size_t gpg_data_readline (gpgme_data_t dh, char *line, size_t nbytes); |
232 |
|
233 |
gpgme_error_t gpg_data_release_and_set_file (gpgme_data_t dh, const char *fname); |
234 |
gpgme_error_t gpg_data_mail_quote (gpgme_data_t *r_dh); |
235 |
gpgme_error_t gpg_data_extract_plaintext (gpgme_data_t sig, gpgme_data_t *r_plain); |
236 |
void gpg_data_putc (gpgme_data_t hd, int c); |
237 |
|
238 |
/*-- wptGPGUtil.cpp --*/ |
239 |
gpgme_error_t gpg_rebuild_cache (char **r_inf); |
240 |
gpgme_error_t gpg_get_version (char **r_inf); |
241 |
void gpg_set_debug_mode (int val); |
242 |
gpgme_error_t gpg_export_seckey (const char *keyid, const char *outfile); |
243 |
gpgme_error_t gpg_manage_ownertrust (char **data, int do_export); |
244 |
gpgme_error_t gpg_get_photoid_data (const char *keyid, char **r_status_data, |
245 |
unsigned char **r_data, |
246 |
unsigned long *ndata); |
247 |
gpgme_error_t gpg_revoke_cert (int desig_revoke, const char *inp_data, |
248 |
const char *keyid, char **r_revcert); |
249 |
gpgme_error_t gpg_decode_c_string (const char *src, char **destp, size_t len); |
250 |
gpgme_error_t gpg_import_key_list (const char *fname, char **r_out); |
251 |
gpgme_error_t gpg_extract_keys (const char *keyfile, const char **keys, DWORD nkeys, |
252 |
char **new_keyfile); |
253 |
gpgme_error_t get_uat_validity (const char *keyid, gpgme_validity_t *r_valid); |
254 |
gpgme_error_t gpg_get_recipients (const char *file, gpgme_recipient_t *r_list); |
255 |
gpgme_error_t gpg_find_key_subpacket (const char *key, int subpktid, |
256 |
char **value); |
257 |
|
258 |
#endif /* WPT_GPG_H */ |