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

Annotation of /trunk/Src/wptKeyPropsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 22 - (hide annotations)
Wed Aug 10 11:33:35 2005 UTC (19 years, 6 months ago) by twoaday
File size: 9539 byte(s)
2005-08-06  Timo Schulz  <twoaday@freakmail.de>
 
        * wptGPGME.cpp (keycache_update): Reload OpenPGP parts
        of the secret key.
        (keycache_init): cache name of secret keyring.
        * wptKeyList.cpp (keylist_upd_key): Do not add long keyid.
        (get_key_type): Do not assume 'ultimate' means key pair.
        * wptKeyEditDlgs.cpp (diff_time): New.
        (keyedit_addsubkey_dlg_proc): Changed design and use
        diff_time. Drop checks for invalid keylength (< 1024, > 4096)
        because the combo box automatically handles this.
        * wptKeyManager.cpp (km_set_implicit_trust): Return error code.
        * wptGPG.cpp (get_backup_name): New.
        (gnupg_backup_keyrings): Rotate backup names, from 0..3.
        * wptClipImportDialog.cpp (clip_import_dlg_proc): Free memory.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Use 0x short keyid and
        not the long keyid.


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     int keyedit_ownertrust_get_val (void);
37    
38    
39     static void
40 twoaday 22 do_change_ownertrust (winpt_key_t k, const char *s)
41 twoaday 2 {
42 twoaday 22 char ot[64];
43 twoaday 2
44     if( strstr( s, "ultimate" ) ) {
45 twoaday 22 listview_get_item_text (k->callback.ctl, k->callback.idx, 5, ot, DIM (ot)-1);
46     strcpy (ot, "Ultimate");
47     listview_add_sub_item (k->callback.ctl, k->callback.idx, 5, ot);
48 twoaday 2 /* fixme: If we switch back from Ultimate to a lower level */
49     }
50     } /* do_change_ownertrust */
51    
52    
53     static int
54 twoaday 22 do_check_key (gpgme_key_t key)
55 twoaday 2 {
56     int okay = 0;
57 twoaday 22 okay = gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_EXPIRED, NULL, 0);
58     if (!okay)
59     okay = gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_REVOKED, NULL, 0);
60 twoaday 2 return okay;
61     } /* do_check_key */
62    
63    
64     static const char*
65     ownertrust_to_string (gpgme_editkey_t ctx, int val)
66     {
67     const char * inf;
68     int id;
69    
70     if (ctx)
71     id = keyedit_ownertrust_get_val ();
72     else if (!ctx && val)
73     id = val;
74     switch (id) {
75     case 1: inf = _("Don't know"); break;
76     case 2: inf = _("I do NOT trust"); break;
77     case 3: inf = _("I trust marginally"); break;
78     case 4: inf = _("I trust fully"); break;
79     case 5:
80     case 6: inf = _("I trust ultimately"); break;
81     default:inf = _("Unknown"); break;
82     }
83    
84     return inf;
85     } /* ownertrust_to_string */
86    
87    
88 twoaday 22 #define PHOTO_TMPNAME "winpt_temp_photo.jpg"
89    
90 twoaday 2 static int
91     keyprops_show_photo (HWND dlg, gpgme_key_t key)
92     {
93     RECT r;
94     POINT p;
95     HWND h;
96     const BYTE *img;
97     DWORD imglen = 0;
98     int pos=0;
99    
100 twoaday 22 img = (const byte *)gpgme_key_get_string_attr (key, GPGME_ATTR_PHOTO,
101     (void **)&imglen, 0);
102 twoaday 2 if (!img || !imglen)
103     return -1;
104 twoaday 22 FILE *f = fopen (PHOTO_TMPNAME, "wb");
105 twoaday 2 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    
114     h = GetDlgItem (dlg, IDC_KEYPROPS_IMG);
115     GetWindowRect (h, &r);
116     p.x = r.left + 5;
117     p.y = r.top - 2;
118 twoaday 22 memset (&p, 0, sizeof (p));
119     PTD_jpg_show (h, &p, PHOTO_TMPNAME);
120     unlink (PHOTO_TMPNAME);
121 twoaday 2
122     return 0;
123     }
124    
125    
126 twoaday 22 static const char*
127     get_validity (gpgme_key_t key)
128     {
129     int val;
130     val = gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_EXPIRED, NULL, 0);
131     if (val)
132     return "Expired";
133     val = gpgme_key_get_ulong_attr( key, GPGME_ATTR_KEY_REVOKED, NULL, 0 );
134     if (val)
135     return "Revoked";
136     val = gpgme_key_get_ulong_attr (key, GPGME_ATTR_VALIDITY, NULL, 0);
137     return gpgme_key_expand_attr (GPGME_ATTR_VALIDITY, val);
138     }
139    
140    
141 twoaday 2 BOOL CALLBACK
142     keyprops_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
143     {
144     static winpt_key_t k;
145     static gpgme_key_t key, sk;
146     static int photo_done = 0;
147     gpgme_editkey_t ek;
148     gpgme_ctx_t ctx;
149     gpgme_error_t ec;
150     refresh_cache_s rcs = {0};
151     const char *inf;
152     const char * sym_prefs;
153     char info[2048], dummy_symprefs[] = {0x01, 0x00};
154     u32 created, expires;
155 twoaday 22 int ot, cancel = 0;
156 twoaday 2 int rc;
157    
158     switch (msg) {
159     case WM_INITDIALOG:
160     if (!lparam)
161     dlg_fatal_error( dlg, "Could not get dialog param!" );
162     k = (winpt_key_t)lparam;
163     #ifndef LANG_DE
164     SetWindowText( dlg, _("Key Properties") );
165     SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change"));
166     SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers"));
167     SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Passwd"));
168     #endif
169    
170     photo_done = 0;
171     get_seckey (k->keyid, &sk);
172     if (sk)
173     k->is_protected = gpgme_key_get_ulong_attr( sk, GPGME_ATTR_IS_PROTECTED, NULL, 0 );
174     if (get_pubkey (k->keyid, &key))
175     BUG (0);
176     created = gpgme_key_get_ulong_attr( key, GPGME_ATTR_CREATED, NULL, 0 );
177     expires = gpgme_key_get_ulong_attr( key, GPGME_ATTR_EXPIRES, NULL, 0 );
178     sym_prefs = gpgme_key_get_string_attr( key, GPGME_ATTR_KEY_SYMPREFS, NULL, 0 );
179     if (!sym_prefs)
180 twoaday 22 sym_prefs = dummy_symprefs;
181 twoaday 2 _snprintf (info, sizeof info -1,
182     "Type: %s\r\n"
183     "Key ID: %s\r\n"
184     "Algorithm: %s\r\n"
185     "Size: %s\r\n"
186     "Created: %s\r\n"
187     "Expires: %s\r\n"
188     "Validity: %s\r\n"
189     "Cipher: %s\r\n",
190     get_key_type( key ),
191     k->keyid,
192     get_key_algo( key, 0 ),
193     get_key_size( key, 0 ),
194     get_key_created( created ),
195     get_key_expire_date( expires ),
196 twoaday 22 get_validity (key),
197 twoaday 2 gpgme_key_expand_attr( GPGME_ATTR_KEY_SYMPREFS, *sym_prefs ) );
198     SetDlgItemText( dlg, IDC_KEYPROPS_INFO, info );
199     SetDlgItemText( dlg, IDC_KEYPROPS_FPR, get_key_fpr( key ) );
200     ot = gpgme_key_get_ulong_attr( key, GPGME_ATTR_OTRUST, NULL, 0 );
201     inf = ownertrust_to_string( NULL, ot );
202     SetDlgItemText( dlg, IDC_KEYPROPS_OT, inf );
203     if( k->key_pair )
204     EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_CHANGE_PWD ), TRUE );
205     if( gpgme_key_count_items( key, GPGME_ATTR_REVKEY_FPR ) )
206     EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_REVOKERS ), TRUE );
207     center_window (dlg);
208     SetForegroundWindow (dlg);
209     return TRUE;
210    
211     case WM_PAINT:
212     if (photo_done == 0) {
213     photo_done = 1;
214     keyprops_show_photo (dlg, key);
215     }
216     break;
217    
218     case WM_SYSCOMMAND:
219     if( LOWORD( wparam ) == SC_CLOSE )
220     EndDialog( dlg, TRUE );
221     return FALSE;
222    
223     case WM_COMMAND:
224     switch( LOWORD( wparam ) ) {
225     case IDOK:
226     EndDialog( dlg, TRUE );
227     return TRUE;
228    
229     case IDC_KEYPROPS_OT_CHANGE:
230     if( do_check_key( key ) ) {
231     msg_box( dlg, _("The status of this key is 'revoked' or 'expired'.\n"
232     "You cannot change the ownertrust of such keys."),
233     _("WinPT Warning"), MB_ERR );
234     return FALSE;
235     }
236     if( !k->key_pair && gpgme_key_get_ulong_attr( key, GPGME_ATTR_VALIDITY, NULL, 0 ) < 3 ) {
237     rc = msg_box( dlg, _("This is a non-valid key.\n"
238     "Modifying the ownertrust has no effect on such keys.\n"
239     "Do you really want to continue?"),
240     _("WinPT Warning"), MB_ICONWARNING|MB_YESNO );
241     if (rc == IDNO)
242     return FALSE;
243     }
244     GetDlgItemText( dlg, IDC_KEYPROPS_OT, info, sizeof info -1 );
245     gpgme_editkey_new( &ek );
246     gpgme_editkey_is_secret( ek, k->key_pair );
247     dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST,
248     dlg, (DLGPROC)keyedit_ownertrust_dlg_proc,
249     (LPARAM)ek, _("Change Ownertrust"),
250     IDS_WINPT_KEYEDIT_OWNERTRUST );
251     if (!gpgme_editkey_is_valid (ek))
252     return FALSE;
253     ec = gpgme_new (&ctx);
254     if (ec)
255     BUG (0);
256     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_TRUST );
257     ec = gpgme_op_editkey( ctx, k->keyid );
258     gpgme_editkey_release( ek );
259     gpgme_release( ctx );
260     if( ec ) {
261     msg_box( dlg, gpgme_strerror( ec ), _("Ownertrust"), MB_ERR );
262     return FALSE;
263     }
264     inf = ownertrust_to_string (ek, 0);
265     k->callback.new_val = keyedit_ownertrust_get_val ();
266     do_change_ownertrust (k, inf);
267     SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf);
268     msg_box (dlg, _("Ownertrust successfully changed."), _("GnuPG Status"), MB_OK);
269    
270     /* reload only the keylist */
271     rcs.kr_reload = 1; rcs.kr_update = 1;
272     rcs.tr_update = 0;
273     DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,
274     keycache_dlg_proc, (LPARAM)&rcs );
275     get_seckey (k->keyid, &sk);
276     if (get_pubkey (k->keyid, &key))
277     BUG (0);
278     return TRUE;
279    
280     case IDC_KEYPROPS_CHANGE_PWD:
281     keyedit_change_passwd (k, dlg);
282     return TRUE;
283    
284     case IDC_KEYPROPS_REVOKERS:
285     dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg,
286     key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"),
287     IDS_WINPT_KEY_REVOKERS );
288     break;
289     }
290     }
291    
292     return FALSE;
293     } /* keyprops_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26