/[winpt]/trunk/Src/wptKeyPropsDlg.cpp
ViewVC logotype

Annotation of /trunk/Src/wptKeyPropsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (hide annotations)
Mon Dec 19 13:05:59 2005 UTC (19 years, 2 months ago) by twoaday
File size: 9829 byte(s)
2005-12-17  Timo Schulz  <ts@g10code.com>
 
        * wptUTF8.cpp: Removed unused charset array.
        * wptSigList.cpp (siglist_build): Increase size for 'class'
        column.
        * wptGPG.cpp (get_gnupg_path): Simplified.
        * WinPT.cpp (load_gpg_env): New.
        (check_crypto_engine): Return type is now bool.
        * wptRegistry.cpp (is_gpg4win_installed): New.
        * wptGPGPrefsDlg.cpp (gpgprefs_dlg_proc): More consistent
        dialog design.
        * wptKeyManagerDlg.cpp (translate_menu_strings): New.
        (translate_popupmenu_strings): New.
        * wptKeyEditDlgs.cpp (is_jpg_file): New.


1 werner 36 /* wptKeyPropsDlg.cpp - WinPT key properties dialog
2     * Copyright (C) 2000, 2001, 2002, 2003, 2005 Timo Schulz
3     *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * WinPT is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with WinPT; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
20 werner 42 #ifdef HAVE_CONFIG_H
21     #include <config.h>
22     #endif
23    
24 werner 36 #include <windows.h>
25    
26 werner 47 #include "resource.h"
27 werner 36 #include "wptErrors.h"
28     #include "wptGPG.h"
29     #include "wptCommonCtl.h"
30     #include "wptContext.h" /* for passphrase_s */
31     #include "wptNLS.h"
32     #include "wptDlgs.h"
33     #include "wptTypes.h"
34     #include "wptKeylist.h"
35     #include "wptW32API.h"
36     #include "wptVersion.h"
37     #include "wptKeyEdit.h"
38    
39    
40     /* Check that the key is not expired or revoked. */
41     static int
42     do_check_key (gpgme_key_t key)
43     {
44     int okay = 0;
45     okay = key->expired;
46     if (!okay)
47     okay = key->revoked;
48     return okay;
49     }
50    
51    
52     /* Convert a trust integer into a string representation. */
53     static const char*
54     ownertrust_to_string (int val)
55     {
56 twoaday 41 const char *inf;
57 werner 36 int id = val;
58 twoaday 41
59 werner 36 switch (id) {
60     case 1: inf = _("Don't know"); break;
61     case 2: inf = _("I do NOT trust"); break;
62     case 3: inf = _("I trust marginally"); break;
63     case 4: inf = _("I trust fully"); break;
64     case 5:
65     case 6: inf = _("I trust ultimately"); break;
66     default:inf = _("Unknown"); break;
67     }
68    
69     return inf;
70     }
71    
72    
73     /* Generate a unique temp name for the photo which
74     depends on the dialog handle and return it. */
75     static const char*
76     get_photo_tmpname (HWND dlg)
77     {
78     static char buf[64];
79    
80     _snprintf (buf, sizeof (buf)-1, "winpt_photo_%08lX.tmp", (DWORD)dlg);
81     return buf;
82     }
83    
84    
85     /* Load the photo from the key @key */
86     static int
87     keyprops_load_photo (HWND dlg, gpgme_key_t key, gpgme_validity_t *r_valid)
88     {
89     winpt_key_s k;
90     FILE *f;
91     const BYTE *img;
92     DWORD imglen = 0;
93     int pos=0;
94    
95     winpt_get_pubkey (key->subkeys->keyid, &k);
96     img = k.ext->attrib.d;
97     imglen = k.ext->attrib.len;
98     if (!k.ext->attrib.validity)
99     get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity);
100     *r_valid = k.ext->attrib.validity;
101    
102     if (!img || !imglen)
103     return -1;
104     f = fopen (get_photo_tmpname (dlg), "wb");
105     if (f) {
106     for (pos = 0; img[pos] != 0x10; pos++)
107     ;
108     pos += 16;
109     fwrite (img + pos, 1, imglen - pos, f);
110     fwrite (img, 1, imglen, f);
111     fclose (f);
112     }
113     return 0;
114     }
115    
116    
117     /* Display the photo in the image control in the dialog @dlg. */
118     static int
119     keyprops_show_photo (HWND dlg)
120     {
121     RECT r;
122     POINT p;
123     HWND h;
124    
125     h = GetDlgItem (dlg, IDC_KEYPROPS_IMG);
126     GetWindowRect (h, &r);
127     p.x = r.left + 5;
128     p.y = r.top - 2;
129     memset (&p, 0, sizeof (p));
130     PTD_jpg_show (h, &p, get_photo_tmpname (dlg));
131    
132     return 0;
133     }
134    
135    
136     /* Return string representation of the key validity. @key. */
137     static const char*
138     get_validity (gpgme_key_t key)
139     {
140     int val;
141     val = key->expired;
142     if (val)
143     return _("Expired");
144     val = key->revoked;
145     if (val)
146     return _("Revoked");
147 twoaday 41 val = key->disabled;
148     if (val)
149     return _("Disabled");
150 werner 36 return get_key_trust2 (NULL, key->uids->validity, 0, 0);
151     }
152    
153    
154     /* Return the preferred sym. algorithm from @key as a string. */
155     static const char*
156     get_pref_cipher (winpt_key_t k)
157     {
158     if (k->is_v3)
159     return "IDEA";
160     if (!k->ext->sym_prefs)
161     return "3DES";
162     switch (*k->ext->sym_prefs) {
163     case 1: return "IDEA";
164     case 2: return "3DES";
165     case 3: return "CAST5";
166     case 4: return "Blowfish";
167     case 7:
168     case 8:
169     case 9: return "AES";
170     case 10:return "Twofish";
171     }
172     return "Unknown";
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     memset (&k, 0, sizeof (k));
182     if (!winpt_get_pubkey (key->subkeys->keyid, &k))
183     return k.ext->gloflags.has_desig_rev? true : false;
184     return false;
185     }
186    
187    
188     /* Print information (name) of the smart card. */
189     static const char*
190     get_card_type (winpt_key_t k)
191     {
192     static char buf[64];
193    
194     if (!k->ext->card_type)
195     return "";
196     _snprintf (buf, sizeof (buf)-1, _("Card-Type: %s\r\n"), k->ext->card_type);
197     return buf;
198     }
199    
200    
201     /* Display the key information for key @k.
202     Return value: gpgme key on success. */
203     static void
204     display_key_info (HWND dlg, winpt_key_t k, gpgme_key_t *r_key)
205     {
206     struct winpt_key_s k2;
207     gpgme_key_t sk, key;
208     char info[512];
209     const char *inf;
210 twoaday 128 u32 created, expires;
211 werner 36
212     memset (&k2, 0, sizeof (k2));
213     if (k->key_pair)
214     winpt_get_seckey (k->keyid, &k2);
215     else
216     winpt_get_pubkey (k->keyid, &k2);
217 twoaday 128 sk = k2.ctx;
218 werner 36 if (sk)
219     k->is_protected = k2.is_protected;
220     if (get_pubkey (k->keyid, &key))
221     BUG (0);
222     created = key->subkeys->timestamp;
223     expires = key->subkeys->expires;
224     _snprintf (info, DIM (info)-1,
225     _("Type: %s\r\n"
226     "Key ID: %s\r\n"
227     "Algorithm: %s\r\n"
228 twoaday 128 "Size: %s bits\r\n"
229 werner 36 "Created: %s\r\n"
230     "Expires: %s\r\n"
231     "Validity: %s\r\n"
232     "Cipher: %s\r\n"
233     "%s\r\n"),
234     get_key_type (key),
235     k->keyid,
236     get_key_algo (key, 0),
237     get_key_size (key, 0),
238     get_key_created (created),
239     get_key_expire_date (expires),
240     get_validity (key),
241     get_pref_cipher (&k2),
242     get_card_type (&k2));
243    
244     SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info);
245     SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key));
246     inf = ownertrust_to_string (key->owner_trust);
247     SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
248    
249     *r_key = key;
250     }
251    
252    
253     /* Dialog box procedure to show the key properties. */
254     BOOL CALLBACK
255     keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
256     {
257     static winpt_key_t k;
258     static gpgme_key_t key;
259     gpgme_validity_t valid;
260     refresh_cache_s rcs = {0};
261     const char *inf;
262     int rc;
263    
264     /* XXX: static variable (k) prevent that the dialog can
265     be opened twice. */
266     switch (msg) {
267     case WM_INITDIALOG:
268     if (!lparam)
269     dlg_fatal_error (dlg, "Could not get dialog param!");
270     k = (winpt_key_t)lparam;
271     SetWindowText (dlg, _("Key Properties"));
272     SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change"));
273     SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers"));
274     SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Passwd"));
275     SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust"));
276    
277     display_key_info (dlg, k, &key);
278     if (!keyprops_load_photo (dlg, key, &valid)) {
279     k->has_photo = 1;
280     if (valid < GPGME_VALIDITY_MARGINAL)
281     SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not validated."));
282     }
283     if (k->key_pair)
284     EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE);
285     if (check_for_desig_rev (key))
286     EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE);
287     center_window (dlg, NULL);
288     SetForegroundWindow (dlg);
289     return TRUE;
290    
291     case WM_DESTROY:
292 werner 47 remove (get_photo_tmpname (dlg));
293 werner 36 break;
294    
295     case WM_PAINT:
296     if (k->has_photo)
297     keyprops_show_photo (dlg);
298     break;
299    
300     case WM_SYSCOMMAND:
301     if (LOWORD (wparam) == SC_CLOSE)
302     EndDialog (dlg, TRUE);
303     return FALSE;
304    
305     case WM_COMMAND:
306     switch (LOWORD (wparam)) {
307     case IDOK:
308     EndDialog (dlg, TRUE);
309     return TRUE;
310    
311     case IDC_KEYPROPS_OT_CHANGE:
312     if (do_check_key (key)) {
313     msg_box (dlg, _("The status of this key is 'revoked' or 'expired'.\n"
314     "You cannot change the ownertrust of such keys."),
315     _("WinPT Warning"), MB_ERR);
316     return TRUE;
317     }
318     if( !k->key_pair && key->uids->validity < 3 ) {
319     rc = msg_box( dlg, _("This is a non-valid key.\n"
320     "Modifying the ownertrust has no effect on such keys.\n\n"
321     "Do you really want to continue?"),
322     _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );
323     if (rc == IDNO)
324     return TRUE;
325     }
326     dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,
327     dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,
328     (LPARAM)k, _("Change Ownertrust"),
329     IDS_WINPT_KEYEDIT_OWNERTRUST);
330     if (k->callback.new_val == -1) { /* Cancel */
331     EndDialog (dlg, FALSE);
332     break;
333     }
334    
335     inf = ownertrust_to_string (k->callback.new_val);
336     SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
337     msg_box (dlg, _("Ownertrust successfully changed."),
338     _("GnuPG Status"), MB_OK);
339    
340 twoaday 41 /* XXX: modified ownertrust values can effect the entire
341     WoT so we reload the cache. But this is very slow. */
342     memset (&rcs, 0, sizeof (rcs));
343     rcs.kr_reload = 1; rcs.kr_update = 1; /* reload only keylist */
344 werner 36 DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,
345     keycache_dlg_proc, (LPARAM)&rcs);
346     return TRUE;
347    
348     case IDC_KEYPROPS_CHANGE_PWD:
349     keyedit_change_passwd (k, dlg);
350     return TRUE;
351    
352     case IDC_KEYPROPS_REVOKERS:
353     dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,
354 twoaday 41 key_revokers_dlg_proc, (LPARAM)key,
355     _("Key Revokers"), IDS_WINPT_KEY_REVOKERS);
356 werner 36 break;
357     }
358     }
359    
360     return FALSE;
361     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26