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

Legend:
Removed from v.32  
changed lines
  Added in v.48

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26