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

Annotation of /trunk/Src/wptKeyRevokeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 36 - (hide annotations)
Thu Oct 27 15:25:13 2005 UTC (19 years, 4 months ago) by werner
File size: 5691 byte(s)
First set of changes to use autotools for building.
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     #include <windows.h>
27    
28     #include "../resource.h"
29     #include "gpgme.h"
30     #include "wptErrors.h"
31     #include "wptGPG.h"
32     #include "wptW32API.h"
33     #include "wptTypes.h"
34     #include "wptCommonCtl.h"
35     #include "wptContext.h" /* for passphrase_s */
36     #include "wptDlgs.h"
37     #include "wptNLS.h"
38     #include "wptUTF8.h"
39    
40    
41     /* Generate a file template for the cert based on the key
42     with the keyid @keyid. */
43     static void
44     mk_cert_fname (const char *keyid, char *fname, size_t flen)
45     {
46     gpgme_key_t k;
47     size_t i;
48    
49     get_pubkey (keyid, &k);
50     _snprintf (fname, flen-1, "%s-RevocationCert.asc", k->uids->name);
51     for (i=0; i < strlen (fname); i++)
52     if (fname[i] == ' ')
53     fname[i] = '_';
54     }
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     gpg_data_release_and_set_file (rev, fname);
67     else
68     msg_box (NULL, gpgme_strerror (err), _("Key Revocation"), MB_ERR);
69     free (revcert);
70     }
71    
72    
73     /* Dialog box procedure for key revocation. */
74     BOOL CALLBACK
75     key_revoke_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
76     {
77     static winpt_key_t k;
78     gpgme_error_t err;
79     HWND list;
80     int idx, use_desc, chk = 0;
81     char desc[256], file[256], *p = NULL;
82     char pwd[256];
83     char *inp_data = NULL, *revcert=NULL;
84    
85     switch( msg ) {
86     case WM_INITDIALOG:
87     if( !lparam )
88     dlg_fatal_error(dlg, "Could not get dialog param!");
89     k = (winpt_key_t )lparam;
90     #ifndef LANG_DE
91     SetWindowText (dlg, _("Key Revocation"));
92     #endif
93     SetDlgItemText (dlg, IDC_KEYREVOKE_HINT,
94     _("Please move this certificate to a medium where it can be "
95     "stored in a safe place (floppy, CDR, etc..). "
96     "If an attacker gets access to this certificate he can use it to "
97     "render your key unusable!"));
98     list = GetDlgItem( dlg, IDC_KEYREVOKE_REASON );
99     listbox_add_string (list, _("0. No reason specified"));
100     listbox_add_string (list, _("1. Key has been compromised"));
101     listbox_add_string (list, _("2. Key is superseded"));
102     listbox_add_string (list, _("3. Key is no longer used"));
103     SetForegroundWindow (dlg);
104     center_window (dlg, NULL);
105     return TRUE;
106    
107     case WM_SYSCOMMAND:
108     if( LOWORD( wparam ) == SC_CLOSE ) {
109     SetDlgItemText( dlg, IDC_KEYREVOKE_PWD, "" );
110     EndDialog( dlg, TRUE );
111     }
112     return FALSE;
113    
114     case WM_COMMAND:
115     switch( LOWORD( wparam ) ) {
116     case IDC_KEYREVOKE_CHOOSE:
117     const char *s;
118     mk_cert_fname (k->keyid, file, sizeof file-1);
119     s = get_filename_dlg (dlg, FILE_SAVE, _("Choose File to save the Certificate"), NULL, file);
120     if (s && *s)
121     SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s);
122     return TRUE;
123    
124     case IDOK:
125     list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON);
126     idx = SendMessage (list, LB_GETCURSEL, NULL, NULL);
127     if (idx < 0 || idx > 3) {
128     msg_box (dlg, _("Please select a reason."),
129     _("Key Revocation"), MB_ERR);
130     return TRUE;
131     }
132     if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) {
133     msg_box (dlg, _("Please enter a file name."),
134     _("Key Revocation"), MB_ERR);
135     return TRUE;
136     }
137     use_desc = 1;
138     if (!GetDlgItemText (dlg, IDC_KEYREVOKE_TEXT, desc, sizeof (desc)-1))
139     use_desc = 0;
140     if( !GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) {
141     msg_box (dlg, _("Please enter the passphrase."), _("Key Revocation"), MB_ERR);
142     return TRUE;
143     }
144    
145     if (use_desc)
146     p = wincp_to_utf8 (desc, strlen (desc));
147     /* we use the keyid to avoid charset problems and UTF8 encodings.*/
148     inp_data = generate_revoc_input (idx, use_desc? p : NULL, pwd);
149    
150     err = gpg_revoke_key (inp_data, k->keyid, &revcert);
151     wipememory (&pwd, sizeof (pwd));
152     memset (inp_data, 0, strlen (inp_data));
153     free (inp_data);
154     free_if_alloc (p);
155    
156     if (err) {
157     msg_box (dlg, gpgme_strerror (err), _("Key Revocation"), MB_ERR);
158     if (revcert)
159     free (revcert);
160     }
161     else {
162     msg_box (dlg, _("Revocation certificate generated."), _("GnuPG Status"), MB_OK);
163     release_cert_as_file (revcert, file);
164     }
165     EndDialog (dlg, TRUE);
166     return TRUE;
167    
168     case IDCANCEL:
169     EndDialog (dlg, FALSE);
170     return FALSE;
171     }
172     break;
173     }
174    
175     return FALSE;
176     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26