/[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 23 by twoaday, Fri Sep 30 10:10:16 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 (GpgKeyEdit *ctx, int val)
64  {  {
65      const char * inf;      const char * inf;
66      int id;      int id;
67            
68      if (ctx)      if (ctx)
69          id = keyedit_ownertrust_get_val ();          id = ctx->trust_id;
70      else if (!ctx && val)      else if (!ctx && val)
71          id = val;          id = val;
72      switch (id) {      switch (id) {
# Line 96  keyprops_show_photo (HWND dlg, gpgme_key Line 94  keyprops_show_photo (HWND dlg, gpgme_key
94      const BYTE *img;      const BYTE *img;
95      DWORD imglen = 0;      DWORD imglen = 0;
96      int pos=0;      int pos=0;
97        winpt_key_s k;
98    
99        winpt_get_pubkey (key->subkeys->keyid, &k);
100        img = k.ext->attrib.d;
101        imglen = k.ext->attrib.len;
102    
     img = (const byte *)gpgme_key_get_string_attr (key, GPGME_ATTR_PHOTO,  
                                                    (void **)&imglen, 0);  
103      if (!img || !imglen)      if (!img || !imglen)
104          return -1;          return -1;
105      FILE *f = fopen (PHOTO_TMPNAME, "wb");      FILE *f = fopen (PHOTO_TMPNAME, "wb");
# Line 123  keyprops_show_photo (HWND dlg, gpgme_key Line 124  keyprops_show_photo (HWND dlg, gpgme_key
124  }  }
125    
126    
127    /* Return string representation of the key validity. @key. */
128  static const char*  static const char*
129  get_validity (gpgme_key_t key)  get_validity (gpgme_key_t key)
130  {  {
131      int val;      int val;
132      val = gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_EXPIRED, NULL, 0);      val = key->expired;
133      if (val)      if (val)
134          return "Expired";                return "Expired";      
135      val = gpgme_key_get_ulong_attr( key, GPGME_ATTR_KEY_REVOKED, NULL, 0 );      val = key->revoked;
136      if (val)      if (val)
137          return "Revoked";          return "Revoked";
138      val = gpgme_key_get_ulong_attr (key, GPGME_ATTR_VALIDITY, NULL, 0);      return get_key_trust2 (NULL, key->uids->validity, 0, 0);
139      return gpgme_key_expand_attr (GPGME_ATTR_VALIDITY, val);  }
140    
141    
142    /* Return string representation of cipher @algo. */
143    static const char*
144    get_pref_str_cipher (int algo)
145    {
146        /* XXX: finish the code */
147        switch (algo) {
148        case 1: return "IDEA";
149        case 2: return "3DES";
150        case 4: return "Blowfish";
151        case 7:
152        case 8:
153        case 9: return "AES";
154        case 10: return "Twofish";
155        }
156        return "Unknown";
157  }  }
158    
159    
160    /* Return the preferred sym. algorithm from @key. */
161    static const char*
162    get_pref_cipher (gpgme_key_t key)
163    {
164        const char *sym_prefs=NULL;
165        winpt_key_s k;
166    
167        winpt_get_seckey (key->subkeys->keyid, &k);
168        if (k.is_v3)
169            return "IDEA";
170        if (!k.ext->sym_prefs)
171            return "3DES";
172        return get_pref_str_cipher (*k.ext->sym_prefs);
173    }
174    
175    
176    /* Return true if the key has designated revokers. */
177    static bool
178    check_for_desig_rev (gpgme_key_t key)
179    {
180        winpt_key_s k;
181        if (!winpt_get_pubkey (key->subkeys->keyid, &k))
182            return k.ext->gloflags.has_desig_rev? true : false;
183        return false;
184    }
185    
186    
187    /* Dialog box procedure to show the key properties. */
188  BOOL CALLBACK  BOOL CALLBACK
189  keyprops_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )  keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
190  {  {
191      static winpt_key_t k;      static winpt_key_t k;
192      static gpgme_key_t key, sk;      static gpgme_key_t key, sk;
193      static int photo_done = 0;      static int photo_done = 0;
194      gpgme_editkey_t ek;      struct winpt_key_s k2;
195      gpgme_ctx_t ctx;      GpgKeyEdit *ek;
     gpgme_error_t ec;      
196      refresh_cache_s rcs = {0};      refresh_cache_s rcs = {0};
197      const char *inf;      const char *inf;
198      const char * sym_prefs;      char info[2048];
     char info[2048], dummy_symprefs[] = {0x01, 0x00};  
199      u32 created, expires;      u32 created, expires;
200      int ot, cancel = 0;      int ot, cancel = 0;
201      int rc;      int rc;
# Line 168  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 213  keyprops_dlg_proc( HWND dlg, UINT msg, W
213          #endif            #endif  
214    
215          photo_done = 0;          photo_done = 0;
216          get_seckey (k->keyid, &sk);          winpt_get_seckey (k->keyid, &k2);
217            sk = k2.ctx;
218          if (sk)          if (sk)
219              k->is_protected = gpgme_key_get_ulong_attr( sk, GPGME_ATTR_IS_PROTECTED, NULL, 0 );              k->is_protected = k2.is_protected;
220          if (get_pubkey (k->keyid, &key))          if (get_pubkey (k->keyid, &key))
221              BUG (0);              BUG (0);
222          created = gpgme_key_get_ulong_attr( key, GPGME_ATTR_CREATED, NULL, 0 );          created = key->subkeys->timestamp;
223          expires = gpgme_key_get_ulong_attr( key, GPGME_ATTR_EXPIRES, NULL, 0 );          expires = key->subkeys->expires;
224          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,  
225                    "Type: %s\r\n"                    "Type: %s\r\n"
226                    "Key ID: %s\r\n"                    "Key ID: %s\r\n"
227                    "Algorithm: %s\r\n"                    "Algorithm: %s\r\n"
# Line 187  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 230  keyprops_dlg_proc( HWND dlg, UINT msg, W
230                    "Expires: %s\r\n"                    "Expires: %s\r\n"
231                    "Validity: %s\r\n"                    "Validity: %s\r\n"
232                    "Cipher: %s\r\n",                    "Cipher: %s\r\n",
233                    get_key_type( key ),                    get_key_type (key),
234                    k->keyid,                    k->keyid,
235                    get_key_algo( key, 0 ),                    get_key_algo (key, 0),
236                    get_key_size( key, 0 ),                    get_key_size (key, 0),
237                    get_key_created( created ),                    get_key_created (created),
238                    get_key_expire_date( expires ),                    get_key_expire_date (expires),
239                    get_validity (key),                    get_validity (key),
240                    gpgme_key_expand_attr( GPGME_ATTR_KEY_SYMPREFS, *sym_prefs ) );                    get_pref_cipher (key));
241          SetDlgItemText( dlg, IDC_KEYPROPS_INFO, info );          SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info);
242          SetDlgItemText( dlg, IDC_KEYPROPS_FPR, get_key_fpr( key ) );          SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key));
243          ot = gpgme_key_get_ulong_attr( key, GPGME_ATTR_OTRUST, NULL, 0 );                        ot = gpgme_key_get_ulong_attr( key, GPGME_ATTR_OTRUST, NULL, 0 );              
244          inf = ownertrust_to_string( NULL, ot );          inf = ownertrust_to_string (NULL, ot);
245          SetDlgItemText( dlg, IDC_KEYPROPS_OT, inf );          SetDlgItemText( dlg, IDC_KEYPROPS_OT, inf );
246          if( k->key_pair )          if (k->key_pair)
247              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_CHANGE_PWD ), TRUE );              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_CHANGE_PWD ), TRUE );
248          if( gpgme_key_count_items( key, GPGME_ATTR_REVKEY_FPR ) )          if (check_for_desig_rev (key))
249              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_REVOKERS ), TRUE );              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_REVOKERS ), TRUE );
250          center_window (dlg);          center_window (dlg, NULL);
251          SetForegroundWindow (dlg);                SetForegroundWindow (dlg);      
252          return TRUE;          return TRUE;
253                
# Line 233  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 276  keyprops_dlg_proc( HWND dlg, UINT msg, W
276                                  _("WinPT Warning"), MB_ERR );                                  _("WinPT Warning"), MB_ERR );
277                  return FALSE;                  return FALSE;
278              }              }
279              if( !k->key_pair && gpgme_key_get_ulong_attr( key, GPGME_ATTR_VALIDITY, NULL, 0 ) < 3 ) {              if( !k->key_pair && key->uids->validity < 3 ) {
280                  rc = msg_box( dlg, _("This is a non-valid key.\n"                  rc = msg_box( dlg, _("This is a non-valid key.\n"
281                                       "Modifying the ownertrust has no effect on such keys.\n"                                       "Modifying the ownertrust has no effect on such keys.\n\n"
282                                       "Do you really want to continue?"),                                       "Do you really want to continue?"),
283                                       _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );                                       _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );
284                  if (rc == IDNO)                  if (rc == IDNO)
285                      return FALSE;                      return FALSE;
286              }              }
287              GetDlgItemText( dlg, IDC_KEYPROPS_OT, info, sizeof info -1 );              GetDlgItemText( dlg, IDC_KEYPROPS_OT, info, sizeof info -1 );
288              gpgme_editkey_new( &ek );  
289              gpgme_editkey_is_secret( ek, k->key_pair );              ek = new GpgKeyEdit (k->keyid);
290              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,
291                               dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,                                dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,
292                               (LPARAM)ek, _("Change Ownertrust"),                                (LPARAM)ek, _("Change Ownertrust"),
293                               IDS_WINPT_KEYEDIT_OWNERTRUST );                                IDS_WINPT_KEYEDIT_OWNERTRUST);
294              if (!gpgme_editkey_is_valid (ek))              
                 return FALSE;  
             ec = gpgme_new (&ctx);  
             if (ec)  
                 BUG (0);  
             gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_TRUST );  
             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;  
             }  
