1 |
twoaday |
2 |
/* wptKeyRevokeDlg.cpp - Key revocation dialog |
2 |
twoaday |
22 |
* Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz |
3 |
twoaday |
24 |
* Copyright (C) 2005 g10 Code GmbH |
4 |
twoaday |
2 |
* |
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 |
|
|
#include <windows.h> |
22 |
|
|
|
23 |
|
|
#include "../resource.h" |
24 |
twoaday |
25 |
#include "gpgme.h" |
25 |
twoaday |
2 |
#include "wptErrors.h" |
26 |
|
|
#include "wptGPG.h" |
27 |
|
|
#include "wptW32API.h" |
28 |
|
|
#include "wptTypes.h" |
29 |
|
|
#include "wptCommonCtl.h" |
30 |
|
|
#include "wptContext.h" /* for passphrase_s */ |
31 |
|
|
#include "wptDlgs.h" |
32 |
|
|
#include "wptNLS.h" |
33 |
|
|
#include "wptUTF8.h" |
34 |
|
|
|
35 |
|
|
|
36 |
twoaday |
32 |
/* Generate a file template for the cert based on the key |
37 |
|
|
with the keyid @keyid. */ |
38 |
twoaday |
24 |
static void |
39 |
|
|
mk_cert_fname (const char *keyid, char *fname, size_t flen) |
40 |
twoaday |
2 |
{ |
41 |
twoaday |
24 |
gpgme_key_t k; |
42 |
|
|
size_t i; |
43 |
twoaday |
2 |
|
44 |
twoaday |
24 |
get_pubkey (keyid, &k); |
45 |
|
|
_snprintf (fname, flen-1, "%s-RevocationCert.asc", k->uids->name); |
46 |
|
|
for (i=0; i < strlen (fname); i++) |
47 |
|
|
if (fname[i] == ' ') |
48 |
|
|
fname[i] = '_'; |
49 |
twoaday |
23 |
} |
50 |
twoaday |
2 |
|
51 |
|
|
|
52 |
twoaday |
24 |
/* Release the cert data and store it in the file @fname. */ |
53 |
|
|
static void |
54 |
|
|
release_cert_as_file (char *revcert, const char *fname) |
55 |
|
|
{ |
56 |
|
|
gpgme_error_t err; |
57 |
|
|
gpgme_data_t rev; |
58 |
|
|
|
59 |
|
|
err = gpgme_data_new_from_mem (&rev, revcert, strlen (revcert), 1); |
60 |
|
|
if (!err) |
61 |
|
|
gpg_data_release_and_set_file (rev, fname); |
62 |
|
|
else |
63 |
|
|
msg_box (NULL, gpgme_strerror (err), _("Key Revocation"), MB_ERR); |
64 |
|
|
free (revcert); |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
|
68 |
|
|
/* Dialog box procedure for key revocation. */ |
69 |
twoaday |
2 |
BOOL CALLBACK |
70 |
twoaday |
22 |
key_revoke_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
71 |
twoaday |
2 |
{ |
72 |
|
|
static winpt_key_t k; |
73 |
twoaday |
24 |
gpgme_error_t err; |
74 |
twoaday |
2 |
HWND list; |
75 |
twoaday |
23 |
int idx, use_desc, chk = 0; |
76 |
|
|
char desc[256], file[256], *p = NULL; |
77 |
twoaday |
2 |
char pwd[256]; |
78 |
twoaday |
24 |
char *inp_data = NULL, *revcert=NULL; |
79 |
twoaday |
2 |
|
80 |
|
|
switch( msg ) { |
81 |
|
|
case WM_INITDIALOG: |
82 |
|
|
if( !lparam ) |
83 |
|
|
dlg_fatal_error(dlg, "Could not get dialog param!"); |
84 |
|
|
k = (winpt_key_t )lparam; |
85 |
twoaday |
23 |
#ifndef LANG_DE |
86 |
twoaday |
32 |
SetWindowText (dlg, _("Key Revocation")); |
87 |
twoaday |
23 |
#endif |
88 |
|
|
SetDlgItemText (dlg, IDC_KEYREVOKE_HINT, |
89 |
|
|
_("Please move this certificate to a medium where it can be " |
90 |
|
|
"stored in a safe place (floppy, CDR, etc..). " |
91 |
|
|
"If an attacker gets access to this certificate he can use it to " |
92 |
|
|
"render your key unusable!")); |
93 |
twoaday |
2 |
list = GetDlgItem( dlg, IDC_KEYREVOKE_REASON ); |
94 |
twoaday |
23 |
listbox_add_string (list, _("0. No reason specified")); |
95 |
|
|
listbox_add_string (list, _("1. Key has been compromised")); |
96 |
|
|
listbox_add_string (list, _("2. Key is superseded")); |
97 |
|
|
listbox_add_string (list, _("3. Key is no longer used")); |
98 |
twoaday |
2 |
SetForegroundWindow (dlg); |
99 |
twoaday |
23 |
center_window (dlg, NULL); |
100 |
twoaday |
2 |
return TRUE; |
101 |
|
|
|
102 |
|
|
case WM_SYSCOMMAND: |
103 |
|
|
if( LOWORD( wparam ) == SC_CLOSE ) { |
104 |
|
|
SetDlgItemText( dlg, IDC_KEYREVOKE_PWD, "" ); |
105 |
|
|
EndDialog( dlg, TRUE ); |
106 |
|
|
} |
107 |
|
|
return FALSE; |
108 |
|
|
|
109 |
|
|
case WM_COMMAND: |
110 |
|
|
switch( LOWORD( wparam ) ) { |
111 |
|
|
case IDC_KEYREVOKE_CHOOSE: |
112 |
twoaday |
23 |
const char *s; |
113 |
twoaday |
24 |
mk_cert_fname (k->keyid, file, sizeof file-1); |
114 |
twoaday |
23 |
s = get_filename_dlg (dlg, FILE_SAVE, _("Choose File to save the Certificate"), NULL, file); |
115 |
|
|
if (s && *s) |
116 |
|
|
SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s); |
117 |
twoaday |
2 |
return TRUE; |
118 |
|
|
|
119 |
|
|
case IDOK: |
120 |
twoaday |
23 |
list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON); |
121 |
|
|
idx = SendMessage (list, LB_GETCURSEL, NULL, NULL); |
122 |
|
|
if (idx < 0 || idx > 3) { |
123 |
twoaday |
32 |
msg_box (dlg, _("Please select a reason."), |
124 |
|
|
_("Key Revocation"), MB_ERR); |
125 |
twoaday |
24 |
return TRUE; |
126 |
twoaday |
2 |
} |
127 |
twoaday |
32 |
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) { |
128 |
|
|
msg_box (dlg, _("Please enter a file name."), |
129 |
|
|
_("Key Revocation"), MB_ERR); |
130 |
twoaday |
24 |
return TRUE; |
131 |
twoaday |
2 |
} |
132 |
|
|
use_desc = 1; |
133 |
twoaday |
32 |
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_TEXT, desc, sizeof (desc)-1)) |
134 |
twoaday |
2 |
use_desc = 0; |
135 |
twoaday |
32 |
if( !GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) { |
136 |
|
|
msg_box (dlg, _("Please enter the passphrase."), _("Key Revocation"), MB_ERR); |
137 |
twoaday |
24 |
return TRUE; |
138 |
twoaday |
2 |
} |
139 |
twoaday |
24 |
|
140 |
|
|
if (use_desc) |
141 |
twoaday |
2 |
p = wincp_to_utf8 (desc, strlen (desc)); |
142 |
|
|
/* we use the keyid to avoid charset problems and UTF8 encodings.*/ |
143 |
twoaday |
24 |
inp_data = generate_revoc_input (idx, use_desc? p : NULL, pwd); |
144 |
twoaday |
2 |
|
145 |
twoaday |
24 |
err = gpg_revoke_key (inp_data, k->keyid, &revcert); |
146 |
twoaday |
32 |
wipememory (&pwd, sizeof (pwd)); |
147 |
twoaday |
24 |
memset (inp_data, 0, strlen (inp_data)); |
148 |
|
|
free (inp_data); |
149 |
|
|
free_if_alloc (p); |
150 |
|
|
|
151 |
|
|
if (err) { |
152 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Key Revocation"), MB_ERR); |
153 |
|
|
if (revcert) |
154 |
|
|
free (revcert); |
155 |
|
|
} |
156 |
|
|
else { |
157 |
|
|
msg_box (dlg, _("Revocation certificate generated."), _("GnuPG Status"), MB_OK); |
158 |
|
|
release_cert_as_file (revcert, file); |
159 |
|
|
} |
160 |
|
|
EndDialog (dlg, TRUE); |
161 |
twoaday |
2 |
return TRUE; |
162 |
|
|
|
163 |
|
|
case IDCANCEL: |
164 |
twoaday |
32 |
EndDialog (dlg, FALSE); |
165 |
twoaday |
2 |
return FALSE; |
166 |
|
|
} |
167 |
|
|
break; |
168 |
|
|
} |
169 |
|
|
|
170 |
|
|
return FALSE; |
171 |
twoaday |
24 |
} |