/[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 22 by twoaday, Wed Aug 10 11:33:35 2005 UTC revision 26 by twoaday, Mon Oct 17 08:49:30 2005 UTC
# 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)
# Line 54  static int Line 52  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 96  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 (PHOTO_TMPNAME, "wb");      FILE *f = fopen (PHOTO_TMPNAME, "wb");
# Line 123  keyprops_show_photo (HWND dlg, gpgme_key Line 119  keyprops_show_photo (HWND dlg, gpgme_key
119  }  }
120    
121    
122    /* Return string representation of the key validity. @key. */
123  static const char*  static const char*
124  get_validity (gpgme_key_t key)  get_validity (gpgme_key_t key)
125  {  {
126      int val;      int val;
127      val = gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_EXPIRED, NULL, 0);      val = key->expired;
128      if (val)      if (val)
129          return "Expired";                return "Expired";      
130      val = gpgme_key_get_ulong_attr( key, GPGME_ATTR_KEY_REVOKED, NULL, 0 );      val = key->revoked;
131      if (val)      if (val)
132          return "Revoked";          return "Revoked";
133      val = gpgme_key_get_ulong_attr (key, GPGME_ATTR_VALIDITY, NULL, 0);      return get_key_trust2 (NULL, key->uids->validity, 0, 0);
134      return gpgme_key_expand_attr (GPGME_ATTR_VALIDITY, val);  }
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    /* Dialog box procedure to show the key properties. */
174  BOOL CALLBACK  BOOL CALLBACK
175  keyprops_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )  keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
176  {  {
177      static winpt_key_t k;      static winpt_key_t k;
178      static gpgme_key_t key, sk;      static gpgme_key_t key, sk;
179      static int photo_done = 0;      static int photo_done = 0;
180      gpgme_editkey_t ek;      struct winpt_key_s k2;
     gpgme_ctx_t ctx;  
     gpgme_error_t ec;      
181      refresh_cache_s rcs = {0};      refresh_cache_s rcs = {0};
182      const char *inf;      const char *inf;
183      const char * sym_prefs;      char info[512];
     char info[2048], dummy_symprefs[] = {0x01, 0x00};  
184      u32 created, expires;      u32 created, expires;
185      int ot, cancel = 0;      int ot, cancel = 0;
186      int rc;      int rc;
# Line 168  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 198  keyprops_dlg_proc( HWND dlg, UINT msg, W
198          #endif            #endif  
199    
200          photo_done = 0;          photo_done = 0;
201          get_seckey (k->keyid, &sk);          memset (&k2, 0, sizeof (k2));
202            if (k->key_pair)
203                winpt_get_seckey (k->keyid, &k2);
204            else
205                winpt_get_pubkey (k->keyid, &k2);
206            sk = k2.ctx;
207          if (sk)          if (sk)
208              k->is_protected = gpgme_key_get_ulong_attr( sk, GPGME_ATTR_IS_PROTECTED, NULL, 0 );              k->is_protected = k2.is_protected;
209          if (get_pubkey (k->keyid, &key))          if (get_pubkey (k->keyid, &key))
210              BUG (0);              BUG (0);
211          created = gpgme_key_get_ulong_attr( key, GPGME_ATTR_CREATED, NULL, 0 );          created = key->subkeys->timestamp;
212          expires = gpgme_key_get_ulong_attr( key, GPGME_ATTR_EXPIRES, NULL, 0 );          expires = key->subkeys->expires;
213          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;        
         _snprintf (info, sizeof info -1,  
214                    "Type: %s\r\n"                    "Type: %s\r\n"
215                    "Key ID: %s\r\n"                    "Key ID: %s\r\n"
216                    "Algorithm: %s\r\n"                    "Algorithm: %s\r\n"
# Line 187  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 219  keyprops_dlg_proc( HWND dlg, UINT msg, W
219                    "Expires: %s\r\n"                    "Expires: %s\r\n"
220                    "Validity: %s\r\n"                    "Validity: %s\r\n"
221                    "Cipher: %s\r\n",                    "Cipher: %s\r\n",
222                    get_key_type( key ),                    get_key_type (key),
223                    k->keyid,                    k->keyid,
224                    get_key_algo( key, 0 ),                    get_key_algo (key, 0),
225                    get_key_size( key, 0 ),                    get_key_size (key, 0),
226                    get_key_created( created ),                    get_key_created (created),
227                    get_key_expire_date( expires ),                    get_key_expire_date (expires),
228                    get_validity (key),                    get_validity (key),
229                    gpgme_key_expand_attr( GPGME_ATTR_KEY_SYMPREFS, *sym_prefs ) );                    get_pref_cipher (&k2));
230          SetDlgItemText( dlg, IDC_KEYPROPS_INFO, info );          SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info);
231          SetDlgItemText( dlg, IDC_KEYPROPS_FPR, get_key_fpr( key ) );          SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key));
232          ot = gpgme_key_get_ulong_attr( key, GPGME_ATTR_OTRUST, NULL, 0 );                        ot = gpgme_key_get_ulong_attr( key, GPGME_ATTR_OTRUST, NULL, 0 );              
233          inf = ownertrust_to_string( NULL, ot );          inf = ownertrust_to_string (ot);
234          SetDlgItemText( dlg, IDC_KEYPROPS_OT, inf );          SetDlgItemText( dlg, IDC_KEYPROPS_OT, inf );
235          if( k->key_pair )          if (k->key_pair)
236              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_CHANGE_PWD ), TRUE );              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_CHANGE_PWD ), TRUE );
237          if( gpgme_key_count_items( key, GPGME_ATTR_REVKEY_FPR ) )          if (check_for_desig_rev (key))
238              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_REVOKERS ), TRUE );              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_REVOKERS ), TRUE );
239          center_window (dlg);          center_window (dlg, NULL);
240          SetForegroundWindow (dlg);                SetForegroundWindow (dlg);      
241          return TRUE;          return TRUE;
242                
# Line 233  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 265  keyprops_dlg_proc( HWND dlg, UINT msg, W
265                                  _("WinPT Warning"), MB_ERR );                                  _("WinPT Warning"), MB_ERR );
266                  return FALSE;                  return FALSE;
267              }              }
268              if( !k->key_pair && gpgme_key_get_ulong_attr( key, GPGME_ATTR_VALIDITY, NULL, 0 ) < 3 ) {              if( !k->key_pair && key->uids->validity < 3 ) {
269                  rc = msg_box( dlg, _("This is a non-valid key.\n"                  rc = msg_box( dlg, _("This is a non-valid key.\n"
270                                       "Modifying the ownertrust has no effect on such keys.\n"                                       "Modifying the ownertrust has no effect on such keys.\n\n"
271                                       "Do you really want to continue?"),                                       "Do you really want to continue?"),
272                                       _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );                                       _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );
273                  if (rc == IDNO)                  if (rc == IDNO)
274                      return FALSE;                      return FALSE;
275              }              }
276              GetDlgItemText( dlg, IDC_KEYPROPS_OT, info, sizeof info -1 );              GetDlgItemText( dlg, IDC_KEYPROPS_OT, info, sizeof info -1 );
277              gpgme_editkey_new( &ek );  
278              gpgme_editkey_is_secret( ek, k->key_pair );              
279              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,
280                               dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,                                dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,
281                               (LPARAM)ek, _("Change Ownertrust"),                                (LPARAM)k, _("Change Ownertrust"),
282                               IDS_WINPT_KEYEDIT_OWNERTRUST );                                IDS_WINPT_KEYEDIT_OWNERTRUST);
283              if (!gpgme_editkey_is_valid (ek))              if (k->callback.new_val == -1) { /* Cancel */
284                  return FALSE;                  EndDialog (dlg, FALSE);
285              ec = gpgme_new (&ctx);                  break;
286              if (ec)              }
287                  BUG (0);  
288              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 ();  
289              do_change_ownertrust (k, inf);              do_change_ownertrust (k, inf);
290              SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);              SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
291              msg_box (dlg, _("Ownertrust successfully changed."), _("GnuPG Status"), MB_OK);              msg_box (dlg, _("Ownertrust successfully changed."), _("GnuPG Status"), MB_OK);
# Line 272  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 295  keyprops_dlg_proc( HWND dlg, UINT msg, W
295              rcs.tr_update = 0;              rcs.tr_update = 0;
296              DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,              DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,
297                              keycache_dlg_proc, (LPARAM)&rcs );                              keycache_dlg_proc, (LPARAM)&rcs );
298                /* XXX: old code!?
299              get_seckey (k->keyid, &sk);              get_seckey (k->keyid, &sk);
300              if (get_pubkey (k->keyid, &key))              if (get_pubkey (k->keyid, &key))
301                  BUG (0);                  BUG (0);
302                */
303              return TRUE;              return TRUE;
304                            
305          case IDC_KEYPROPS_CHANGE_PWD:          case IDC_KEYPROPS_CHANGE_PWD:
# Line 282  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 307  keyprops_dlg_proc( HWND dlg, UINT msg, W
307              return TRUE;              return TRUE;
308    
309          case IDC_KEYPROPS_REVOKERS:                  case IDC_KEYPROPS_REVOKERS:        
310              dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,
311                                key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"),                                key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"),
312                                IDS_WINPT_KEY_REVOKERS );                                IDS_WINPT_KEY_REVOKERS);
313              break;              break;
314          }          }
315      }      }
316            
317      return FALSE;      return FALSE;
318  } /* keyprops_dlg_proc */  }
319    

Legend:
Removed from v.22  
changed lines
  Added in v.26

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26