/[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 204 by twoaday, Wed Apr 26 06:37:23 2006 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] == ' ')      char *uid;
48              fname[i] = '_';  
49  }      if (get_pubkey (keyid, &k))
50            BUG (NULL);
51        uid = utf8_to_native (k->uids->name);
52  /* Release the cert data and store it in the file @fname. */      _snprintf (fname, flen-1, "%s_RevocationCert.asc", uid);
53  static void      for (i=0; i < strlen (fname); i++) {
54  release_cert_as_file (char *revcert, const char *fname)          if (fname[i] == ' ')
55  {              fname[i] = '_';
56      gpgme_error_t err;      }
57      gpgme_data_t rev;      safe_free (uid);
58    }
59      err = gpgme_data_new_from_mem (&rev, revcert, strlen (revcert), 1);  
60      if (!err)  
61          gpg_data_release_and_set_file (rev, fname);  /* Release the cert data and store it in the file @fname. */
62      else  static void
63          msg_box (NULL, gpgme_strerror (err), _("Key Revocation"), MB_ERR);  release_cert_as_file (char *revcert, const char *fname)
64      free (revcert);  {
65  }      gpgme_error_t err;
66        gpgme_data_t rev;
67    
68  /* Dialog box procedure for key revocation. */      err = gpgme_data_new_from_mem (&rev, revcert, strlen (revcert), 1);
69  BOOL CALLBACK      if (!err)
70  key_revoke_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)          gpg_data_release_and_set_file (rev, fname);
71  {            else
72      static winpt_key_t k;          msg_box (NULL, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR);
73      gpgme_error_t err;      safe_free (revcert);
74      HWND list;    }
75      int idx, use_desc, chk = 0;  
76      char desc[256], file[256], *p = NULL;  
77      char pwd[256];  static void
78      char *inp_data = NULL, *revcert=NULL;  on_init_dialog (HWND dlg)
79        {
80      switch( msg ) {      HWND list;
81      case WM_INITDIALOG:  
82          if( !lparam )      SetWindowText (dlg, _("Key Revocation Cert"));
83              dlg_fatal_error(dlg, "Could not get dialog param!");      SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
84          k = (winpt_key_t )lparam;      SetDlgItemText (dlg, IDC_KEYREVOKE_REASONINF, _("Reason for revocation"));
85      #ifndef LANG_DE      SetDlgItemText (dlg, IDC_KEYREVOKE_OPTINF, _("Optional description text"));
86          SetWindowText (dlg, _("Key Revocation"));      SetDlgItemText (dlg, IDC_KEYREVOKE_PWDINF, _("&Passphrase"));
87      #endif      SetDlgItemText (dlg, IDC_KEYREVOKE_OUTINF, _("Output file"));
88          SetDlgItemText (dlg, IDC_KEYREVOKE_HINT,      list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON);
89                          _("Please move this certificate to a medium where it can be "      listbox_add_string (list, _("0. No reason specified"));
90                            "stored in a safe place (floppy, CDR, etc..). "      listbox_add_string (list, _("1. Key has been compromised"));
91                            "If an attacker gets access to this certificate he can use it to "      listbox_add_string (list, _("2. Key is superseded"));
92                            "render your key unusable!"));      listbox_add_string (list, _("3. Key is no longer used"));
93          list = GetDlgItem( dlg, IDC_KEYREVOKE_REASON );      SendMessage (list, LB_SETCURSEL, (WPARAM)0, 0);
94          listbox_add_string (list, _("0. No reason specified"));      SetForegroundWindow (dlg);
95          listbox_add_string (list, _("1. Key has been compromised"));      center_window (dlg, NULL);
96          listbox_add_string (list, _("2. Key is superseded"));  }
97          listbox_add_string (list, _("3. Key is no longer used"));  
98          SetForegroundWindow (dlg);  
99          center_window (dlg, NULL);  /* Dialog box procedure for key revocation. */
100          return TRUE;  BOOL CALLBACK
101            key_revoke_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
102      case WM_SYSCOMMAND:  {      
103          if( LOWORD( wparam ) == SC_CLOSE ) {      static winpt_key_t k;
104              SetDlgItemText( dlg, IDC_KEYREVOKE_PWD, "" );      gpgme_error_t err;
105              EndDialog( dlg, TRUE );      HWND list;
106          }      int idx, use_desc;
107          return FALSE;      char file[256];
108                char pwd[256];
109      case WM_COMMAND:      char *desc=NULL;
110          switch( LOWORD( wparam ) ) {      char *inp_data = NULL, *revcert=NULL;
111          case IDC_KEYREVOKE_CHOOSE:      const char *warning =
112              const char *s;          _("Please move this certificate to a medium where it can be"
113              mk_cert_fname (k->keyid, file, sizeof file-1);            "stored in a safe place (floppy, CDR, etc..).\n"
114              s = get_filename_dlg (dlg, FILE_SAVE, _("Choose File to save the Certificate"), NULL, file);            "If an attacker gets access to this certificate he can use it to "
115              if (s && *s)            "render your key unusable!");
116                  SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s);      
117              return TRUE;      switch( msg ) {
118        case WM_INITDIALOG:
119          case IDOK:          if (!lparam)
120              list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON);              dlg_fatal_error (dlg, "Could not get dialog param!");
121              idx = SendMessage (list, LB_GETCURSEL, NULL, NULL);          k = (winpt_key_t )lparam;
122              if (idx < 0 || idx > 3) {          on_init_dialog (dlg);
123                  msg_box (dlg, _("Please select a reason."),          return TRUE;
124                           _("Key Revocation"), MB_ERR);          
125                  return TRUE;      case WM_SYSCOMMAND:
126              }          if (LOWORD (wparam) == SC_CLOSE)
127              if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) {              EndDialog (dlg, FALSE);
128                  msg_box (dlg, _("Please enter a file name."),          return FALSE;
129                           _("Key Revocation"), MB_ERR);          
130                  return TRUE;      case WM_COMMAND:
131              }          switch (LOWORD (wparam)) {
132              use_desc = 1;          case IDC_KEYREVOKE_CHOOSE:
133              if (!GetDlgItemText (dlg, IDC_KEYREVOKE_TEXT, desc, sizeof (desc)-1))              const char *s;
134                  use_desc = 0;              mk_cert_fname (k->keyid, file, sizeof file-1);
135              if( !GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) {              s = get_filesave_dlg (dlg, _("Choose File to save the Certificate"), NULL, file);
136                  msg_box (dlg, _("Please enter the passphrase."), _("Key Revocation"), MB_ERR);              if (s && *s)
137                  return TRUE;                  SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s);
138              }              return TRUE;
139              
140              if (use_desc)          case IDOK:
141                  p = wincp_to_utf8 (desc, strlen (desc));              list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON);
142              /* we use the keyid to avoid charset problems and UTF8 encodings.*/              idx = SendMessage (list, LB_GETCURSEL, 0, 0);
143              inp_data = generate_revoc_input (idx, use_desc? p : NULL, pwd);              if (idx < 0 || idx > 3) {
144                                msg_box (dlg, _("Please select a reason."),
145              err = gpg_revoke_key (inp_data, k->keyid, &revcert);                           _("Key Revocation Cert"), MB_ERR);
146              wipememory (&pwd, sizeof (pwd));                  return TRUE;
147              memset (inp_data, 0, strlen (inp_data));              }
148              free (inp_data);              if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) {
149              free_if_alloc (p);                  msg_box (dlg, _("Please enter a file name."),
150                             _("Key Revocation Cert"), MB_ERR);
151              if (err) {                  return TRUE;
152                  msg_box (dlg, gpgme_strerror (err), _("Key Revocation"), MB_ERR);              }
153                  if (revcert)              use_desc = 1;
154                      free (revcert);              if (!GetDlgItemText_utf8 (dlg, IDC_KEYREVOKE_TEXT, &desc))
155              }                  use_desc = 0;
156              else {              if (!GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) {
157                  msg_box (dlg, _("Revocation certificate generated."), _("GnuPG Status"), MB_OK);                  msg_box (dlg, _("Please enter the passphrase."),
158                  release_cert_as_file (revcert, file);                           _("Key Revocation Cert"), MB_ERR);
159              }                  return TRUE;
160              EndDialog (dlg, TRUE);              }
161              return TRUE;            
162                            inp_data = generate_revoke_input (idx, desc, pwd);
163          case IDCANCEL:              err = gpg_revoke_cert (inp_data, k->keyid, &revcert);
164              EndDialog (dlg, FALSE);              wipememory (pwd, sizeof (pwd));
165              return FALSE;              wipememory (inp_data, strlen (inp_data));
166          }              if (err) {
167          break;                  msg_box (dlg, gpgme_strerror (err), _("Key Revocation Cert"), MB_ERR);
168      }                  safe_free (revcert);
169                    }
170      return FALSE;              else {
171  }                  show_msg (dlg, 1000, _("Revocation certificate generated."));
172                    msg_box (dlg, warning, _("Key Revocation Cert"), MB_INFO);
173                    release_cert_as_file (revcert, file);
174                }
175                safe_free (inp_data);
176                free_if_alloc (desc);
177                EndDialog (dlg, TRUE);
178                return TRUE;
179                
180            case IDCANCEL:
181                EndDialog (dlg, FALSE);
182                return FALSE;
183            }
184            break;
185        }
186        
187        return FALSE;
188    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26