1 |
twoaday |
2 |
/* wptKeyRevokeDlg.cpp - Key revocation dialog |
2 |
twoaday |
22 |
* Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz |
3 |
twoaday |
2 |
* |
4 |
|
|
* This file is part of WinPT. |
5 |
|
|
* |
6 |
|
|
* WinPT is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* WinPT is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
|
|
*/ |
20 |
|
|
#include <windows.h> |
21 |
|
|
|
22 |
|
|
#include "../resource.h" |
23 |
|
|
#include "wptErrors.h" |
24 |
|
|
#include "wptGPG.h" |
25 |
|
|
#include "wptW32API.h" |
26 |
|
|
#include "wptTypes.h" |
27 |
|
|
#include "wptCommonCtl.h" |
28 |
|
|
#include "wptContext.h" /* for passphrase_s */ |
29 |
|
|
#include "wptDlgs.h" |
30 |
|
|
#include "wptNLS.h" |
31 |
|
|
#include "wptUTF8.h" |
32 |
|
|
|
33 |
|
|
|
34 |
|
|
static const char * |
35 |
|
|
mk_cert_fname( const char * keyid ) |
36 |
|
|
{ |
37 |
|
|
static char fname[128]; |
38 |
|
|
|
39 |
|
|
if( strlen( keyid ) > 32 ) |
40 |
|
|
return NULL; |
41 |
|
|
_snprintf( fname, sizeof fname-1, "%s-revcert.asc", keyid ); |
42 |
|
|
return fname; |
43 |
|
|
} /* mk_cert_fname */ |
44 |
|
|
|
45 |
|
|
|
46 |
|
|
BOOL CALLBACK |
47 |
twoaday |
22 |
key_revoke_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
48 |
twoaday |
2 |
{ |
49 |
|
|
static winpt_key_t k; |
50 |
|
|
HWND list; |
51 |
|
|
int idx, use_desc, chk = 0, pgpmode = 0; |
52 |
|
|
char desc[256], file[256], * p = NULL; |
53 |
|
|
char pwd[256]; |
54 |
|
|
gpgme_editkey_t rev; |
55 |
|
|
gpgme_data_t rev_cert; |
56 |
|
|
gpgme_ctx_t c; |
57 |
|
|
gpgme_error_t err; |
58 |
|
|
|
59 |
|
|
switch( msg ) { |
60 |
|
|
case WM_INITDIALOG: |
61 |
|
|
if( !lparam ) |
62 |
|
|
dlg_fatal_error(dlg, "Could not get dialog param!"); |
63 |
|
|
k = (winpt_key_t )lparam; |
64 |
|
|
#ifndef LANG_DE |
65 |
|
|
SetWindowText( dlg, _("Key Revocation") ); |
66 |
|
|
#endif |
67 |
|
|
SetDlgItemText( dlg, IDC_KEYREVOKE_HINT, |
68 |
|
|
_("Please move this certificate to a medium where it can be " |
69 |
|
|
"stored in a safe place (floppy, CDR, etc..). " |
70 |
|
|
"If an attacker gets access to this certificate he can use it to " |
71 |
|
|
"render your key unusable!") ); |
72 |
|
|
list = GetDlgItem( dlg, IDC_KEYREVOKE_REASON ); |
73 |
|
|
listbox_add_string( list, _("0. No reason specified") ); |
74 |
|
|
listbox_add_string( list, _("1. Key has been compromised") ); |
75 |
|
|
listbox_add_string( list, _("2. Key is superseded") ); |
76 |
|
|
listbox_add_string( list, _("3. Key is no longer used") ); |
77 |
|
|
/* we set the PGP revoke mode by default because it does not do any |
78 |
|
|
* harm and makes sure the revocation certificate is compatible with PGP. |
79 |
|
|
*/ |
80 |
|
|
CheckDlgButton (dlg, IDC_KEYREVOKE_PGPMODE, BST_CHECKED); |
81 |
|
|
SetDlgItemText (dlg, IDC_KEYREVOKE_PGPMODE, _("Make output &PGP compatible")); |
82 |
|
|
SetForegroundWindow (dlg); |
83 |
|
|
center_window (dlg); |
84 |
|
|
return TRUE; |
85 |
|
|
|
86 |
|
|
case WM_SYSCOMMAND: |
87 |
|
|
if( LOWORD( wparam ) == SC_CLOSE ) { |
88 |
|
|
SetDlgItemText( dlg, IDC_KEYREVOKE_PWD, "" ); |
89 |
|
|
EndDialog( dlg, TRUE ); |
90 |
|
|
} |
91 |
|
|
return FALSE; |
92 |
|
|
|
93 |
|
|
case WM_COMMAND: |
94 |
twoaday |
22 |
if (HIWORD (wparam) == BN_CLICKED && |
95 |
|
|
LOWORD (wparam) == IDC_KEYREVOKE_PGPMODE) { |
96 |
|
|
if (!IsDlgButtonChecked (dlg, IDC_KEYREVOKE_PGPMODE)) |
97 |
|
|
msg_box (dlg, _("PGP < 8 will not be able to handle the output."), _("Key Revocation"), MB_WARN); |
98 |
|
|
} |
99 |
|
|
|
100 |
twoaday |
2 |
switch( LOWORD( wparam ) ) { |
101 |
|
|
case IDC_KEYREVOKE_CHOOSE: |
102 |
|
|
const char *s, * name; |
103 |
|
|
name = mk_cert_fname( k->keyid ); |
104 |
|
|
s = get_filename_dlg( dlg, 1, _("Choose File to save the Certificate"), NULL, name ); |
105 |
|
|
if( s && *s ) |
106 |
|
|
SetDlgItemText( dlg, IDC_KEYREVOKE_FILE, s ); |
107 |
|
|
return TRUE; |
108 |
|
|
|
109 |
|
|
case IDOK: |
110 |
|
|
list = GetDlgItem( dlg, IDC_KEYREVOKE_REASON ); |
111 |
|
|
idx = SendMessage( list, LB_GETCURSEL, NULL, NULL ); |
112 |
|
|
if( idx < 0 || idx > 3 ) { |
113 |
|
|
msg_box( dlg, _("Please select a reason."), _("Key Revocation"), MB_ERR ); |
114 |
|
|
return FALSE; |
115 |
|
|
} |
116 |
|
|
if( !GetDlgItemText(dlg, IDC_KEYREVOKE_FILE, file, sizeof file-1 ) ) { |
117 |
|
|
msg_box( dlg, _("Please enter a filename."), _("Key Revocation"), MB_ERR ); |
118 |
|
|
return FALSE; |
119 |
|
|
} |
120 |
|
|
use_desc = 1; |
121 |
|
|
if( !GetDlgItemText( dlg, IDC_KEYREVOKE_TEXT, desc, sizeof desc-1 ) ) |
122 |
|
|
use_desc = 0; |
123 |
|
|
if( !GetDlgItemText( dlg, IDC_KEYREVOKE_PWD, pwd, sizeof pwd-1 ) ) { |
124 |
|
|
msg_box( dlg, _("Please enter the passphrase."), _("Key Revocation"), MB_ERR ); |
125 |
|
|
return FALSE; |
126 |
|
|
} |
127 |
|
|
err = gpgme_editkey_new( &rev ); |
128 |
|
|
if( err ) |
129 |
|
|
BUG( dlg ); |
130 |
|
|
|
131 |
|
|
if( use_desc ) |
132 |
|
|
p = wincp_to_utf8 (desc, strlen (desc)); |
133 |
|
|
/* we use the keyid to avoid charset problems and UTF8 encodings.*/ |
134 |
|
|
if( IsDlgButtonChecked( dlg, IDC_KEYREVOKE_PGPMODE ) ) |
135 |
|
|
pgpmode = 1; |
136 |
|
|
gpgme_revoke_set( rev, k->keyid, use_desc? p : NULL, idx, pgpmode, pwd ); |
137 |
|
|
err = gpgme_data_new( &rev_cert ); |
138 |
|
|
if( !err ) |
139 |
|
|
err = gpgme_new( &c ); |
140 |
|
|
if( err ) |
141 |
|
|
BUG( dlg ); |
142 |
|
|
|
143 |
|
|
err = gpgme_op_revoke( c, rev, rev_cert ); |
144 |
|
|
memset( &pwd, 0, sizeof pwd ); |
145 |
|
|
if( err ) { |
146 |
|
|
msg_box( dlg, gpgme_strerror( err ), _("Key Revocation"), MB_ERR ); |
147 |
|
|
gpgme_data_release( rev_cert ); |
148 |
|
|
gpgme_editkey_release( rev ); |
149 |
|
|
gpgme_release( c ); |
150 |
|
|
free_if_alloc( p ); |
151 |
|
|
return FALSE; |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
msg_box( dlg, _("Revocation certificate generated."), _("GnuPG Status"), MB_OK ); |
155 |
|
|
chk = file_exist_check( file ); |
156 |
|
|
if( !chk ) |
157 |
|
|
log_box( _("Key Revocation"), MB_YESNO|MB_INFO, |
158 |
|
|
_("\"%s\" already exists.\nOverwrite the file?"), file ); |
159 |
|
|
if( idx == IDYES || chk ) |
160 |
|
|
gpgme_data_release_and_set_file( rev_cert, file ); |
161 |
|
|
else |
162 |
|
|
gpgme_data_release( rev_cert ); |
163 |
|
|
gpgme_editkey_release( rev ); |
164 |
|
|
gpgme_release( c ); |
165 |
|
|
free_if_alloc( p ); |
166 |
|
|
EndDialog( dlg, TRUE ); |
167 |
|
|
return TRUE; |
168 |
|
|
|
169 |
|
|
case IDCANCEL: |
170 |
|
|
EndDialog( dlg, FALSE ); |
171 |
|
|
return FALSE; |
172 |
|
|
} |
173 |
|
|
break; |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
return FALSE; |
177 |
|
|
} /* key_revoke_dlg_proc */ |