114 |
} |
} |
115 |
|
|
116 |
|
|
117 |
|
/* Load the GPG environment. On the first start, some |
118 |
|
checks are performed to find out in what state GPG is. |
119 |
|
Return value: 0 everything OK. |
120 |
|
>0 fatal error. |
121 |
|
-1 public keyring is empty or does not exist. */ |
122 |
|
static int |
123 |
|
load_gpg_env (void) |
124 |
|
{ |
125 |
|
SECURITY_ATTRIBUTES sec_attr; |
126 |
|
char *p; |
127 |
|
char *pkr; |
128 |
|
|
129 |
|
p = get_reg_entry_gpg4win ("gpg.exe"); |
130 |
|
if (!p) |
131 |
|
return (1); |
132 |
|
if (file_exist_check (p)) { |
133 |
|
free_if_alloc (p); |
134 |
|
return (1); |
135 |
|
} |
136 |
|
free_if_alloc (p); |
137 |
|
p = multi_gnupg_path (0); |
138 |
|
if (p && dir_exist_check (p)) { |
139 |
|
memset (&sec_attr, 0, sizeof (sec_attr)); |
140 |
|
sec_attr.nLength = sizeof (sec_attr); |
141 |
|
if (!CreateDirectory (p, &sec_attr)) { |
142 |
|
msg_box (NULL, _("Could not create GPG home directory"), |
143 |
|
_("WinPT Error"), MB_ERR); |
144 |
|
free_if_alloc (p); |
145 |
|
return (2); |
146 |
|
} |
147 |
|
} |
148 |
|
pkr = make_filename (p, "pubring", "gpg"); |
149 |
|
free_if_alloc (p); |
150 |
|
if (!pkr) |
151 |
|
return -1; |
152 |
|
if (get_file_size (pkr) == 0) { |
153 |
|
free_if_alloc (pkr); |
154 |
|
return -1; |
155 |
|
} |
156 |
|
return 0; |
157 |
|
} |
158 |
|
|
159 |
/* check if the default key from the gpg.conf file is available in the |
/* check if the default key from the gpg.conf file is available in the |
160 |
keyring. if not, bail out because encryption won't work properly then. */ |
keyring. if not, bail out because encryption won't work properly then. */ |
161 |
static int |
static int |
163 |
{ |
{ |
164 |
gpgme_key_t key; |
gpgme_key_t key; |
165 |
gpgme_error_t err = GPG_ERR_NO_ERROR; |
gpgme_error_t err = GPG_ERR_NO_ERROR; |
166 |
char * defkey; |
char *defkey; |
167 |
|
|
168 |
defkey = get_gnupg_default_key (); |
defkey = get_gnupg_default_key (); |
169 |
if (defkey) |
if (defkey) |
170 |
err = gpg_keycache_find_key (kc, defkey, 0, &key); |
err = gpg_keycache_find_key (kc, defkey, 0, &key); |
171 |
else |
else |
172 |
msg_box (NULL, _("No useable secret key found."), _("WinPT Error"), MB_ERR); |
msg_box (NULL, _("No useable secret key found."), |
173 |
|
_("WinPT Error"), MB_ERR); |
174 |
free_if_alloc (defkey); |
free_if_alloc (defkey); |
175 |
return err? -1 : 0; |
return err? -1 : 0; |
176 |
} |
} |
177 |
|
|
178 |
|
|
179 |
/* Return the WinPT program file name (with full pathname). */ |
/* Return the WinPT program file name (with full pathname). */ |
180 |
static const char * |
static const char* |
181 |
get_prog_part (const char * fname, int use_cwd) |
get_prog_part (const char * fname, int use_cwd) |
182 |
{ |
{ |
183 |
static char program[512]; |
static char program[512]; |
211 |
|
|
212 |
/* Check that the underlying crypto engine fullfills the minimal |
/* Check that the underlying crypto engine fullfills the minimal |
213 |
requirements so all commands work properly. */ |
requirements so all commands work properly. */ |
214 |
static int |
static bool |
215 |
check_crypto_engine (void) |
check_crypto_engine (void) |
216 |
{ |
{ |
217 |
int ma=1, mi=4, pa=2; /* GPG 1.4.2 */ |
int ma=1, mi=4, pa=2; /* GPG 1.4.2 */ |
221 |
if (rc == -1) { |
if (rc == -1) { |
222 |
msg_box (NULL, _("Could not read GnuPG version."), |
msg_box (NULL, _("Could not read GnuPG version."), |
223 |
_("WinPT Error"), MB_ERR); |
_("WinPT Error"), MB_ERR); |
224 |
return rc; |
return false; |
225 |
} |
} |
226 |
else if (rc) { |
else if (rc) { |
227 |
log_box (_("WinPT Error"), MB_ERR, |
log_box (_("WinPT Error"), MB_ERR, |
228 |
_("Sorry, you need a newer GPG version.\n" |
_("Sorry, you need a newer GPG version.\n" |
229 |
"GPG version %d.%d.%d required GPG version "MIN_GPG_VER), |
"GPG version %d.%d.%d required GPG version "MIN_GPG_VER), |
230 |
ma, mi, pa); |
ma, mi, pa); |
231 |
return rc; |
return false; |
232 |
} |
} |
233 |
/* We enable smartcard support for GPG: >= 2 or >= 1.4.3 */ |
/* We enable smartcard support for GPG: >= 2 or >= 1.4.3 */ |
234 |
if (ma > 1 || pa >= 3) |
if (ma > 1 || pa >= 3) |
235 |
scard_support = 1; |
scard_support = 1; |
236 |
|
|
237 |
gpgver[0] = ma; |
gpgver[0] = ma; |
238 |
gpgver[1] = mi; |
gpgver[1] = mi; |
239 |
gpgver[2] = pa; |
gpgver[2] = pa; |
240 |
return rc; |
return true; |
241 |
} |
} |
242 |
|
|
243 |
|
|
246 |
static int |
static int |
247 |
load_keyserver_conf (int quiet) |
load_keyserver_conf (int quiet) |
248 |
{ |
{ |
249 |
const char * t; |
const char *t; |
250 |
int rc; |
int rc; |
251 |
|
|
252 |
if (reg_prefs.kserv_conf) |
if (reg_prefs.kserv_conf) |
279 |
reg_prefs.use_viewer = 0; /* XXX */ |
reg_prefs.use_viewer = 0; /* XXX */ |
280 |
} |
} |
281 |
|
|
|
char* multi_gnupg_path (void); |
|
|
|
|
|
const char * fm_get_file_type (const char *fname, int *r_type); |
|
282 |
|
|
283 |
/* Main entry point. */ |
/* Main entry point. */ |
284 |
int WINAPI |
int WINAPI |
286 |
{ |
{ |
287 |
WNDCLASS wc = {0, winpt_main_proc, 0, 0, hinst, 0, 0, 0, 0, PGM_NAME}; |
WNDCLASS wc = {0, winpt_main_proc, 0, 0, hinst, 0, 0, 0, 0, PGM_NAME}; |
288 |
HACCEL accel_tab; |
HACCEL accel_tab; |
289 |
int rc, ec, created = 0, nfiles = 0; |
MSG msg; |
290 |
|
HWND hwnd = NULL; |
291 |
|
WORD ver[3], ptdver[4]; |
292 |
|
int rc, ec, created = 0; |
293 |
int first_start = 0, start_gpgprefs = 0; |
int first_start = 0, start_gpgprefs = 0; |
294 |
int winpt_inst_found = 0; |
int winpt_inst_found = 0; |
295 |
|
int start_manager = 0; |
296 |
const char *s; |
const char *s; |
|
MSG msg; |
|
|
HWND hwnd = NULL; |
|
297 |
|
|
298 |
glob_hinst = hinst; |
glob_hinst = hinst; |
299 |
|
if (cmdline && stristr (cmdline, "--stop")) { |
300 |
|
hwnd = FindWindow ("WinPT", "WinPT"); |
301 |
|
if (hwnd != NULL) |
302 |
|
PostMessage (hwnd, WM_DESTROY, 0, 0); |
303 |
|
return 0; |
304 |
|
} |
305 |
|
|
306 |
#ifdef _DEBUG |
/* |
307 |
|
OSVERSIONINFO osinf; |
308 |
|
memset (&osinf, 0, sizeof (osinf)); |
309 |
|
if (GetVersionEx (&osinf) && |
310 |
|
osinf.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && |
311 |
|
osinf.dwMinorVersion == 0) { |
312 |
|
msg_box (NULL, "WinPT propably does not work on Windows 95 without restrictions", |
313 |
|
"WinPT Warning", MB_INFO); |
314 |
|
} |
315 |
|
*/ |
316 |
|
|
317 |
|
#ifdef _DEBUG |
318 |
gpg_set_debug_mode (1); |
gpg_set_debug_mode (1); |
319 |
debug = 1; |
debug = 1; |
320 |
#endif |
#endif |
321 |
|
|
322 |
|
get_file_version ("WinPT.exe", &ver[0], &ver[1], &ver[2], &ver[3]); |
323 |
|
get_file_version ("PTD.dll", &ptdver[0], &ptdver[1], |
324 |
|
&ptdver[2], &ptdver[3]); |
325 |
|
/* XXX |
326 |
|
if (ptdver[0] != ver[0] || ptdver[1] != ver[1]|| ptdver[2] != ver[2]) { |
327 |
|
log_box (_("WinPT Error"), MB_ERR, |
328 |
|
_("The PTD.dll file has a different version than WinPT.exe\n" |
329 |
|
"Please update the PTD.dll to version %d.%d.%d"), |
330 |
|
ver[0], ver[1], ver[2]); |
331 |
|
return 0; |
332 |
|
} |
333 |
|
*/ |
334 |
|
|
335 |
if (gpg_md_selftest ()) { |
if (gpg_md_selftest ()) { |
336 |
msg_box (NULL, _("Cryptographic selftest failed."), |
msg_box (NULL, _("Cryptographic selftest failed."), |
356 |
} |
} |
357 |
|
|
358 |
set_default_kserver (); |
set_default_kserver (); |
359 |
|
load_gettext (winpt_inst_found); |
360 |
|
|
361 |
if (!mobile) { |
if (!mobile) { |
362 |
regist_inst_gnupg (1); |
regist_inst_gnupg (1); |
378 |
gnupg_load_config (); |
gnupg_load_config (); |
379 |
} |
} |
380 |
|
|
381 |
|
if (is_gpg4win_installed ()) |
382 |
|
load_gpg_env (); /* XXX: check return code. */ |
383 |
|
|
384 |
rc = gnupg_check_homedir (); |
rc = gnupg_check_homedir (); |
385 |
if (rc) { |
if (rc) { |
386 |
log_box (_("WinPT Error"), MB_ERR, |
log_box (_("WinPT Error"), MB_ERR, |
388 |
"Please check the GPG registry settings:\n%s."), |
"Please check the GPG registry settings:\n%s."), |
389 |
winpt_strerror (rc)); |
winpt_strerror (rc)); |
390 |
s = get_fileopen_dlg (GetActiveWindow (), |
s = get_fileopen_dlg (GetActiveWindow (), |
391 |
_("Select GPG Public Keyring"), |
_("Select GPG Public Keyring"), |
392 |
_("GPG Keyrings (*.gpg)\0*.gpg\0\0"), |
_("GPG Keyrings (*.gpg)\0*.gpg\0\0"), |
393 |
NULL); |
NULL); |
394 |
if (s != NULL) { |
if (s != NULL) { |
395 |
size_t n; |
size_t n; |
396 |
char * p = strrchr (s, '\\'); |
char *p = strrchr (s, '\\'); |
397 |
if (!p) |
if (!p) |
398 |
BUG (0); |
BUG (0); |
399 |
n = p - s; |
n = p - s; |
400 |
if (n) { |
if (n) { |
401 |
char * file = new char[n+1]; |
char *file = new char[n+1]; |
402 |
if (!file) |
if (!file) |
403 |
BUG (NULL); |
BUG (NULL); |
404 |
memset (file, 0, n); |
memset (file, 0, n); |
423 |
"correct this problem?"), _("WinPT Error"), |
"correct this problem?"), _("WinPT Error"), |
424 |
MB_INFO|MB_YESNO) == IDYES) |
MB_INFO|MB_YESNO) == IDYES) |
425 |
start_gpgprefs = 1; |
start_gpgprefs = 1; |
426 |
else |
else { |
|
{ |
|
427 |
msg_box (NULL, winpt_strerror (rc), _("WinPT Error"), MB_ERR); |
msg_box (NULL, winpt_strerror (rc), _("WinPT Error"), MB_ERR); |
428 |
return 0; |
return 0; |
429 |
} |
} |
453 |
else if (rc) |
else if (rc) |
454 |
return 0; |
return 0; |
455 |
} |
} |
456 |
|
|
|
load_gettext (winpt_inst_found); |
|
457 |
init_gnupg_table (); |
init_gnupg_table (); |
458 |
|
|
459 |
nfiles = fm_parse_command_line (cmdline); |
if (fm_parse_command_line (cmdline) > 0) { |
|
if (nfiles > 0) { |
|
460 |
free_gnupg_table (); |
free_gnupg_table (); |
461 |
return 0; |
return 0; |
462 |
} |
} |
473 |
|
|
474 |
if (cmdline && (stristr (cmdline, "--keymanager") |
if (cmdline && (stristr (cmdline, "--keymanager") |
475 |
|| stristr (cmdline, "--cardmanager"))) { |
|| stristr (cmdline, "--cardmanager"))) { |
476 |
update_keycache (GetDesktopWindow ()); |
/* If an instance of WinPT is running, just send the command |
477 |
|
to open the key manager. Otherwise start a new instance. |
478 |
|
*/ |
479 |
|
HWND tray = FindWindow ("WinPT", "WinPT"); |
480 |
if (stristr (cmdline, "keymanager")) |
if (stristr (cmdline, "keymanager")) |
481 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
start_manager = ID_WINPT_KEY; |
482 |
GetDesktopWindow(), keymanager_dlg_proc, 0, |
else |
483 |
_("Key Manager"), IDS_WINPT_KEYMISC); |
start_manager = ID_WINPT_CARD; |
484 |
else { |
if (tray != NULL) { |
485 |
gpg_card_t crd = gpg_card_load (); |
PostMessage (tray, WM_COMMAND, start_manager, 0); |
486 |
if (crd) |
free_gnupg_table (); |
487 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_EDIT, |
return 0; |
|
GetDesktopWindow(), card_edit_dlg_proc, |
|
|
(LPARAM)crd, _("Card Manager"), |
|
|
IDS_WINPT_CARD_EDIT); |
|
|
gpg_card_release (crd); |
|
488 |
} |
} |
|
keycache_release (0); |
|
|
free_gnupg_table (); |
|
|
return 0; |
|
489 |
} |
} |
490 |
|
|
491 |
/* If we found another WinPT instance, just quit to avoid it |
/* If we found another WinPT instance, just quit to avoid it |
497 |
} |
} |
498 |
|
|
499 |
if (cmdline) { |
if (cmdline) { |
500 |
if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) { |
if (stristr (cmdline, "--enable-debug") || |
501 |
|
stristr (cmdline, "--debug")) { |
502 |
gpg_set_debug_mode (1); |
gpg_set_debug_mode (1); |
503 |
winpt_debug_msg (); |
winpt_debug_msg (); |
504 |
debug = 1; |
debug = 1; |
531 |
|
|
532 |
if (!first_start && !start_gpgprefs) { |
if (!first_start && !start_gpgprefs) { |
533 |
gnupg_backup_options (); |
gnupg_backup_options (); |
534 |
rc = check_crypto_engine (); |
if (!check_crypto_engine ()) { |
|
if (rc) { |
|
535 |
DestroyWindow (hwnd); |
DestroyWindow (hwnd); |
536 |
free_gnupg_table (); |
free_gnupg_table (); |
537 |
return 0; |
return 0; |
540 |
|
|
541 |
if (start_gpgprefs) { |
if (start_gpgprefs) { |
542 |
char *ring; |
char *ring; |
|
|
|
543 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd, |
544 |
gpgprefs_dlg_proc, 0); |
gpgprefs_dlg_proc, 0); |
545 |
ring = get_gnupg_keyring (0, !NO_STRICT); |
ring = get_gnupg_keyring (0, !NO_STRICT); |
608 |
} |
} |
609 |
} |
} |
610 |
if (check_default_key (c)) { |
if (check_default_key (c)) { |
611 |
char * p = get_gnupg_default_key (); |
char *p = get_gnupg_default_key (); |
612 |
log_box (_("WinPT Error"), MB_ERR, |
log_box (_("WinPT Error"), MB_ERR, |
613 |
_("Default key from the GPG options file could not be found.\n" |
_("Default key from the GPG options file could not be found.\n" |
614 |
"Please check your gpg.conf (options) to correct this:\n\n" |
"Please check your gpg.conf (options) to correct this:\n\n" |
623 |
elgamal_warn_dlg_proc, 0); |
elgamal_warn_dlg_proc, 0); |
624 |
} |
} |
625 |
|
|
626 |
|
if (start_manager) |
627 |
|
PostMessage (hwnd, WM_COMMAND, start_manager, 0); |
628 |
|
|
629 |
accel_tab = LoadAccelerators (glob_hinst, (LPCTSTR)IDR_WINPT_ACCELERATOR); |
accel_tab = LoadAccelerators (glob_hinst, (LPCTSTR)IDR_WINPT_ACCELERATOR); |
630 |
keyring_check_last_access (); /* init */ |
keyring_check_last_access (); /* init */ |
631 |
while (GetMessage (&msg, hwnd, 0, 0)) { |
while (GetMessage (&msg, hwnd, 0, 0)) { |