23 |
#endif |
#endif |
24 |
|
|
25 |
#include <windows.h> |
#include <windows.h> |
|
#include <windows.h> |
|
26 |
|
|
27 |
#include "resource.h" |
#include "resource.h" |
28 |
#include "gpgme.h" |
#include "gpgme.h" |
44 |
{ |
{ |
45 |
gpgme_key_t k; |
gpgme_key_t k; |
46 |
size_t i; |
size_t i; |
47 |
|
char *uid; |
48 |
|
|
49 |
get_pubkey (keyid, &k); |
if (get_pubkey (keyid, &k)) |
50 |
_snprintf (fname, flen-1, "%s-RevocationCert.asc", k->uids->name); |
BUG (NULL); |
51 |
for (i=0; i < strlen (fname); i++) |
uid = utf8_to_native (k->uids->name); |
52 |
|
_snprintf (fname, flen-1, "%s_RevocationCert.asc", uid); |
53 |
|
for (i=0; i < strlen (fname); i++) { |
54 |
if (fname[i] == ' ') |
if (fname[i] == ' ') |
55 |
fname[i] = '_'; |
fname[i] = '_'; |
56 |
|
} |
57 |
|
safe_free (uid); |
58 |
} |
} |
59 |
|
|
60 |
|
|
69 |
if (!err) |
if (!err) |
70 |
gpg_data_release_and_set_file (rev, fname); |
gpg_data_release_and_set_file (rev, fname); |
71 |
else |
else |
72 |
msg_box (NULL, gpgme_strerror (err), _("Key Revocation"), MB_ERR); |
msg_box (NULL, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR); |
73 |
free (revcert); |
free (revcert); |
74 |
} |
} |
75 |
|
|
80 |
{ |
{ |
81 |
static winpt_key_t k; |
static winpt_key_t k; |
82 |
gpgme_error_t err; |
gpgme_error_t err; |
83 |
HWND list; |
HWND list; |
84 |
int idx, use_desc, chk = 0; |
int idx, use_desc; |
85 |
char desc[256], file[256], *p = NULL; |
char desc[256], file[256]; |
86 |
char pwd[256]; |
char pwd[256]; |
87 |
|
char *p = NULL; |
88 |
char *inp_data = NULL, *revcert=NULL; |
char *inp_data = NULL, *revcert=NULL; |
89 |
|
const char *warning = |
90 |
|
_("Please move this certificate to a medium where it can be" |
91 |
|
"stored in a safe place (floppy, CDR, etc..).\n" |
92 |
|
"If an attacker gets access to this certificate he can use it to " |
93 |
|
"render your key unusable!"); |
94 |
|
|
95 |
switch( msg ) { |
switch( msg ) { |
96 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
97 |
if( !lparam ) |
if( !lparam ) |
98 |
dlg_fatal_error(dlg, "Could not get dialog param!"); |
dlg_fatal_error(dlg, "Could not get dialog param!"); |
99 |
k = (winpt_key_t )lparam; |
k = (winpt_key_t )lparam; |
100 |
#ifndef LANG_DE |
SetWindowText (dlg, _("Key Revocation Cert")); |
101 |
SetWindowText (dlg, _("Key Revocation")); |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
102 |
#endif |
SetDlgItemText (dlg, IDC_KEYREVOKE_REASONINF, _("Reason for revocation")); |
103 |
SetDlgItemText (dlg, IDC_KEYREVOKE_HINT, |
SetDlgItemText (dlg, IDC_KEYREVOKE_OPTINF, _("Optional description text")); |
104 |
_("Please move this certificate to a medium where it can be " |
SetDlgItemText (dlg, IDC_KEYREVOKE_PWDINF, _("&Passphrase")); |
105 |
"stored in a safe place (floppy, CDR, etc..). " |
SetDlgItemText (dlg, IDC_KEYREVOKE_OUTINF, _("Output file")); |
106 |
"If an attacker gets access to this certificate he can use it to " |
list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON); |
|
"render your key unusable!")); |
|
|
list = GetDlgItem( dlg, IDC_KEYREVOKE_REASON ); |
|
107 |
listbox_add_string (list, _("0. No reason specified")); |
listbox_add_string (list, _("0. No reason specified")); |
108 |
listbox_add_string (list, _("1. Key has been compromised")); |
listbox_add_string (list, _("1. Key has been compromised")); |
109 |
listbox_add_string (list, _("2. Key is superseded")); |
listbox_add_string (list, _("2. Key is superseded")); |
110 |
listbox_add_string (list, _("3. Key is no longer used")); |
listbox_add_string (list, _("3. Key is no longer used")); |
111 |
|
SendMessage (list, LB_SETCURSEL, (WPARAM)0, 0); |
112 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
113 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
114 |
return TRUE; |
return TRUE; |
115 |
|
|
116 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
117 |
if( LOWORD( wparam ) == SC_CLOSE ) { |
if (LOWORD (wparam) == SC_CLOSE) { |
118 |
SetDlgItemText( dlg, IDC_KEYREVOKE_PWD, "" ); |
SetDlgItemText (dlg, IDC_KEYREVOKE_PWD, ""); |
119 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
120 |
} |
} |
121 |
return FALSE; |
return FALSE; |
122 |
|
|
123 |
case WM_COMMAND: |
case WM_COMMAND: |
124 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
125 |
case IDC_KEYREVOKE_CHOOSE: |
case IDC_KEYREVOKE_CHOOSE: |
126 |
const char *s; |
const char *s; |
127 |
mk_cert_fname (k->keyid, file, sizeof file-1); |
mk_cert_fname (k->keyid, file, sizeof file-1); |
128 |
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); |
129 |
if (s && *s) |
if (s && *s) |
130 |
SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s); |
SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s); |
131 |
return TRUE; |
return TRUE; |
132 |
|
|
133 |
case IDOK: |
case IDOK: |
134 |
list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON); |
list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON); |
135 |
idx = SendMessage (list, LB_GETCURSEL, NULL, NULL); |
idx = SendMessage (list, LB_GETCURSEL, 0, 0); |
136 |
if (idx < 0 || idx > 3) { |
if (idx < 0 || idx > 3) { |
137 |
msg_box (dlg, _("Please select a reason."), |
msg_box (dlg, _("Please select a reason."), |
138 |
_("Key Revocation"), MB_ERR); |
_("Key Revocation Cert"), MB_ERR); |
139 |
return TRUE; |
return TRUE; |
140 |
} |
} |
141 |
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) { |
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) { |
142 |
msg_box (dlg, _("Please enter a file name."), |
msg_box (dlg, _("Please enter a file name."), |
143 |
_("Key Revocation"), MB_ERR); |
_("Key Revocation Cert"), MB_ERR); |
144 |
return TRUE; |
return TRUE; |
145 |
} |
} |
146 |
use_desc = 1; |
use_desc = 1; |
147 |
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_TEXT, desc, sizeof (desc)-1)) |
if (!GetDlgItemText (dlg, IDC_KEYREVOKE_TEXT, desc, sizeof (desc)-1)) |
148 |
use_desc = 0; |
use_desc = 0; |
149 |
if( !GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) { |
if( !GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) { |
150 |
msg_box (dlg, _("Please enter the passphrase."), _("Key Revocation"), MB_ERR); |
msg_box (dlg, _("Please enter the passphrase."), |
151 |
|
_("Key Revocation Cert"), MB_ERR); |
152 |
return TRUE; |
return TRUE; |
153 |
} |
} |
154 |
|
|
155 |
if (use_desc) |
if (use_desc) |
156 |
p = wincp_to_utf8 (desc, strlen (desc)); |
p = native_to_utf8 (desc); |
157 |
/* we use the keyid to avoid charset problems and UTF8 encodings.*/ |
/* we use the keyid to avoid charset problems and UTF8 encodings.*/ |
158 |
inp_data = generate_revoc_input (idx, use_desc? p : NULL, pwd); |
inp_data = generate_revoke_input (idx, use_desc? p : NULL, pwd); |
159 |
|
|
160 |
err = gpg_revoke_key (inp_data, k->keyid, &revcert); |
err = gpg_revoke_cert (inp_data, k->keyid, &revcert); |
161 |
wipememory (&pwd, sizeof (pwd)); |
wipememory (pwd, sizeof (pwd)); |
162 |
memset (inp_data, 0, strlen (inp_data)); |
wipememory (inp_data, strlen (inp_data)); |
163 |
free (inp_data); |
free (inp_data); |
164 |
free_if_alloc (p); |
free_if_alloc (p); |
165 |
|
|
166 |
if (err) { |
if (err) { |
167 |
msg_box (dlg, gpgme_strerror (err), _("Key Revocation"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR); |
168 |
if (revcert) |
if (revcert) |
169 |
free (revcert); |
free (revcert); |
170 |
} |
} |
171 |
else { |
else { |
172 |
msg_box (dlg, _("Revocation certificate generated."), _("GnuPG Status"), MB_OK); |
show_msg (dlg, 1000, _("Revocation certificate generated.")); |
173 |
|
msg_box (dlg, warning, _("Key Revocation Cert"), MB_INFO); |
174 |
release_cert_as_file (revcert, file); |
release_cert_as_file (revcert, file); |
175 |
} |
} |
176 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |