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

Diff of /trunk/Src/wptKeysignDlg.cpp

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

revision 25 by twoaday, Wed Oct 12 10:04:26 2005 UTC revision 88 by twoaday, Mon Nov 21 12:06:59 2005 UTC
# Line 1  Line 1 
1  /* wptKeysignDlg.cpp - Key signing dialog  /* wptKeysignDlg.cpp - Key signing dialog
2   *      Copyright (C) 2001-2005 Timo Schulz   *      Copyright (C) 2001-2005 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
6   * WinPT is free software; you can redistribute it and/or modify   * 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   * 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   * the Free Software Foundation; either version 2 of the License, or
9   * (at your option) any later version.   * (at your option) any later version.
10   *   *
11   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.   * GNU General Public License for more details.
15   *   *
16   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
20    #ifdef HAVE_CONFIG_H
21  #include <windows.h>  #include <config.h>
22  #include <commctrl.h>  #endif
23    
24  #include "../resource.h"  #include <windows.h>
25  #include "wptGPG.h"  #include <commctrl.h>
26  #include "wptNLS.h"  
27  #include "wptW32API.h"  #include "resource.h"
28  #include "wptVersion.h"  #include "wptGPG.h"
29  #include "wptTypes.h"  #include "wptNLS.h"
30  #include "wptErrors.h"  #include "wptW32API.h"
31  #include "wptCommonCtl.h"  #include "wptVersion.h"
32  #include "wptContext.h"  #include "wptTypes.h"
33  #include "wptDlgs.h"  #include "wptErrors.h"
34  #include "wptUTF8.h"  #include "wptCommonCtl.h"
35  #include "wptRegistry.h"  #include "wptContext.h"
36  #include "wptKeyList.h"  #include "wptDlgs.h"
37  #include "wptKeyEdit.h"  #include "wptUTF8.h"
38    #include "wptRegistry.h"
39  static int sig_class_choice = 0;  #include "wptKeylist.h"
40    #include "wptKeyEdit.h"
41  /* Return a beautified printable fingerprint of @fpr. */  
42  static const char*  static int sig_class_choice = 0;
43  get_printable_fpr (const char *fpr)  
44  {  /* Return a beautified printable fingerprint of @fpr. */
45      static char pfpr[64];      static const char*
46      int pos = 0;  get_printable_fpr (const char *fpr)
47      size_t i;  {
48        static char pfpr[64];    
49      for (i = 0; i < strlen (fpr); i += 4) {      int pos = 0;
50          pfpr[pos++] = fpr[i];      size_t i;
51          pfpr[pos++] = fpr[i+1];  
52          pfpr[pos++] = fpr[i+2];      for (i = 0; i < strlen (fpr); i += 4) {
53          pfpr[pos++] = fpr[i+3];          pfpr[pos++] = fpr[i];
54          pfpr[pos++] = ' ';          pfpr[pos++] = fpr[i+1];
55      }          pfpr[pos++] = fpr[i+2];
56      return pfpr;          pfpr[pos++] = fpr[i+3];
57  }          pfpr[pos++] = ' ';
58        }
59        return pfpr;
60  /* Return human friendly information about the key @key. */  }
61  static const char*  
62  get_keyinfo (gpgme_key_t key)  
63  {  /* Return human friendly information about the key @key. */
64      static char buf[64+16];  static const char*
65      struct winpt_key_s k;  get_keyinfo (gpgme_key_t key)
66    {
67      memset (&k, 0, sizeof (k));      static char buf[64+16];
68      winpt_get_seckey (key->subkeys->keyid, &k);      struct winpt_key_s k;
69      _snprintf (buf, DIM (buf)-1-16, "%d-bit %s key, ID %s",  
70          key->subkeys->length,      memset (&k, 0, sizeof (k));
71          get_key_pubalgo (key->subkeys->pubkey_algo),      winpt_get_seckey (key->subkeys->keyid, &k);
72          key->subkeys->keyid+8);      _snprintf (buf, DIM (buf)-1-16, "%d-bit %s key, ID %s",
73      if (k.ext->gloflags.divert_to_card)          key->subkeys->length,
74          strcat (buf, " (Card)");          get_key_pubalgo (key->subkeys->pubkey_algo),
75      return buf;          key->subkeys->keyid+8);
76  }      if (k.ext->gloflags.divert_to_card)
77            strcat (buf, " (Card)");
78        return buf;
79  /* Fill the secret key combo-box with all entries from the cache.  }
80     @dlg is the handle to the combo-box. @keyid show which key to skip.  
81     Return value: 0 on success. */  
82  static int  /* Fill the secret key combo-box with all entries from the cache.
83  do_fill_seckeylist (HWND dlg, const char *keyid)     @dlg is the handle to the combo-box. @keyid show which key to skip.
84  {     Return value: 0 on success. */
85      gpg_keycache_t sec;  static int
86      gpgme_key_t pk;  do_fill_seckeylist (HWND dlg, const char *keyid)
87      const char * s;  {
88      char * uid, * p;          gpg_keycache_t sec;
89      int i = 0, n=0;      gpgme_key_t pk;
90        const char * s;
91      sec = keycache_get_ctx (0);      char * uid, * p;    
92      if (!sec)      int i = 0, n=0;
93          BUG (0);  
94      gpg_keycache_rewind (sec);      sec = keycache_get_ctx (0);
95      while (!gpg_keycache_next_key (sec, 1, &pk)) {      if (!sec)
96          if (!pk)          BUG (0);
97              continue;      gpg_keycache_rewind (sec);
98          s = pk->subkeys->keyid;      while (!gpg_keycache_next_key (sec, 1, &pk)) {
99          if (!strcmp (s, keyid))          if (!pk)
100              continue;              continue;
101          /* skip all ElGamal sign+encrypt keys */          s = pk->subkeys->keyid;
102          if (pk->subkeys->pubkey_algo == GPGME_PK_ELG)          if (!strcmp (s, keyid))
103              continue;              continue;
104          /* make sure the public key is okay not: revoked, expired or disabled. */          /* skip all ElGamal sign+encrypt keys */
105          if (pk->expired ||pk->revoked || pk->disabled)          if (pk->subkeys->pubkey_algo == GPGME_PK_ELG)
106              continue;              continue;
107          s = pk->uids->name;          /* make sure the public key is okay not: revoked, expired or disabled. */
108          if (!s)          if (pk->expired ||pk->revoked || pk->disabled)
109              continue;              continue;
110          uid = utf8_to_wincp (s, strlen (s));          s = pk->uids->name;
111          p = new char[strlen (uid) + 64];          if (!s)
112          if (!p)              continue;
113              BUG (NULL);          uid = utf8_to_wincp (s, strlen (s));
114          _snprintf (p, strlen (uid) + 63, "%s (%s)", uid, get_keyinfo (pk));          p = new char[strlen (uid) + 64];
115          SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_ADDSTRING, i, (LPARAM)(char *)p);          if (!p)
116          SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk);              BUG (NULL);
117          free_if_alloc (p);          _snprintf (p, strlen (uid) + 63, "%s (%s)", uid, get_keyinfo (pk));
118          free (uid);          SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_ADDSTRING, i, (LPARAM)(char *)p);
119          n++;          SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk);
120      }          free_if_alloc (p);
121      SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETCURSEL, 0, 0);          free (uid);
122      if (!n)          n++;
123          return -1;      }
124      return 0;      SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETCURSEL, 0, 0);
125  }      if (!n)
126            return -1;
127        return 0;
128  /* Check if the selected key is protected and en- or disable the  }
129     passphrase control. */  
130  static void  
131  do_check_protection (HWND dlg)  /* Check if the selected key is protected and en- or disable the
132  {     passphrase control. */
133      int idx, protec;  static void
134      gpgme_key_t key;  do_check_protection (HWND dlg)
135      struct winpt_key_s k;  {
136        int idx, protec;
137      idx = SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0 );      gpgme_key_t key;
138      key = (gpgme_key_t)SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETITEMDATA, (WPARAM)idx, 0 );      struct winpt_key_s k;
139      if (key) {  
140          winpt_get_seckey (key->subkeys->keyid, &k);      idx = SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0 );
141          protec = k.is_protected;      key = (gpgme_key_t)SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETITEMDATA, (WPARAM)idx, 0 );
142          if (!protec)      if (key) {
143              protec = k.ext->gloflags.divert_to_card;          winpt_get_seckey (key->subkeys->keyid, &k);
144          EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE), protec? TRUE : FALSE);          protec = k.is_protected;
145      }          if (!protec)
146  }              protec = k.ext->gloflags.divert_to_card;
147            EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE), protec? TRUE : FALSE);
148        }
149  /* Dialog box procedure to choose the signature class. */  }
150  BOOL CALLBACK  
151  sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  
152  {  /* Dialog box procedure to choose the signature class. */
153      switch (msg) {  BOOL CALLBACK
154      case WM_INITDIALOG:  sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
155          SetWindowText (dlg, _("Choose Signature Class"));  {
156          SetDlgItemText (dlg, IDC_SIGCLASS_TITLEINF, _("How carefully have you verified the key you are about to sign actually belongs to the person? If you don't know what to anwser, use \"0\"."));      switch (msg) {
157          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS0, _("(0) I will not answer (default)"));      case WM_INITDIALOG:
158          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS1, _("(1) I have not checked at all."));          SetWindowText (dlg, _("Choose Signature Class"));
159          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS2, _("(2) I have done causal checking."));          SetDlgItemText (dlg, IDC_SIGCLASS_TITLEINF, _("How carefully have you verified the key you are about to sign actually belongs to the person? If you don't know what to anwser, use \"0\"."));
160          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS3, _("(3) I have done very careful checkings."));          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS0, _("(0) I will not answer (default)"));
161          CheckDlgButton (dlg, IDC_SIGCLASS_CLASS0, BST_CHECKED);          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS1, _("(1) I have not checked at all."));
162          SetForegroundWindow (dlg);          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS2, _("(2) I have done causal checking."));
163          center_window (dlg, NULL);          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS3, _("(3) I have done very careful checkings."));
164          return TRUE;          CheckDlgButton (dlg, IDC_SIGCLASS_CLASS0, BST_CHECKED);
165            SetForegroundWindow (dlg);
166      case WM_COMMAND:          center_window (dlg, NULL);
167          switch( LOWORD( wparam ) ) {          return TRUE;
168          case IDOK:  
169              if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS0))      case WM_COMMAND:
170                  sig_class_choice = 0;          switch( LOWORD( wparam ) ) {
171              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS1))          case IDOK:
172                  sig_class_choice = 1;              if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS0))
173              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS2))                  sig_class_choice = 0;
174                  sig_class_choice = 2;              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS1))
175              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS3))                  sig_class_choice = 1;
176                  sig_class_choice = 3;              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS2))
177              else                  sig_class_choice = 2;
178                  sig_class_choice = 0;              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS3))
179              EndDialog (dlg, TRUE);                  sig_class_choice = 3;
180              return TRUE;              else
181          }                  sig_class_choice = 0;
182          break;              EndDialog (dlg, TRUE);
183      }              return TRUE;
184            }
185      return FALSE;          break;
186  }      }
187    
188        return FALSE;
189  /* Return the humand friendly expiration date of @key. */  }
190  static const char*  
191  get_expire_date (gpgme_key_t key)  
192  {  /* Return the humand friendly expiration date of @key. */
193      static char tmp[64];  static const char*
194    get_expire_date (gpgme_key_t key)
195      u32 u = key->subkeys->expires;  {
196      if (!u)      u32 u = key->subkeys->expires;
197          return "never";      if (!u)
198      return get_key_expire_date (u);          return _("never");
199  }      return get_key_expire_date (u);
200    }
201    
202  /* Dialog box procedure to sign a key. */  /* Display photo of key @key in a separate window. */
203  BOOL CALLBACK  static void
204  keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  show_photo (winpt_key_t key)
205  {  {
206      static winpt_key_t key;      /* XXX: fill it with life. */
207      GpgKeyEdit *ke;  }
208      gpgme_error_t err;  
209      gpgme_key_t k;  
210      SYSTEMTIME st;  /* Dialog box procedure to sign a key. */
211      HWND h;  BOOL CALLBACK
212      char keymsg[4096], pwd[256], *uid = NULL;  keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
213      const char *keyid, *s;  {
214      u32 created;      static winpt_key_t key;
215      int type, expires=0, idx;      GpgKeyEdit *ke;
216            gpgme_error_t err;
217      switch ( msg )  {      gpgme_key_t k;
218      case WM_INITDIALOG:      SYSTEMTIME st;
219          if (lparam == NULL)      HWND h;
220              dlg_fatal_error (dlg, "Could not get dialog param.");      char keymsg[2048], pwd[256];
221          #ifndef LANG_DE      char *uid = NULL;
222          SetWindowText (dlg, _("Key Signing"));      const char *keyid, *s;
223          #endif      int type, expires=0, idx;
224          key = (winpt_key_t) lparam;      
225          created = key->ctx->subkeys->timestamp;      switch ( msg )  {
226          s = key->ctx->uids->uid;      case WM_INITDIALOG:
227          if (s)          if (lparam == 0)
228              uid = utf8_to_wincp (s, strlen (s));              dlg_fatal_error (dlg, "Could not get dialog param.");
229          _snprintf (keymsg, sizeof keymsg -1,          #ifndef LANG_DE
230                     _("pub %d/%s  created: %s    expires: %s\n\n"          SetWindowText (dlg, _("Key Signing"));
231                       "Primary key fingerprint: %s\n\n"          #endif
232                       "\t%s\n\n"          key = (winpt_key_t) lparam;
233                       "\nAre you really sure that you want to sign this key with YOUR key?\n"),          s = key->ctx->uids->uid;
234                     key->ctx->subkeys->length,          uid = utf8_to_wincp (s, strlen (s));
235                     key->ctx->subkeys->keyid+8,          _snprintf (keymsg, sizeof keymsg -1,
236                     get_key_created (key->ctx->subkeys->timestamp),                     _("pub %d/%s  created: %s    expires: %s\n\n"
237                     get_expire_date (key->ctx),                       "Primary key fingerprint: %s\n\n"
238                     get_printable_fpr (key->ctx->subkeys->fpr),                       "\t%s\n\n"
239                     uid);                       "\nAre you really sure that you want to sign this key with YOUR key?\n"),
240          free (uid);                     key->ctx->subkeys->length,
241          s = key->ctx->subkeys->keyid;                     key->ctx->subkeys->keyid+8,
242          if (do_fill_seckeylist (dlg, s)) {                     get_key_created (key->ctx->subkeys->timestamp),
243              msg_box( dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR );                     get_expire_date (key->ctx),
244              EndDialog( dlg, FALSE );                     get_printable_fpr (key->ctx->subkeys->fpr),
245          }                     uid);
246          SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, keymsg);          free (uid);
247          #ifndef LANG_DE          s = key->ctx->subkeys->keyid;
248          SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)"));          if (do_fill_seckeylist (dlg, s)) {
249          SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on"));              msg_box (dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR);
250          SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably"));              EndDialog (dlg, FALSE);
251          #endif          }
252          CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED);          SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, keymsg);
253          CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED);          SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)"));
254          CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED);          SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on"));
255          EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), FALSE);          SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably"));
256          if (reg_prefs.expert == 0)          SetDlgItemText (dlg, IDC_KEYSIGN_ASKLEVEL, _("&Ask for certification level"));
257              ShowWindow (GetDlgItem (dlg, IDC_KEYSIGN_NREV), SW_HIDE);          SetDlgItemText (dlg, IDC_KEYSIGN_PWDINF, _("Passphrase"));
258          SetForegroundWindow( dlg );          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
259          h = GetDlgItem( dlg, IDC_KEYSIGN_PASSPHRASE );          SetDlgItemText (dlg, IDC_KEYSIGN_SHOWIMG, _("&Show photo"));
260          SetFocus( h );          CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED);
261          return FALSE;          CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED);
262                CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED);
263      case WM_DESTROY:          EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), FALSE);
264          sig_class_choice = 0;          if (reg_prefs.expert == 0)
265          break;              ShowWindow (GetDlgItem (dlg, IDC_KEYSIGN_NREV), SW_HIDE);
266            if (key->ext && key->ext->attrib.len > 0)
267      case WM_SYSCOMMAND:              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_SHOWIMG), TRUE);
268          if( LOWORD( wparam ) == SC_CLOSE ) {          if (!reg_prefs.gpg.ask_cert_level)
269              SetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, "" );              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_ASKLEVEL), FALSE);
270              EndDialog( dlg, TRUE );          SetForegroundWindow (dlg);
271          }          h = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE);
272          return FALSE;          SetFocus (h);
273                    return FALSE;
274      case WM_COMMAND:      
275          if( HIWORD( wparam ) == CBN_SELCHANGE ) {      case WM_DESTROY:
276              do_check_protection( dlg );          sig_class_choice = 0;
277              break;          break;
278          }  
279          if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) {      case WM_SYSCOMMAND:
280              int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG);          if( LOWORD( wparam ) == SC_CLOSE ) {
281              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE);              SetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, "" );
282          }              EndDialog( dlg, TRUE );
283            }
284          switch( LOWORD( wparam ) ) {          return FALSE;
285          case IDOK:          
286              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL))      case WM_COMMAND:
287                  dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_SIGCLASS, dlg,          if (HIWORD( wparam ) == CBN_SELCHANGE) {
288                                    sig_class_dlg_proc, (LPARAM)NULL,              do_check_protection (dlg);
289                                    _("Choose Signature Class"),  IDS_WINPT_SIGCLASS);              break;
290              type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL);          }
291              if (type)          if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) {
292                  type = GPG_EDITKEY_LSIGN;              int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG);
293              else              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE);
294                  type = GPG_EDITKEY_SIGN;          }
295    
296              if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) {          switch( LOWORD( wparam ) ) {
297                  type = GPG_EDITKEY_NRSIGN;          case IDOK:
298                  if (type == GPG_EDITKEY_LSIGN)              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL))
299                      type = GPG_EDITKEY_NRLSIGN;                  dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_SIGCLASS, dlg,
300              }                                    sig_class_dlg_proc, (LPARAM)NULL,
301              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) {                                    _("Choose Signature Class"),  IDS_WINPT_SIGCLASS);
302                  expires = 1;              type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL);
303                  DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st);              if (type)
304                  sprintf (keymsg, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay);                  type = GPG_EDITKEY_LSIGN;
305              }              else
306                    type = GPG_EDITKEY_SIGN;
307              /* XXX: check for --ask-cert-level and --ask-cert-expire in the gpg.conf  
308                      if an advanced button is checked and offer to add it to the config              if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) {
309                      file. */                  type = GPG_EDITKEY_NRSIGN;
310                    if (type == GPG_EDITKEY_LSIGN)
311              GetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, pwd, DIM (pwd)-1);                      type = GPG_EDITKEY_NRLSIGN;
312              keyid = key->ctx->subkeys->keyid;              }
313              if( !keyid ) {              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) {
314                  msg_box( dlg, _("Could not get Key ID from key."), _("Key Signing"), MB_ERR );                  expires = 1;
315                  return TRUE;                  DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st);
316              }                  sprintf (keymsg, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay);
317              ke = new GpgKeyEdit (keyid);              }
318              if (!ke)  
319                  BUG (NULL);              /* XXX: check for --ask-cert-level and --ask-cert-expire in the gpg.conf
320              ke->setPassphrase (pwd);                      if an advanced button is checked and offer to add it to the config
321              idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0);                      file. */
322              k = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,  
323                                                   CB_GETITEMDATA, (WPARAM)idx, 0);              GetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, pwd, DIM (pwd)-1);
324              if (k)              keyid = key->ctx->subkeys->keyid;
325                  ke->setLocalUser (k);              if( !keyid ) {
326                    msg_box( dlg, _("Could not get Key ID from key."), _("Key Signing"), MB_ERR );
327              err = ke->signKey (type, sig_class_choice, expires? keymsg : "0");                  return TRUE;
328              memset (&pwd, 0, sizeof pwd);                        }
329              if (err) {              ke = new GpgKeyEdit (keyid);
330                  delete ke;              if (!ke)
331                  msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR);                  BUG (NULL);
332                  return TRUE;              ke->setPassphrase (pwd);
333              }              idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0);
334              if (ke->getResultValue () != 0)              k = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,
335                  msg_box (dlg, _("This key is already signed by your key"), _("Key Signing"), MB_INFO);                                                   CB_GETITEMDATA, (WPARAM)idx, 0);
336              else {              if (k)
337                  status_box (dlg, _("Key successfully signed."), PGM_NAME);                  ke->setLocalUser (k);
338                  key->update = 1;  
339              }              err = ke->signKey (type, sig_class_choice, expires? keymsg : "0");
340              delete ke;              memset (&pwd, 0, sizeof pwd);          
341              EndDialog (dlg, TRUE);              if (err) {
342              return TRUE;                  delete ke;
343                                msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR);
344          case IDCANCEL:                  return TRUE;
345              EndDialog (dlg, FALSE);              }
346              return TRUE;              if (ke->getResult () != 0)
347          }                  msg_box (dlg, _("This key is already signed by your key"), _("Key Signing"), MB_INFO);
348          break;              else {
349      }                  status_box (dlg, _("Key successfully signed."), PGM_NAME);
350                        key->update = 1;
351      return FALSE;              }
352  }              delete ke;
353                EndDialog (dlg, TRUE);
354                return TRUE;
355                
356            case IDCANCEL:
357                EndDialog (dlg, FALSE);
358                return TRUE;
359    
360            case IDC_KEYSIGN_SHOWIMG:
361                show_photo (key);
362                return TRUE;
363            }
364            break;
365        }
366        
367        return FALSE;
368    }
369    

Legend:
Removed from v.25  
changed lines
  Added in v.88

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26