17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
*/ |
|
|
|
20 |
#include <windows.h> |
#include <windows.h> |
21 |
|
|
22 |
#include "../resource.h" |
#include "../resource.h" |
33 |
#include "wptCard.h" |
#include "wptCard.h" |
34 |
#include "wptFileManager.h" |
#include "wptFileManager.h" |
35 |
#include "wptContext.h" |
#include "wptContext.h" |
36 |
|
#include "wptCardEdit.h" |
37 |
|
|
38 |
HINSTANCE glob_hinst; /* global instance for the dialogs */ |
HINSTANCE glob_hinst; /* global instance for the dialogs */ |
39 |
HWND glob_hwnd; /* global window handle for the dialogs */ |
HWND glob_hwnd; /* global window handle for the dialogs */ |
45 |
int gpg_read_only = 0; |
int gpg_read_only = 0; |
46 |
char gpgver[3]; |
char gpgver[3]; |
47 |
|
|
48 |
|
/* Internal IPC */ |
49 |
|
int start_keymanager = 0; |
50 |
|
|
51 |
static void |
static void |
52 |
update_keycache (HWND hwnd) |
update_keycache (HWND hwnd) |
98 |
check_default_key (gpgme_keycache_t kc) |
check_default_key (gpgme_keycache_t kc) |
99 |
{ |
{ |
100 |
gpgme_key_t key; |
gpgme_key_t key; |
101 |
gpgme_error_t err = GPGME_No_Error; |
gpgme_error_t err = GPG_ERR_NO_ERROR; |
102 |
char * defkey; |
char * defkey; |
103 |
|
|
104 |
defkey = get_gnupg_default_key (); |
defkey = get_gnupg_default_key (); |
144 |
static int |
static int |
145 |
check_crypto_engine (void) |
check_crypto_engine (void) |
146 |
{ |
{ |
147 |
int ma=1, mi=2, pa=4; /* GPG 1.2.4 */ |
int ma=1, mi=4, pa=0; /* GPG 1.4.0 */ |
148 |
int rc; |
int rc; |
149 |
|
|
150 |
rc = check_gnupg_engine (&ma, &mi, &pa); |
rc = check_gnupg_engine (&ma, &mi, &pa); |
155 |
else if (rc) { |
else if (rc) { |
156 |
log_box (_("WinPT Error"), MB_ERR, |
log_box (_("WinPT Error"), MB_ERR, |
157 |
_("Sorry, you need a newer GPG version.\n" |
_("Sorry, you need a newer GPG version.\n" |
158 |
"GPG version %d.%d.%d requred GPG version 1.2.4"), |
"GPG version %d.%d.%d required GPG version 1.4.0"), |
159 |
ma, mi, pa); |
ma, mi, pa); |
160 |
return rc; |
return rc; |
161 |
} |
} |
205 |
reg_prefs.use_viewer = 0; /* XXX */ |
reg_prefs.use_viewer = 0; /* XXX */ |
206 |
} |
} |
207 |
|
|
208 |
|
char* get_subkey_fingerprint (gpgme_ctx_t ctx, const char *keyid); |
209 |
|
|
210 |
int WINAPI |
int WINAPI |
211 |
|
#ifndef WINPT_IPC |
212 |
WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
213 |
|
#else |
214 |
|
win_main (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
215 |
|
#endif |
216 |
{ |
{ |
217 |
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}; |
218 |
HACCEL accel_tab; |
HACCEL accel_tab; |
220 |
int first_start = 0, start_gpgprefs = 0; |
int first_start = 0, start_gpgprefs = 0; |
221 |
const char * s; |
const char * s; |
222 |
MSG msg; |
MSG msg; |
223 |
HWND hwnd; |
HWND hwnd = NULL; |
224 |
|
|
225 |
glob_hinst = hinst; |
glob_hinst = hinst; |
226 |
|
|
|
gpgme_lib_init (); |
|
227 |
#ifdef _DEBUG |
#ifdef _DEBUG |
228 |
gpgme_set_debug_mode (1); |
gpgme_set_debug_mode (1); |
229 |
#endif |
#endif |
|
gpgme_set_pgm_string ("WinPT "PGM_VERSION); |
|
230 |
|
|
231 |
s = PTD_get_version (); |
s = PTD_get_version (); |
232 |
if (strcmp (s, "0.8.0")) { |
if (strcmp (s, "0.8.0")) { |
242 |
return 0; |
return 0; |
243 |
} |
} |
244 |
|
|
245 |
if (cmdline && stristr (cmdline, "--mobile")) |
if (cmdline && stristr (cmdline, "--mobile")) { |
246 |
|
msg_box (NULL, "WARNING: mobile modus is not fully implemented yet!", |
247 |
|
"WinPT", MB_INFO); |
248 |
mobile = 1; |
mobile = 1; |
249 |
|
} |
250 |
|
|
251 |
set_default_kserver (); |
set_default_kserver (); |
252 |
|
|
279 |
_("Select GPG Public Keyring"), |
_("Select GPG Public Keyring"), |
280 |
_("GPG Keyrings (*.gpg)\0*.gpg\0\0"), |
_("GPG Keyrings (*.gpg)\0*.gpg\0\0"), |
281 |
NULL); |
NULL); |
282 |
if (s && !file_exist_check (s)) |
if (s != NULL) { |
|
{ |
|
283 |
size_t n; |
size_t n; |
284 |
char * p = strrchr (s, '\\'); |
char * p = strrchr (s, '\\'); |
285 |
if (!p) |
if (!p) |
364 |
} |
} |
365 |
|
|
366 |
load_keyserver_conf (cmdline? 1 : 0); |
load_keyserver_conf (cmdline? 1 : 0); |
367 |
|
if (start_keymanager) { |
368 |
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
369 |
|
GetDesktopWindow(), keymanager_dlg_proc, NULL, |
370 |
|
_("Key Manager"), IDS_WINPT_KEYMISC); |
371 |
|
keycache_release (); |
372 |
|
free_gnupg_table (); |
373 |
|
return 0; |
374 |
|
} |
375 |
|
|
376 |
if (cmdline && (stristr (cmdline, "--keymanager") |
if (cmdline && (stristr (cmdline, "--keymanager") |
377 |
|| stristr (cmdline, "--cardmanager"))) { |
|| stristr (cmdline, "--cardmanager"))) { |
378 |
update_keycache (GetDesktopWindow ()); |
update_keycache (GetDesktopWindow ()); |
379 |
if (stristr (cmdline, "keymanager")) |
if (stristr (cmdline, "keymanager")) |
380 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
381 |
GetDesktopWindow(), keymanager_dlg_proc, NULL, |
GetDesktopWindow(), keymanager_dlg_proc, NULL, |
382 |
_("Key Manager"), IDS_WINPT_KEYMISC); |
_("Key Manager"), IDS_WINPT_KEYMISC); |
383 |
else { |
else { |
384 |
gpgme_card_t crd = smartcard_init (); |
gpg_card_t crd = smartcard_init (); |
385 |
if (crd) |
if (crd) |
386 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_EDIT, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_EDIT, |
387 |
GetDesktopWindow(), card_edit_dlg_proc, |
GetDesktopWindow(), card_edit_dlg_proc, |
388 |
(LPARAM)crd, _("Card Manager"), |
(LPARAM)crd, _("Card Manager"), |
389 |
IDS_WINPT_CARD_EDIT); |
IDS_WINPT_CARD_EDIT); |
390 |
gpgme_card_release (crd); |
gpg_card_release (crd); |
391 |
} |
} |
392 |
keycache_release (); |
keycache_release (); |
393 |
free_gnupg_table (); |
free_gnupg_table (); |
402 |
|
|
403 |
if (cmdline) { |
if (cmdline) { |
404 |
if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) { |
if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) { |
405 |
gpgme_set_debug_mode (1); |
gpg_set_debug_mode (1); |
406 |
winpt_debug_msg (); |
winpt_debug_msg (); |
407 |
debug = 1; |
debug = 1; |
408 |
} |
} |
432 |
UpdateWindow (hwnd); |
UpdateWindow (hwnd); |
433 |
|
|
434 |
if (!first_start && !start_gpgprefs) { |
if (!first_start && !start_gpgprefs) { |
435 |
gnupg_backup_options (1); |
gnupg_backup_options (); |
|
gnupg_backup_options (0); |
|
|
|
|
436 |
rc = check_crypto_engine (); |
rc = check_crypto_engine (); |
437 |
if (rc) { |
if (rc) { |
438 |
DestroyWindow (hwnd); |
DestroyWindow (hwnd); |
440 |
return 0; |
return 0; |
441 |
} |
} |
442 |
} |
} |
443 |
|
|
444 |
if (start_gpgprefs) |
if (start_gpgprefs) { |
|
{ |
|
445 |
char *ring; |
char *ring; |
446 |
size_t size = 0; |
size_t size = 0; |
447 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd, |
453 |
} |
} |
454 |
|
|
455 |
if (first_start) { |
if (first_start) { |
456 |
struct key_wizard_s c, dummy; |
struct first_start_s fs; |
457 |
|
struct genkey_s c; |
458 |
|
HWND h; |
459 |
start: |
start: |
460 |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, hwnd, |
h = GetDesktopWindow (); |
461 |
first_run_dlg_proc, (LPARAM)&dummy); |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h, |
462 |
switch (dummy.interactive) |
gpgprefs_dlg_proc, NULL); |
463 |
{ |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h, |
464 |
|
first_run_dlg_proc, (LPARAM)&fs); |
465 |
|
switch (fs.choice) { |
466 |
case SETUP_KEYGEN: |
case SETUP_KEYGEN: |
467 |
c.interactive = 1; |
c.interactive = 1; |
468 |
|
c.first_start = 1; |
469 |
rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, |
rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, |
470 |
hwnd, keygen_wizard_dlg_proc, (LPARAM)&c); |
h, keygen_wizard_dlg_proc, (LPARAM)&c); |
471 |
if (!rc) |
if (!rc) |
472 |
goto start; |
goto start; |
473 |
break; |
break; |
480 |
} |
} |
481 |
break; |
break; |
482 |
|
|
|
case SETUP_EXISTING: |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd, |
|
|
gpgprefs_dlg_proc, NULL); |
|
|
break; |
|
|
|
|
483 |
case -1: |
case -1: |
484 |
DestroyWindow (hwnd); |
DestroyWindow (hwnd); |
485 |
free_gnupg_table (); |
free_gnupg_table (); |