/[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 310 by twoaday, Sat Apr 7 11:07:20 2007 UTC revision 328 by twoaday, Fri Sep 25 16:07:38 2009 UTC
# Line 1  Line 1 
1  /* wptKeyPropsDlg.cpp - WinPT key property dialog  /* wptKeyPropsDlg.cpp - WinPT key property dialog
2   *      Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006 Timo Schulz   *      Copyright (C) 2000-2003, 2005-2006, 2008 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 12  Line 12 
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.   * GNU General Public License for more details.
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  
15   */   */
16  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
17  #include <config.h>  #include <config.h>
# Line 38  Line 34 
34  #include "wptKeyEdit.h"  #include "wptKeyEdit.h"
35    
36    
37    /* Context to store associated data of the dialog. */
38    struct prop_info_s {
39        winpt_key_t key;
40        char photo_file[MAX_PATH+128+1];
41        bool has_photo;
42    };
43    
44    
45  /* Check that the key is not expired or revoked. */  /* Check that the key is not expired or revoked. */
46  static int  static int
47  do_check_key (gpgme_key_t key)  do_check_key (gpgme_key_t key)
# Line 76  ownertrust_to_string (int val, bool is_k Line 80  ownertrust_to_string (int val, bool is_k
80  }  }
81    
82    
83  /* Generate a unique temp name for the photo which  int
84     depends on the dialog handle and return it. */  get_photo_tmpname (gpgme_key_t key, char *buf, size_t buflen)
 const char*  
 get_photo_tmpname (HWND dlg)  
85  {  {
86      static char buf[MAX_PATH+128+1];      const char *fmt = "winpt_photo_%p.tmp";
87      char name[64];      char name[64];
88    
89      _snprintf (name, DIM (name)-1, "winpt_photo_%08lX.tmp", (DWORD)dlg);      if (buflen < (MAX_PATH+strlen(fmt)+8+1))
90      get_temp_name (buf, DIM (buf)-1, name);          return WPTERR_GENERAL;
91      return buf;      _snprintf (name, DIM (name)-1, fmt, key);
92  }      get_temp_name (buf, buflen-1, name);
93        return 0;
   
 static void  
 draw_nophoto_img (HWND dlg)  
 {  
     /*..  
     n = DrawText (hdc, "No Photo-ID", -1, &r, DT_LEFT);  
     ..*/  
94  }  }
95    
96    
97    
 /* Delete temporary photo file. */  
 void  
 key_unload_photo (HWND dlg)  
 {  
     DeleteFile (get_photo_tmpname (dlg));  
 }  
   
98    
99  /* Load the photo from the key @key */  /* Load the photo from the key @key */
100  int  int
101  key_load_photo (HWND dlg, gpgme_key_t key, gpgme_validity_t *r_valid)  key_load_photo (winpt_key_t key,
102                    char *photo_file, size_t photo_file_size,
103                    gpgme_validity_t *r_valid)
104  {  {
     winpt_key_s k;  
105      FILE *fp;      FILE *fp;
106      const BYTE *img;      const BYTE *img;
107      DWORD imglen;      DWORD imglen;
108        
109      if (winpt_get_pubkey (key->subkeys->keyid, &k))      img = key->ext->attrib.d;
110          BUG (0);      imglen = key->ext->attrib.len;
111      img = k.ext->attrib.d;      if (img && !key->ext->attrib.validity)
112      imglen = k.ext->attrib.len;          get_uat_validity (key->ctx->subkeys->keyid,
113      if (img && !k.ext->attrib.validity)                            &key->ext->attrib.validity);
         get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity);  
114      if (r_valid)      if (r_valid)
115          *r_valid = k.ext->attrib.validity;          *r_valid = key->ext->attrib.validity;
116    
117      if (!img || !imglen) {      if (!img || imglen < 1)
         draw_nophoto_img (dlg);  
118          return -1;          return -1;
119      }              
120        get_photo_tmpname (key->ctx, photo_file, photo_file_size);
121      fp = fopen (get_photo_tmpname (dlg), "wb");      fp = fopen (photo_file, "wb");
122      if (fp) {      if (fp != NULL) {
123          const int pos = 16;          const int pos = 16;
124          fwrite (img + pos, 1, imglen - pos, fp);          fwrite (img + pos, 1, imglen - pos, fp);
125          fclose (fp);          fclose (fp);
126            return 0;
127      }      }
128      return 0;      
129        return -1;    
130  }  }
131    
132    
# Line 157  get_validity (gpgme_key_t key) Line 146  get_validity (gpgme_key_t key)
146  }  }
147    
148    
 /* Return the preferred sym. algorithm from @key as a string. */  
 static const char*  
 get_pref_cipher (winpt_key_t k)  
 {  
     if (k->is_v3)  
         return "IDEA";  
     if (!k->ext || !k->ext->sym_prefs)  
         return "3DES";  
     switch (*k->ext->sym_prefs) {  
     case 1: return "IDEA";  
     case 2: return "3DES";  
     case 3: return "CAST5";  
     case 4: return "Blowfish";  
     case 7: return "AES128";  
     case 8: return "AES192";  
     case 9: return "AES256";  
     case 10:return "Twofish";  
     default:break;  
     }  
     return "Unknown";  
 }  
   
   
