1 |
werner |
36 |
/* wptKeyRevokeDlg.cpp - Key revocation dialog |
2 |
|
|
* Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz |
3 |
|
|
* Copyright (C) 2005 g10 Code GmbH |
4 |
|
|
* |
5 |
|
|
* This file is part of WinPT. |
6 |
|
|
* |
7 |
|
|
* WinPT is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* WinPT is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
20 |
|
|
*/ |
21 |
|
|
#ifdef HAVE_CONFIG_H |
22 |
|
|
#include <config.h> |
23 |
|
|
#endif |
24 |
|
|
|
25 |
|
|
#include <windows.h> |
26 |
|
|
|
27 |
werner |
47 |
#include "resource.h" |
28 |
werner |
36 |
#include "gpgme.h" |
29 |
|
|
#include "wptErrors.h" |
30 |
|
|
#include "wptGPG.h" |
31 |
|
|
#include "wptW32API.h" |
32 |
|
|
#include "wptTypes.h" |
33 |
|
|
#include "wptCommonCtl.h" |
34 |
|
|
#include "wptContext.h" /* for passphrase_s */ |
35 |
|
|
#include "wptDlgs.h" |
36 |
|
|
#include "wptNLS.h" |
37 |
|
|
#include "wptUTF8.h" |
38 |
|
|
|
39 |
|
|
|
40 |
|
|
/* Generate a file template for the cert based on the key |
41 |
|
|
with the keyid @keyid. */ |
42 |
|
|
static void |
43 |
|
|
mk_cert_fname (const char *keyid, char *fname, size_t flen) |
44 |
|
|
{ |
45 |
|
|
gpgme_key_t k; |
46 |
|
|
size_t i; |
47 |
twoaday |
129 |
char *uid; |
48 |
werner |
36 |
|
49 |
twoaday |
129 |
if (get_pubkey (keyid, &k)) |
50 |
|
|
BUG (NULL); |
51 |
twoaday |
187 |
uid = utf8_to_native (k->uids->name); |
52 |
twoaday |
129 |
_snprintf (fname, flen-1, "%s_RevocationCert.asc", uid); |
53 |
|
|
for (i=0; i < strlen (fname); i++) { |
54 |
werner |
36 |
if (fname[i] == ' ') |
55 |
|
|
fname[i] = '_'; |
56 |
twoaday |
129 |
} |
57 |
|
|
safe_free (uid); |
58 |
werner |
36 |
} |
59 |
|
|
|
60 |
|
|
|
61 |
|
|
/* Release the cert data and store it in the file @fname. */ |
62 |
|
|
static void |
63 |
|
|
release_cert_as_file (char *revcert, const char *fname) |
64 |
|
|
{ |
65 |
|
|
gpgme_error_t err; |
66 |
|
|
gpgme_data_t rev; |
67 |
|
|
|
68 |
|
|
err = gpgme_data_new_from_mem (&rev, revcert, strlen (revcert), 1); |
69 |
|
|
if (!err) |
70 |
|
|
gpg_data_release_and_set_file (rev, fname); |
71 |
|
|
else |
72 |
twoaday |
129 |
msg_box (NULL, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR); |
73 |
twoaday |
200 |
safe_free (revcert); |
74 |
werner |
36 |
} |
75 |
|
|
|
76 |
|
|
|
77 |
twoaday |
200 |
static void |
78 |
|
|
on_init_dialog (HWND dlg) |
79 |
|
|
{ |
80 |
|
|
HWND list; |
81 |
|
|
|
82 |
|
|
SetWindowText (dlg, _("Key Revocation Cert")); |
83 |
|
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
84 |
|
|
SetDlgItemText (dlg, IDC_KEYREVOKE_REASONINF, _("Reason for revocation")); |
85 |
|
|
SetDlgItemText (dlg, IDC_KEYREVOKE_OPTINF, _("Optional description text")); |
86 |
|
|
SetDlgItemText (dlg, IDC_KEYREVOKE_PWDINF, _("&Passphrase")); |
87 |
|
|
SetDlgItemText (dlg, IDC_KEYREVOKE_OUTINF, _("Output file")); |
88 |
|
|
list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON); |
89 |
|
|
listbox_add_string (list, _("0. No reason specified")); |
90 |
|
|
listbox_add_string (list, _("1. Key has been compromised")); |
91 |
|
|
listbox_add_string (list, _("2. Key is superseded")); |
92 |
|
|
listbox_add_string (list, _("3. Key is no longer used")); |
93 |
|
|
SendMessage (list, LB_SETCURSEL, (WPARAM)0, 0); |
94 |
|
|
SetForegroundWindow (dlg); |
95 |
|
|
center_window (dlg, NULL); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
|
99 |
werner |
36 |
/* Dialog box procedure for key revocation. */ |
100 |
|
|
BOOL CALLBACK |
101 |
|
|
key_revoke_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
102 |
|
|
{ |
103 |
|
|
static winpt_key_t k; |
104 |
|
|
gpgme_error_t err; |
105 |
twoaday |
129 |
HWND list; |
106 |
twoaday |
65 |
int idx, use_desc; |
107 |
twoaday |
204 |
char file[256]; |
108 |
werner |
36 |
char pwd[256]; |
109 |
twoaday |
204 |
char *desc=NULL; |
110 |
werner |
36 |
char *inp_data = NULL, *revcert=NULL; |
111 |
twoaday |
129 |
const char *warning = |
112 |
|
|
_("Please move this certificate to a medium where it can be" |
113 |
|
|
"stored in a safe place (floppy, CDR, etc..).\n" |
114 |
|
|
"If an attacker gets access to this certificate he can use it to " |
115 |
|
|
"render your key unusable!"); |
116 |
werner |
36 |
|
117 |
|
|
switch( msg ) { |
118 |
|
|
case WM_INITDIALOG: |
119 |
twoaday |
200 |
if (!lparam) |
120 |
|
|
dlg_fatal_error (dlg, "Could not get dialog param!"); |
121 |
werner |
36 |
k = (winpt_key_t )lparam; |
122 |
twoaday |
200 |
on_init_dialog (dlg); |
123 |
werner |
36 |
return TRUE; |
124 |
|
|
|
125 |
|
|
case WM_SYSCOMMAND: |
126 |
twoaday |
200 |
if (LOWORD (wparam) == SC_CLOSE) |
127 |
|
|
EndDialog (dlg, FALSE); |
128 |
werner |
36 |
return FALSE; |
129 |
|
|
|
130 |
|
|
case WM_COMMAND: |
131 |
twoaday |
129 |
switch (LOWORD (wparam)) { |
132 |
werner |
36 |
case IDC_KEYREVOKE_CHOOSE: |
133 |
|
|
const char *s; |
134 |
|
|
mk_cert_fname (k->keyid, file, sizeof file-1); |
135 |
twoaday |
77 |
s = get_filesave_dlg (dlg, _("Choose File to save the Certificate"), NULL, file); |
136 |
werner |
36 |
if (s && *s) |
137 |
|
|
SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s); |
138 |
|
|
return TRUE; |
139 |
|
|
|
140 |
|
|
case IDOK: |
141 |
|
|
list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON); |
142 |
twoaday |
65 |
idx = SendMessage (list, LB_GETCURSEL, 0, 0); |
143 |
werner |
36 |
if (idx < 0 || idx > 3) { |
144 |
|
|
msg_box (dlg, _("Please select a reason."), |
145 |
twoaday |
129 |
_("Key Revocation Cert"), MB_ERR); |
146 |
werner |
36 |
return TRUE; |
147 |
|
|
} |
148 |
|
|
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) { |
149 |
|
|
msg_box (dlg, _("Please enter a file name."), |
150 |
twoaday |
129 |
_("Key Revocation Cert"), MB_ERR); |
151 |
werner |
36 |
return TRUE; |
152 |
|
|
} |
153 |
|
|
use_desc = 1; |
154 |
twoaday |
204 |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYREVOKE_TEXT, &desc)) |
155 |
werner |
36 |
use_desc = 0; |
156 |
twoaday |
200 |
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) { |
157 |
twoaday |
129 |
msg_box (dlg, _("Please enter the passphrase."), |
158 |
|
|
_("Key Revocation Cert"), MB_ERR); |
159 |
werner |
36 |
return TRUE; |
160 |
|
|
} |
161 |
|
|
|
162 |
twoaday |
204 |
inp_data = generate_revoke_input (idx, desc, pwd); |
163 |
twoaday |
129 |
err = gpg_revoke_cert (inp_data, k->keyid, &revcert); |
164 |
|
|
wipememory (pwd, sizeof (pwd)); |
165 |
|
|
wipememory (inp_data, strlen (inp_data)); |
166 |
werner |
36 |
if (err) { |
167 |
twoaday |
129 |
msg_box (dlg, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR); |
168 |
twoaday |
200 |
safe_free (revcert); |
169 |
werner |
36 |
} |
170 |
|
|
else { |
171 |
twoaday |
129 |
show_msg (dlg, 1000, _("Revocation certificate generated.")); |
172 |
|
|
msg_box (dlg, warning, _("Key Revocation Cert"), MB_INFO); |
173 |
werner |
36 |
release_cert_as_file (revcert, file); |
174 |
|
|
} |
175 |
twoaday |
200 |
safe_free (inp_data); |
176 |
twoaday |
204 |
free_if_alloc (desc); |
177 |
werner |
36 |
EndDialog (dlg, TRUE); |
178 |
|
|
return TRUE; |
179 |
|
|
|
180 |
|
|
case IDCANCEL: |
181 |
|
|
EndDialog (dlg, FALSE); |
182 |
|
|
return FALSE; |
183 |
|
|
} |
184 |
|
|
break; |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
return FALSE; |
188 |
|
|
} |