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

Annotation of /trunk/Src/wptKeyPropsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 27 - (hide annotations)
Tue Oct 18 07:57:13 2005 UTC (19 years, 4 months ago) by twoaday
File size: 9482 byte(s)
Some bug fixes and adjustments for the latest
GPGME changes.

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     } /* do_change_ownertrust */
49    
50    
51     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     } /* do_check_key */
60    
61    
62     static const char*
63 twoaday 24 ownertrust_to_string (int val)
64 twoaday 2 {
65     const char * inf;
66 twoaday 24 int id = val;
67 twoaday 2 switch (id) {
68     case 1: inf = _("Don't know"); break;
69     case 2: inf = _("I do NOT trust"); break;
70     case 3: inf = _("I trust marginally"); break;
71     case 4: inf = _("I trust fully"); break;
72     case 5:
73     case 6: inf = _("I trust ultimately"); break;
74     default:inf = _("Unknown"); break;
75     }
76    
77     return inf;
78     } /* ownertrust_to_string */
79    
80    
81 twoaday 22 #define PHOTO_TMPNAME "winpt_temp_photo.jpg"
82    
83 twoaday 2 static int
84     keyprops_show_photo (HWND dlg, gpgme_key_t key)
85     {
86     RECT r;
87     POINT p;
88     HWND h;
89     const BYTE *img;
90     DWORD imglen = 0;
91     int pos=0;
92 twoaday 23 winpt_key_s k;
93 twoaday 2
94 twoaday 23 winpt_get_pubkey (key->subkeys->keyid, &k);
95     img = k.ext->attrib.d;
96     imglen = k.ext->attrib.len;
97    
98 twoaday 2 if (!img || !imglen)
99     return -1;
100 twoaday 22 FILE *f = fopen (PHOTO_TMPNAME, "wb");
101 twoaday 2 if (f) {
102     for (pos = 0; img[pos] != 0x10; pos++)
103     ;
104     pos += 16;
105     fwrite (img + pos, 1, imglen - pos, f);
106     fwrite (img, 1, imglen, f);
107     fclose (f);
108     }
109    
110     h = GetDlgItem (dlg, IDC_KEYPROPS_IMG);
111     GetWindowRect (h, &r);
112     p.x = r.left + 5;
113     p.y = r.top - 2;
114 twoaday 22 memset (&p, 0, sizeof (p));
115     PTD_jpg_show (h, &p, PHOTO_TMPNAME);
116     unlink (PHOTO_TMPNAME);
117 twoaday 2
118     return 0;
119     }
120    
121    
122 twoaday 23 /* Return string representation of the key validity. @key. */
123 twoaday 22 static const char*
124     get_validity (gpgme_key_t key)
125     {
126     int val;
127 twoaday 23 val = key->expired;
128 twoaday 22 if (val)
129     return "Expired";
130 twoaday 23 val = key->revoked;
131 twoaday 22 if (val)
132     return "Revoked";
133 twoaday 23 return get_key_trust2 (NULL, key->uids->validity, 0, 0);
134 twoaday 22 }
135    
136    
137 twoaday 24 /* Return the preferred sym. algorithm from @key as a string. */
138 twoaday 23 static const char*
139 twoaday 24 get_pref_cipher (winpt_key_t k)
140 twoaday 23 {
141 twoaday 24 const char *sym_prefs=NULL;
142    
143     if (k->is_v3)
144     return "IDEA";
145     if (!k->ext->sym_prefs)
146     return "3DES";
147     switch (*k->ext->sym_prefs) {
148 twoaday 23 case 1: return "IDEA";
149     case 2: return "3DES";
150 twoaday 24 case 3: return "CAST5";
151 twoaday 23 case 4: return "Blowfish";
152     case 7:
153     case 8:
154     case 9: return "AES";
155 twoaday 24 case 10:return "Twofish";
156 twoaday 23 }
157     return "Unknown";
158     }
159    
160    
161     /* Return true if the key has designated revokers. */
162     static bool
163     check_for_desig_rev (gpgme_key_t key)
164     {
165     winpt_key_s k;
166 twoaday 24 memset (&k, 0, sizeof (k));
167 twoaday 23 if (!winpt_get_pubkey (key->subkeys->keyid, &k))
168     return k.ext->gloflags.has_desig_rev? true : false;
169     return false;
170     }
171    
172    
173 twoaday 27 /* Print information (name) of the smart card. */
174     static const char*
175     get_card_type (winpt_key_t k)
176     {
177     static char buf[64];
178    
179     if (!k->ext->card_type)
180     return "";
181     _snprintf (buf, sizeof (buf)-1, "Card-Type: %s\r\n", k->ext->card_type);
182     return buf;
183     }
184    
185    
186 twoaday 23 /* Dialog box procedure to show the key properties. */
187 twoaday 2 BOOL CALLBACK
188 twoaday 23 keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
189 twoaday 2 {
190     static winpt_key_t k;
191     static gpgme_key_t key, sk;
192     static int photo_done = 0;
193 twoaday 23 struct winpt_key_s k2;
194 twoaday 2 refresh_cache_s rcs = {0};
195     const char *inf;
196 twoaday 26 char info[512];
197 twoaday 2 u32 created, expires;
198 twoaday 22 int ot, cancel = 0;
199 twoaday 2 int rc;
200    
201     switch (msg) {
202     case WM_INITDIALOG:
203     if (!lparam)
204     dlg_fatal_error( dlg, "Could not get dialog param!" );
205     k = (winpt_key_t)lparam;
206     #ifndef LANG_DE
207     SetWindowText( dlg, _("Key Properties") );
208     SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change"));
209     SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers"));
210     SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Passwd"));
211     #endif
212    
213     photo_done = 0;
214 twoaday 24 memset (&k2, 0, sizeof (k2));
215     if (k->key_pair)
216     winpt_get_seckey (k->keyid, &k2);
217     else
218     winpt_get_pubkey (k->keyid, &k2);
219 twoaday 23 sk = k2.ctx;
220 twoaday 2 if (sk)
221 twoaday 23 k->is_protected = k2.is_protected;
222 twoaday 2 if (get_pubkey (k->keyid, &key))
223     BUG (0);
224 twoaday 23 created = key->subkeys->timestamp;
225     expires = key->subkeys->expires;
226     _snprintf (info, DIM (info)-1,
227 twoaday 2 "Type: %s\r\n"
228     "Key ID: %s\r\n"
229     "Algorithm: %s\r\n"
230     "Size: %s\r\n"
231     "Created: %s\r\n"
232     "Expires: %s\r\n"
233     "Validity: %s\r\n"
234 twoaday 27 "Cipher: %s\r\n"
235     "%s\r\n",
236 twoaday 23 get_key_type (key),
237     k->keyid,
238     get_key_algo (key, 0),
239     get_key_size (key, 0),
240     get_key_created (created),
241     get_key_expire_date (expires),
242 twoaday 22 get_validity (key),
243 twoaday 27 get_pref_cipher (&k2),
244     get_card_type (&k2));
245 twoaday 23 SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info);
246     SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key));
247 twoaday 2 ot = gpgme_key_get_ulong_attr( key, GPGME_ATTR_OTRUST, NULL, 0 );
248 twoaday 24 inf = ownertrust_to_string (ot);
249 twoaday 2 SetDlgItemText( dlg, IDC_KEYPROPS_OT, inf );
250 twoaday 23 if (k->key_pair)
251 twoaday 2 EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_CHANGE_PWD ), TRUE );
252 twoaday 23 if (check_for_desig_rev (key))
253 twoaday 2 EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_REVOKERS ), TRUE );
254 twoaday 23 center_window (dlg, NULL);
255 twoaday 2 SetForegroundWindow (dlg);
256     return TRUE;
257    
258     case WM_PAINT:
259     if (photo_done == 0) {
260     photo_done = 1;
261     keyprops_show_photo (dlg, key);
262     }
263     break;
264    
265     case WM_SYSCOMMAND:
266     if( LOWORD( wparam ) == SC_CLOSE )
267     EndDialog( dlg, TRUE );
268     return FALSE;
269    
270     case WM_COMMAND:
271     switch( LOWORD( wparam ) ) {
272     case IDOK:
273     EndDialog( dlg, TRUE );
274     return TRUE;
275    
276     case IDC_KEYPROPS_OT_CHANGE:
277     if( do_check_key( key ) ) {
278     msg_box( dlg, _("The status of this key is 'revoked' or 'expired'.\n"
279     "You cannot change the ownertrust of such keys."),
280     _("WinPT Warning"), MB_ERR );
281     return FALSE;
282     }
283 twoaday 23 if( !k->key_pair && key->uids->validity < 3 ) {
284 twoaday 2 rc = msg_box( dlg, _("This is a non-valid key.\n"
285 twoaday 23 "Modifying the ownertrust has no effect on such keys.\n\n"
286 twoaday 2 "Do you really want to continue?"),
287     _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );
288     if (rc == IDNO)
289     return FALSE;
290     }
291     GetDlgItemText( dlg, IDC_KEYPROPS_OT, info, sizeof info -1 );
292 twoaday 23
293 twoaday 24
294 twoaday 23 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,
295     dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,
296 twoaday 24 (LPARAM)k, _("Change Ownertrust"),
297 twoaday 23 IDS_WINPT_KEYEDIT_OWNERTRUST);
298 twoaday 24 if (k->callback.new_val == -1) { /* Cancel */
299     EndDialog (dlg, FALSE);
300     break;
301     }
302    
303     inf = ownertrust_to_string (k->callback.new_val);
304 twoaday 2 do_change_ownertrust (k, inf);
305     SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
306     msg_box (dlg, _("Ownertrust successfully changed."), _("GnuPG Status"), MB_OK);
307    
308     /* reload only the keylist */
309     rcs.kr_reload = 1; rcs.kr_update = 1;
310     rcs.tr_update = 0;
311     DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,
312     keycache_dlg_proc, (LPARAM)&rcs );
313 twoaday 24 /* XXX: old code!?
314 twoaday 2 get_seckey (k->keyid, &sk);
315     if (get_pubkey (k->keyid, &key))
316     BUG (0);
317 twoaday 24 */
318 twoaday 2 return TRUE;
319    
320     case IDC_KEYPROPS_CHANGE_PWD:
321     keyedit_change_passwd (k, dlg);
322     return TRUE;
323    
324     case IDC_KEYPROPS_REVOKERS:
325 twoaday 23 dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,
326     key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"),
327     IDS_WINPT_KEY_REVOKERS);
328 twoaday 2 break;
329     }
330     }
331    
332     return FALSE;
333 twoaday 23 }
334    

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26