149  /* Return true if the key has designated revokers. */  /* Return true if the key has designated revokers. */
150  static bool  static bool
151  check_for_desig_rev (gpgme_key_t key)  check_for_desig_rev (gpgme_key_t key)
# Line 201  get_card_type (winpt_key_t k) Line 167  get_card_type (winpt_key_t k)
167    
168      if (!k->ext || !k->ext->card_type)      if (!k->ext || !k->ext->card_type)
169          return "";          return "";
170      _snprintf (buf, DIM (buf)-1, _("Card-Type: %s\r\n"), k->ext->card_type);      _snprintf (buf, DIM (buf)-1, _("Card-Type: %s\r\n"),
171                   k->ext->card_type);
172      return buf;      return buf;
173  }  }
174    
# Line 233  props_get_key_algo (gpgme_key_t key, int Line 200  props_get_key_algo (gpgme_key_t key, int
200  }  }
201    
202    
203  /* Display the key information for key @k.  /* Display the key information for key @k. */
    Return value: gpgme key on success. */  
204  static void  static void
205  display_key_info (HWND dlg, winpt_key_t k)  display_key_info (HWND dlg, winpt_key_t k)
206  {  {
# Line 259  display_key_info (HWND dlg, winpt_key_t Line 225  display_key_info (HWND dlg, winpt_key_t
225                 "Created: %s\r\n"                 "Created: %s\r\n"
226                 "Expires: %s\r\n"                 "Expires: %s\r\n"
227                 "Validity: %s\r\n"                 "Validity: %s\r\n"
                "Cipher: %s\r\n"  
228                 "%s\r\n"),                 "%s\r\n"),
229                 get_key_type (key),                 get_key_type (key),
230                 k->keyid,                 k->keyid,
# Line 268  display_key_info (HWND dlg, winpt_key_t Line 233  display_key_info (HWND dlg, winpt_key_t
233                 get_key_created (created),                 get_key_created (created),
234                 get_key_expire_date (expires),                 get_key_expire_date (expires),
235                 get_validity (key),                 get_validity (key),
                get_pref_cipher (k),  
236                 get_card_type (&sk));                 get_card_type (&sk));
237    
238      SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info);      SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info);
# Line 278  display_key_info (HWND dlg, winpt_key_t Line 242  display_key_info (HWND dlg, winpt_key_t
242  }  }
243    
244    
 /* Context to store associated data of the dialog. */  
 struct prop_info_s {  
     winpt_key_t key;  
 };  
   
245    
246  static void  static void
247  on_init_dialog (HWND dlg, WPARAM wparam, LPARAM lparam)  on_init_dialog (HWND dlg, WPARAM wparam, LPARAM lparam)
248  {  {
     gpgme_validity_t valid;  
   
249      winpt_key_t k = (winpt_key_t)lparam;      winpt_key_t k = (winpt_key_t)lparam;
250      assert (k != NULL);      assert (k != NULL);
251      SetWindowText (dlg, _("Key Properties"));      SetWindowText (dlg, _("Key Properties"));
252      SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change"));      SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change"));
253      SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers"));      SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers"));
254      SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Password"));      SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Password"));
255      SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust"));        SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust:"));
256        SetDlgItemText (dlg, IDC_KEYPROPS_FPRTXT, _("Fingerprint:"));
257            
258      display_key_info (dlg, k);      display_key_info (dlg, k);
259      if (!key_load_photo (dlg, k->ctx, &valid)) {      
         k->has_photo = 1;  
         if (valid < GPGME_VALIDITY_MARGINAL)  
             SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not validated."));  
     }  
