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

Diff of /trunk/Src/wptKeyPropsDlg.cpp

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

revision 73 by twoaday, Tue Nov 8 07:15:13 2005 UTC revision 212 by twoaday, Tue May 9 10:29:07 2006 UTC
# Line 1  Line 1 
1  /* wptKeyPropsDlg.cpp - WinPT key properties dialog  /* wptKeyPropsDlg.cpp - WinPT key properties dialog
2   *      Copyright (C) 2000, 2001, 2002, 2003, 2005 Timo Schulz   *      Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 17  Line 17 
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  #ifdef HAVE_CONFIG_H
21  #include <config.h>  #include <config.h>
22  #endif  #endif
# Line 52  do_check_key (gpgme_key_t key) Line 51  do_check_key (gpgme_key_t key)
51    
52  /* Convert a trust integer into a string representation. */  /* Convert a trust integer into a string representation. */
53  static const char*  static const char*
54  ownertrust_to_string (int val)  ownertrust_to_string (int val, bool is_keypair)
55  {  {
56      const char *inf;      const char *inf;
57      int id = val;      int id = val;
# Line 63  ownertrust_to_string (int val) Line 62  ownertrust_to_string (int val)
62      case 3: inf = _("I trust marginally"); break;      case 3: inf = _("I trust marginally"); break;
63      case 4: inf = _("I trust fully");      break;      case 4: inf = _("I trust fully");      break;
64      case 5:      case 5:
65      case 6: inf = _("I trust ultimately"); break;      case 6:
66            if (is_keypair)
67                inf = _("I trust ultimately (implicit)");
68            else
69                inf = _("I trust ultimately"); break;
70      default:inf = _("Unknown");            break;      default:inf = _("Unknown");            break;
71      }      }
72            
# Line 76  ownertrust_to_string (int val) Line 79  ownertrust_to_string (int val)
79  static const char*  static const char*
80  get_photo_tmpname (HWND dlg)  get_photo_tmpname (HWND dlg)
81  {  {
82      static char buf[64];      static char buf[MAX_PATH+128+1];
83        char name[64];
84    
85      _snprintf (buf, sizeof (buf)-1, "winpt_photo_%08lX.tmp", (DWORD)dlg);      _snprintf (name, sizeof (name)-1, "winpt_photo_%08lX.tmp", (DWORD)dlg);
86        get_temp_name (buf, DIM (buf)-1, name);
87      return buf;      return buf;
88  }  }
89    
90    
91    static void
92    draw_nophoto_img (HWND dlg)
93    {
94        /*..
95        n = DrawText (hdc, "No Photo-ID", -1, &r, DT_LEFT);
96        ..*/
97    }
98    
99    
100  /* Load the photo from the key @key */  /* Load the photo from the key @key */
101  static int  static int
102  keyprops_load_photo (HWND dlg, gpgme_key_t key, gpgme_validity_t *r_valid)  keyprops_load_photo (HWND dlg, gpgme_key_t key, gpgme_validity_t *r_valid)
# Line 93  keyprops_load_photo (HWND dlg, gpgme_key Line 107  keyprops_load_photo (HWND dlg, gpgme_key
107      DWORD imglen = 0;      DWORD imglen = 0;
108      int pos=0;      int pos=0;
109    
110      winpt_get_pubkey (key->subkeys->keyid, &k);      if (winpt_get_pubkey (key->subkeys->keyid, &k))
111            BUG (0);
112      img = k.ext->attrib.d;      img = k.ext->attrib.d;
113      imglen = k.ext->attrib.len;      imglen = k.ext->attrib.len;
114      if (!k.ext->attrib.validity)      if (!k.ext->attrib.validity)
115          get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity);          get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity);
116      *r_valid = k.ext->attrib.validity;      *r_valid = k.ext->attrib.validity;
117    
118      if (!img || !imglen)      if (!img || !imglen) {
119            draw_nophoto_img (dlg);
120          return -1;          return -1;
121        }
122    
123      f = fopen (get_photo_tmpname (dlg), "wb");      f = fopen (get_photo_tmpname (dlg), "wb");
124      if (f) {      if (f) {
         for (pos = 0; img[pos] != 0x10; pos++)  
                 ;  
125          pos += 16;          pos += 16;
126          fwrite (img + pos, 1, imglen - pos, f);          fwrite (img + pos, 1, imglen - pos, f);
         fwrite (img, 1, imglen, f);  
127          fclose (f);          fclose (f);
128      }      }
129      return 0;      return 0;
# Line 138  keyprops_show_photo (HWND dlg) Line 153  keyprops_show_photo (HWND dlg)
153  static const char*  static const char*
154  get_validity (gpgme_key_t key)  get_validity (gpgme_key_t key)
155  {  {
156      int val;      if (key->expired)
     val = key->expired;  
     if (val)  
157          return _("Expired");              return _("Expired");    
158      val = key->revoked;      if (key->revoked)
     if (val)  
159          return _("Revoked");          return _("Revoked");
160      val = key->disabled;      if (key->disabled)
     if (val)  
161          return _("Disabled");          return _("Disabled");
162      return get_key_trust2 (NULL, key->uids->validity, 0, 0);      return get_key_trust2 (NULL, key->uids->validity, 0, 0);
163  }  }
# Line 158  get_pref_cipher (winpt_key_t k) Line 169  get_pref_cipher (winpt_key_t k)
169  {  {
170      if (k->is_v3)      if (k->is_v3)
171          return "IDEA";          return "IDEA";
172      if (!k->ext->sym_prefs)      if (!k->ext || !k->ext->sym_prefs)
173          return "3DES";          return "3DES";
174      switch (*k->ext->sym_prefs) {      switch (*k->ext->sym_prefs) {
175      case 1: return "IDEA";      case 1: return "IDEA";
176      case 2: return "3DES";      case 2: return "3DES";
177      case 3: return "CAST5";      case 3: return "CAST5";
178      case 4: return "Blowfish";      case 4: return "Blowfish";
179      case 7:      case 7: return "AES128";
180      case 8:      case 8: return "AES192";
181      case 9: return "AES";      case 9: return "AES256";
182      case 10:return "Twofish";      case 10:return "Twofish";
183      }      }
184      return "Unknown";      return "Unknown";
# Line 192  get_card_type (winpt_key_t k) Line 203  get_card_type (winpt_key_t k)
203  {      {    
204      static char buf[64];      static char buf[64];
205    
206      if (!k->ext->card_type)      if (!k->ext || !k->ext->card_type)
207          return "";          return "";
208      _snprintf (buf, sizeof (buf)-1, _("Card-Type: %s\r\n"), k->ext->card_type);      _snprintf (buf, sizeof (buf)-1, _("Card-Type: %s\r\n"), k->ext->card_type);
209      return buf;      return buf;
210  }  }
211    
212    
213    /* Return 1 if at least one user-ID is valid. */
214    static int
215    key_is_valid (gpgme_key_t k)
216    {
217        gpgme_user_id_t u;
218    
219        for (u=k->uids; u; u=u->next) {
220            if (u->validity >= GPGME_VALIDITY_MARGINAL)
221                return 1;
222        }
223        return 0;
224    }
225    
226    
227    
228  /* Display the key information for key @k.  /* Display the key information for key @k.
229     Return value: gpgme key on success. */     Return value: gpgme key on success. */
230  static void  static void
231  display_key_info (HWND dlg, winpt_key_t k, gpgme_key_t *r_key)  display_key_info (HWND dlg, winpt_key_t k)
232  {  {
233      struct winpt_key_s k2;      gpgme_key_t key;
234      gpgme_key_t sk, key;      struct winpt_key_s sk;
235      char info[512];      char info[512];
236      const char *inf;      const char *inf;
237      u32 created, expires;          DWORD created, expires;
238    
239      memset (&k2, 0, sizeof (k2));            gpg_keycache_update_attr (k->ext, KC_ATTR_PREFSYM, 0);
240      if (k->key_pair)      memset (&sk, 0, sizeof (sk));      
241          winpt_get_seckey (k->keyid, &k2);      if (k->key_pair && !winpt_get_seckey (k->keyid, &sk))
242      else              k->is_protected = sk.is_protected;
243          winpt_get_pubkey (k->keyid, &k2);      key = k->ext->key;
244      sk = k2.ctx;              created = key->subkeys->timestamp;
245      if (sk)      expires = key->subkeys->expires;
         k->is_protected = k2.is_protected;  
     if (get_pubkey (k->keyid, &key))  
         BUG (0);      
     created = key->subkeys->timestamp;    
     expires = key->subkeys->expires;      
246      _snprintf (info, DIM (info)-1,      _snprintf (info, DIM (info)-1,
247                 _("Type: %s\r\n"                 _("Type: %s\r\n"
248                 "Key ID: %s\r\n"                 "Key ID: 0x%s\r\n"
249                 "Algorithm: %s\r\n"                 "Algorithm: %s\r\n"
250                 "Size: %s\r\n"                 "Size: %s bits\r\n"
251                 "Created: %s\r\n"                 "Created: %s\r\n"
252                 "Expires: %s\r\n"                 "Expires: %s\r\n"
253                 "Validity: %s\r\n"                 "Validity: %s\r\n"
# Line 239  display_key_info (HWND dlg, winpt_key_t Line 260  display_key_info (HWND dlg, winpt_key_t
260                 get_key_created (created),                 get_key_created (created),
261                 get_key_expire_date (expires),                 get_key_expire_date (expires),
262                 get_validity (key),                 get_validity (key),
263                 get_pref_cipher (&k2),                 get_pref_cipher (k),
264                 get_card_type (&k2));                 get_card_type (&sk));
265    
266      SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info);      SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info);
267      SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key));        SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key));  
268      inf = ownertrust_to_string (key->owner_trust);      inf = ownertrust_to_string (key->owner_trust, k->key_pair);
269      SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);      SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
   
     *r_key = key;  
