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

Annotation of /trunk/Src/wptKeyRevokeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 225 - (hide annotations)
Tue Jun 6 13:37:59 2006 UTC (18 years, 8 months ago) by twoaday
File size: 6342 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    
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 twoaday 205 winpt_key_s k;
46 werner 36 size_t i;
47    
48 twoaday 205 memset (&k, 0, sizeof (k));
49     if (winpt_get_pubkey (keyid, &k))
50 twoaday 129 BUG (NULL);
51 twoaday 205 _snprintf (fname, flen-1, "%s_RevocationCert.asc", k.ext->uids->name);
52 twoaday 129 for (i=0; i < strlen (fname); i++) {
53 werner 36 if (fname[i] == ' ')
54     fname[i] = '_';
55 twoaday 129 }
56 werner 36 }
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 twoaday 129 msg_box (NULL, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR);
71 twoaday 200 safe_free (revcert);
72 werner 36 }
73    
74    
75 twoaday 200 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 twoaday 208 /* 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 twoaday 200
104 twoaday 208 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    
123 werner 36 /* Dialog box procedure for key revocation. */
124     BOOL CALLBACK
125     key_revoke_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
126     {
127     static winpt_key_t k;
128     gpgme_error_t err;
129 twoaday 129 HWND list;
130 twoaday 65 int idx, use_desc;
131 twoaday 204 char file[256];
132 werner 36 char pwd[256];
133 twoaday 204 char *desc=NULL;
134 werner 36 char *inp_data = NULL, *revcert=NULL;
135 twoaday 129 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 werner 36
141     switch( msg ) {
142     case WM_INITDIALOG:
143 twoaday 200 if (!lparam)
144 twoaday 225 BUG (0);
145 twoaday 208 k = (winpt_key_t)lparam;
146 twoaday 200 on_init_dialog (dlg);
147 werner 36 return TRUE;
148    
149     case WM_COMMAND:
150 twoaday 129 switch (LOWORD (wparam)) {
151 werner 36 case IDC_KEYREVOKE_CHOOSE:
152     const char *s;
153     mk_cert_fname (k->keyid, file, sizeof file-1);
154 twoaday 77 s = get_filesave_dlg (dlg, _("Choose File to save the Certificate"), NULL, file);
155 werner 36 if (s && *s)
156     SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s);
157     return TRUE;
158    
159     case IDOK:
160     list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON);
161 twoaday 65 idx = SendMessage (list, LB_GETCURSEL, 0, 0);
162 werner 36 if (idx < 0 || idx > 3) {
163 twoaday 225 msg_box (dlg, _("Please select a reason."),
164 twoaday 129 _("Key Revocation Cert"), MB_ERR);
165 werner 36 return TRUE;
166     }
167     if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) {
168 twoaday 225 msg_box (dlg, _("Please enter a file name."),
169 twoaday 129 _("Key Revocation Cert"), MB_ERR);
170 werner 36 return TRUE;
171     }
172     use_desc = 1;
173 twoaday 204 if (!GetDlgItemText_utf8 (dlg, IDC_KEYREVOKE_TEXT, &desc))
174 werner 36 use_desc = 0;
175 twoaday 200 if (!GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) {
176 twoaday 129 msg_box (dlg, _("Please enter the passphrase."),
177     _("Key Revocation Cert"), MB_ERR);
178 werner 36 return TRUE;
179     }
180    
181 twoaday 204 inp_data = generate_revoke_input (idx, desc, pwd);
182 twoaday 208 err = gpg_revoke_cert (k->internal, inp_data, k->keyid, &revcert);
183 twoaday 225 sfree_if_alloc (inp_data);
184     sfree_if_alloc (desc);
185 werner 36 if (err) {
186 twoaday 129 msg_box (dlg, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR);
187 twoaday 200 safe_free (revcert);
188 twoaday 225 return TRUE;
189 werner 36 }
190     else {
191 twoaday 129 show_msg (dlg, 1000, _("Revocation certificate generated."));
192     msg_box (dlg, warning, _("Key Revocation Cert"), MB_INFO);
193 werner 36 release_cert_as_file (revcert, file);
194 twoaday 225 EndDialog (dlg, TRUE);
195 werner 36 }
196     return TRUE;
197    
198     case IDCANCEL:
199     EndDialog (dlg, FALSE);
200     return FALSE;
201     }
202     break;
203     }
204    
205     return FALSE;
206     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26