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

Annotation of /trunk/Src/wptKeyRevokeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 77 - (hide annotations)
Mon Nov 14 15:01:01 2005 UTC (19 years, 3 months ago) by twoaday
File size: 5641 byte(s)
2005-11-12  Timo Schulz  <ts@g10code.com>
 
        Fix more GCC warnings.
 
2005-11-10  Timo Schulz  <ts@g10code.com>
 
        * wptClipSignDlg.cpp (one_key_proc): Use
        release_gpg_passphrase_cb() to free the context.
        * wptListView.cpp (listview_deselect_all): New.
        * wptMAPI.cpp (mapi_send_pubkey): Works again.
        * wptFileManagerDlg.cpp (file_manager_dlg_proc): Support encrypt &
        zip.
        * wptPassphraseCB.cpp (passphrase_callback_proc): Fix passphrase
        caching for signing operations.
        * wptKeyManager.cpp (km_send_to_mail_recipient): Works again.
        * wptFileManager.cpp (fm_send_file): Likewise.
        (fm_encrypt_into_zip): New.
         

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     #ifndef LANG_DE
90     SetWindowText (dlg, _("Key Revocation"));
91     #endif
92     SetDlgItemText (dlg, IDC_KEYREVOKE_HINT,
93     _("Please move this certificate to a medium where it can be "
94     "stored in a safe place (floppy, CDR, etc..). "
95     "If an attacker gets access to this certificate he can use it to "
96     "render your key unusable!"));
97     list = GetDlgItem( dlg, IDC_KEYREVOKE_REASON );
98     listbox_add_string (list, _("0. No reason specified"));
99     listbox_add_string (list, _("1. Key has been compromised"));
100     listbox_add_string (list, _("2. Key is superseded"));
101     listbox_add_string (list, _("3. Key is no longer used"));
102     SetForegroundWindow (dlg);
103     center_window (dlg, NULL);
104     return TRUE;
105    
106     case WM_SYSCOMMAND:
107     if( LOWORD( wparam ) == SC_CLOSE ) {
108     SetDlgItemText( dlg, IDC_KEYREVOKE_PWD, "" );
109     EndDialog( dlg, TRUE );
110     }
111     return FALSE;
112    
113     case WM_COMMAND:
114     switch( LOWORD( wparam ) ) {
115     case IDC_KEYREVOKE_CHOOSE:
116     const char *s;
117     mk_cert_fname (k->keyid, file, sizeof file-1);
118 twoaday 77 s = get_filesave_dlg (dlg, _("Choose File to save the Certificate"), NULL, file);
119 werner 36 if (s && *s)
120     SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s);
121     return TRUE;
122    
123     case IDOK:
124     list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON);
125 twoaday 65 idx = SendMessage (list, LB_GETCURSEL, 0, 0);
126 werner 36 if (idx < 0 || idx > 3) {
127     msg_box (dlg, _("Please select a reason."),
128     _("Key Revocation"), MB_ERR);
129     return TRUE;
130     }
131     if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) {
132     msg_box (dlg, _("Please enter a file name."),
133     _("Key Revocation"), MB_ERR);
134     return TRUE;
135     }
136     use_desc = 1;
137     if (!GetDlgItemText (dlg, IDC_KEYREVOKE_TEXT, desc, sizeof (desc)-1))
138     use_desc = 0;
139     if( !GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) {
140     msg_box (dlg, _("Please enter the passphrase."), _("Key Revocation"), MB_ERR);
141     return TRUE;
142     }
143    
144     if (use_desc)
145     p = wincp_to_utf8 (desc, strlen (desc));
146     /* we use the keyid to avoid charset problems and UTF8 encodings.*/
147     inp_data = generate_revoc_input (idx, use_desc? p : NULL, pwd);
148    
149     err = gpg_revoke_key (inp_data, k->keyid, &revcert);
150     wipememory (&pwd, sizeof (pwd));
151     memset (inp_data, 0, strlen (inp_data));
152     free (inp_data);
153     free_if_alloc (p);
154    
155     if (err) {
156     msg_box (dlg, gpgme_strerror (err), _("Key Revocation"), MB_ERR);
157     if (revcert)
158     free (revcert);
159     }
160     else {
161     msg_box (dlg, _("Revocation certificate generated."), _("GnuPG Status"), MB_OK);
162     release_cert_as_file (revcert, file);
163     }
164     EndDialog (dlg, TRUE);
165     return TRUE;
166    
167     case IDCANCEL:
168     EndDialog (dlg, FALSE);
169     return FALSE;
170     }
171     break;
172     }
173    
174     return FALSE;
175     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26