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

Annotation of /trunk/Src/wptKeyRevokeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 247 - (hide annotations)
Fri Jul 21 08:19:24 2006 UTC (18 years, 7 months ago) by twoaday
File size: 6542 byte(s)


1 werner 36 /* wptKeyRevokeDlg.cpp - Key revocation dialog
2 twoaday 225 * Copyright (C) 2001, 2002, 2003, 2005, 2006 Timo Schulz
3 werner 36 * 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 werner 47 #include "resource.h"
28 werner 36 #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 twoaday 247 void secure_filename (char *file, size_t len);
40 werner 36
41 twoaday 247
42 werner 36 /* Generate a file template for the cert based on the key
43     with the keyid @keyid. */
44     static void
45     mk_cert_fname (const char *keyid, char *fname, size_t flen)
46     {
47 twoaday 205 winpt_key_s k;
48 werner 36
49 twoaday 205 memset (&k, 0, sizeof (k));
50     if (winpt_get_pubkey (keyid, &k))
51 twoaday 129 BUG (NULL);
52 twoaday 205 _snprintf (fname, flen-1, "%s_RevocationCert.asc", k.ext->uids->name);
53 twoaday 247 secure_filename (fname, strlen (fname));
54 werner 36 }
55    
56    
57     /* Release the cert data and store it in the file @fname. */
58     static void
59     release_cert_as_file (char *revcert, const char *fname)
60     {
61     gpgme_error_t err;
62     gpgme_data_t rev;
63    
64     err = gpgme_data_new_from_mem (&rev, revcert, strlen (revcert), 1);
65     if (!err)
66 twoaday 247 err = gpg_data_release_and_set_file (rev, fname);
67     if (err)
68 twoaday 129 msg_box (NULL, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR);
69 twoaday 200 safe_free (revcert);
70 werner 36 }
71    
72    
73 twoaday 200 static void
74     on_init_dialog (HWND dlg)
75     {
76     HWND list;
77    
78     SetWindowText (dlg, _("Key Revocation Cert"));
79     SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
80     SetDlgItemText (dlg, IDC_KEYREVOKE_REASONINF, _("Reason for revocation"));
81     SetDlgItemText (dlg, IDC_KEYREVOKE_OPTINF, _("Optional description text"));
82     SetDlgItemText (dlg, IDC_KEYREVOKE_PWDINF, _("&Passphrase"));
83     SetDlgItemText (dlg, IDC_KEYREVOKE_OUTINF, _("Output file"));
84     list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON);
85     listbox_add_string (list, _("0. No reason specified"));
86     listbox_add_string (list, _("1. Key has been compromised"));
87     listbox_add_string (list, _("2. Key is superseded"));
88     listbox_add_string (list, _("3. Key is no longer used"));
89     SendMessage (list, LB_SETCURSEL, (WPARAM)0, 0);
90     SetForegroundWindow (dlg);
91     center_window (dlg, NULL);
92     }
93    
94 twoaday 208 /* Generate the data expected by the gpg command handler. */
95     static char*
96     generate_revoke_input (int code, const char *cmt, const char *pass)
97     {
98     const char *fmt;
99     char *p;
100     size_t n;
101 twoaday 200
102 twoaday 208 fmt = "Y\n" /* gen_revoke.okay */
103     "%d\n" /* ask_revocation_reason.code */
104     "%s\n" /* ask_revocation_reason.text */
105     "%s" /* text != NULL '\n' otherwise '' */
106     "Y\n" /* ask_revocation_reason.okay */
107     "%s\n"; /* passphrase.enter. */
108     n = strlen (fmt) + 32;
109     if (pass)
110     n += strlen (pass) + 1;
111     if (cmt)
112     n += strlen (cmt) + 1;
113     p = new char[n+1];
114     if (!p)
115     BUG (0);
116     sprintf (p, fmt, code, cmt? cmt : "", cmt? "\n" : "", pass? pass : "");
117     return p;
118     }
119    
120    
121 werner 36 /* Dialog box procedure for key revocation. */
122     BOOL CALLBACK
123     key_revoke_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
124     {
125     static winpt_key_t k;
126     gpgme_error_t err;
127 twoaday 129 HWND list;
128 twoaday 65 int idx, use_desc;
129 twoaday 204 char file[256];
130 twoaday 229 char *pwd=NULL;
131 twoaday 204 char *desc=NULL;
132 werner 36 char *inp_data = NULL, *revcert=NULL;
133 twoaday 129 const char *warning =
134     _("Please move this certificate to a medium where it can be"
135     "stored in a safe place (floppy, CDR, etc..).\n"
136     "If an attacker gets access to this certificate he can use it to "
137     "render your key unusable!");
138 werner 36
139     switch( msg ) {
140     case WM_INITDIALOG:
141 twoaday 200 if (!lparam)
142 twoaday 225 BUG (0);
143 twoaday 208 k = (winpt_key_t)lparam;
144 twoaday 200 on_init_dialog (dlg);
145 werner 36 return TRUE;
146    
147     case WM_COMMAND:
148 twoaday 129 switch (LOWORD (wparam)) {
149 werner 36 case IDC_KEYREVOKE_CHOOSE:
150     const char *s;
151     mk_cert_fname (k->keyid, file, sizeof file-1);
152 twoaday 77 s = get_filesave_dlg (dlg, _("Choose File to save the Certificate"), NULL, file);
153 werner 36 if (s && *s)
154     SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s);
155     return TRUE;
156    
157     case IDOK:
158     list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON);
159 twoaday 65 idx = SendMessage (list, LB_GETCURSEL, 0, 0);
160 werner 36 if (idx < 0 || idx > 3) {
161 twoaday 225 msg_box (dlg, _("Please select a reason."),
162 twoaday 129 _("Key Revocation Cert"), MB_ERR);
163 werner 36 return TRUE;
164     }
165     if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) {
166 twoaday 225 msg_box (dlg, _("Please enter a file name."),
167 twoaday 129 _("Key Revocation Cert"), MB_ERR);
168 werner 36 return TRUE;
169     }
170 twoaday 247 if (check_file_name (file, IS_PATH)) {
171     msg_box (dlg, _("The file name contains one or more illegal characters."),
172     _("Key Revocation Cert"), MB_ERR);
173     return TRUE;
174     }
175    
176 werner 36 use_desc = 1;
177 twoaday 204 if (!GetDlgItemText_utf8 (dlg, IDC_KEYREVOKE_TEXT, &desc))
178 werner 36 use_desc = 0;
179 twoaday 229 if (!GetDlgItemText_utf8 (dlg, IDC_KEYREVOKE_PWD, &pwd)) {
180 twoaday 129 msg_box (dlg, _("Please enter the passphrase."),
181     _("Key Revocation Cert"), MB_ERR);
182 werner 36 return TRUE;
183     }
184    
185 twoaday 204 inp_data = generate_revoke_input (idx, desc, pwd);
186 twoaday 208 err = gpg_revoke_cert (k->internal, inp_data, k->keyid, &revcert);
187 twoaday 225 sfree_if_alloc (inp_data);
188     sfree_if_alloc (desc);
189 twoaday 229 sfree_if_alloc (pwd);
190 werner 36 if (err) {
191 twoaday 129 msg_box (dlg, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR);
192 twoaday 200 safe_free (revcert);
193 twoaday 225 return TRUE;
194 werner 36 }
195     else {
196 twoaday 129 show_msg (dlg, 1000, _("Revocation certificate generated."));
197     msg_box (dlg, warning, _("Key Revocation Cert"), MB_INFO);
198 werner 36 release_cert_as_file (revcert, file);
199 twoaday 225 EndDialog (dlg, TRUE);
200 werner 36 }
201     return TRUE;
202    
203     case IDCANCEL:
204     EndDialog (dlg, FALSE);
205     return FALSE;
206     }
207     break;
208     }
209    
210     return FALSE;
211     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26