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