/[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 2 by twoaday, Mon Jan 31 11:02:21 2005 UTC revision 28 by twoaday, Thu Oct 20 12:35:59 2005 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 Timo Schulz   *      Copyright (C) 2000, 2001, 2002, 2003, 2005 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 33  Line 33 
33  #include "wptVersion.h"  #include "wptVersion.h"
34  #include "wptKeyEdit.h"  #include "wptKeyEdit.h"
35    
 int keyedit_ownertrust_get_val (void);  
   
36    
37  static void  static void
38  do_change_ownertrust( winpt_key_t k, const char *s )  do_change_ownertrust (winpt_key_t k, const char *s)
39  {  {
40      char ot[64], *p;      char ot[64];
41            
42      if( strstr( s, "ultimate" ) ) {      if( strstr( s, "ultimate" ) ) {
43          listview_get_item_text( k->callback.ctl, k->callback.idx, 5, ot, sizeof ot-1 );          listview_get_item_text (k->callback.ctl, k->callback.idx, 5, ot, DIM (ot)-1);
44          if( (p = strrchr( ot, ']' )) )          strcpy (ot, "Ultimate");
45              strcpy( ot + (p - ot) + 2, "Ultimate" );          listview_add_sub_item (k->callback.ctl, k->callback.idx, 5, ot);
         else  
             strcpy( ot, "Ultimate" );  
         listview_add_sub_item( k->callback.ctl, k->callback.idx, 5, ot );  
46          /* fixme: If we switch back from Ultimate to a lower level */          /* fixme: If we switch back from Ultimate to a lower level */
47      }      }
48  } /* do_change_ownertrust */  } /* do_change_ownertrust */
49    
50    
51  static int  static int
52  do_check_key( gpgme_key_t key )  do_check_key (gpgme_key_t key)
53  {  {
54      int okay = 0;      int okay = 0;
55      okay = gpgme_key_get_ulong_attr( key, GPGME_ATTR_KEY_EXPIRED, NULL, 0 );      okay = key->expired;
56      if( !okay )      if (!okay)
57          okay = gpgme_key_get_ulong_attr( key, GPGME_ATTR_KEY_REVOKED, NULL, 0 );          okay = key->revoked;
58      return okay;      return okay;
59  } /* do_check_key */  } /* do_check_key */
60    
61    
62  static const char*  static const char*
63  ownertrust_to_string (gpgme_editkey_t ctx, int val)  ownertrust_to_string (int val)
64  {  {
65      const char * inf;      const char * inf;
66      int id;      int id = val;
       
     if (ctx)  
         id = keyedit_ownertrust_get_val ();  
     else if (!ctx && val)  
         id = val;  
67      switch (id) {      switch (id) {
68      case 1: inf = _("Don't know");         break;      case 1: inf = _("Don't know");         break;
69      case 2: inf = _("I do NOT trust");     break;      case 2: inf = _("I do NOT trust");     break;
# Line 88  ownertrust_to_string (gpgme_editkey_t ct Line 78  ownertrust_to_string (gpgme_editkey_t ct
78  } /* ownertrust_to_string */  } /* ownertrust_to_string */
79    
80    
81    #define PHOTO_TMPNAME "winpt_temp_photo.jpg"
82    
83  static int  static int
84  keyprops_show_photo (HWND dlg, gpgme_key_t key)  keyprops_show_photo (HWND dlg, gpgme_key_t key)
85  {  {
# Line 97  keyprops_show_photo (HWND dlg, gpgme_key Line 89  keyprops_show_photo (HWND dlg, gpgme_key
89      const BYTE *img;      const BYTE *img;
90      DWORD imglen = 0;      DWORD imglen = 0;
91      int pos=0;      int pos=0;
92        winpt_key_s k;
93    
94        winpt_get_pubkey (key->subkeys->keyid, &k);
95        img = k.ext->attrib.d;
96        imglen = k.ext->attrib.len;
97    
     img = (const byte *)gpgme_key_get_string_attr( key, GPGME_ATTR_PHOTO,  
                                                     (void **)&imglen, 0 );  
98      if (!img || !imglen)      if (!img || !imglen)
99          return -1;          return -1;
100      FILE * f = fopen ("temp.jpg", "wb");      FILE *f = fopen (PHOTO_TMPNAME, "wb");
101      if (f) {      if (f) {
102          for (pos = 0; img[pos] != 0x10; pos++)          for (pos = 0; img[pos] != 0x10; pos++)
103                  ;                  ;
# Line 116  keyprops_show_photo (HWND dlg, gpgme_key Line 111  keyprops_show_photo (HWND dlg, gpgme_key
111      GetWindowRect (h, &r);      GetWindowRect (h, &r);
112      p.x = r.left + 5;      p.x = r.left + 5;
113      p.y = r.top - 2;      p.y = r.top - 2;
114      memset (&p, 0, sizeof p);      memset (&p, 0, sizeof (p));
115      PTD_jpg_show (h, &p, "temp.jpg");      PTD_jpg_show (h, &p, PHOTO_TMPNAME);
116      unlink ("temp.jpg");      unlink (PHOTO_TMPNAME);
117    
118      return 0;      return 0;
119  }  }
120    
121    
122    /* Return string representation of the key validity. @key. */
123    static const char*
124    get_validity (gpgme_key_t key)
125    {
126        int val;
127        val = key->expired;
128        if (val)
129            return "Expired";      
130        val = key->revoked;
131        if (val)
132            return "Revoked";
133        return get_key_trust2 (NULL, key->uids->validity, 0, 0);
134    }
135    
136    
137    /* Return the preferred sym. algorithm from @key as a string. */
138    static const char*
139    get_pref_cipher (winpt_key_t k)
140    {
141        const char *sym_prefs=NULL;    
142    
143        if (k->is_v3)
144            return "IDEA";
145        if (!k->ext->sym_prefs)
146            return "3DES";
147        switch (*k->ext->sym_prefs) {
148        case 1: return "IDEA";
149        case 2: return "3DES";
150        case 3: return "CAST5";
151        case 4: return "Blowfish";
152        case 7:
153        case 8:
154        case 9: return "AES";
155        case 10:return "Twofish";
156        }
157        return "Unknown";
158    }
159    
160    
161    /* Return true if the key has designated revokers. */
162    static bool
163    check_for_desig_rev (gpgme_key_t key)
164    {
165        winpt_key_s k;
166        memset (&k, 0, sizeof (k));
167        if (!winpt_get_pubkey (key->subkeys->keyid, &k))
168            return k.ext->gloflags.has_desig_rev? true : false;
169        return false;
170    }
171    
172    
173    /* Print information (name) of the smart card. */
174    static const char*
175    get_card_type (winpt_key_t k)
176    {
177        static char buf[64];
178    
179        if (!k->ext->card_type)
180            return "";
181        _snprintf (buf, sizeof (buf)-1, "Card-Type: %s\r\n", k->ext->card_type);
182        return buf;
183    }
184    
185    
186    /* Dialog box procedure to show the key properties. */
187  BOOL CALLBACK  BOOL CALLBACK
188  keyprops_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )  keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
189  {  {
190      static winpt_key_t k;      static winpt_key_t k;
191      static gpgme_key_t key, sk;      static gpgme_key_t key, sk;
192      static int photo_done = 0;      static int photo_done = 0;
193      gpgme_editkey_t ek;      struct winpt_key_s k2;
     gpgme_ctx_t ctx;  
     gpgme_error_t ec;      
194      refresh_cache_s rcs = {0};      refresh_cache_s rcs = {0};
195      const char *inf;      const char *inf;
196      const char * sym_prefs;      char info[512];
     char info[2048], dummy_symprefs[] = {0x01, 0x00};  
197      u32 created, expires;      u32 created, expires;
198      int valid, ot, cancel = 0;      int ot, cancel = 0;
199      int rc;      int rc;
200            
201      switch (msg) {      switch (msg) {
202      case WM_INITDIALOG:      case WM_INITDIALOG:
203          if (!lparam)          if (!lparam)
204              dlg_fatal_error( dlg, "Could not get dialog param!" );              dlg_fatal_error (dlg, "Could not get dialog param!");
205          k = (winpt_key_t)lparam;          k = (winpt_key_t)lparam;
206          #ifndef LANG_DE          #ifndef LANG_DE
207          SetWindowText( dlg, _("Key Properties") );          SetWindowText( dlg, _("Key Properties") );
# Line 154  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 211  keyprops_dlg_proc( HWND dlg, UINT msg, W
211          #endif            #endif  
212    
213          photo_done = 0;          photo_done = 0;
214          get_seckey (k->keyid, &sk);          memset (&k2, 0, sizeof (k2));
215            if (k->key_pair)
216                winpt_get_seckey (k->keyid, &k2);
217            else
218                winpt_get_pubkey (k->keyid, &k2);
219            sk = k2.ctx;
220          if (sk)          if (sk)
221              k->is_protected = gpgme_key_get_ulong_attr( sk, GPGME_ATTR_IS_PROTECTED, NULL, 0 );              k->is_protected = k2.is_protected;
222          if (get_pubkey (k->keyid, &key))          if (get_pubkey (k->keyid, &key))
223              BUG (0);              BUG (0);
224          created = gpgme_key_get_ulong_attr( key, GPGME_ATTR_CREATED, NULL, 0 );          created = key->subkeys->timestamp;
225          expires = gpgme_key_get_ulong_attr( key, GPGME_ATTR_EXPIRES, NULL, 0 );          expires = key->subkeys->expires;
226          sym_prefs = gpgme_key_get_string_attr( key, GPGME_ATTR_KEY_SYMPREFS, NULL, 0 );          _snprintf (info, DIM (info)-1,
         if (!sym_prefs)  
             sym_prefs = dummy_symprefs;  
         valid = gpgme_key_get_ulong_attr (key, GPGME_ATTR_VALIDITY, NULL, 0);  
         _snprintf (info, sizeof info -1,  
227                    "Type: %s\r\n"                    "Type: %s\r\n"
228                    "Key ID: %s\r\n"                    "Key ID: %s\r\n"
229                    "Algorithm: %s\r\n"                    "Algorithm: %s\r\n"
# Line 173  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 231  keyprops_dlg_proc( HWND dlg, UINT msg, W
231                    "Created: %s\r\n"                    "Created: %s\r\n"
232                    "Expires: %s\r\n"                    "Expires: %s\r\n"
233                    "Validity: %s\r\n"                    "Validity: %s\r\n"
234                    "Cipher: %s\r\n",                    "Cipher: %s\r\n"
235                    get_key_type( key ),                    "%s\r\n",
236                    k->keyid,                    get_key_type (key),
237                    get_key_algo( key, 0 ),                    k->keyid,
238                    get_key_size( key, 0 ),                    get_key_algo (key, 0),
239                    get_key_created( created ),                    get_key_size (key, 0),
240                    get_key_expire_date( expires ),                    get_key_created (created),
241                    gpgme_key_expand_attr( GPGME_ATTR_VALIDITY, valid ),                    get_key_expire_date (expires),
242                    gpgme_key_expand_attr( GPGME_ATTR_KEY_SYMPREFS, *sym_prefs ) );                    get_validity (key),
243          SetDlgItemText( dlg, IDC_KEYPROPS_INFO, info );                    get_pref_cipher (&k2),
244          SetDlgItemText( dlg, IDC_KEYPROPS_FPR, get_key_fpr( key ) );                    get_card_type (&k2));
245            SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info);
246            SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key));
247          ot = gpgme_key_get_ulong_attr( key, GPGME_ATTR_OTRUST, NULL, 0 );                        ot = gpgme_key_get_ulong_attr( key, GPGME_ATTR_OTRUST, NULL, 0 );              
248          inf = ownertrust_to_string( NULL, ot );          inf = ownertrust_to_string (ot);
249          SetDlgItemText( dlg, IDC_KEYPROPS_OT, inf );          SetDlgItemText( dlg, IDC_KEYPROPS_OT, inf );
250          if( k->key_pair )          if (k->key_pair)
251              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_CHANGE_PWD ), TRUE );              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_CHANGE_PWD ), TRUE );
252          if( gpgme_key_count_items( key, GPGME_ATTR_REVKEY_FPR ) )          if (check_for_desig_rev (key))
253              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_REVOKERS ), TRUE );              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_REVOKERS ), TRUE );
254          center_window (dlg);          center_window (dlg, NULL);
255          SetForegroundWindow (dlg);                SetForegroundWindow (dlg);      
256          return TRUE;          return TRUE;
257                
# Line 220  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 280  keyprops_dlg_proc( HWND dlg, UINT msg, W
280                                  _("WinPT Warning"), MB_ERR );                                  _("WinPT Warning"), MB_ERR );
281                  return FALSE;                  return FALSE;
282              }              }
283              if( !k->key_pair && gpgme_key_get_ulong_attr( key, GPGME_ATTR_VALIDITY, NULL, 0 ) < 3 ) {              if( !k->key_pair && key->uids->validity < 3 ) {
284                  rc = msg_box( dlg, _("This is a non-valid key.\n"                  rc = msg_box( dlg, _("This is a non-valid key.\n"
285                                       "Modifying the ownertrust has no effect on such keys.\n"                                       "Modifying the ownertrust has no effect on such keys.\n\n"
286                                       "Do you really want to continue?"),                                       "Do you really want to continue?"),
287                                       _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );                                       _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );
288                  if (rc == IDNO)                  if (rc == IDNO)
289                      return FALSE;                      return FALSE;
290              }              }
291              GetDlgItemText( dlg, IDC_KEYPROPS_OT, info, sizeof info -1 );              GetDlgItemText( dlg, IDC_KEYPROPS_OT, info, sizeof info -1 );
292              gpgme_editkey_new( &ek );  
293              gpgme_editkey_is_secret( ek, k->key_pair );              
294              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,
295                               dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,                                dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,
296                               (LPARAM)ek, _("Change Ownertrust"),                                (LPARAM)k, _("Change Ownertrust"),
297                               IDS_WINPT_KEYEDIT_OWNERTRUST );                                IDS_WINPT_KEYEDIT_OWNERTRUST);
298              if (!gpgme_editkey_is_valid (ek))              if (k->callback.new_val == -1) { /* Cancel */
299                  return FALSE;                  EndDialog (dlg, FALSE);
300              ec = gpgme_new (&ctx);                  break;
301              if (ec)              }
302                  BUG (0);  
303              gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_TRUST );              inf = ownertrust_to_string (k->callback.new_val);
             ec = gpgme_op_editkey( ctx, k->keyid );  
             gpgme_editkey_release( ek );  
                 gpgme_release( ctx );  
             if( ec ) {  
                 msg_box( dlg, gpgme_strerror( ec ), _("Ownertrust"), MB_ERR );  
                 return FALSE;  
             }  
             inf = ownertrust_to_string (ek, 0);  
             k->callback.new_val = keyedit_ownertrust_get_val ();  
