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) |
60 |
} /* update_keycache */ |
} /* update_keycache */ |
61 |
|
|
62 |
|
|
63 |
|
/* Set GPGME debug mode. If @val is 0, the debug mode is disabled. */ |
64 |
|
void |
65 |
|
gpg_set_debug_mode (int val) |
66 |
|
{ |
67 |
|
if (val) |
68 |
|
putenv ("GPGME_DEBUG=5:gpgme.dbg"); |
69 |
|
else |
70 |
|
putenv ("GPGME_DEBUG="); |
71 |
|
} |
72 |
|
|
73 |
static char * |
static char * |
74 |
get_gettext_lang (void) |
get_gettext_lang (void) |
75 |
{ |
{ |
84 |
static void |
static void |
85 |
load_gettext (void) |
load_gettext (void) |
86 |
{ |
{ |
87 |
char * nls = NULL; |
char *nls = NULL; |
88 |
char * file = NULL; |
char *file = NULL; |
89 |
|
|
90 |
nls = get_gettext_lang (); |
nls = get_gettext_lang (); |
91 |
if (nls) { |
if (nls) { |
108 |
check_default_key (gpgme_keycache_t kc) |
check_default_key (gpgme_keycache_t kc) |
109 |
{ |
{ |
110 |
gpgme_key_t key; |
gpgme_key_t key; |
111 |
gpgme_error_t err = GPGME_No_Error; |
gpgme_error_t err = GPG_ERR_NO_ERROR; |
112 |
char * defkey; |
char * defkey; |
113 |
|
|
114 |
defkey = get_gnupg_default_key (); |
defkey = get_gnupg_default_key (); |
154 |
static int |
static int |
155 |
check_crypto_engine (void) |
check_crypto_engine (void) |
156 |
{ |
{ |
157 |
int ma=1, mi=2, pa=4; /* GPG 1.2.4 */ |
int ma=1, mi=4, pa=0; /* GPG 1.4.0 */ |
158 |
int rc; |
int rc; |
159 |
|
|
160 |
rc = check_gnupg_engine (&ma, &mi, &pa); |
rc = check_gnupg_engine (&ma, &mi, &pa); |
165 |
else if (rc) { |
else if (rc) { |
166 |
log_box (_("WinPT Error"), MB_ERR, |
log_box (_("WinPT Error"), MB_ERR, |
167 |
_("Sorry, you need a newer GPG version.\n" |
_("Sorry, you need a newer GPG version.\n" |
168 |
"GPG version %d.%d.%d requred GPG version 1.2.4"), |
"GPG version %d.%d.%d required GPG version 1.4.0"), |
169 |
ma, mi, pa); |
ma, mi, pa); |
170 |
return rc; |
return rc; |
171 |
} |
} |
215 |
reg_prefs.use_viewer = 0; /* XXX */ |
reg_prefs.use_viewer = 0; /* XXX */ |
216 |
} |
} |
217 |
|
|
218 |
|
char* get_subkey_fingerprint (gpgme_ctx_t ctx, const char *keyid); |
219 |
|
|
220 |
int WINAPI |
int WINAPI |
221 |
|
#ifndef WINPT_IPC |
222 |
WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
223 |
|
#else |
224 |
|
win_main (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
225 |
|
#endif |
226 |
{ |
{ |
227 |
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}; |
228 |
HACCEL accel_tab; |
HACCEL accel_tab; |
230 |
int first_start = 0, start_gpgprefs = 0; |
int first_start = 0, start_gpgprefs = 0; |
231 |
const char * s; |
const char * s; |
232 |
MSG msg; |
MSG msg; |
233 |
HWND hwnd; |
HWND hwnd = NULL; |
234 |
|
|
235 |
glob_hinst = hinst; |
glob_hinst = hinst; |
236 |
|
|
|
gpgme_lib_init (); |
|
237 |
#ifdef _DEBUG |
#ifdef _DEBUG |
238 |
gpgme_set_debug_mode (1); |
gpg_set_debug_mode (1); |
239 |
|
debug = 1; |
240 |
#endif |
#endif |
|
gpgme_set_pgm_string ("WinPT "PGM_VERSION); |
|
241 |
|
|
242 |
s = PTD_get_version (); |
s = PTD_get_version (); |
243 |
if (strcmp (s, "0.8.0")) { |
if (strcmp (s, "0.8.0")) { |
253 |
return 0; |
return 0; |
254 |
} |
} |
255 |
|
|
256 |
if (cmdline && stristr (cmdline, "--mobile")) |
s = gpgme_check_version ("1.1.0"); |
257 |
|
if (!s || !*s) { |
258 |
|
msg_box (NULL, _("A newer GPGME version is needed."), "WinPT Error", MB_ERR); |
259 |
|
return 0; |
260 |
|
} |
261 |
|
|
262 |
|
if (cmdline && stristr (cmdline, "--mobile")) { |
263 |
|
msg_box (NULL, "WARNING: mobile modus is not fully implemented yet!", |
264 |
|
"WinPT", MB_INFO); |
265 |
mobile = 1; |
mobile = 1; |
266 |
|
} |
267 |
|
|
268 |
set_default_kserver (); |
set_default_kserver (); |
269 |
|
|
296 |
_("Select GPG Public Keyring"), |
_("Select GPG Public Keyring"), |
297 |
_("GPG Keyrings (*.gpg)\0*.gpg\0\0"), |
_("GPG Keyrings (*.gpg)\0*.gpg\0\0"), |
298 |
NULL); |
NULL); |
299 |
if (s && !file_exist_check (s)) |
if (s != NULL) { |
|
{ |
|
300 |
size_t n; |
size_t n; |
301 |
char * p = strrchr (s, '\\'); |
char * p = strrchr (s, '\\'); |
302 |
if (!p) |
if (!p) |
381 |
} |
} |
382 |
|
|
383 |
load_keyserver_conf (cmdline? 1 : 0); |
load_keyserver_conf (cmdline? 1 : 0); |
384 |
|
if (start_keymanager) { |
385 |
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
386 |
|
GetDesktopWindow(), keymanager_dlg_proc, NULL, |
387 |
|
_("Key Manager"), IDS_WINPT_KEYMISC); |
388 |
|
keycache_release (); |
389 |
|
free_gnupg_table (); |
390 |
|
return 0; |
391 |
|
} |
392 |
|
|
393 |
if (cmdline && (stristr (cmdline, "--keymanager") |
if (cmdline && (stristr (cmdline, "--keymanager") |
394 |
|| stristr (cmdline, "--cardmanager"))) { |
|| stristr (cmdline, "--cardmanager"))) { |
395 |
update_keycache (GetDesktopWindow ()); |
update_keycache (GetDesktopWindow ()); |
396 |
if (stristr (cmdline, "keymanager")) |
if (stristr (cmdline, "keymanager")) |
397 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
398 |
GetDesktopWindow(), keymanager_dlg_proc, NULL, |
GetDesktopWindow(), keymanager_dlg_proc, NULL, |
399 |
_("Key Manager"), IDS_WINPT_KEYMISC); |
_("Key Manager"), IDS_WINPT_KEYMISC); |
400 |
else { |
else { |
401 |
gpgme_card_t crd = smartcard_init (); |
gpg_card_t crd = smartcard_init (); |
402 |
if (crd) |
if (crd) |
403 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_EDIT, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_CARD_EDIT, |
404 |
GetDesktopWindow(), card_edit_dlg_proc, |
GetDesktopWindow(), card_edit_dlg_proc, |
405 |
(LPARAM)crd, _("Card Manager"), |
(LPARAM)crd, _("Card Manager"), |
406 |
IDS_WINPT_CARD_EDIT); |
IDS_WINPT_CARD_EDIT); |
407 |
gpgme_card_release (crd); |
gpg_card_release (crd); |
408 |
} |
} |
409 |
keycache_release (); |
keycache_release (); |
410 |
free_gnupg_table (); |
free_gnupg_table (); |
419 |
|
|
420 |
if (cmdline) { |
if (cmdline) { |
421 |
if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) { |
if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) { |
422 |
gpgme_set_debug_mode (1); |
gpg_set_debug_mode (1); |
423 |
winpt_debug_msg (); |
winpt_debug_msg (); |
424 |
debug = 1; |
debug = 1; |
425 |
} |
} |
449 |
UpdateWindow (hwnd); |
UpdateWindow (hwnd); |
450 |
|
|
451 |
if (!first_start && !start_gpgprefs) { |
if (!first_start && !start_gpgprefs) { |
452 |
gnupg_backup_options (1); |
gnupg_backup_options (); |
|
gnupg_backup_options (0); |
|
|
|
|
453 |
rc = check_crypto_engine (); |
rc = check_crypto_engine (); |
454 |
if (rc) { |
if (rc) { |
455 |
DestroyWindow (hwnd); |
DestroyWindow (hwnd); |
457 |
return 0; |
return 0; |
458 |
} |
} |
459 |
} |
} |
460 |
|
|
461 |
if (start_gpgprefs) |
if (start_gpgprefs) { |
|
{ |
|
462 |
char *ring; |
char *ring; |
463 |
size_t size = 0; |
size_t size = 0; |
464 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd, |
470 |
} |
} |
471 |
|
|
472 |
if (first_start) { |
if (first_start) { |
473 |
struct key_wizard_s c, dummy; |
struct first_start_s fs; |
474 |
|
struct genkey_s c; |
475 |
|
HWND h; |
476 |
start: |
start: |
477 |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, hwnd, |
h = GetDesktopWindow (); |
478 |
first_run_dlg_proc, (LPARAM)&dummy); |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h, |
479 |
switch (dummy.interactive) |
gpgprefs_dlg_proc, NULL); |
480 |
{ |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h, |
481 |
|
first_run_dlg_proc, (LPARAM)&fs); |
482 |
|
switch (fs.choice) { |
483 |
case SETUP_KEYGEN: |
case SETUP_KEYGEN: |
484 |
c.interactive = 1; |
c.interactive = 1; |
485 |
|
c.first_start = 1; |
486 |
rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, |
rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, |
487 |
hwnd, keygen_wizard_dlg_proc, (LPARAM)&c); |
h, keygen_wizard_dlg_proc, (LPARAM)&c); |
488 |
if (!rc) |
if (!rc) |
489 |
goto start; |
goto start; |
490 |
break; |
break; |
497 |
} |
} |
498 |
break; |
break; |
499 |
|
|
|
case SETUP_EXISTING: |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd, |
|
|
gpgprefs_dlg_proc, NULL); |
|
|
break; |
|
|
|
|
500 |
case -1: |
case -1: |
501 |
DestroyWindow (hwnd); |
DestroyWindow (hwnd); |
502 |
free_gnupg_table (); |
free_gnupg_table (); |