/[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 35 by twoaday, Mon Oct 24 08:03:48 2005 UTC revision 36 by werner, Thu Oct 27 15:25:13 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"  #include <windows.h>
27  #include "wptW32API.h"  
28  #include "wptTypes.h"  #include "../resource.h"
29  #include "wptCommonCtl.h"  #include "gpgme.h"
30  #include "wptContext.h" /* for passphrase_s */  #include "wptErrors.h"
31  #include "wptDlgs.h"  #include "wptGPG.h"
32  #include "wptNLS.h"  #include "wptW32API.h"
33  #include "wptUTF8.h"  #include "wptTypes.h"
34    #include "wptCommonCtl.h"
35    #include "wptContext.h" /* for passphrase_s */
36  /* Generate a file template for the cert based on the key  #include "wptDlgs.h"
37     with the keyid @keyid. */  #include "wptNLS.h"
38  static void  #include "wptUTF8.h"
39  mk_cert_fname (const char *keyid, char *fname, size_t flen)  
40  {  
41      gpgme_key_t k;  /* Generate a file template for the cert based on the key
42      size_t i;     with the keyid @keyid. */
43    static void
44      get_pubkey (keyid, &k);  mk_cert_fname (const char *keyid, char *fname, size_t flen)
45      _snprintf (fname, flen-1, "%s-RevocationCert.asc", k->uids->name);  {
46      for (i=0; i < strlen (fname); i++)      gpgme_key_t k;
47          if (fname[i] == ' ')      size_t i;
48              fname[i] = '_';  
49  }      get_pubkey (keyid, &k);
50        _snprintf (fname, flen-1, "%s-RevocationCert.asc", k->uids->name);
51        for (i=0; i < strlen (fname); i++)
52  /* Release the cert data and store it in the file @fname. */          if (fname[i] == ' ')
53  static void              fname[i] = '_';
54  release_cert_as_file (char *revcert, const char *fname)  }
55  {  
56      gpgme_error_t err;  
57      gpgme_data_t rev;  /* Release the cert data and store it in the file @fname. */
58    static void
59      err = gpgme_data_new_from_mem (&rev, revcert, strlen (revcert), 1);  release_cert_as_file (char *revcert, const char *fname)
60      if (!err)  {
61          gpg_data_release_and_set_file (rev, fname);      gpgme_error_t err;
62      else      gpgme_data_t rev;
63          msg_box (NULL, gpgme_strerror (err), _("Key Revocation"), MB_ERR);  
64      free (revcert);      err = gpgme_data_new_from_mem (&rev, revcert, strlen (revcert), 1);
65  }      if (!err)
66            gpg_data_release_and_set_file (rev, fname);
67        else
68  /* Dialog box procedure for key revocation. */          msg_box (NULL, gpgme_strerror (err), _("Key Revocation"), MB_ERR);
69  BOOL CALLBACK      free (revcert);
70  key_revoke_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  }
71  {        
72      static winpt_key_t k;  
73      gpgme_error_t err;  /* Dialog box procedure for key revocation. */
74      HWND list;    BOOL CALLBACK
75      int idx, use_desc, chk = 0;  key_revoke_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
76      char desc[256], file[256], *p = NULL;  {      
77      char pwd[256];      static winpt_key_t k;
78      char *inp_data = NULL, *revcert=NULL;      gpgme_error_t err;
79            HWND list;  
80      switch( msg ) {      int idx, use_desc, chk = 0;
81      case WM_INITDIALOG:      char desc[256], file[256], *p = NULL;
82          if( !lparam )      char pwd[256];
83              dlg_fatal_error(dlg, "Could not get dialog param!");      char *inp_data = NULL, *revcert=NULL;
84          k = (winpt_key_t )lparam;      
85      #ifndef LANG_DE      switch( msg ) {
86          SetWindowText (dlg, _("Key Revocation"));      case WM_INITDIALOG:
87      #endif          if( !lparam )
88          SetDlgItemText (dlg, IDC_KEYREVOKE_HINT,              dlg_fatal_error(dlg, "Could not get dialog param!");
89                          _("Please move this certificate to a medium where it can be "          k = (winpt_key_t )lparam;
90                            "stored in a safe place (floppy, CDR, etc..). "      #ifndef LANG_DE
91                            "If an attacker gets access to this certificate he can use it to "          SetWindowText (dlg, _("Key Revocation"));
92                            "render your key unusable!"));      #endif
93          list = GetDlgItem( dlg, IDC_KEYREVOKE_REASON );          SetDlgItemText (dlg, IDC_KEYREVOKE_HINT,
94          listbox_add_string (list, _("0. No reason specified"));                          _("Please move this certificate to a medium where it can be "
95          listbox_add_string (list, _("1. Key has been compromised"));                            "stored in a safe place (floppy, CDR, etc..). "
96          listbox_add_string (list, _("2. Key is superseded"));                            "If an attacker gets access to this certificate he can use it to "
97          listbox_add_string (list, _("3. Key is no longer used"));                            "render your key unusable!"));
98          SetForegroundWindow (dlg);          list = GetDlgItem( dlg, IDC_KEYREVOKE_REASON );
99          center_window (dlg, NULL);          listbox_add_string (list, _("0. No reason specified"));
100          return TRUE;          listbox_add_string (list, _("1. Key has been compromised"));
101                    listbox_add_string (list, _("2. Key is superseded"));
102      case WM_SYSCOMMAND:          listbox_add_string (list, _("3. Key is no longer used"));
103          if( LOWORD( wparam ) == SC_CLOSE ) {          SetForegroundWindow (dlg);
104              SetDlgItemText( dlg, IDC_KEYREVOKE_PWD, "" );          center_window (dlg, NULL);
105              EndDialog( dlg, TRUE );          return TRUE;
106          }          
107          return FALSE;      case WM_SYSCOMMAND:
108                    if( LOWORD( wparam ) == SC_CLOSE ) {
109      case WM_COMMAND:              SetDlgItemText( dlg, IDC_KEYREVOKE_PWD, "" );
110          switch( LOWORD( wparam ) ) {              EndDialog( dlg, TRUE );
111          case IDC_KEYREVOKE_CHOOSE:          }
112              const char *s;          return FALSE;
113              mk_cert_fname (k->keyid, file, sizeof file-1);          
114              s = get_filename_dlg (dlg, FILE_SAVE, _("Choose File to save the Certificate"), NULL, file);      case WM_COMMAND:
115              if (s && *s)          switch( LOWORD( wparam ) ) {
116                  SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s);          case IDC_KEYREVOKE_CHOOSE:
117              return TRUE;              const char *s;
118                mk_cert_fname (k->keyid, file, sizeof file-1);
119          case IDOK:              s = get_filename_dlg (dlg, FILE_SAVE, _("Choose File to save the Certificate"), NULL, file);
120              list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON);              if (s && *s)
121              idx = SendMessage (list, LB_GETCURSEL, NULL, NULL);                  SetDlgItemText (dlg, IDC_KEYREVOKE_FILE, s);
122              if (idx < 0 || idx > 3) {              return TRUE;
123                  msg_box (dlg, _("Please select a reason."),  
124                           _("Key Revocation"), MB_ERR);          case IDOK:
125                  return TRUE;              list = GetDlgItem (dlg, IDC_KEYREVOKE_REASON);
126              }              idx = SendMessage (list, LB_GETCURSEL, NULL, NULL);
127              if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) {              if (idx < 0 || idx > 3) {
128                  msg_box (dlg, _("Please enter a file name."),                  msg_box (dlg, _("Please select a reason."),
129                           _("Key Revocation"), MB_ERR);                           _("Key Revocation"), MB_ERR);
130                  return TRUE;                  return TRUE;
131              }              }
132              use_desc = 1;              if (!GetDlgItemText (dlg, IDC_KEYREVOKE_FILE, file, sizeof (file)-1)) {
133              if (!GetDlgItemText (dlg, IDC_KEYREVOKE_TEXT, desc, sizeof (desc)-1))                  msg_box (dlg, _("Please enter a file name."),
134                  use_desc = 0;                           _("Key Revocation"), MB_ERR);
135              if( !GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) {                  return TRUE;
136                  msg_box (dlg, _("Please enter the passphrase."), _("Key Revocation"), MB_ERR);              }
137                  return TRUE;              use_desc = 1;
138              }              if (!GetDlgItemText (dlg, IDC_KEYREVOKE_TEXT, desc, sizeof (desc)-1))
139                              use_desc = 0;
140              if (use_desc)              if( !GetDlgItemText (dlg, IDC_KEYREVOKE_PWD, pwd, sizeof (pwd)-1)) {
141                  p = wincp_to_utf8 (desc, strlen (desc));                  msg_box (dlg, _("Please enter the passphrase."), _("Key Revocation"), MB_ERR);
142              /* we use the keyid to avoid charset problems and UTF8 encodings.*/                  return TRUE;
143              inp_data = generate_revoc_input (idx, use_desc? p : NULL, pwd);              }
144                          
145              err = gpg_revoke_key (inp_data, k->keyid, &revcert);              if (use_desc)
146              wipememory (&pwd, sizeof (pwd));                  p = wincp_to_utf8 (desc, strlen (desc));
147              memset (inp_data, 0, strlen (inp_data));              /* we use the keyid to avoid charset problems and UTF8 encodings.*/
148              free (inp_data);              inp_data = generate_revoc_input (idx, use_desc? p : NULL, pwd);
149              free_if_alloc (p);              
150                err = gpg_revoke_key (inp_data, k->keyid, &revcert);
151              if (err) {              wipememory (&pwd, sizeof (pwd));
152                  msg_box (dlg, gpgme_strerror (err), _("Key Revocation"), MB_ERR);              memset (inp_data, 0, strlen (inp_data));
153                  if (revcert)              free (inp_data);
154                      free (revcert);              free_if_alloc (p);
155              }  
156              else {              if (err) {
157                  msg_box (dlg, _("Revocation certificate generated."), _("GnuPG Status"), MB_OK);                  msg_box (dlg, gpgme_strerror (err), _("Key Revocation"), MB_ERR);
158                  release_cert_as_file (revcert, file);                  if (revcert)
159              }                      free (revcert);
160              EndDialog (dlg, TRUE);              }
161              return TRUE;              else {
162                                msg_box (dlg, _("Revocation certificate generated."), _("GnuPG Status"), MB_OK);
163          case IDCANCEL:                  release_cert_as_file (revcert, file);
164              EndDialog (dlg, FALSE);              }
165              return FALSE;              EndDialog (dlg, TRUE);
166          }              return TRUE;
167          break;              
168      }          case IDCANCEL:
169                    EndDialog (dlg, FALSE);
170      return FALSE;              return FALSE;
171  }          }
172            break;
173        }
174        
175        return FALSE;
176    }

Legend:
Removed from v.35  
changed lines
  Added in v.36

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26