46 |
static int wipe_contents = 0; |
static int wipe_contents = 0; |
47 |
|
|
48 |
|
|
49 |
|
/* Dialog box procedure to display all insecure all ElGamal keys. */ |
50 |
BOOL CALLBACK |
BOOL CALLBACK |
51 |
elgamal_warn_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
elgamal_warn_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
52 |
{ |
{ |
53 |
gpgme_keycache_t pc; |
gpg_keycache_t pc; |
54 |
gpgme_key_t key; |
gpgme_key_t key; |
55 |
|
char tmp[128+64+1]; |
56 |
|
|
57 |
switch( msg ) { |
switch( msg ) { |
58 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
59 |
pc = keycache_get_ctx( 1 ); |
pc = keycache_get_ctx (1); |
60 |
while( !gpgme_keycache_next_key( pc, 0, &key ) ) { |
while (!gpg_keycache_next_key (pc, 0, &key)) { |
61 |
if( key->subkeys->pubkey_algo == GPGME_PK_ELG ) { |
if (key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
62 |
char tmp[128+64+1]; |
_snprintf (tmp, sizeof (tmp)-1, "(0x%s) %s", |
|
_snprintf( tmp, sizeof (tmp)-1, "(0x%s) %s", |
|
63 |
key->subkeys->keyid+8, key->uids->uid); |
key->subkeys->keyid+8, key->uids->uid); |
64 |
SendDlgItemMessage( dlg, IDC_ELGWARN_LIST, LB_ADDSTRING, |
SendDlgItemMessage( dlg, IDC_ELGWARN_LIST, LB_ADDSTRING, |
65 |
0, (LPARAM)(const char *) tmp ); |
0, (LPARAM)(const char *) tmp ); |
66 |
} |
} |
67 |
} |
} |
68 |
gpgme_keycache_rewind( pc ); |
gpg_keycache_rewind (pc); |
69 |
center_window( dlg, NULL ); |
center_window (dlg, NULL); |
70 |
SetForegroundWindow( dlg ); |
SetForegroundWindow (dlg); |
71 |
break; |
break; |
72 |
|
|
73 |
case WM_COMMAND: |
case WM_COMMAND: |
74 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
75 |
case IDOK: |
case IDOK: |
76 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
77 |
break; |
break; |
78 |
} |
} |
79 |
break; |
break; |
80 |
} |
} |
81 |
return FALSE; |
return FALSE; |
82 |
} /* elgamal_warn_dlg_proc */ |
} |
83 |
|
|
84 |
|
|
85 |
static void |
|
86 |
|
static int |
87 |
cleanup_tmp_files (void) |
cleanup_tmp_files (void) |
88 |
{ |
{ |
89 |
struct _finddata_t dat; |
struct _finddata_t dat; |
93 |
if (GetTempPath (sizeof (tmp)-1, tmp) == FALSE || |
if (GetTempPath (sizeof (tmp)-1, tmp) == FALSE || |
94 |
SetCurrentDirectory (tmp) == FALSE) { |
SetCurrentDirectory (tmp) == FALSE) { |
95 |
winpt_errmsg ("GetTempPath", 0); |
winpt_errmsg ("GetTempPath", 0); |
96 |
return; |
return WPTERR_GENERAL; |
97 |
} |
} |
98 |
hd = _findfirst ("gpgmeOUT*", &dat); |
hd = _findfirst ("gpgmeOUT*", &dat); |
99 |
if (hd == -1) |
if (hd == -1) |
100 |
return; |
return 0; |
101 |
do { |
do { |
102 |
secure_unlink (dat.name, WIPE_MODE_SIMPLE); |
secure_unlink (dat.name, WIPE_MODE_SIMPLE); |
103 |
} while (_findnext (hd, &dat) == 0); |
} while (_findnext (hd, &dat) == 0); |
104 |
_findclose (hd); |
_findclose (hd); |
105 |
|
return 0; |
106 |
} |
} |
107 |
|
|
108 |
|
|
109 |
|
/* Dialog box procedure to confirm to delete the clipboard contents. */ |
110 |
static BOOL CALLBACK |
static BOOL CALLBACK |
111 |
confirm_delclipboard_dlg (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
confirm_delclipboard_dlg (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
112 |
{ |
{ |
135 |
break; |
break; |
136 |
} |
} |
137 |
return FALSE; |
return FALSE; |
138 |
} /* confirm_delclipboard_dlg */ |
} |
139 |
|
|
140 |
|
|
141 |
static gpgme_error_t |
static gpgme_error_t |
142 |
currwnd_gpg_dlg (HWND hwnd, UINT id, int *ret_set) |
currwnd_gpg_dlg (HWND hwnd, UINT id, int *ret_set) |
143 |
{ |
{ |
144 |
gpgme_error_t err; |
gpgme_error_t err; |
145 |
gpgme_pgptype_t type; |
gpg_pgptype_t type; |
146 |
|
|
147 |
if( ret_set ) |
if (ret_set) |
148 |
*ret_set = 1; |
*ret_set = 1; |
149 |
switch( id ) { |
switch (id) { |
150 |
case ID_WINPT_CURRWND_SYMENC: |
case ID_WINPT_CURRWND_SYMENC: |
151 |
gpgme_encrypt_symmetric (); |
gpg_encrypt_symmetric (); |
152 |
break; |
break; |
153 |
|
|
154 |
case ID_WINPT_CURRWND_ENCRYPT: |
case ID_WINPT_CURRWND_ENCRYPT: |
170 |
break; |
break; |
171 |
|
|
172 |
case ID_WINPT_CURRWND_DECRYPT_VERIFY: |
case ID_WINPT_CURRWND_DECRYPT_VERIFY: |
173 |
err = gpgme_clip_get_pgptype( &type ); |
err = gpg_clip_get_pgptype (&type); |
174 |
if( err ) { |
if (err) { |
175 |
msg_box( hwnd, gpgme_strerror( err ), _("Clipboard"), MB_ERR ); |
msg_box (hwnd, gpgme_strerror (err), _("Clipboard"), MB_ERR); |
176 |
break; |
break; |
177 |
} |
} |
178 |
if( (type & PGP_MESSAGE) && !(type & PGP_CLEARSIG) ) { |
if( (type & PGP_MESSAGE) && !(type & PGP_CLEARSIG) ) { |
199 |
} |
} |
200 |
|
|
201 |
return err; |
return err; |
202 |
} /* currwnd_gpg_dlg */ |
} |
203 |
|
|
204 |
|
|
205 |
static void |
static void |
206 |
clip_gpg_dlg( HWND hwnd, UINT id ) |
clip_gpg_dlg (HWND hwnd, UINT id) |
207 |
{ |
{ |
208 |
gpgme_error_t err; |
gpgme_error_t err; |
209 |
gpgme_pgptype_t type; |
gpg_pgptype_t type; |
210 |
size_t size = 0; |
size_t size = 0; |
211 |
|
|
212 |
if( (id == ID_WINPT_SIGN || id == ID_WINPT_SIGNENCRYPT) |
if( (id == ID_WINPT_SIGN || id == ID_WINPT_SIGNENCRYPT) |
217 |
|
|
218 |
switch( id ) { |
switch( id ) { |
219 |
case ID_WINPT_SYMENC: |
case ID_WINPT_SYMENC: |
220 |
gpgme_encrypt_symmetric(); |
gpg_encrypt_symmetric(); |
221 |
break; |
break; |
222 |
|
|
223 |
case ID_WINPT_ENCRYPT: |
case ID_WINPT_ENCRYPT: |
239 |
break; |
break; |
240 |
|
|
241 |
case ID_WINPT_DECRYPT_VERIFY: |
case ID_WINPT_DECRYPT_VERIFY: |
242 |
err = gpgme_clip_get_pgptype( &type ); |
err = gpg_clip_get_pgptype (&type); |
243 |
if( err ) { |
if (err) { |
244 |
msg_box( hwnd, gpgme_strerror( err ), _("Clipboard"), MB_ERR ); |
msg_box( hwnd, gpgme_strerror( err ), _("Clipboard"), MB_ERR ); |
245 |
break; |
break; |
246 |
} |
} |
289 |
} /* clip_gpg_dlg */ |
} /* clip_gpg_dlg */ |
290 |
|
|
291 |
|
|
292 |
gpg_card_t |
/* Add the winpt symbol to the task bar. */ |
293 |
smartcard_init (void) |
static void |
294 |
|
add_taskbar_icon (HWND hwnd, NOTIFYICONDATA *nid) |
295 |
{ |
{ |
296 |
/* |
nid->cbSize = sizeof (NOTIFYICONDATA); |
297 |
pcsc_loadlib (scard_support); |
nid->uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; |
298 |
rc = show_card_status (); |
nid->uCallbackMessage = WM_USER; |
299 |
if( rc ) |
nid->hWnd = hwnd; |
300 |
break; |
nid->hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT)); |
301 |
*/ |
strcpy (nid->szTip, "Windows Privacy Tray v"PGM_VERSION); |
302 |
return gpg_load_scard (); |
Shell_NotifyIcon (NIM_ADD, nid); |
303 |
} /* smartcard_init */ |
DestroyIcon (nid->hIcon); |
304 |
|
} |
305 |
|
|
306 |
|
|
307 |
|
/* Main message loop for the tray window. */ |
308 |
LRESULT CALLBACK |
LRESULT CALLBACK |
309 |
winpt_main_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) |
winpt_main_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) |
310 |
{ |
{ |
319 |
gpgme_error_t err; |
gpgme_error_t err; |
320 |
gpg_card_t card; |
gpg_card_t card; |
321 |
|
|
322 |
switch( msg ) { |
switch (msg) { |
323 |
case WM_CREATE: |
case WM_CREATE: |
324 |
NID.cbSize = sizeof (NID); |
add_taskbar_icon (hwnd, &NID); |
|
NID.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; |
|
|
NID.uCallbackMessage = WM_USER; |
|
|
NID.hWnd = hwnd; |
|
|
NID.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT)); |
|
|
strcpy (NID.szTip, "Windows Privacy Tray v"PGM_VERSION); |
|
|
Shell_NotifyIcon (NIM_ADD, &NID); |
|
|
DestroyIcon (NID.hIcon); |
|
325 |
rc = wsock_init (); |
rc = wsock_init (); |
326 |
if (rc) |
if (rc) |
327 |
msg_box (NULL, winpt_strerror (rc), "Winsock2 DLL", MB_ERR); |
msg_box (NULL, winpt_strerror (rc), "Winsock2 DLL", MB_ERR); |
332 |
} |
} |
333 |
rc = PTD_initialize (); |
rc = PTD_initialize (); |
334 |
if (!rc) |
if (!rc) |
335 |
msg_box (hwnd, _("Could not set current window mode hooks."), _("WinPT Error"), MB_OK); |
msg_box (hwnd, _("Could not set current window mode hooks."), |
336 |
|
_("WinPT Error"), MB_OK); |
337 |
mapi_init (); |
mapi_init (); |
338 |
/* init common controls: date control. */ |
/* init common controls: date control. */ |
339 |
cce.dwSize = sizeof (INITCOMMONCONTROLSEX); |
cce.dwSize = sizeof (INITCOMMONCONTROLSEX); |
349 |
cryptdisk_cleanup (); |
cryptdisk_cleanup (); |
350 |
mapi_deinit (); |
mapi_deinit (); |
351 |
wsock_end (); |
wsock_end (); |
352 |
keycache_release (); |
keycache_release (1); |
353 |
gnupg_backup_keyrings (); |
gnupg_backup_keyrings (); |
354 |
free_reg_prefs (); |
free_reg_prefs (); |
355 |
free_gnupg_table (); |
free_gnupg_table (); |
357 |
release_file_lock (&mo_file); |
release_file_lock (&mo_file); |
358 |
PTD_delete (); |
PTD_delete (); |
359 |
agent_flush_cache (); |
agent_flush_cache (); |
360 |
if (!gpgme_clip_istext_avail (&has_data) && has_data) { |
if (!gpg_clip_istext_avail (&has_data) && has_data) { |
361 |
int chk = get_reg_winpt_flag ("WipeClipboard"); |
int chk = get_reg_winpt_flag ("WipeClipboard"); |
362 |
if (chk == -1) |
if (chk == -1) |
363 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CONFDELCLIP, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CONFDELCLIP, |
486 |
case ID_WINPT_SIGN: |
case ID_WINPT_SIGN: |
487 |
case ID_WINPT_SIGNENCRYPT: |
case ID_WINPT_SIGNENCRYPT: |
488 |
case ID_WINPT_DECRYPT_VERIFY: |
case ID_WINPT_DECRYPT_VERIFY: |
489 |
err = gpgme_clip_istext_avail( &has_data ); |
err = gpg_clip_istext_avail( &has_data ); |
490 |
if( err ) { |
if( err ) { |
491 |
msg_box( hwnd, gpgme_strerror( err ),_("Clipboard"), MB_ERR ); |
msg_box( hwnd, gpgme_strerror( err ),_("Clipboard"), MB_ERR ); |
492 |
break; |
break; |
540 |
break; |
break; |
541 |
|
|
542 |
case ID_WINPT_CARD: |
case ID_WINPT_CARD: |
543 |
card = smartcard_init (); |
card = gpg_card_load (); |
544 |
if( card ) { |
if (card) { |
545 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_CARD_EDIT, |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_CARD_EDIT, |
546 |
GetDesktopWindow(), card_edit_dlg_proc, |
GetDesktopWindow (), card_edit_dlg_proc, |
547 |
(LPARAM)card, |
(LPARAM)card, |
548 |
_("Card Edit"), IDS_WINPT_CARD_EDIT ); |
_("Card Edit"), IDS_WINPT_CARD_EDIT); |
549 |
gpg_card_release( card ); card = NULL; |
gpg_card_release (card); |
550 |
|
card = NULL; |
551 |
} |
} |
552 |
break; |
break; |
553 |
|
|
570 |
break; |
break; |
571 |
|
|
572 |
case ID_WINPT_GPGPREFS: |
case ID_WINPT_GPGPREFS: |
573 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, GetDesktopWindow(), |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, GetDesktopWindow(), |
574 |
gpgprefs_dlg_proc, NULL, |
gpgprefs_dlg_proc, NULL, |
575 |
_("GnuPG Preferences"), IDS_WINPT_GPGPREFS ); |
_("GnuPG Preferences"), IDS_WINPT_GPGPREFS); |
576 |
break; |
break; |
577 |
|
|
578 |
case ID_WINPT_CDISKNEW: |
case ID_WINPT_CDISKNEW: |