270  }  }
271    
272    
# Line 255  display_key_info (HWND dlg, winpt_key_t Line 274  display_key_info (HWND dlg, winpt_key_t
274  BOOL CALLBACK  BOOL CALLBACK
275  keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
276  {  {
277      static winpt_key_t k;      static winpt_key_t k = NULL;
     static gpgme_key_t key;  
278      gpgme_validity_t valid;      gpgme_validity_t valid;
     refresh_cache_s rcs = {0};  
279      const char *inf;      const char *inf;
280      int rc;      int rc;
281            
# Line 269  keyprops_dlg_proc (HWND dlg, UINT msg, W Line 286  keyprops_dlg_proc (HWND dlg, UINT msg, W
286          if (!lparam)          if (!lparam)
287              dlg_fatal_error (dlg, "Could not get dialog param!");              dlg_fatal_error (dlg, "Could not get dialog param!");
288          k = (winpt_key_t)lparam;          k = (winpt_key_t)lparam;
         #ifndef LANG_DE  
289          SetWindowText (dlg, _("Key Properties"));          SetWindowText (dlg, _("Key Properties"));
290          SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change"));          SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change"));
291          SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers"));          SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers"));
292          SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Passwd"));          SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Password"));
293          SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust"));          SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust"));
294          #endif            
295            display_key_info (dlg, k);
296          display_key_info (dlg, k, &key);          if (!keyprops_load_photo (dlg, k->ctx, &valid)) {
         if (!keyprops_load_photo (dlg, key, &valid)) {  
297              k->has_photo = 1;                k->has_photo = 1;  
298              if (valid < GPGME_VALIDITY_MARGINAL)              if (valid < GPGME_VALIDITY_MARGINAL)
299                  SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not validated."));                  SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not validated."));
300          }          }
301          if (k->key_pair)          if (k->key_pair)
302              EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE);              EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE);
303          if (check_for_desig_rev (key))          if (check_for_desig_rev (k->ctx))
304              EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE);              EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE);
305            if (k->ctx->revoked || k->ctx->expired)
306                EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_OT_CHANGE), FALSE);
307          center_window (dlg, NULL);          center_window (dlg, NULL);
308          SetForegroundWindow (dlg);                SetForegroundWindow (dlg);      
309          return TRUE;          return TRUE;
# Line 302  keyprops_dlg_proc (HWND dlg, UINT msg, W Line 319  keyprops_dlg_proc (HWND dlg, UINT msg, W
319    
320      case WM_SYSCOMMAND:      case WM_SYSCOMMAND:
321          if (LOWORD (wparam) == SC_CLOSE)          if (LOWORD (wparam) == SC_CLOSE)
322              EndDialog (dlg, TRUE);              EndDialog (dlg, FALSE);
323          return FALSE;          return FALSE;
324                    
325      case WM_COMMAND:      case WM_COMMAND:
# Line 310  keyprops_dlg_proc (HWND dlg, UINT msg, W Line 327  keyprops_dlg_proc (HWND dlg, UINT msg, W
327          case IDOK:          case IDOK:
328              EndDialog (dlg, TRUE);              EndDialog (dlg, TRUE);
329              return TRUE;              return TRUE;
330    
331            case IDCANCEL:
332                EndDialog (dlg, FALSE);
333                return TRUE;
334                            
335          case IDC_KEYPROPS_OT_CHANGE:          case IDC_KEYPROPS_OT_CHANGE:
336              if (do_check_key (key)) {              if (do_check_key (k->ctx)) {
337                  msg_box (dlg, _("The status of this key is 'revoked' or 'expired'.\n"                  msg_box (dlg, _("The status of this key is 'revoked' or 'expired'.\n"
338                                  "You cannot change the ownertrust of such keys."),                                  "You cannot change the ownertrust of such keys."),
339                                  _("WinPT Warning"), MB_ERR);                                  _("WinPT Warning"), MB_ERR);
340                  return TRUE;                  return TRUE;
341              }              }
342              if( !k->key_pair && key->uids->validity < 3 ) {              if (!k->key_pair && !key_is_valid (k->ctx)) {
343                  rc = msg_box( dlg, _("This is a non-valid key.\n"                  rc = msg_box (dlg, _("This is a non-valid key.\n"
344                                       "Modifying the ownertrust has no effect on such keys.\n\n"                                       "Modifying the ownertrust has no effect on such keys.\n\n"
345                                       "Do you really want to continue?"),                                       "Do you really want to continue?"),
346                                       _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );                                       _("WinPT Warning"), MB_ICONWARNING|MB_YESNO);
347                  if (rc == IDNO)                  if (rc == IDNO)
348                      return TRUE;                      return TRUE;
349              }              }
350              //GetDlgItemText (dlg, IDC_KEYPROPS_OT, info, sizeof info -1);              rc = dialog_box_param (glob_hinst,
351              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,                                     (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,
352                                dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,                                      dlg, keyedit_ownertrust_dlg_proc,
353                                (LPARAM)k, _("Change Ownertrust"),                                     (LPARAM)k, _("Change Ownertrust"),
354                                IDS_WINPT_KEYEDIT_OWNERTRUST);                                      IDS_WINPT_KEYEDIT_OWNERTRUST);
355              if (k->callback.new_val == -1) { /* Cancel */              if (rc == FALSE) /* Cancel */
356                  EndDialog (dlg, FALSE);                  return TRUE;
                 break;  
             }  
