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

Annotation of /trunk/Src/wptKeyPropsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 133 - (hide annotations)
Mon Jan 9 09:15:29 2006 UTC (19 years, 1 month ago) by twoaday
File size: 9958 byte(s)
A lot of minor bug fixes.
New icons.

For a complete history, see the ChangeLog entries.


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 twoaday 129 static void
86     draw_nophoto_img (HWND dlg)
87     {
88     /*..
89     n = DrawText (hdc, "No Photo-ID", -1, &r, DT_LEFT);
90     ..*/
91     }
92    
93    
94 werner 36 /* Load the photo from the key @key */
95     static int
96     keyprops_load_photo (HWND dlg, gpgme_key_t key, gpgme_validity_t *r_valid)
97     {
98     winpt_key_s k;
99     FILE *f;
100     const BYTE *img;
101     DWORD imglen = 0;
102     int pos=0;
103    
104     winpt_get_pubkey (key->subkeys->keyid, &k);
105     img = k.ext->attrib.d;
106     imglen = k.ext->attrib.len;
107     if (!k.ext->attrib.validity)
108     get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity);
109     *r_valid = k.ext->attrib.validity;
110    
111 twoaday 129 if (!img || !imglen) {
112     draw_nophoto_img (dlg);
113 werner 36 return -1;
114 twoaday 129 }
115 twoaday 133
116 werner 36 f = fopen (get_photo_tmpname (dlg), "wb");
117     if (f) {
118 twoaday 133 //for (pos = 0; img[pos] != 0x10; pos++)
119     // ;
120 werner 36 pos += 16;
121     fwrite (img + pos, 1, imglen - pos, f);
122     fclose (f);
123     }
124     return 0;
125     }
126    
127    
128     /* Display the photo in the image control in the dialog @dlg. */
129     static int
130     keyprops_show_photo (HWND dlg)
131     {
132     RECT r;
133     POINT p;
134     HWND h;
135    
136     h = GetDlgItem (dlg, IDC_KEYPROPS_IMG);
137     GetWindowRect (h, &r);
138     p.x = r.left + 5;
139     p.y = r.top - 2;
140     memset (&p, 0, sizeof (p));
141     PTD_jpg_show (h, &p, get_photo_tmpname (dlg));
142    
143     return 0;
144     }
145    
146    
147     /* Return string representation of the key validity. @key. */
148     static const char*
149     get_validity (gpgme_key_t key)
150     {
151     int val;
152     val = key->expired;
153     if (val)
154     return _("Expired");
155     val = key->revoked;
156     if (val)
157     return _("Revoked");
158 twoaday 41 val = key->disabled;
159     if (val)
160     return _("Disabled");
161 werner 36 return get_key_trust2 (NULL, key->uids->validity, 0, 0);
162     }
163    
164    
165     /* Return the preferred sym. algorithm from @key as a string. */
166     static const char*
167     get_pref_cipher (winpt_key_t k)
168     {
169     if (k->is_v3)
170     return "IDEA";
171     if (!k->ext->sym_prefs)
172     return "3DES";
173     switch (*k->ext->sym_prefs) {
174     case 1: return "IDEA";
175     case 2: return "3DES";
176     case 3: return "CAST5";
177     case 4: return "Blowfish";
178     case 7:
179     case 8:
180     case 9: return "AES";
181     case 10:return "Twofish";
182     }
183     return "Unknown";
184     }
185    
186    
187     /* Return true if the key has designated revokers. */
188     static bool
189     check_for_desig_rev (gpgme_key_t key)
190     {
191     winpt_key_s k;
192     memset (&k, 0, sizeof (k));
193     if (!winpt_get_pubkey (key->subkeys->keyid, &k))
194     return k.ext->gloflags.has_desig_rev? true : false;
195     return false;
196     }
197    
198    
199     /* Print information (name) of the smart card. */
200     static const char*
201     get_card_type (winpt_key_t k)
202     {
203     static char buf[64];
204    
205     if (!k->ext->card_type)
206     return "";
207     _snprintf (buf, sizeof (buf)-1, _("Card-Type: %s\r\n"), k->ext->card_type);
208     return buf;
209     }
210    
211    
212     /* Display the key information for key @k.
213     Return value: gpgme key on success. */
214     static void
215     display_key_info (HWND dlg, winpt_key_t k, gpgme_key_t *r_key)
216     {
217     struct winpt_key_s k2;
218     gpgme_key_t sk, key;
219     char info[512];
220     const char *inf;
221 twoaday 128 u32 created, expires;
222 werner 36
223     memset (&k2, 0, sizeof (k2));
224     if (k->key_pair)
225     winpt_get_seckey (k->keyid, &k2);
226     else
227     winpt_get_pubkey (k->keyid, &k2);
228 twoaday 128 sk = k2.ctx;
229 werner 36 if (sk)
230     k->is_protected = k2.is_protected;
231     if (get_pubkey (k->keyid, &key))
232     BUG (0);
233     created = key->subkeys->timestamp;
234     expires = key->subkeys->expires;
235     _snprintf (info, DIM (info)-1,
236     _("Type: %s\r\n"
237     "Key ID: %s\r\n"
238     "Algorithm: %s\r\n"
239 twoaday 128 "Size: %s bits\r\n"
240 werner 36 "Created: %s\r\n"
241     "Expires: %s\r\n"
242     "Validity: %s\r\n"
243     "Cipher: %s\r\n"
244     "%s\r\n"),
245     get_key_type (key),
246     k->keyid,
247     get_key_algo (key, 0),
248     get_key_size (key, 0),
249     get_key_created (created),
250     get_key_expire_date (expires),
251     get_validity (key),
252     get_pref_cipher (&k2),
253     get_card_type (&k2));
254    
255     SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info);
256     SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key));
257     inf = ownertrust_to_string (key->owner_trust);
258     SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
259    
260     *r_key = key;
261     }
262    
263    
264     /* Dialog box procedure to show the key properties. */
265     BOOL CALLBACK
266     keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
267     {
268     static winpt_key_t k;
269     static gpgme_key_t key;
270     gpgme_validity_t valid;
271     refresh_cache_s rcs = {0};
272     const char *inf;
273     int rc;
274    
275     /* XXX: static variable (k) prevent that the dialog can
276     be opened twice. */
277     switch (msg) {
278     case WM_INITDIALOG:
279     if (!lparam)
280     dlg_fatal_error (dlg, "Could not get dialog param!");
281     k = (winpt_key_t)lparam;
282     SetWindowText (dlg, _("Key Properties"));
283     SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change"));
284     SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers"));
285     SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Passwd"));
286     SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust"));
287    
288     display_key_info (dlg, k, &key);
289     if (!keyprops_load_photo (dlg, key, &valid)) {
290     k->has_photo = 1;
291     if (valid < GPGME_VALIDITY_MARGINAL)
292     SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not validated."));
293     }
294     if (k->key_pair)
295     EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE);
296     if (check_for_desig_rev (key))
297     EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE);
298     center_window (dlg, NULL);
299     SetForegroundWindow (dlg);
300     return TRUE;
301    
302     case WM_DESTROY:
303 werner 47 remove (get_photo_tmpname (dlg));
304 werner 36 break;
305    
306     case WM_PAINT:
307     if (k->has_photo)
308     keyprops_show_photo (dlg);
309     break;
310    
311     case WM_SYSCOMMAND:
312     if (LOWORD (wparam) == SC_CLOSE)
313     EndDialog (dlg, TRUE);
314     return FALSE;
315    
316     case WM_COMMAND:
317     switch (LOWORD (wparam)) {
318     case IDOK:
319     EndDialog (dlg, TRUE);
320     return TRUE;
321    
322     case IDC_KEYPROPS_OT_CHANGE:
323     if (do_check_key (key)) {
324     msg_box (dlg, _("The status of this key is 'revoked' or 'expired'.\n"
325     "You cannot change the ownertrust of such keys."),
326     _("WinPT Warning"), MB_ERR);
327     return TRUE;
328     }
329     if( !k->key_pair && key->uids->validity < 3 ) {
330     rc = msg_box( dlg, _("This is a non-valid key.\n"
331     "Modifying the ownertrust has no effect on such keys.\n\n"
332     "Do you really want to continue?"),
333     _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );
334     if (rc == IDNO)
335     return TRUE;
336     }
337     dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,
338     dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,
339     (LPARAM)k, _("Change Ownertrust"),
340     IDS_WINPT_KEYEDIT_OWNERTRUST);
341     if (k->callback.new_val == -1) { /* Cancel */
342     EndDialog (dlg, FALSE);
343     break;
344     }
345    
346     inf = ownertrust_to_string (k->callback.new_val);
347     SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
348     msg_box (dlg, _("Ownertrust successfully changed."),
349     _("GnuPG Status"), MB_OK);
350    
351 twoaday 41 /* XXX: modified ownertrust values can effect the entire
352     WoT so we reload the cache. But this is very slow. */
353     memset (&rcs, 0, sizeof (rcs));
354     rcs.kr_reload = 1; rcs.kr_update = 1; /* reload only keylist */
355 werner 36 DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,
356     keycache_dlg_proc, (LPARAM)&rcs);
357     return TRUE;
358    
359     case IDC_KEYPROPS_CHANGE_PWD:
360     keyedit_change_passwd (k, dlg);
361     return TRUE;
362    
363     case IDC_KEYPROPS_REVOKERS:
364     dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,
365 twoaday 41 key_revokers_dlg_proc, (LPARAM)key,
366     _("Key Revokers"), IDS_WINPT_KEY_REVOKERS);
367 werner 36 break;
368     }
369     }
370    
371     return FALSE;
372     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26