/[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 26 by twoaday, Mon Oct 17 08:49:30 2005 UTC revision 32 by twoaday, Mon Oct 24 08:03:48 2005 UTC
# Line 45  do_change_ownertrust (winpt_key_t k, con Line 45  do_change_ownertrust (winpt_key_t k, con
45          listview_add_sub_item (k->callback.ctl, k->callback.idx, 5, ot);          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 */  }
49    
50    
51    /* Check that the key is not expired or revoked. */
52  static int  static int
53  do_check_key (gpgme_key_t key)  do_check_key (gpgme_key_t key)
54  {  {
# Line 56  do_check_key (gpgme_key_t key) Line 57  do_check_key (gpgme_key_t key)
57      if (!okay)      if (!okay)
58          okay = key->revoked;          okay = key->revoked;
59      return okay;      return okay;
60  } /* do_check_key */  }
61    
62    
63    /* Convert a trust integer into a string representation. */
64  static const char*  static const char*
65  ownertrust_to_string (int val)  ownertrust_to_string (int val)
66  {  {
# Line 75  ownertrust_to_string (int val) Line 77  ownertrust_to_string (int val)
77      }      }
78            
79      return inf;      return inf;
80  } /* ownertrust_to_string */  }
81    
82    
83  #define PHOTO_TMPNAME "winpt_temp_photo.jpg"  #define PHOTO_TMPNAME "winpt_temp_photo.jpg"
84    
85    /* Load the photo from the key @key */
86  static int  static int
87  keyprops_show_photo (HWND dlg, gpgme_key_t key)  keyprops_load_photo (gpgme_key_t key)
88  {  {
89      RECT r;          winpt_key_s k;
90      POINT p;      FILE *f;
     HWND h;  
91      const BYTE *img;      const BYTE *img;
92      DWORD imglen = 0;      DWORD imglen = 0;
93      int pos=0;      int pos=0;
     winpt_key_s k;  
94    
95      winpt_get_pubkey (key->subkeys->keyid, &k);      winpt_get_pubkey (key->subkeys->keyid, &k);
96      img = k.ext->attrib.d;      img = k.ext->attrib.d;
# Line 97  keyprops_show_photo (HWND dlg, gpgme_key Line 98  keyprops_show_photo (HWND dlg, gpgme_key
98    
99      if (!img || !imglen)      if (!img || !imglen)
100          return -1;          return -1;
101      FILE *f = fopen (PHOTO_TMPNAME, "wb");      f = fopen (PHOTO_TMPNAME, "wb");
102      if (f) {      if (f) {
103          for (pos = 0; img[pos] != 0x10; pos++)          for (pos = 0; img[pos] != 0x10; pos++)
104                  ;                  ;
# Line 106  keyprops_show_photo (HWND dlg, gpgme_key Line 107  keyprops_show_photo (HWND dlg, gpgme_key
107          fwrite (img, 1, imglen, f);          fwrite (img, 1, imglen, f);
108          fclose (f);          fclose (f);
109      }      }
110        return 0;
111    }
112    
113    
114    /* Display the photo in the image control in the dialog @dlg. */
115    static int
116    keyprops_show_photo (HWND dlg)
117    {
118        RECT r;    
119        POINT p;
120        HWND h;
121    
122      h = GetDlgItem (dlg, IDC_KEYPROPS_IMG);      h = GetDlgItem (dlg, IDC_KEYPROPS_IMG);
123      GetWindowRect (h, &r);      GetWindowRect (h, &r);
# Line 113  keyprops_show_photo (HWND dlg, gpgme_key Line 125  keyprops_show_photo (HWND dlg, gpgme_key
125      p.y = r.top - 2;      p.y = r.top - 2;
126      memset (&p, 0, sizeof (p));      memset (&p, 0, sizeof (p));
127      PTD_jpg_show (h, &p, PHOTO_TMPNAME);      PTD_jpg_show (h, &p, PHOTO_TMPNAME);
128      unlink (PHOTO_TMPNAME);      
   
129      return 0;      return 0;
130  }  }
131    
# Line 126  get_validity (gpgme_key_t key) Line 137  get_validity (gpgme_key_t key)
137      int val;      int val;
138      val = key->expired;      val = key->expired;
139      if (val)      if (val)
140          return "Expired";                return _("Expired");    
141      val = key->revoked;      val = key->revoked;
142      if (val)      if (val)
143          return "Revoked";          return _("Revoked");
144      return get_key_trust2 (NULL, key->uids->validity, 0, 0);      return get_key_trust2 (NULL, key->uids->validity, 0, 0);
145  }  }
146    
# Line 170  check_for_desig_rev (gpgme_key_t key) Line 181  check_for_desig_rev (gpgme_key_t key)
181  }  }
182    
183    
184    /* Print information (name) of the smart card. */
185    static const char*
186    get_card_type (winpt_key_t k)
187    {    
188        static char buf[64];
189    
190        if (!k->ext->card_type)
191            return "";
192        _snprintf (buf, sizeof (buf)-1, _("Card-Type: %s\r\n"), k->ext->card_type);
193        return buf;
194    }
195    
196    
197    /* Display the key information for key @k.
198       Return value: gpgme key on success. */
199    static void
200    display_key_info (HWND dlg, winpt_key_t k, gpgme_key_t *r_key)
201    {
202        struct winpt_key_s k2;
203        gpgme_key_t sk, key;
204        char info[512];
205        const char *inf;
206        u32 created, expires;    
207    
208        memset (&k2, 0, sizeof (k2));      
209        if (k->key_pair)
210            winpt_get_seckey (k->keyid, &k2);
211        else    
212            winpt_get_pubkey (k->keyid, &k2);
213        sk = k2.ctx;        
214        if (sk)
215            k->is_protected = k2.is_protected;
216        if (get_pubkey (k->keyid, &key))
217            BUG (0);    
218        created = key->subkeys->timestamp;  
219        expires = key->subkeys->expires;    
220        _snprintf (info, DIM (info)-1,
221                   _("Type: %s\r\n"
222                   "Key ID: %s\r\n"
223                   "Algorithm: %s\r\n"
224                   "Size: %s\r\n"
225                   "Created: %s\r\n"
226                   "Expires: %s\r\n"
227                   "Validity: %s\r\n"
228                   "Cipher: %s\r\n"
229                   "%s\r\n"),
230                   get_key_type (key),
231                   k->keyid,
232                   get_key_algo (key, 0),
233                   get_key_size (key, 0),
234                   get_key_created (created),
235                   get_key_expire_date (expires),
236                   get_validity (key),
237                   get_pref_cipher (&k2),
238                   get_card_type (&k2));
239    
240        SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info);
241        SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key));  
242        inf = ownertrust_to_string (key->owner_trust);
243        SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
244    
245        *r_key = key;
246    }
247    
248    
249  /* Dialog box procedure to show the key properties. */  /* Dialog box procedure to show the key properties. */
250  BOOL CALLBACK  BOOL CALLBACK
251  keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
252  {  {
253      static winpt_key_t k;      static winpt_key_t k;
254      static gpgme_key_t key, sk;      static gpgme_key_t key;
255      static int photo_done = 0;      static int has_photo = 0;
     struct winpt_key_s k2;  
256      refresh_cache_s rcs = {0};      refresh_cache_s rcs = {0};
257      const char *inf;      const char *inf;
258      char info[512];      int cancel = 0;
     u32 created, expires;  
     int ot, cancel = 0;  
259      int rc;      int rc;
260            
261      switch (msg) {      switch (msg) {
262      case WM_INITDIALOG:      case WM_INITDIALOG:
263          if (!lparam)          if (!lparam)
264              dlg_fatal_error( dlg, "Could not get dialog param!" );              dlg_fatal_error (dlg, "Could not get dialog param!");
265          k = (winpt_key_t)lparam;          k = (winpt_key_t)lparam;
266          #ifndef LANG_DE          #ifndef LANG_DE
267          SetWindowText( dlg, _("Key Properties") );          SetWindowText (dlg, _("Key Properties"));
268          SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change"));          SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change"));
269          SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers"));          SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers"));
270          SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Passwd"));          SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Passwd"));
271          #endif            #endif  
272    
273          photo_done = 0;          display_key_info (dlg, k, &key);
274          memset (&k2, 0, sizeof (k2));          if (!keyprops_load_photo (key))
275          if (k->key_pair)              has_photo = 1;
             winpt_get_seckey (k->keyid, &k2);  
         else  
             winpt_get_pubkey (k->keyid, &k2);  
         sk = k2.ctx;  
         if (sk)  
             k->is_protected = k2.is_protected;  
         if (get_pubkey (k->keyid, &key))  
             BUG (0);  
         created = key->subkeys->timestamp;  
         expires = key->subkeys->expires;  
         _snprintf (info, DIM (info)-1,  
                   "Type: %s\r\n"  
                   "Key ID: %s\r\n"  
                   "Algorithm: %s\r\n"  
                   "Size: %s\r\n"  
                   "Created: %s\r\n"  
                   "Expires: %s\r\n"  
                   "Validity: %s\r\n"  
                   "Cipher: %s\r\n",  
                   get_key_type (key),  
                   k->keyid,  
                   get_key_algo (key, 0),  
                   get_key_size (key, 0),  
                   get_key_created (created),  
                   get_key_expire_date (expires),  
                   get_validity (key),  
                   get_pref_cipher (&k2));  
         SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info);  
         SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key));  
         ot = gpgme_key_get_ulong_attr( key, GPGME_ATTR_OTRUST, NULL, 0 );                
         inf = ownertrust_to_string (ot);  
         SetDlgItemText( dlg, IDC_KEYPROPS_OT, inf );  
