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

Annotation of /trunk/Src/wptKeyPropsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 34 - (hide annotations)
Wed Oct 26 11:20:09 2005 UTC (19 years, 4 months ago) by twoaday
File size: 10530 byte(s)
2005-10-25  Timo Schulz  <twoaday@g10code.com>
                                                                                
        * wptGPGUtil.cpp (create_process): Hide window.
        * wptKeyPropsDlg.cpp (get_photo_tmpname): New.
        * wptClipSignEncDlg.cpp (clip_signenc_dlg_proc): Remove
        static var 'enable'.
        * wptKeygenDlg.cpp (keygen_dlg_proc): Likewise.
        (gpg_genkey_params): Make sure all primary keys are capable
        for signing and certification.
        * wptKeySigDlg.cpp (is_sig): If no item is selected, return 0.
        * wptGPG.cpp (gnupg_access_keyring): Check return value for
        NULL. Noted by Ralf.
        (get_gnupg_prog): Simplified.
        (check_homedir): Fixed. Return 0 when the dir is successfully created.
        * wptKeyManagerDlg.cpp (km_file_import): Use the hourglass to
        indicate a pending GPG process.
        * wptFileManager.cpp (op_begin, op_end): New. Indicate an start
        and and of an operation. For now just the cursor changes.
        (fm_parse_command_line): Remove debug output. Thanks to Ralf again.
        * WinPT.cpp (WinMain): Check if there is already an instance and
        set a variable early as possible.
        (load_gettext): If a previous instance was found, do not output
        any errors. Kudos to Ralf.


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26