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

Annotation of /trunk/Src/wptKeyRevokeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File size: 6166 byte(s)
WinPT initial checkin.


1 twoaday 2 /* wptKeyRevokeDlg.cpp - Key revocation dialog
2     * Copyright (C) 2001, 2002, 2003 Timo Schulz
3     *
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    
21     #include <windows.h>
22    
23     #include "../resource.h"
24     #include "wptErrors.h"
25     #include "wptGPG.h"
26     #include "wptW32API.h"
27     #include "wptTypes.h"
28     #include "wptCommonCtl.h"
29     #include "wptContext.h" /* for passphrase_s */
30     #include "wptDlgs.h"
31     #include "wptNLS.h"
32     #include "wptUTF8.h"
33    
34    
35     static const char *
36     mk_cert_fname( const char * keyid )
37     {
38     static char fname[128];
39    
40     if( strlen( keyid ) > 32 )
41     return NULL;
42     _snprintf( fname, sizeof fname-1, "%s-revcert.asc", keyid );
43     return fname;
44     } /* mk_cert_fname */
45    
46    
47     BOOL CALLBACK
48     key_revoke_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
49     {
50     static winpt_key_t k;
51     HWND list;
52     int idx, use_desc, chk = 0, pgpmode = 0;
53     char desc[256], file[256], * p = NULL;
54     char pwd[256];
55     gpgme_editkey_t rev;
56     gpgme_data_t rev_cert;
57     gpgme_ctx_t c;
58     gpgme_error_t err;
59    
60     switch( msg ) {
61     case WM_INITDIALOG:
62     if( !lparam )
63     dlg_fatal_error(dlg, "Could not get dialog param!");
64     k = (winpt_key_t )lparam;
65     #ifndef LANG_DE
66     SetWindowText( dlg, _("Key Revocation") );
67     #endif
68     SetDlgItemText( dlg, IDC_KEYREVOKE_HINT,
69     _("Please move this certificate to a medium where it can be "
70     "stored in a safe place (floppy, CDR, etc..). "
71     "If an attacker gets access to this certificate he can use it to "
72     "render your key unusable!") );
73     list = GetDlgItem( dlg, IDC_KEYREVOKE_REASON );
74     listbox_add_string( list, _("0. No reason specified") );
75     listbox_add_string( list, _("1. Key has been compromised") );
76     listbox_add_string( list, _("2. Key is superseded") );
77     listbox_add_string( list, _("3. Key is no longer used") );
78     /* we set the PGP revoke mode by default because it does not do any
79     * harm and makes sure the revocation certificate is compatible with PGP.
80     */
81     CheckDlgButton (dlg, IDC_KEYREVOKE_PGPMODE, BST_CHECKED);
82     SetDlgItemText (dlg, IDC_KEYREVOKE_PGPMODE, _("Make output &PGP compatible"));
83     SetForegroundWindow (dlg);
84     center_window (dlg);
85     return TRUE;
86    
87     case WM_SYSCOMMAND:
88     if( LOWORD( wparam ) == SC_CLOSE ) {
89     SetDlgItemText( dlg, IDC_KEYREVOKE_PWD, "" );
90     EndDialog( dlg, TRUE );
91     }
92     return FALSE;
93    
94     case WM_COMMAND:
95     switch( LOWORD( wparam ) ) {
96     case IDC_KEYREVOKE_CHOOSE:
97     const char *s, * name;
98     name = mk_cert_fname( k->keyid );
99     s = get_filename_dlg( dlg, 1, _("Choose File to save the Certificate"), NULL, name );
100     if( s && *s )
101     SetDlgItemText( dlg, IDC_KEYREVOKE_FILE, s );
102     return TRUE;
103    
104     case IDOK:
105     list = GetDlgItem( dlg, IDC_KEYREVOKE_REASON );
106     idx = SendMessage( list, LB_GETCURSEL, NULL, NULL );
107     if( idx < 0 || idx > 3 ) {
108     msg_box( dlg, _("Please select a reason."), _("Key Revocation"), MB_ERR );
109     return FALSE;
110     }
111     if( !GetDlgItemText(dlg, IDC_KEYREVOKE_FILE, file, sizeof file-1 ) ) {
112     msg_box( dlg, _("Please enter a filename."), _("Key Revocation"), MB_ERR );
113     return FALSE;
114     }
115     use_desc = 1;
116     if( !GetDlgItemText( dlg, IDC_KEYREVOKE_TEXT, desc, sizeof desc-1 ) )
117     use_desc = 0;
118     if( !GetDlgItemText( dlg, IDC_KEYREVOKE_PWD, pwd, sizeof pwd-1 ) ) {
119     msg_box( dlg, _("Please enter the passphrase."), _("Key Revocation"), MB_ERR );
120     return FALSE;
121     }
122     err = gpgme_editkey_new( &rev );
123     if( err )
124     BUG( dlg );
125    
126     if( use_desc )
127     p = wincp_to_utf8 (desc, strlen (desc));
128     /* we use the keyid to avoid charset problems and UTF8 encodings.*/
129     if( IsDlgButtonChecked( dlg, IDC_KEYREVOKE_PGPMODE ) )
130     pgpmode = 1;
131     gpgme_revoke_set( rev, k->keyid, use_desc? p : NULL, idx, pgpmode, pwd );
132     err = gpgme_data_new( &rev_cert );
133     if( !err )
134     err = gpgme_new( &c );
135     if( err )
136     BUG( dlg );
137    
138     err = gpgme_op_revoke( c, rev, rev_cert );
139     memset( &pwd, 0, sizeof pwd );
140     if( err ) {
141     msg_box( dlg, gpgme_strerror( err ), _("Key Revocation"), MB_ERR );
142     gpgme_data_release( rev_cert );
143     gpgme_editkey_release( rev );
144     gpgme_release( c );
145     free_if_alloc( p );
146     return FALSE;
147     }
148    
149     msg_box( dlg, _("Revocation certificate generated."), _("GnuPG Status"), MB_OK );
150     chk = file_exist_check( file );
151     if( !chk )
152     log_box( _("Key Revocation"), MB_YESNO|MB_INFO,
153     _("\"%s\" already exists.\nOverwrite the file?"), file );
154     if( idx == IDYES || chk )
155     gpgme_data_release_and_set_file( rev_cert, file );
156     else
157     gpgme_data_release( rev_cert );
158     gpgme_editkey_release( rev );
159     gpgme_release( c );
160     free_if_alloc( p );
161     EndDialog( dlg, TRUE );
162     return TRUE;
163    
164     case IDCANCEL:
165     EndDialog( dlg, FALSE );
166     return FALSE;
167     }
168     break;
169     }
170    
171     return FALSE;
172     } /* key_revoke_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26