295              inf = ownertrust_to_string (ek, 0);              inf = ownertrust_to_string (ek, 0);
296              k->callback.new_val = keyedit_ownertrust_get_val ();              k->callback.new_val = ek->trust_id;
297              do_change_ownertrust (k, inf);              do_change_ownertrust (k, inf);
298              SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);              SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
299              msg_box (dlg, _("Ownertrust successfully changed."), _("GnuPG Status"), MB_OK);              msg_box (dlg, _("Ownertrust successfully changed."), _("GnuPG Status"), MB_OK);
# Line 275  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 306  keyprops_dlg_proc( HWND dlg, UINT msg, W
306              get_seckey (k->keyid, &sk);              get_seckey (k->keyid, &sk);
307              if (get_pubkey (k->keyid, &key))              if (get_pubkey (k->keyid, &key))
308                  BUG (0);                  BUG (0);
309                delete ek;
310              return TRUE;              return TRUE;
311                            
312          case IDC_KEYPROPS_CHANGE_PWD:          case IDC_KEYPROPS_CHANGE_PWD:
# Line 282  keyprops_dlg_proc( HWND dlg, UINT msg, W Line 314  keyprops_dlg_proc( HWND dlg, UINT msg, W
314              return TRUE;              return TRUE;
315    
316          case IDC_KEYPROPS_REVOKERS:                  case IDC_KEYPROPS_REVOKERS:        
317              dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,
318                                key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"),                                key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"),
319                                IDS_WINPT_KEY_REVOKERS );                                IDS_WINPT_KEY_REVOKERS);
320              break;              break;
321          }          }
322      }      }
323            
324      return FALSE;      return FALSE;
325  } /* keyprops_dlg_proc */  }
326    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26