1 |
/* wptKeyEditDlgs.cpp - GPG key edit dialogs |
/* wptKeyEditDlgs.cpp - GPG key edit dialogs |
2 |
* Copyright (C) 2002-2009 Timo Schulz |
* Copyright (C) 2002-2009, 2011 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
303 |
bool |
bool |
304 |
is_jpg_file (const char *fname) |
is_jpg_file (const char *fname) |
305 |
{ |
{ |
306 |
FILE *fp; |
FILE *fp = fopen (fname, "rb"); |
|
BYTE buf[10]; |
|
|
int n; |
|
|
|
|
|
fp = fopen (fname, "rb"); |
|
307 |
if (!fp) |
if (!fp) |
308 |
return false; |
return false; |
309 |
n = fread (buf, 1, DIM (buf), fp); |
|
310 |
|
BYTE buf[10]; |
311 |
|
size_t n = fread (buf, 1, DIM (buf), fp); |
312 |
fclose (fp); |
fclose (fp); |
313 |
if (n < (int)DIM (buf)) |
if (n < DIM (buf)) |
314 |
return false; |
return false; |
315 |
return buf[6] == 'J' && buf[7] == 'F' && |
return buf[6] == 'J' && buf[7] == 'F' && |
316 |
buf[8] == 'I' && buf[9] == 'F'; |
buf[8] == 'I' && buf[9] == 'F'; |
624 |
} |
} |
625 |
|
|
626 |
|
|
627 |
|
/* Helper to map dialog indexes to GPG addkey commands */ |
628 |
|
typedef struct subkey_menu_t { |
629 |
|
int index; |
630 |
|
const char *text; |
631 |
|
int gpg_index; |
632 |
|
gpgme_pubkey_algo_t algo; |
633 |
|
}; |
634 |
|
subkey_menu_t SUBKEY_MENU[] = { |
635 |
|
{0, _("DSA (sign only)"), 3, GPGME_PK_DSA}, |
636 |
|
{1, _("ElGamal (encrypt only)"), 4, GPGME_PK_ELG_E}, |
637 |
|
{2, _("RSA (sign only)"), 5, GPGME_PK_RSA_E}, |
638 |
|
{3, _("RSA (encrypt only)"), 6, GPGME_PK_RSA_S} |
639 |
|
}; |
640 |
|
#define N_SUBKEY_MENU 4 |
641 |
|
|
642 |
|
|
643 |
/* Dialog procedure for adding a new secondary key. */ |
/* Dialog procedure for adding a new secondary key. */ |
644 |
BOOL CALLBACK |
BOOL CALLBACK |
645 |
keyedit_addsubkey_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyedit_addsubkey_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
664 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
665 |
|
|
666 |
hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO); |
hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO); |
667 |
listbox_add_string (hwnd, _("DSA (sign only)")); |
for (int i=0; i < N_SUBKEY_MENU; i++) { |
668 |
listbox_add_string (hwnd, _("ElGamal (encrypt only)")); |
listbox_add_string (hwnd, SUBKEY_MENU[i].text); |
669 |
listbox_add_string (hwnd, _("RSA (sign only)")); |
} |
|
listbox_add_string (hwnd, _("RSA (encrypt only)")); |
|
670 |
CheckDlgButton (dlg, IDC_ADDSUBKEY_EXPIRE, BST_CHECKED); |
CheckDlgButton (dlg, IDC_ADDSUBKEY_EXPIRE, BST_CHECKED); |
671 |
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE); |
672 |
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_SIZE), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_SIZE), FALSE); |
687 |
else |
else |
688 |
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), TRUE); |
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), TRUE); |
689 |
} |
} |
|
if (HIWORD (wparam) == LBN_SELCHANGE && |
|
|
LOWORD (wparam) == IDC_ADDSUBKEY_ALGO) { |
|
|
/* If DSA is selected, we disable the selection box since it |
|
|
is hardocded to 2048-bit. */ |
|
|
index = SendMessage ((HWND)lparam, LB_GETCURSEL, 0, 0); |
|
|
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_SIZE), |
|
|
index != 0? TRUE : FALSE); |
|
|
} |
|
690 |
|
|
691 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
692 |
case IDOK: |
case IDOK: |
693 |
keygen = (keygen_cb_t)ctx->opaque; |
keygen = (keygen_cb_t)ctx->opaque; |
694 |
if (!keygen) |
if (!keygen) |
695 |
BUG (NULL); |
BUG (NULL); |
|
hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO); |
|
|
int map[4]; |
|
|
/* this is for GPG 1.4.9 */ |
|
|
map[0] = 2; |
|
|
map[1] = 4; |
|
|
map[2] = 5; |
|
|
map[3] = 6; |
|
|
/* >1.4.10 changed the menu IDs. */ |
|
|
if (gpgver[0] == 1 && gpgver[1] >= 4 && gpgver[2] > 9) { |
|
|
map[0] = 3; |
|
|
map[1] = 5; |
|
|
map[2] = 4; |
|
|
map[3] = 6; |
|
|
} |
|
|
|
|
696 |
/* Map combo box numbers to GPG answers. */ |
/* Map combo box numbers to GPG answers. */ |
697 |
switch (listbox_get_cursel (hwnd)) { |
hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO); |
698 |
case 0: |
index = listbox_get_cursel (hwnd); |
699 |
case 1: |
if (index < 0 || index > N_SUBKEY_MENU) { |
|
case 2: |
|
|
case 3: |
|
|
break; |
|
|
default: |
|
700 |
show_balloon_msg (GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO), |
show_balloon_msg (GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO), |
701 |
_("Please select one entry."), IDI_ERROR); |
_("Please select one entry."), IDI_ERROR); |
702 |
return FALSE; |
return FALSE; |
703 |
} |
} |
|
index = map[listbox_get_cursel (hwnd)]; |
|
704 |
size = get_keysize_from_box (dlg, IDC_ADDSUBKEY_SIZE); |
size = get_keysize_from_box (dlg, IDC_ADDSUBKEY_SIZE); |
705 |
if (index == 2) /* DSA */ |
|
706 |
size = 2048; |
DateTime_GetSystemtime (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), &st); |
|
|
|
|
hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE); |
|
|
DateTime_GetSystemtime (hwnd, &st); |
|
707 |
valid = w32_mktime (&st) - time (NULL); |
valid = w32_mktime (&st) - time (NULL); |
708 |
valid /= 86400; |
valid /= 86400; |
|
|
|
|
keygen->bits = size; |
|
|
switch (index) { |
|
|
case 2: keygen->algo = GPGME_PK_DSA; break; |
|
|
case 4: keygen->algo = GPGME_PK_ELG_E; break; |
|
|
case 5: keygen->algo = GPGME_PK_RSA_S; break; |
|
|
case 6: keygen->algo = GPGME_PK_RSA_E; break; |
|
|
} |
|
709 |
if (valid > 0) |
if (valid > 0) |
710 |
keygen->expire = time (NULL) + valid*24*60*60; |
keygen->expire = time (NULL) + valid*24*60*60; |
711 |
|
keygen->bits = size; |
712 |
|
keygen->algo = SUBKEY_MENU[index].algo; |
713 |
|
|
714 |
{ |
{ |
715 |
GpgKeyEdit ke; |
GpgKeyEdit ke; |
716 |
passphrase_cb_s pcb; |
passphrase_cb_s pcb; |
717 |
|
|
718 |
set_gpg_auto_passphrase_cb (&pcb, _("Add Revoker")); |
set_gpg_auto_passphrase_cb (&pcb, _("Add Subkey")); |
719 |
|
|
720 |
ke.setPassphraseCallback (passphrase_cb, (void*)&pcb); |
ke.setPassphraseCallback (passphrase_cb, (void*)&pcb); |
721 |
ke.setKeyID (ctx->keyid); |
ke.setKeyID (ctx->keyid); |
722 |
ke.setCallback (keygen_cb, NULL); |
ke.setCallback (keygen_cb, NULL); |
723 |
keygen_cb_dlg_create (); |
keygen_cb_dlg_create (); |
724 |
err = ke.addSubkey ((gpgme_pubkey_algo_t)index, size, valid); |
err = ke.addSubkey ((gpgme_pubkey_algo_t)SUBKEY_MENU[index].gpg_index, size, valid); |
725 |
|
|
726 |
release_gpg_passphrase_cb (&pcb); |
release_gpg_passphrase_cb (&pcb); |
727 |
} |
} |
730 |
if (err) |
if (err) |
731 |
msg_box (dlg, gpgme_strerror (err), _("Add Subkey"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Add Subkey"), MB_ERR); |
732 |
else { |
else { |
733 |
msg_box (dlg, _("Subkey successfully added."), |
msg_box (dlg, _("Subkey successfully added."), _("GnuPG Status"), MB_OK); |
|
_("GnuPG Status"), MB_OK); |
|
734 |
ctx->finished = 1; |
ctx->finished = 1; |
735 |
} |
} |
736 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
1040 |
struct listview_column_s cols[] = { |
struct listview_column_s cols[] = { |
1041 |
{0, 80, (char *)_("Description")}, |
{0, 80, (char *)_("Description")}, |
1042 |
{1, 78, (char *)_("Key ID")}, |
{1, 78, (char *)_("Key ID")}, |
1043 |
{2, 66, (char *)_("Creation")}, |
{2, 72, (char *)_("Creation")}, |
1044 |
{3, 66, (char *)_("Expires")}, |
{3, 72, (char *)_("Expires")}, |
1045 |
{4, 64, (char *)_("Status")}, |
{4, 64, (char *)_("Status")}, |
1046 |
{5, 16, (char *) "C"/*ertify*/}, |
{5, 16, (char *) "C"/*ertify*/}, |
1047 |
{6, 16, (char *) "S"/*ign*/}, |
{6, 16, (char *) "S"/*ign*/}, |