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

Diff of /trunk/Src/wptKeyRevokeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.22  
changed lines
  Added in v.105

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26