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

Annotation of /trunk/Src/wptKeyRevokeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 105 - (hide annotations)
Wed Nov 30 10:22:00 2005 UTC (19 years, 3 months ago) by twoaday
File size: 5936 byte(s)
Several cleanups and improved translation.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26