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

Annotation of /trunk/Src/wptKeyPropsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (hide annotations)
Mon Oct 24 08:03:48 2005 UTC (19 years, 4 months ago) by twoaday
File size: 9814 byte(s)
2005-10-23  Timo Schulz  <twoaday@g10code.com>
 
        * wptFileManager.cpp (fm_get_file_type): Detect detached sigs.
        * wptKeyList.cpp (keylist_cmp_cb): Take care of expired/revoked keys.
        (get_ext_validity): New.
        * wptFileVerifyDlg.cpp (file_verify_dlg_proc): Several cleanups.
        * wptClipEditDlg.cpp (load_clipboard): Factored out some code into
        this function.
        (load_clipboard_from_file): Likewise.
        (save_clipboard_to_file): New.
        * wptKeyManagerDlg.cpp (keyprops_dlg_proc): Fix stack overflow.

For complete details, see the ChangeLog files.

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    
37     static void
38 twoaday 22 do_change_ownertrust (winpt_key_t k, const char *s)
39 twoaday 2 {
40 twoaday 22 char ot[64];
41 twoaday 2
42     if( strstr( s, "ultimate" ) ) {
43 twoaday 22 listview_get_item_text (k->callback.ctl, k->callback.idx, 5, ot, DIM (ot)-1);
44     strcpy (ot, "Ultimate");
45     listview_add_sub_item (k->callback.ctl, k->callback.idx, 5, ot);
46 twoaday 2 /* fixme: If we switch back from Ultimate to a lower level */
47     }
48 twoaday 32 }
49 twoaday 2
50    
51 twoaday 32 /* Check that the key is not expired or revoked. */
52 twoaday 2 static int
53 twoaday 22 do_check_key (gpgme_key_t key)
54 twoaday 2 {
55     int okay = 0;
56 twoaday 23 okay = key->expired;
57 twoaday 22 if (!okay)
58 twoaday 23 okay = key->revoked;
59 twoaday 2 return okay;
60 twoaday 32 }
61 twoaday 2
62    
63 twoaday 32 /* Convert a trust integer into a string representation. */
64 twoaday 2 static const char*
65 twoaday 24 ownertrust_to_string (int val)
66 twoaday 2 {
67     const char * inf;
68 twoaday 24 int id = val;
69 twoaday 2 switch (id) {
70     case 1: inf = _("Don't know"); break;
71     case 2: inf = _("I do NOT trust"); break;
72     case 3: inf = _("I trust marginally"); break;
73     case 4: inf = _("I trust fully"); break;
74     case 5:
75     case 6: inf = _("I trust ultimately"); break;
76     default:inf = _("Unknown"); break;
77     }
78    
79     return inf;
80 twoaday 32 }
81 twoaday 2
82    
83 twoaday 22 #define PHOTO_TMPNAME "winpt_temp_photo.jpg"
84    
85 twoaday 32 /* Load the photo from the key @key */
86 twoaday 2 static int
87 twoaday 32 keyprops_load_photo (gpgme_key_t key)
88 twoaday 2 {
89 twoaday 32 winpt_key_s k;
90     FILE *f;
91 twoaday 2 const BYTE *img;
92     DWORD imglen = 0;
93     int pos=0;
94    
95 twoaday 23 winpt_get_pubkey (key->subkeys->keyid, &k);
96     img = k.ext->attrib.d;
97     imglen = k.ext->attrib.len;
98    
99 twoaday 2 if (!img || !imglen)
100     return -1;
101 twoaday 32 f = fopen (PHOTO_TMPNAME, "wb");
102 twoaday 2 if (f) {
103     for (pos = 0; img[pos] != 0x10; pos++)
104     ;
105     pos += 16;
106     fwrite (img + pos, 1, imglen - pos, f);
107     fwrite (img, 1, imglen, f);
108     fclose (f);
109     }
110 twoaday 32 return 0;
111     }
112 twoaday 2
113 twoaday 32
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 twoaday 2 h = GetDlgItem (dlg, IDC_KEYPROPS_IMG);
123     GetWindowRect (h, &r);
124     p.x = r.left + 5;
125     p.y = r.top - 2;
126 twoaday 22 memset (&p, 0, sizeof (p));
127     PTD_jpg_show (h, &p, PHOTO_TMPNAME);
128 twoaday 32
129 twoaday 2 return 0;
130     }
131    
132    
133 twoaday 23 /* Return string representation of the key validity. @key. */
134 twoaday 22 static const char*
135     get_validity (gpgme_key_t key)
136     {
137     int val;
138 twoaday 23 val = key->expired;
139 twoaday 22 if (val)
140 twoaday 32 return _("Expired");
141 twoaday 23 val = key->revoked;
142 twoaday 22 if (val)
143 twoaday 32 return _("Revoked");
144 twoaday 23 return get_key_trust2 (NULL, key->uids->validity, 0, 0);
145 twoaday 22 }
146    
147    
148 twoaday 24 /* Return the preferred sym. algorithm from @key as a string. */
149 twoaday 23 static const char*
150 twoaday 24 get_pref_cipher (winpt_key_t k)
151 twoaday 23 {
152 twoaday 24 const char *sym_prefs=NULL;
153    
154     if (k->is_v3)
155     return "IDEA";
156     if (!k->ext->sym_prefs)
157     return "3DES";
158     switch (*k->ext->sym_prefs) {
159 twoaday 23 case 1: return "IDEA";
160     case 2: return "3DES";
161 twoaday 24 case 3: return "CAST5";
162 twoaday 23 case 4: return "Blowfish";
163     case 7:
164     case 8:
165     case 9: return "AES";
166 twoaday 24 case 10:return "Twofish";
167 twoaday 23 }
168     return "Unknown";
169     }
170    
171    
172     /* Return true if the key has designated revokers. */
173     static bool
174     check_for_desig_rev (gpgme_key_t key)
175     {
176     winpt_key_s k;
177 twoaday 24 memset (&k, 0, sizeof (k));
178 twoaday 23 if (!winpt_get_pubkey (key->subkeys->keyid, &k))
179     return k.ext->gloflags.has_desig_rev? true : false;
180     return false;
181     }
182    
183    
184 twoaday 27 /* Print information (name) of the smart card. */
185     static const char*
186     get_card_type (winpt_key_t k)
187 twoaday 32 {
188 twoaday 27 static char buf[64];
189    
190     if (!k->ext->card_type)
191     return "";
192 twoaday 32 _snprintf (buf, sizeof (buf)-1, _("Card-Type: %s\r\n"), k->ext->card_type);
193 twoaday 27 return buf;
194     }
195    
196    
197 twoaday 32 /* 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 twoaday 23 /* Dialog box procedure to show the key properties. */
250 twoaday 2 BOOL CALLBACK
251 twoaday 23 keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
252 twoaday 2 {
253     static winpt_key_t k;
254 twoaday 32 static gpgme_key_t key;
255     static int has_photo = 0;
256 twoaday 2 refresh_cache_s rcs = {0};
257     const char *inf;
258 twoaday 32 int cancel = 0;
259 twoaday 2 int rc;
260    
261     switch (msg) {
262     case WM_INITDIALOG:
263     if (!lparam)
264 twoaday 28 dlg_fatal_error (dlg, "Could not get dialog param!");
265 twoaday 2 k = (winpt_key_t)lparam;
266     #ifndef LANG_DE
267 twoaday 32 SetWindowText (dlg, _("Key Properties"));
268 twoaday 2 SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change"));
269     SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers"));
270     SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Passwd"));
271     #endif
272    
273 twoaday 32 display_key_info (dlg, k, &key);
274     if (!keyprops_load_photo (key))
275     has_photo = 1;
276 twoaday 23 if (k->key_pair)
277 twoaday 32 EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE);
278 twoaday 23 if (check_for_desig_rev (key))
279 twoaday 32 EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE);
280 twoaday 23 center_window (dlg, NULL);
281 twoaday 2 SetForegroundWindow (dlg);
282     return TRUE;
283 twoaday 32
284     case WM_DESTROY:
285     has_photo = 0;
286     unlink (PHOTO_TMPNAME);
287     break;
288 twoaday 2
289 twoaday 32 case WM_PAINT:
290     if (has_photo)
291     keyprops_show_photo (dlg);
292 twoaday 2 break;
293    
294     case WM_SYSCOMMAND:
295 twoaday 32 if (LOWORD (wparam) == SC_CLOSE)
296     EndDialog (dlg, TRUE);
297 twoaday 2 return FALSE;
298    
299     case WM_COMMAND:
300 twoaday 32 switch (LOWORD (wparam)) {
301 twoaday 2 case IDOK:
302 twoaday 32 EndDialog (dlg, TRUE);
303 twoaday 2 return TRUE;
304    
305     case IDC_KEYPROPS_OT_CHANGE:
306 twoaday 32 if (do_check_key (key)) {
307     msg_box (dlg, _("The status of this key is 'revoked' or 'expired'.\n"
308     "You cannot change the ownertrust of such keys."),
309     _("WinPT Warning"), MB_ERR);
310     return TRUE;
311 twoaday 2 }
312 twoaday 23 if( !k->key_pair && key->uids->validity < 3 ) {
313 twoaday 2 rc = msg_box( dlg, _("This is a non-valid key.\n"
314 twoaday 23 "Modifying the ownertrust has no effect on such keys.\n\n"
315 twoaday 2 "Do you really want to continue?"),
316     _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );
317     if (rc == IDNO)
318 twoaday 32 return TRUE;
319 twoaday 2 }
320 twoaday 32 //GetDlgItemText (dlg, IDC_KEYPROPS_OT, info, sizeof info -1);
321 twoaday 23 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,
322     dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,
323 twoaday 24 (LPARAM)k, _("Change Ownertrust"),
324 twoaday 23 IDS_WINPT_KEYEDIT_OWNERTRUST);
325 twoaday 24 if (k->callback.new_val == -1) { /* Cancel */
326     EndDialog (dlg, FALSE);
327     break;
328     }
329    
330     inf = ownertrust_to_string (k->callback.new_val);
331 twoaday 2 do_change_ownertrust (k, inf);
332     SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
333 twoaday 32 msg_box (dlg, _("Ownertrust successfully changed."),
334     _("GnuPG Status"), MB_OK);
335 twoaday 2
336     /* reload only the keylist */
337     rcs.kr_reload = 1; rcs.kr_update = 1;
338     rcs.tr_update = 0;
339 twoaday 32 DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,
340     keycache_dlg_proc, (LPARAM)&rcs);
341 twoaday 2 return TRUE;
342    
343     case IDC_KEYPROPS_CHANGE_PWD:
344     keyedit_change_passwd (k, dlg);
345     return TRUE;
346    
347 twoaday 32 case IDC_KEYPROPS_REVOKERS:
348 twoaday 23 dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,
349     key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"),
350     IDS_WINPT_KEY_REVOKERS);
351 twoaday 2 break;
352     }
353     }
354    
355     return FALSE;
356 twoaday 23 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26