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, 2006 Timo Schulz |
3 |
* Copyright (C) 2005 g10 Code GmbH |
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
42 |
static void |
static void |
43 |
mk_cert_fname (const char *keyid, char *fname, size_t flen) |
mk_cert_fname (const char *keyid, char *fname, size_t flen) |
44 |
{ |
{ |
45 |
gpgme_key_t k; |
winpt_key_s k; |
46 |
size_t i; |
size_t i; |
47 |
|
|
48 |
get_pubkey (keyid, &k); |
memset (&k, 0, sizeof (k)); |
49 |
_snprintf (fname, flen-1, "%s-RevocationCert.asc", k->uids->name); |
if (winpt_get_pubkey (keyid, &k)) |
50 |
for (i=0; i < strlen (fname); i++) |
BUG (NULL); |
51 |
|
_snprintf (fname, flen-1, "%s_RevocationCert.asc", k.ext->uids->name); |
52 |
|
for (i=0; i < strlen (fname); i++) { |
53 |
if (fname[i] == ' ') |
if (fname[i] == ' ') |
54 |
fname[i] = '_'; |
fname[i] = '_'; |
55 |
|
} |
56 |
} |
} |
57 |
|
|
58 |
|
|
67 |
if (!err) |
if (!err) |
68 |
gpg_data_release_and_set_file (rev, fname); |
gpg_data_release_and_set_file (rev, fname); |
69 |
else |
else |
70 |
msg_box (NULL, gpgme_strerror (err), _("Key Revocation"), MB_ERR); |
msg_box (NULL, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR); |
71 |
free (revcert); |
safe_free (revcert); |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
|
static void |
76 |
|
on_init_dialog (HWND dlg) |
77 |
|
{ |
78 |
|
HWND list; |
79 |
|
|
80 |
|
SetWindowText (dlg, _("Key Revocation Cert")); |
81 |
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
82 |
|
SetDlgItemText (dlg, IDC_KEYREVOKE_REASONINF, _("Reason for revocation")); |
83 |
|
SetDlgItemText (dlg, IDC_KEYREVOKE_OPTINF, _("Optional description text")); |
84 |
|
SetDlgItemText (dlg, IDC_KEYREVOKE_PWDINF, _("&Passphrase")); |
85 |
|
SetDlgItemText (dlg, IDC_KEYREVOKE_OUTINF, _("Output file")); |
86 |
|
list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON); |
87 |
|
listbox_add_string (list, _("0. No reason specified")); |
88 |
|
listbox_add_string (list, _("1. Key has been compromised")); |
89 |
|
listbox_add_string (list, _("2. Key is superseded")); |
90 |
|
listbox_add_string (list, _("3. Key is no longer used")); |
91 |
|
SendMessage (list, LB_SETCURSEL, (WPARAM)0, 0); |
92 |
|
SetForegroundWindow (dlg); |
93 |
|
center_window (dlg, NULL); |
94 |
|
} |
95 |
|
|
96 |
|
/* Generate the data expected by the gpg command handler. */ |
97 |
|
static char* |
98 |
|
generate_revoke_input (int code, const char *cmt, const char *pass) |
99 |
|
{ |
100 |
|
const char *fmt; |
101 |
|
char *p; |
102 |
|
size_t n; |
103 |
|
|
104 |
|
fmt = "Y\n" /* gen_revoke.okay */ |
105 |
|
"%d\n" /* ask_revocation_reason.code */ |
106 |
|
"%s\n" /* ask_revocation_reason.text */ |
107 |
|
"%s" /* text != NULL '\n' otherwise '' */ |
108 |
|
"Y\n" /* ask_revocation_reason.okay */ |
109 |
|
"%s\n"; /* passphrase.enter. */ |
110 |
|
n = strlen (fmt) + 32; |
111 |
|
if (pass) |
112 |
|
n += strlen (pass) + 1; |
113 |
|
if (cmt) |
114 |
|
n += strlen (cmt) + 1; |
115 |
|
p = new char[n+1]; |
116 |
|
if (!p) |
117 |
|
BUG (0); |
118 |
|
sprintf (p, fmt, code, cmt? cmt : "", cmt? "\n" : "", pass? pass : ""); |
119 |
|
return p; |
120 |
} |
} |
121 |
|
|
122 |
|
|
126 |
{ |
{ |
127 |
static winpt_key_t k; |
static winpt_key_t k; |
128 |
gpgme_error_t err; |
gpgme_error_t err; |
129 |
HWND list; |
HWND list; |
130 |
int idx, use_desc; |
int idx, use_desc; |
131 |
char desc[256], file[256], *p = NULL; |
char file[256]; |
132 |
char pwd[256]; |
char pwd[256]; |
133 |
|
char *desc=NULL; |
134 |
char *inp_data = NULL, *revcert=NULL; |
char *inp_data = NULL, *revcert=NULL; |
135 |
|
const char *warning = |
136 |
|
_("Please move this certificate to a medium where it can be" |
137 |
|
"stored in a safe place (floppy, CDR, etc..).\n" |
138 |
|
"If an attacker gets access to this certificate he can use it to " |
139 |
|
"render your key unusable!"); |
140 |
|
|
141 |
switch( msg ) { |
switch( msg ) { |
142 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
143 |
if( !lparam ) |
if (!lparam) |
144 |
dlg_fatal_error(dlg, "Could not get dialog param!"); |
BUG (0); |
145 |
k = (winpt_key_t )lparam; |
k = (winpt_key_t)lparam; |
146 |
#ifndef LANG_DE |
on_init_dialog (dlg); |
|
SetWindowText (dlg, _("Key Revocation")); |
|
|
#endif |
|
|
SetDlgItemText (dlg, IDC_KEYREVOKE_HINT, |
|
|
_("Please move this certificate to a medium where it can be " |
|
|
"stored in a safe place (floppy, CDR, etc..). " |
|
|
"If an attacker gets access to this certificate he can use it to " |
|
|
"render your key unusable!")); |
|
|
list = GetDlgItem( dlg, IDC_KEYREVOKE_REASON ); |
|
|
listbox_add_string (list, _("0. No reason specified")); |
|
|
listbox_add_string (list, _("1. Key has been compromised")); |
|
|
listbox_add_string (list, _("2. Key is superseded")); |
|
|
listbox_add_string (list, _("3. Key is no longer used")); |
|
|
SetForegroundWindow (dlg); |
|
|
center_window (dlg, NULL); |
|
147 |
return TRUE; |
return TRUE; |
148 |
|
|
|
case WM_SYSCOMMAND: |
|
|
if( LOWORD( wparam ) == SC_CLOSE ) { |
|
|
SetDlgItemText( dlg, IDC_KEYREVOKE_PWD, "" ); |
|
|
EndDialog( dlg, TRUE ); |
|
|
} |
|
|
return FALSE; |
|
|
|
|
149 |
case WM_COMMAND: |
case WM_COMMAND: |
150 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
151 |
case IDC_KEYREVOKE_CHOOSE: |
case IDC_KEYREVOKE_CHOOSE: |
152 |
const char *s; |
const char *s; |
153 |
mk_cert_fname (k->keyid, file, sizeof file-1); |
mk_cert_fname (k->keyid, file, sizeof file-1); |
154 |
s = get_filename_dlg (dlg, FILE_SAVE, _("Choose File to save the Certificate"), NULL, file); |
s = get_filesave_dlg (dlg, _("Choose File to save the Certificate"), NULL, file); |
155 |
if (s && *s) |
if (s && *s) |
156 |
SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s); |
SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s); |
157 |
return TRUE; |
return TRUE; |
160 |
list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON); |
list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON); |
161 |
idx = SendMessage (list, LB_GETCURSEL, 0, 0); |
idx = SendMessage (list, LB_GETCURSEL, 0, 0); |
162 |
if (idx < 0 || idx > 3) { |
if (idx < 0 || idx > 3) { |
163 |
msg_box (dlg, _("Please select a reason."), |
msg_box (dlg, _("Please select a reason."), |
164 |
_("Key Revocation"), MB_ERR); |
_("Key Revocation Cert"), MB_ERR); |
165 |
return TRUE; |
return TRUE; |
166 |
} |
} |
167 |
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) { |
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) { |
168 |
msg_box (dlg, _("Please enter a file name."), |
msg_box (dlg, _("Please enter a file name."), |
169 |
_("Key Revocation"), MB_ERR); |
_("Key Revocation Cert"), MB_ERR); |
170 |
return TRUE; |
return TRUE; |
171 |
} |
} |
172 |
use_desc = 1; |
use_desc = 1; |
173 |
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_TEXT, desc, sizeof (desc)-1)) |
if (!GetDlgItemText_utf8 (dlg, IDC_KEYREVOKE_TEXT, &desc)) |
174 |
use_desc = 0; |
use_desc = 0; |
175 |
if( !GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) { |
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) { |
176 |
msg_box (dlg, _("Please enter the passphrase."), _("Key Revocation"), MB_ERR); |
msg_box (dlg, _("Please enter the passphrase."), |
177 |
|
_("Key Revocation Cert"), MB_ERR); |
178 |
return TRUE; |
return TRUE; |
179 |
} |
} |
180 |
|
|
181 |
if (use_desc) |
inp_data = generate_revoke_input (idx, desc, pwd); |
182 |
p = wincp_to_utf8 (desc, strlen (desc)); |
err = gpg_revoke_cert (k->internal, inp_data, k->keyid, &revcert); |
183 |
/* we use the keyid to avoid charset problems and UTF8 encodings.*/ |
sfree_if_alloc (inp_data); |
184 |
inp_data = generate_revoc_input (idx, use_desc? p : NULL, pwd); |
sfree_if_alloc (desc); |
|
|
|
|
err = gpg_revoke_key (inp_data, k->keyid, &revcert); |
|
|
wipememory (&pwd, sizeof (pwd)); |
|
|
memset (inp_data, 0, strlen (inp_data)); |
|
|
free (inp_data); |
|
|
free_if_alloc (p); |
|
|
|
|
185 |
if (err) { |
if (err) { |
186 |
msg_box (dlg, gpgme_strerror (err), _("Key Revocation"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR); |
187 |
if (revcert) |
safe_free (revcert); |
188 |
free (revcert); |
return TRUE; |
189 |
} |
} |
190 |
else { |
else { |
191 |
msg_box (dlg, _("Revocation certificate generated."), _("GnuPG Status"), MB_OK); |
show_msg (dlg, 1000, _("Revocation certificate generated.")); |
192 |
|
msg_box (dlg, warning, _("Key Revocation Cert"), MB_INFO); |
193 |
release_cert_as_file (revcert, file); |
release_cert_as_file (revcert, file); |
194 |
|
EndDialog (dlg, TRUE); |
195 |
} |
} |
|
EndDialog (dlg, TRUE); |
|
196 |
return TRUE; |
return TRUE; |
197 |
|
|
198 |
case IDCANCEL: |
case IDCANCEL: |