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