276          if (k->key_pair)          if (k->key_pair)
277              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_CHANGE_PWD ), TRUE );              EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE);
278          if (check_for_desig_rev (key))          if (check_for_desig_rev (key))
279              EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_REVOKERS ), TRUE );              EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE);
280          center_window (dlg, NULL);          center_window (dlg, NULL);
281          SetForegroundWindow (dlg);                SetForegroundWindow (dlg);      
282          return TRUE;          return TRUE;
283    
284        case WM_DESTROY:
285            has_photo = 0;
286            unlink (PHOTO_TMPNAME);
287            break;
288                
289      case WM_PAINT:            case WM_PAINT:
290          if (photo_done == 0) {          if (has_photo)
291              photo_done = 1;              keyprops_show_photo (dlg);
             keyprops_show_photo (dlg, key);  
         }  
292          break;          break;
293    
294      case WM_SYSCOMMAND:      case WM_SYSCOMMAND:
295          if( LOWORD( wparam ) == SC_CLOSE )          if (LOWORD (wparam) == SC_CLOSE)
296              EndDialog( dlg, TRUE );              EndDialog (dlg, TRUE);
297          return FALSE;          return FALSE;
298                    
299      case WM_COMMAND:      case WM_COMMAND:
300          switch( LOWORD( wparam ) ) {          switch (LOWORD (wparam)) {
301          case IDOK:          case IDOK:
302              EndDialog( dlg, TRUE );              EndDialog (dlg, TRUE);
303              return TRUE;              return TRUE;
304                            
305          case IDC_KEYPROPS_OT_CHANGE:          case IDC_KEYPROPS_OT_CHANGE:
306              if( do_check_key( key ) ) {              if (do_check_key (key)) {
307                  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"
308                                  "You cannot change the ownertrust of such keys."),                                  "You cannot change the ownertrust of such keys."),
309                                  _("WinPT Warning"), MB_ERR );                                  _("WinPT Warning"), MB_ERR);
310                  return FALSE;                  return TRUE;
311              }              }
312              if( !k->key_pair && key->uids->validity < 3 ) {              if( !k->key_pair && key->uids->validity < 3 ) {
313                  rc = msg_box( dlg, _("This is a non-valid key.\n"                  rc = msg_box( dlg, _("This is a non-valid key.\n"
# Line 271  keyprops_dlg_proc (HWND dlg, UINT msg, W Line 315  keyprops_dlg_proc (HWND dlg, UINT msg, W
315                                       "Do you really want to continue?"),                                       "Do you really want to continue?"),
316                                       _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );                                       _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );
317                  if (rc == IDNO)                  if (rc == IDNO)
318                      return FALSE;                      return TRUE;
319              }              }
320              GetDlgItemText( dlg, IDC_KEYPROPS_OT, info, sizeof info -1 );              //GetDlgItemText (dlg, IDC_KEYPROPS_OT, info, sizeof info -1);
   
               
321              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,
322                                dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,                                dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,
323                                (LPARAM)k, _("Change Ownertrust"),                                (LPARAM)k, _("Change Ownertrust"),
# Line 288  keyprops_dlg_proc (HWND dlg, UINT msg, W Line 330  keyprops_dlg_proc (HWND dlg, UINT msg, W
330              inf = ownertrust_to_string (k->callback.new_val);              inf = ownertrust_to_string (k->callback.new_val);
331              do_change_ownertrust (k, inf);              do_change_ownertrust (k, inf);
332              SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);              SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
333              msg_box (dlg, _("Ownertrust successfully changed."), _("GnuPG Status"), MB_OK);              msg_box (dlg, _("Ownertrust successfully changed."),
334                         _("GnuPG Status"), MB_OK);
335                            
336              /* reload only the keylist */              /* reload only the keylist */
337              rcs.kr_reload = 1; rcs.kr_update = 1;              rcs.kr_reload = 1; rcs.kr_update = 1;
338              rcs.tr_update = 0;              rcs.tr_update = 0;
339              DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,              DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,
340                              keycache_dlg_proc, (LPARAM)&rcs );                              keycache_dlg_proc, (LPARAM)&rcs);
             /* XXX: old code!?  
             get_seckey (k->keyid, &sk);  
             if (get_pubkey (k->keyid, &key))  
                 BUG (0);  
             */  
341              return TRUE;              return TRUE;
342                            
343          case IDC_KEYPROPS_CHANGE_PWD:          case IDC_KEYPROPS_CHANGE_PWD:
344              keyedit_change_passwd (k, dlg);                      keyedit_change_passwd (k, dlg);        
345              return TRUE;              return TRUE;
346    
347          case IDC_KEYPROPS_REVOKERS:                  case IDC_KEYPROPS_REVOKERS:
348              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,
349                                key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"),                                key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"),
350                                IDS_WINPT_KEY_REVOKERS);                                IDS_WINPT_KEY_REVOKERS);
# Line 316  keyprops_dlg_proc (HWND dlg, UINT msg, W Line 354  keyprops_dlg_proc (HWND dlg, UINT msg, W
354            
355      return FALSE;      return FALSE;
356  }  }
   

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26