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

Annotation of /trunk/Src/wptKeyRevokeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File size: 5817 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


1 twoaday 2 /* wptKeyRevokeDlg.cpp - Key revocation dialog
2 twoaday 22 * Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz
3 twoaday 2 *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * WinPT is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with WinPT; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
20     #include <windows.h>
21    
22     #include "../resource.h"
23     #include "wptErrors.h"
24     #include "wptGPG.h"
25     #include "wptW32API.h"
26     #include "wptTypes.h"
27     #include "wptCommonCtl.h"
28     #include "wptContext.h" /* for passphrase_s */
29     #include "wptDlgs.h"
30     #include "wptNLS.h"
31     #include "wptUTF8.h"
32    
33    
34 twoaday 23 static const char*
35     mk_cert_fname (const char *keyid)
36 twoaday 2 {
37     static char fname[128];
38    
39 twoaday 23 if (strlen (keyid) > 32)
40 twoaday 2 return NULL;
41 twoaday 23 _snprintf (fname, sizeof fname-1, "%s-revcert.asc", keyid);
42 twoaday 2 return fname;
43 twoaday 23 }
44 twoaday 2
45    
46     BOOL CALLBACK
47 twoaday 22 key_revoke_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
48 twoaday 2 {
49     static winpt_key_t k;
50     HWND list;
51 twoaday 23 int idx, use_desc, chk = 0;
52     char desc[256], file[256], *p = NULL;
53 twoaday 2 char pwd[256];
54     gpgme_editkey_t rev;
55     gpgme_data_t rev_cert;
56     gpgme_ctx_t c;
57     gpgme_error_t err;
58    
59     switch( msg ) {
60     case WM_INITDIALOG:
61     if( !lparam )
62     dlg_fatal_error(dlg, "Could not get dialog param!");
63     k = (winpt_key_t )lparam;
64 twoaday 23 #ifndef LANG_DE
65 twoaday 2 SetWindowText( dlg, _("Key Revocation") );
66 twoaday 23 #endif
67     SetDlgItemText (dlg, IDC_KEYREVOKE_HINT,
68     _("Please move this certificate to a medium where it can be "
69     "stored in a safe place (floppy, CDR, etc..). "
70     "If an attacker gets access to this certificate he can use it to "
71     "render your key unusable!"));
72 twoaday 2 list = GetDlgItem( dlg, IDC_KEYREVOKE_REASON );
73 twoaday 23 listbox_add_string (list, _("0. No reason specified"));
74     listbox_add_string (list, _("1. Key has been compromised"));
75     listbox_add_string (list, _("2. Key is superseded"));
76     listbox_add_string (list, _("3. Key is no longer used"));
77 twoaday 2 SetForegroundWindow (dlg);
78 twoaday 23 center_window (dlg, NULL);
79 twoaday 2 return TRUE;
80    
81     case WM_SYSCOMMAND:
82     if( LOWORD( wparam ) == SC_CLOSE ) {
83     SetDlgItemText( dlg, IDC_KEYREVOKE_PWD, "" );
84     EndDialog( dlg, TRUE );
85     }
86     return FALSE;
87    
88     case WM_COMMAND:
89     switch( LOWORD( wparam ) ) {
90     case IDC_KEYREVOKE_CHOOSE:
91 twoaday 23 const char *s;
92     _snprintf (file, sizeof file-1, "%s-revcert.asc", keyid);
93     name = mk_cert_fname (k->keyid);
94     s = get_filename_dlg (dlg, FILE_SAVE, _("Choose File to save the Certificate"), NULL, file);
95     if (s && *s)
96     SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s);
97 twoaday 2 return TRUE;
98    
99     case IDOK:
100 twoaday 23 list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON);
101     idx = SendMessage (list, LB_GETCURSEL, NULL, NULL);
102     if (idx < 0 || idx > 3) {
103     msg_box (dlg, _("Please select a reason."), _("Key Revocation"), MB_ERR);
104 twoaday 2 return FALSE;
105     }
106 twoaday 23 if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof file-1)) {
107     msg_box (dlg, _("Please enter a filename."), _("Key Revocation"), MB_ERR);
108 twoaday 2 return FALSE;
109     }
110     use_desc = 1;
111     if( !GetDlgItemText( dlg, IDC_KEYREVOKE_TEXT, desc, sizeof desc-1 ) )
112     use_desc = 0;
113     if( !GetDlgItemText( dlg, IDC_KEYREVOKE_PWD, pwd, sizeof pwd-1 ) ) {
114     msg_box( dlg, _("Please enter the passphrase."), _("Key Revocation"), MB_ERR );
115     return FALSE;
116     }
117     err = gpgme_editkey_new( &rev );
118     if( err )
119     BUG( dlg );
120    
121     if( use_desc )
122     p = wincp_to_utf8 (desc, strlen (desc));
123     /* we use the keyid to avoid charset problems and UTF8 encodings.*/
124 twoaday 23 gpgme_revoke_set( rev, k->keyid, use_desc? p : NULL, idx, 1, pwd );
125 twoaday 2 err = gpgme_data_new( &rev_cert );
126     if( !err )
127     err = gpgme_new( &c );
128     if( err )
129     BUG( dlg );
130    
131     err = gpgme_op_revoke( c, rev, rev_cert );
132     memset( &pwd, 0, sizeof pwd );
133     if( err ) {
134     msg_box( dlg, gpgme_strerror( err ), _("Key Revocation"), MB_ERR );
135     gpgme_data_release( rev_cert );
136     gpgme_editkey_release( rev );
137     gpgme_release( c );
138     free_if_alloc( p );
139     return FALSE;
140     }
141    
142     msg_box( dlg, _("Revocation certificate generated."), _("GnuPG Status"), MB_OK );
143     chk = file_exist_check( file );
144     if( !chk )
145     log_box( _("Key Revocation"), MB_YESNO|MB_INFO,
146     _("\"%s\" already exists.\nOverwrite the file?"), file );
147     if( idx == IDYES || chk )
148 twoaday 23 gpg_data_release_and_set_file( rev_cert, file );
149 twoaday 2 else
150     gpgme_data_release( rev_cert );
151     gpgme_editkey_release( rev );
152     gpgme_release( c );
153     free_if_alloc( p );
154     EndDialog( dlg, TRUE );
155     return TRUE;
156    
157     case IDCANCEL:
158     EndDialog( dlg, FALSE );
159     return FALSE;
160     }
161     break;
162     }
163    
164     return FALSE;
165     } /* key_revoke_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26