260      if (k->key_pair)      if (k->key_pair)
261          EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE);          EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE);
262      if (check_for_desig_rev (k->ctx))      if (check_for_desig_rev (k->ctx))
# Line 320  keyprops_dlg_proc (HWND dlg, UINT msg, W Line 274  keyprops_dlg_proc (HWND dlg, UINT msg, W
274  {  {
275      struct prop_info_s *prop = NULL;      struct prop_info_s *prop = NULL;
276      const char *inf;      const char *inf;
277        gpgme_validity_t valid;
278      int rc;      int rc;
279            
280      if (msg != WM_INITDIALOG &&      if (msg != WM_INITDIALOG) {
281          (prop = (prop_info_s*)GetWindowLong (dlg, GWL_USERDATA)) == NULL)          prop = (struct prop_info_s*)GetWindowLong (dlg, GWL_USERDATA);
282          return FALSE;          if (prop == NULL)
283                return FALSE;
284        }
285    
286      switch (msg) {      switch (msg) {
287      case WM_INITDIALOG:      case WM_INITDIALOG:
288          assert (lparam != 0);          assert (lparam != 0);
289          prop = new struct prop_info_s;          prop = new struct prop_info_s;
290          prop->key = (winpt_key_t)lparam;          prop->key = (winpt_key_t)lparam;
291            prop->has_photo = 0;
292          SetWindowLong (dlg, GWL_USERDATA, (LONG)prop);          SetWindowLong (dlg, GWL_USERDATA, (LONG)prop);
293          on_init_dialog (dlg, wparam, lparam);          on_init_dialog (dlg, wparam, lparam);
294            if (!key_load_photo (prop->key,
295                                 prop->photo_file, DIM (prop->photo_file)-1,
296                                 &valid)) {
297                prop->key->has_photo = 1;
298                prop->has_photo = true;
299                if (valid < GPGME_VALIDITY_MARGINAL)
300                    SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF,
301                                    _("Photo-ID not validated."));
302            }
303          return TRUE;          return TRUE;
304    
305      case WM_DESTROY:      case WM_DESTROY:
306          key_unload_photo (dlg);          if (prop->has_photo)
307                DeleteFile(prop->photo_file);
308          delete prop;prop = NULL;          delete prop;prop = NULL;
309          SetWindowLong (dlg, GWL_USERDATA, 0);          SetWindowLong (dlg, GWL_USERDATA, 0);
310          break;          break;
# Line 344  keyprops_dlg_proc (HWND dlg, UINT msg, W Line 312  keyprops_dlg_proc (HWND dlg, UINT msg, W
312      case WM_PAINT:      case WM_PAINT:
313          /* Display the photo in the frame of the dialog @dlg.          /* Display the photo in the frame of the dialog @dlg.
314             The coordinates are fixed to (0,0). */             The coordinates are fixed to (0,0). */
315          if (prop->key->has_photo) {          if (prop->has_photo) {
316              POINT p;              POINT p;
317              p.x = p.y = 0;              p.x = p.y = 0;
318              PTD_jpg_show (GetDlgItem (dlg, IDC_KEYPROPS_IMG),              /* In case of errors we disable the flag to
319                            &p, get_photo_tmpname (dlg));                 avoid an infinite loop. */
320                if (jpg_show (GetDlgItem (dlg, IDC_KEYPROPS_IMG),
321                              &p, prop->photo_file))
322                    prop->has_photo = false;
323          }          }
324          break;          break;
325    
# Line 393  keyprops_dlg_proc (HWND dlg, UINT msg, W Line 364  keyprops_dlg_proc (HWND dlg, UINT msg, W
364    
365          case IDC_KEYPROPS_REVOKERS:          case IDC_KEYPROPS_REVOKERS:
366              prop->key->update = dialog_box_param (glob_hinst,              prop->key->update = dialog_box_param (glob_hinst,
367                                            (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,                                                    (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,
368                                            key_revokers_dlg_proc, (LPARAM)prop->key,                                                    key_revokers_dlg_proc,
369                                            _("Key Revokers"),                                                    (LPARAM)prop->key,
370                                            IDS_WINPT_KEY_REVOKERS);                                                    _("Key Revokers"),
371                                                      IDS_WINPT_KEY_REVOKERS);
372              UpdateWindow (dlg);              UpdateWindow (dlg);
373              break;              break;
374          }          }

Legend:
Removed from v.310  
changed lines
  Added in v.328

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26