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

Annotation of /trunk/Src/wptKeyRevokeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 205 - (hide annotations)
Thu Apr 27 12:46:03 2006 UTC (18 years, 10 months ago) by twoaday
File size: 5874 byte(s)
2006-04-27  Timo Schulz  <ts@g10code.de>
                                                                                
        * wptKeyManager.cpp (km_get_key_ptr): New.
        * wptListview.cpp (listview_get_item_text): Drop utf8 support.
        * wptKeyCache.cpp (keycache_decode_uids): New.
        (free_native_uids): New.
        * wptKeyEdit.cpp (uid_inf_colon_handler): Do utf8 decodig here.
                                                                                
2006-04-26  Timo Schulz  <ts@g10code.de>
                                                                                
        * wptKeylist.cpp (get_keyid_from_fpr): New.
        * wptDecryptClipDlg.cpp (clip_decrypt_dlg): Use it here.
        * wptVerifyList.cpp (verlist_add_sig): Likewise.


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 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    
97 werner 36 /* Dialog box procedure for key revocation. */
98     BOOL CALLBACK
99     key_revoke_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
100     {
101     static winpt_key_t k;
102     gpgme_error_t err;
103 twoaday 129 HWND list;
104 twoaday 65 int idx, use_desc;
105 twoaday 204 char file[256];
106 werner 36 char pwd[256];
107 twoaday 204 char *desc=NULL;
108 werner 36 char *inp_data = NULL, *revcert=NULL;
109 twoaday 129 const char *warning =
110     _("Please move this certificate to a medium where it can be"
111     "stored in a safe place (floppy, CDR, etc..).\n"
112     "If an attacker gets access to this certificate he can use it to "
113     "render your key unusable!");
114 werner 36
115     switch( msg ) {
116     case WM_INITDIALOG:
117 twoaday 200 if (!lparam)
118     dlg_fatal_error (dlg, "Could not get dialog param!");
119 werner 36 k = (winpt_key_t )lparam;
120 twoaday 200 on_init_dialog (dlg);
121 werner 36 return TRUE;
122    
123     case WM_SYSCOMMAND:
124 twoaday 200 if (LOWORD (wparam) == SC_CLOSE)
125     EndDialog (dlg, FALSE);
126 werner 36 return FALSE;
127    
128     case WM_COMMAND:
129 twoaday 129 switch (LOWORD (wparam)) {
130 werner 36 case IDC_KEYREVOKE_CHOOSE:
131     const char *s;
132     mk_cert_fname (k->keyid, file, sizeof file-1);
133 twoaday 77 s = get_filesave_dlg (dlg, _("Choose File to save the Certificate"), NULL, file);
134 werner 36 if (s && *s)
135     SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s);
136     return TRUE;
137    
138     case IDOK:
139     list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON);
140 twoaday 65 idx = SendMessage (list, LB_GETCURSEL, 0, 0);
141 werner 36 if (idx < 0 || idx > 3) {
142     msg_box (dlg, _("Please select a reason."),
143 twoaday 129 _("Key Revocation Cert"), MB_ERR);
144 werner 36 return TRUE;
145     }
146     if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) {
147     msg_box (dlg, _("Please enter a file name."),
148 twoaday 129 _("Key Revocation Cert"), MB_ERR);
149 werner 36 return TRUE;
150     }
151     use_desc = 1;
152 twoaday 204 if (!GetDlgItemText_utf8 (dlg, IDC_KEYREVOKE_TEXT, &desc))
153 werner 36 use_desc = 0;
154 twoaday 200 if (!GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) {
155 twoaday 129 msg_box (dlg, _("Please enter the passphrase."),
156     _("Key Revocation Cert"), MB_ERR);
157 werner 36 return TRUE;
158     }
159    
160 twoaday 204 inp_data = generate_revoke_input (idx, desc, pwd);
161 twoaday 129 err = gpg_revoke_cert (inp_data, k->keyid, &revcert);
162     wipememory (pwd, sizeof (pwd));
163     wipememory (inp_data, strlen (inp_data));
164 werner 36 if (err) {
165 twoaday 129 msg_box (dlg, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR);
166 twoaday 200 safe_free (revcert);
167 werner 36 }
168     else {
169 twoaday 129 show_msg (dlg, 1000, _("Revocation certificate generated."));
170     msg_box (dlg, warning, _("Key Revocation Cert"), MB_INFO);
171 werner 36 release_cert_as_file (revcert, file);
172     }
173 twoaday 200 safe_free (inp_data);
174 twoaday 204 free_if_alloc (desc);
175 werner 36 EndDialog (dlg, TRUE);
176     return TRUE;
177    
178     case IDCANCEL:
179     EndDialog (dlg, FALSE);
180     return FALSE;
181     }
182     break;
183     }
184    
185     return FALSE;
186     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26