357    
358              inf = ownertrust_to_string (k->callback.new_val);              inf = ownertrust_to_string (k->callback.new_val, k->key_pair);
359              SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);              SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
360              msg_box (dlg, _("Ownertrust successfully changed."),              msg_box (dlg, _("Ownertrust successfully changed."),
361                       _("GnuPG Status"), MB_OK);                       _("GnuPG Status"), MB_OK);
362                            k->update = 1;
             /* XXX: modified ownertrust values can effect the entire  
                     WoT so we reload the cache. But this is very slow. */  
             memset (&rcs, 0, sizeof (rcs));  
             rcs.kr_reload = 1; rcs.kr_update = 1; /* reload only keylist */  
             DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,  
                             keycache_dlg_proc, (LPARAM)&rcs);  
363              return TRUE;              return TRUE;
364                            
365          case IDC_KEYPROPS_CHANGE_PWD:          case IDC_KEYPROPS_CHANGE_PWD:
# Line 354  keyprops_dlg_proc (HWND dlg, UINT msg, W Line 367  keyprops_dlg_proc (HWND dlg, UINT msg, W
367              return TRUE;              return TRUE;
368    
369          case IDC_KEYPROPS_REVOKERS:          case IDC_KEYPROPS_REVOKERS:
370              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,              k->update = dialog_box_param (
371                                key_revokers_dlg_proc, (LPARAM)key,                  glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,
372                                _("Key Revokers"), IDS_WINPT_KEY_REVOKERS);                  key_revokers_dlg_proc, (LPARAM)k,
373                    _("Key Revokers"), IDS_WINPT_KEY_REVOKERS);
374              break;              break;
375          }          }
376      }      }

Legend:
Removed from v.73  
changed lines
  Added in v.212

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26