304              do_change_ownertrust (k, inf);              do_change_ownertrust (k, inf);
305              SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);              SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
306              msg_box (dlg, _("Ownertrust successfully changed."), _("GnuPG Status"), MB_OK);              msg_box (dlg, _("Ownertrust successfully changed."), _("GnuPG Status"), MB_OK);
# Line 259  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 310  keyprops_dlg_proc( HWND dlg, UINT msg, W
310              rcs.tr_update = 0;              rcs.tr_update = 0;
311              DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,              DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,
312                              keycache_dlg_proc, (LPARAM)&rcs );                              keycache_dlg_proc, (LPARAM)&rcs );
313                /* XXX: old code!?
314              get_seckey (k->keyid, &sk);              get_seckey (k->keyid, &sk);
315              if (get_pubkey (k->keyid, &key))              if (get_pubkey (k->keyid, &key))
316                  BUG (0);                  BUG (0);
317                */
318              return TRUE;              return TRUE;
319                            
320          case IDC_KEYPROPS_CHANGE_PWD:          case IDC_KEYPROPS_CHANGE_PWD:
# Line 269  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 322  keyprops_dlg_proc( HWND dlg, UINT msg, W
322              return TRUE;              return TRUE;
323    
324          case IDC_KEYPROPS_REVOKERS:                  case IDC_KEYPROPS_REVOKERS:        
325              dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,
326                                key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"),                                key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"),
327                                IDS_WINPT_KEY_REVOKERS );                                IDS_WINPT_KEY_REVOKERS);
328              break;              break;
329          }          }
330      }      }
331            
332      return FALSE;      return FALSE;
333  } /* keyprops_dlg_proc */  }
334    

Legend:
Removed from v.2  
changed lines
  Added in v.28

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26