1 |
/* wptKeyRevokeDlg.cpp - Key revocation dialog |
/* wptKeyRevokeDlg.cpp - Key revocation dialog |
2 |
* Copyright (C) 2001, 2002, 2003, 2005, 2006 Timo Schulz |
* Copyright (C) 2001-2003, 2005-2006, 2009 Timo Schulz |
3 |
* Copyright (C) 2005 g10 Code GmbH |
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
16 |
*/ |
*/ |
17 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
18 |
#include <config.h> |
#include <config.h> |
41 |
mk_cert_fname (const char *keyid, char *fname, size_t flen) |
mk_cert_fname (const char *keyid, char *fname, size_t flen) |
42 |
{ |
{ |
43 |
winpt_key_s k; |
winpt_key_s k; |
44 |
|
const char *filename = _("Revocation-Certificate"); |
45 |
|
|
46 |
memset (&k, 0, sizeof (k)); |
memset (&k, 0, sizeof (k)); |
47 |
if (winpt_get_pubkey (keyid, &k)) |
if (winpt_get_pubkey (keyid, &k)) |
48 |
BUG (NULL); |
BUG (NULL); |
49 |
_snprintf (fname, flen-1, "%s_RevocationCert.asc", k.ext->uids->name); |
_snprintf (fname, flen-1, "%s_%s.asc", k.ext->uids->name, filename); |
50 |
secure_filename (fname, strlen (fname)); |
secure_filename (fname, strlen (fname)); |
51 |
} |
} |
52 |
|
|
76 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
77 |
SetDlgItemText (dlg, IDC_KEYREVOKE_REASONINF, _("Reason for revocation")); |
SetDlgItemText (dlg, IDC_KEYREVOKE_REASONINF, _("Reason for revocation")); |
78 |
SetDlgItemText (dlg, IDC_KEYREVOKE_OPTINF, _("Optional description text")); |
SetDlgItemText (dlg, IDC_KEYREVOKE_OPTINF, _("Optional description text")); |
79 |
SetDlgItemText (dlg, IDC_KEYREVOKE_PWDINF, _("&Passphrase")); |
SetDlgItemText (dlg, IDC_KEYREVOKE_PWDINF, _("&Passphrase:")); |
80 |
SetDlgItemText (dlg, IDC_KEYREVOKE_OUTINF, _("Output file")); |
SetDlgItemText (dlg, IDC_KEYREVOKE_OUTINF, _("Output file:")); |
81 |
list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON); |
list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON); |
82 |
listbox_add_string (list, _("0. No reason specified")); |
listbox_add_string (list, _("0. No reason specified")); |
83 |
listbox_add_string (list, _("1. Key has been compromised")); |
listbox_add_string (list, _("1. Key has been compromised")); |
141 |
on_init_dialog (dlg); |
on_init_dialog (dlg); |
142 |
return TRUE; |
return TRUE; |
143 |
|
|
144 |
|
case WM_DESTROY: |
145 |
|
balloon_msg_disable (); |
146 |
|
break; |
147 |
|
|
148 |
case WM_COMMAND: |
case WM_COMMAND: |
149 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
150 |
case IDC_KEYREVOKE_CHOOSE: |
case IDC_KEYREVOKE_CHOOSE: |
151 |
|
balloon_msg_disable (); |
152 |
const char *s; |
const char *s; |
153 |
mk_cert_fname (k->keyid, file, sizeof (file)-1); |
mk_cert_fname (k->keyid, file, sizeof (file)-1); |
154 |
s = get_filesave_dlg (dlg, _("Choose File to save the Certificate"), NULL, file); |
s = get_filesave_dlg (dlg, _("Choose file to save the certificate"), NULL, file); |
155 |
if (s && *s) |
if (s && *s) |
156 |
SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s); |
SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s); |
157 |
return TRUE; |
return TRUE; |
160 |
list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON); |
list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON); |
161 |
idx = SendMessage (list, LB_GETCURSEL, 0, 0); |
idx = SendMessage (list, LB_GETCURSEL, 0, 0); |
162 |
if (idx < 0 || idx > 3) { |
if (idx < 0 || idx > 3) { |
163 |
msg_box (dlg, _("Please select a reason."), |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYREVOKE_REASON), |
164 |
_("Key Revocation Cert"), MB_ERR); |
_("Please select a reason."), IDI_ERROR); |
165 |
return TRUE; |
return TRUE; |
166 |
} |
} |
167 |
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) { |
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, |
168 |
msg_box (dlg, _("Please enter a file name."), |
DIM (file)-1)) { |
169 |
_("Key Revocation Cert"), MB_ERR); |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYREVOKE_FILE), |
170 |
|
_("Please enter a file name."), IDI_ERROR); |
171 |
return TRUE; |
return TRUE; |
172 |
} |
} |
173 |
if (check_file_name (file, IS_PATH)) { |
if (check_file_name (file, IS_PATH)) { |
174 |
msg_box (dlg, _("The file name contains one or more illegal characters."), |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYREVOKE_FILE), |
175 |
_("Key Revocation Cert"), MB_ERR); |
_("The file name contains one or more illegal characters."), |
176 |
|
IDI_ERROR); |
177 |
return TRUE; |
return TRUE; |
178 |
} |
} |
179 |
|
|
181 |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYREVOKE_TEXT, &desc)) |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYREVOKE_TEXT, &desc)) |
182 |
use_desc = 0; |
use_desc = 0; |
183 |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYREVOKE_PWD, &pwd)) { |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYREVOKE_PWD, &pwd)) { |
184 |
msg_box (dlg, _("Please enter the passphrase."), |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYREVOKE_PWD), |
185 |
_("Key Revocation Cert"), MB_ERR); |
_("Please enter the passphrase."), IDI_ERROR); |
186 |
|
// FIXME: what if the key is not protected? |
187 |
return TRUE; |
return TRUE; |
188 |
} |
} |
189 |
|
|
193 |
sfree_if_alloc (desc); |
sfree_if_alloc (desc); |
194 |
sfree_if_alloc (pwd); |
sfree_if_alloc (pwd); |
195 |
if (err) { |
if (err) { |
196 |
msg_box (dlg, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), |
197 |
|
_("Key Revocation Cert"), MB_ERR); |
198 |
safe_free (revcert); |
safe_free (revcert); |
199 |
return TRUE; |
return TRUE; |
200 |
} |
} |