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" |
40 |
LOCK mo_file; |
LOCK mo_file; |
41 |
int scard_support = 0; |
int scard_support = 0; |
42 |
int debug = 0; |
int debug = 0; |
43 |
|
int mobile = 0; |
44 |
int gpg_read_only = 0; |
int gpg_read_only = 0; |
45 |
char gpgver[3]; |
char gpgver[3]; |
46 |
|
|
47 |
|
/* Internal IPC */ |
48 |
|
int start_keymanager = 0; |
49 |
|
|
50 |
static void |
static void |
51 |
update_keycache (HWND hwnd) |
update_keycache (HWND hwnd) |
143 |
static int |
static int |
144 |
check_crypto_engine (void) |
check_crypto_engine (void) |
145 |
{ |
{ |
146 |
int ma=1, mi=2, pa=4; /* GPG 1.2.4 */ |
int ma=1, mi=4, pa=0; /* GPG 1.4.0 */ |
147 |
int rc; |
int rc; |
148 |
|
|
149 |
rc = check_gnupg_engine (&ma, &mi, &pa); |
rc = check_gnupg_engine (&ma, &mi, &pa); |
154 |
else if (rc) { |
else if (rc) { |
155 |
log_box (_("WinPT Error"), MB_ERR, |
log_box (_("WinPT Error"), MB_ERR, |
156 |
_("Sorry, you need a newer GPG version.\n" |
_("Sorry, you need a newer GPG version.\n" |
157 |
"GPG version %d.%d.%d requred GPG version 1.2.4"), |
"GPG version %d.%d.%d required GPG version 1.4.0"), |
158 |
ma, mi, pa); |
ma, mi, pa); |
159 |
return rc; |
return rc; |
160 |
} |
} |
161 |
/* We enable smartcard support for GPG: 1.9.x and >= 1.3.90 */ |
/* We enable smartcard support for GPG: 1.9.x or >= 1.4.0 */ |
162 |
if (ma > 1 || mi >= 9 || mi > 3) |
if (ma >= 1 && mi >= 4) |
163 |
scard_support = 1; |
scard_support = 1; |
164 |
|
|
165 |
gpgver[0] = ma; |
gpgver[0] = ma; |
188 |
} |
} |
189 |
|
|
190 |
|
|
191 |
|
static void |
192 |
|
enable_mobile_mode (void) |
193 |
|
{ |
194 |
|
memset (®_prefs, 0, sizeof (reg_prefs)); |
195 |
|
reg_prefs.always_trust = 0; |
196 |
|
reg_prefs.auto_backup = 0; |
197 |
|
reg_prefs.cache_time = 0; |
198 |
|
reg_prefs.expert = 0; |
199 |
|
reg_prefs.keylist_mode = 1; |
200 |
|
reg_prefs.kserv_conf = m_strdup ("keyserver.conf"); |
201 |
|
reg_prefs.no_zip_mmedia = 1; |
202 |
|
reg_prefs.use_tmpfiles = 1; |
203 |
|
reg_prefs.word_wrap = 80; |
204 |
|
reg_prefs.use_viewer = 0; /* XXX */ |
205 |
|
} |
206 |
|
|
207 |
|
char* get_subkey_fingerprint (gpgme_ctx_t ctx, const char *keyid); |
208 |
|
|
209 |
int WINAPI |
int WINAPI |
210 |
|
#ifndef WINPT_IPC |
211 |
WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
212 |
|
#else |
213 |
|
win_main (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
214 |
|
#endif |
215 |
{ |
{ |
216 |
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}; |
217 |
HACCEL accel_tab; |
HACCEL accel_tab; |
219 |
int first_start = 0, start_gpgprefs = 0; |
int first_start = 0, start_gpgprefs = 0; |
220 |
const char * s; |
const char * s; |
221 |
MSG msg; |
MSG msg; |
222 |
HWND hwnd; |
HWND hwnd = NULL; |
223 |
|
|
224 |
glob_hinst = hinst; |
glob_hinst = hinst; |
225 |
|
|
243 |
return 0; |
return 0; |
244 |
} |
} |
245 |
|
|
246 |
|
if (cmdline && stristr (cmdline, "--mobile")) { |
247 |
|
msg_box (NULL, "WARNING: mobile modus is not fully implemented yet!", |
248 |
|
"WinPT", MB_INFO); |
249 |
|
mobile = 1; |
250 |
|
} |
251 |
|
|
252 |
set_default_kserver (); |
set_default_kserver (); |
253 |
regist_inst_gnupg (1); |
|
254 |
regist_inst_winpt (1, &created); |
if (!mobile) { |
255 |
|
regist_inst_gnupg (1); |
256 |
|
regist_inst_winpt (1, &created); |
257 |
|
} |
258 |
|
else { |
259 |
|
enable_mobile_mode (); |
260 |
|
/* XXX: ask for GPG path */ |
261 |
|
created = 1; /* Disable registry writing */ |
262 |
|
} |
263 |
|
|
264 |
if (!created) { |
if (!created) { |
265 |
memset (®_prefs, 0, sizeof (reg_prefs)); |
memset (®_prefs, 0, sizeof (reg_prefs)); |
266 |
reg_prefs.use_tmpfiles = 1; /* default */ |
reg_prefs.use_tmpfiles = 1; /* default */ |
366 |
} |
} |
367 |
|
|
368 |
load_keyserver_conf (cmdline? 1 : 0); |
load_keyserver_conf (cmdline? 1 : 0); |
369 |
|
if (start_keymanager) { |
370 |
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
371 |
|
GetDesktopWindow(), keymanager_dlg_proc, NULL, |
372 |
|
_("Key Manager"), IDS_WINPT_KEYMISC); |
373 |
|
keycache_release (); |
374 |
|
free_gnupg_table (); |
375 |
|
return 0; |
376 |
|
} |
377 |
|
|
378 |
if (cmdline && (stristr (cmdline, "--keymanager") |
if (cmdline && (stristr (cmdline, "--keymanager") |
379 |
|| stristr (cmdline, "--cardmanager"))) { |
|| stristr (cmdline, "--cardmanager"))) { |
380 |
update_keycache (GetDesktopWindow ()); |
update_keycache (GetDesktopWindow ()); |
381 |
if (stristr (cmdline, "keymanager")) |
if (stristr (cmdline, "keymanager")) |
382 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
383 |
GetDesktopWindow(), keymanager_dlg_proc, NULL, |
GetDesktopWindow(), keymanager_dlg_proc, NULL, |
384 |
_("Key Manager"), IDS_WINPT_KEYMISC); |
_("Key Manager"), IDS_WINPT_KEYMISC); |
385 |
else { |
else { |
386 |
gpgme_card_t crd = smartcard_init (); |
gpgme_card_t crd = smartcard_init (); |
387 |
if (crd) |
if (crd) |
402 |
return 0; |
return 0; |
403 |
} |
} |
404 |
|
|
405 |
/*if (file_exist_check ("loadimage.exe")) |
if (cmdline) { |
406 |
PTD_create_loadimage (NULL);*/ |
if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) { |
407 |
|
gpgme_set_debug_mode (1); |
408 |
if (cmdline && stristr (cmdline, "--enable-debug")) { |
winpt_debug_msg (); |
409 |
gpgme_set_debug_mode (1); |
debug = 1; |
410 |
winpt_debug_msg (); |
} |
|
debug = 1; |
|
411 |
} |
} |
412 |
|
|
413 |
wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT)); |
wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT)); |
444 |
return 0; |
return 0; |
445 |
} |
} |
446 |
} |
} |
447 |
|
|
448 |
if (start_gpgprefs) |
if (start_gpgprefs) { |
|
{ |
|
449 |
char *ring; |
char *ring; |
450 |
size_t size = 0; |
size_t size = 0; |
451 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd, |
457 |
} |
} |
458 |
|
|
459 |
if (first_start) { |
if (first_start) { |
460 |
struct key_wizard_s c, dummy; |
struct first_start_s fs; |
461 |
|
struct genkey_s c; |
462 |
|
HWND h; |
463 |
start: |
start: |
464 |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, hwnd, |
h = GetDesktopWindow (); |
465 |
first_run_dlg_proc, (LPARAM)&dummy); |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, h, |
466 |
switch (dummy.interactive) |
gpgprefs_dlg_proc, NULL); |
467 |
{ |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_FIRST, h, |
468 |
|
first_run_dlg_proc, (LPARAM)&fs); |
469 |
|
switch (fs.choice) { |
470 |
case SETUP_KEYGEN: |
case SETUP_KEYGEN: |
471 |
c.interactive = 1; |
c.interactive = 1; |
472 |
|
c.first_start = 1; |
473 |
rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, |
rc = DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, |
474 |
hwnd, keygen_wizard_dlg_proc, (LPARAM)&c); |
h, keygen_wizard_dlg_proc, (LPARAM)&c); |
475 |
if (!rc) |
if (!rc) |
476 |
goto start; |
goto start; |
477 |
break; |
break; |
484 |
} |
} |
485 |
break; |
break; |
486 |
|
|
|
case SETUP_EXISTING: |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_GPGPREFS, hwnd, |
|
|
gpgprefs_dlg_proc, NULL); |
|
|
break; |
|
|
|
|
487 |
case -1: |
case -1: |
488 |
DestroyWindow (hwnd); |
DestroyWindow (hwnd); |
489 |
free_gnupg_table (); |
free_gnupg_table (); |