/[winpt]/trunk/Src/wptKeyRevokeDlg.cpp
ViewVC logotype

Contents of /trunk/Src/wptKeyRevokeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 205 - (show annotations)
Thu Apr 27 12:46:03 2006 UTC (18 years, 10 months ago) by twoaday
File size: 5874 byte(s)
2006-04-27  Timo Schulz  <ts@g10code.de>
                                                                                
        * wptKeyManager.cpp (km_get_key_ptr): New.
        * wptListview.cpp (listview_get_item_text): Drop utf8 support.
        * wptKeyCache.cpp (keycache_decode_uids): New.
        (free_native_uids): New.
        * wptKeyEdit.cpp (uid_inf_colon_handler): Do utf8 decodig here.
                                                                                
2006-04-26  Timo Schulz  <ts@g10code.de>
                                                                                
        * wptKeylist.cpp (get_keyid_from_fpr): New.
        * wptDecryptClipDlg.cpp (clip_decrypt_dlg): Use it here.
        * wptVerifyList.cpp (verlist_add_sig): Likewise.


1 /* wptKeyRevokeDlg.cpp - Key revocation dialog
2 * Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz
3 * Copyright (C) 2005 g10 Code GmbH
4 *
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 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <windows.h>
26
27 #include "resource.h"
28 #include "gpgme.h"
29 #include "wptErrors.h"
30 #include "wptGPG.h"
31 #include "wptW32API.h"
32 #include "wptTypes.h"
33 #include "wptCommonCtl.h"
34 #include "wptContext.h" /* for passphrase_s */
35 #include "wptDlgs.h"
36 #include "wptNLS.h"
37 #include "wptUTF8.h"
38
39
40 /* Generate a file template for the cert based on the key
41 with the keyid @keyid. */
42 static void
43 mk_cert_fname (const char *keyid, char *fname, size_t flen)
44 {
45 winpt_key_s k;
46 size_t i;
47
48 memset (&k, 0, sizeof (k));
49 if (winpt_get_pubkey (keyid, &k))
50 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] == ' ')
54 fname[i] = '_';
55 }
56 }
57
58
59 /* Release the cert data and store it in the file @fname. */
60 static void
61 release_cert_as_file (char *revcert, const char *fname)
62 {
63 gpgme_error_t err;
64 gpgme_data_t rev;
65
66 err = gpgme_data_new_from_mem (&rev, revcert, strlen (revcert), 1);
67 if (!err)
68 gpg_data_release_and_set_file (rev, fname);
69 else
70 msg_box (NULL, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR);
71 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
97 /* Dialog box procedure for key revocation. */
98 BOOL CALLBACK
99 key_revoke_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
100 {
101 static winpt_key_t k;
102 gpgme_error_t err;
103 HWND list;
104 int idx, use_desc;
105 char file[256];
106 char pwd[256];
107 char *desc=NULL;
108 char *inp_data = NULL, *revcert=NULL;
109 const char *warning =
110 _("Please move this certificate to a medium where it can be"
111 "stored in a safe place (floppy, CDR, etc..).\n"
112 "If an attacker gets access to this certificate he can use it to "
113 "render your key unusable!");
114
115 switch( msg ) {
116 case WM_INITDIALOG:
117 if (!lparam)
118 dlg_fatal_error (dlg, "Could not get dialog param!");
119 k = (winpt_key_t )lparam;
120 on_init_dialog (dlg);
121 return TRUE;
122
123 case WM_SYSCOMMAND:
124 if (LOWORD (wparam) == SC_CLOSE)
125 EndDialog (dlg, FALSE);
126 return FALSE;
127
128 case WM_COMMAND:
129 switch (LOWORD (wparam)) {
130 case IDC_KEYREVOKE_CHOOSE:
131 const char *s;
132 mk_cert_fname (k->keyid, file, sizeof file-1);
133 s = get_filesave_dlg (dlg, _("Choose File to save the Certificate"), NULL, file);
134 if (s && *s)
135 SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s);
136 return TRUE;
137
138 case IDOK:
139 list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON);
140 idx = SendMessage (list, LB_GETCURSEL, 0, 0);
141 if (idx < 0 || idx > 3) {
142 msg_box (dlg, _("Please select a reason."),
143 _("Key Revocation Cert"), MB_ERR);
144 return TRUE;
145 }
146 if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) {
147 msg_box (dlg, _("Please enter a file name."),
148 _("Key Revocation Cert"), MB_ERR);
149 return TRUE;
150 }
151 use_desc = 1;
152 if (!GetDlgItemText_utf8 (dlg, IDC_KEYREVOKE_TEXT, &desc))
153 use_desc = 0;
154 if (!GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) {
155 msg_box (dlg, _("Please enter the passphrase."),
156 _("Key Revocation Cert"), MB_ERR);
157 return TRUE;
158 }
159
160 inp_data = generate_revoke_input (idx, desc, pwd);
161 err = gpg_revoke_cert (inp_data, k->keyid, &revcert);
162 wipememory (pwd, sizeof (pwd));
163 wipememory (inp_data, strlen (inp_data));
164 if (err) {
165 msg_box (dlg, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR);
166 safe_free (revcert);
167 }
168 else {
169 show_msg (dlg, 1000, _("Revocation certificate generated."));
170 msg_box (dlg, warning, _("Key Revocation Cert"), MB_INFO);
171 release_cert_as_file (revcert, file);
172 }
173 safe_free (inp_data);
174 free_if_alloc (desc);
175 EndDialog (dlg, TRUE);
176 return TRUE;
177
178 case IDCANCEL:
179 EndDialog (dlg, FALSE);
180 return FALSE;
181 }
182 break;
183 }
184
185 return FALSE;
186 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26