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

Annotation of /trunk/Src/wptKeysignDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 77 - (hide annotations)
Mon Nov 14 15:01:01 2005 UTC (19 years, 3 months ago) by twoaday
File size: 11317 byte(s)
2005-11-12  Timo Schulz  <ts@g10code.com>
 
        Fix more GCC warnings.
 
2005-11-10  Timo Schulz  <ts@g10code.com>
 
        * wptClipSignDlg.cpp (one_key_proc): Use
        release_gpg_passphrase_cb() to free the context.
        * wptListView.cpp (listview_deselect_all): New.
        * wptMAPI.cpp (mapi_send_pubkey): Works again.
        * wptFileManagerDlg.cpp (file_manager_dlg_proc): Support encrypt &
        zip.
        * wptPassphraseCB.cpp (passphrase_callback_proc): Fix passphrase
        caching for signing operations.
        * wptKeyManager.cpp (km_send_to_mail_recipient): Works again.
        * wptFileManager.cpp (fm_send_file): Likewise.
        (fm_encrypt_into_zip): New.
         

1 werner 36 /* wptKeysignDlg.cpp - Key signing dialog
2     * Copyright (C) 2001-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 twoaday 23
21 werner 42 #ifdef HAVE_CONFIG_H
22     #include <config.h>
23     #endif
24    
25 werner 36 #include <windows.h>
26     #include <commctrl.h>
27    
28 werner 47 #include "resource.h"
29 werner 36 #include "wptGPG.h"
30     #include "wptNLS.h"
31     #include "wptW32API.h"
32     #include "wptVersion.h"
33     #include "wptTypes.h"
34     #include "wptErrors.h"
35     #include "wptCommonCtl.h"
36     #include "wptContext.h"
37     #include "wptDlgs.h"
38     #include "wptUTF8.h"
39     #include "wptRegistry.h"
40 werner 47 #include "wptKeylist.h"
41 werner 36 #include "wptKeyEdit.h"
42    
43     static int sig_class_choice = 0;
44    
45     /* Return a beautified printable fingerprint of @fpr. */
46     static const char*
47     get_printable_fpr (const char *fpr)
48     {
49     static char pfpr[64];
50     int pos = 0;
51     size_t i;
52    
53     for (i = 0; i < strlen (fpr); i += 4) {
54     pfpr[pos++] = fpr[i];
55     pfpr[pos++] = fpr[i+1];
56     pfpr[pos++] = fpr[i+2];
57     pfpr[pos++] = fpr[i+3];
58     pfpr[pos++] = ' ';
59     }
60     return pfpr;
61     }
62    
63    
64     /* Return human friendly information about the key @key. */
65     static const char*
66     get_keyinfo (gpgme_key_t key)
67     {
68     static char buf[64+16];
69     struct winpt_key_s k;
70    
71     memset (&k, 0, sizeof (k));
72     winpt_get_seckey (key->subkeys->keyid, &k);
73     _snprintf (buf, DIM (buf)-1-16, "%d-bit %s key, ID %s",
74     key->subkeys->length,
75     get_key_pubalgo (key->subkeys->pubkey_algo),
76     key->subkeys->keyid+8);
77     if (k.ext->gloflags.divert_to_card)
78     strcat (buf, " (Card)");
79     return buf;
80     }
81    
82    
83     /* Fill the secret key combo-box with all entries from the cache.
84     @dlg is the handle to the combo-box. @keyid show which key to skip.
85     Return value: 0 on success. */
86     static int
87     do_fill_seckeylist (HWND dlg, const char *keyid)
88     {
89     gpg_keycache_t sec;
90     gpgme_key_t pk;
91     const char * s;
92     char * uid, * p;
93     int i = 0, n=0;
94    
95     sec = keycache_get_ctx (0);
96     if (!sec)
97     BUG (0);
98     gpg_keycache_rewind (sec);
99     while (!gpg_keycache_next_key (sec, 1, &pk)) {
100     if (!pk)
101     continue;
102     s = pk->subkeys->keyid;
103     if (!strcmp (s, keyid))
104     continue;
105     /* skip all ElGamal sign+encrypt keys */
106     if (pk->subkeys->pubkey_algo == GPGME_PK_ELG)
107     continue;
108     /* make sure the public key is okay not: revoked, expired or disabled. */
109     if (pk->expired ||pk->revoked || pk->disabled)
110     continue;
111     s = pk->uids->name;
112     if (!s)
113     continue;
114     uid = utf8_to_wincp (s, strlen (s));
115     p = new char[strlen (uid) + 64];
116     if (!p)
117     BUG (NULL);
118     _snprintf (p, strlen (uid) + 63, "%s (%s)", uid, get_keyinfo (pk));
119     SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_ADDSTRING, i, (LPARAM)(char *)p);
120     SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk);
121     free_if_alloc (p);
122     free (uid);
123     n++;
124     }
125     SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETCURSEL, 0, 0);
126     if (!n)
127     return -1;
128     return 0;
129     }
130    
131    
132     /* Check if the selected key is protected and en- or disable the
133     passphrase control. */
134     static void
135     do_check_protection (HWND dlg)
136     {
137     int idx, protec;
138     gpgme_key_t key;
139     struct winpt_key_s k;
140    
141     idx = SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0 );
142     key = (gpgme_key_t)SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETITEMDATA, (WPARAM)idx, 0 );
143     if (key) {
144     winpt_get_seckey (key->subkeys->keyid, &k);
145     protec = k.is_protected;
146     if (!protec)
147     protec = k.ext->gloflags.divert_to_card;
148     EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE), protec? TRUE : FALSE);
149     }
150     }
151    
152    
153     /* Dialog box procedure to choose the signature class. */
154     BOOL CALLBACK
155     sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
156     {
157     switch (msg) {
158     case WM_INITDIALOG:
159     SetWindowText (dlg, _("Choose Signature Class"));
160     SetDlgItemText (dlg, IDC_SIGCLASS_TITLEINF, _("How carefully have you verified the key you are about to sign actually belongs to the person? If you don't know what to anwser, use \"0\"."));
161     SetDlgItemText (dlg, IDC_SIGCLASS_CLASS0, _("(0) I will not answer (default)"));
162     SetDlgItemText (dlg, IDC_SIGCLASS_CLASS1, _("(1) I have not checked at all."));
163     SetDlgItemText (dlg, IDC_SIGCLASS_CLASS2, _("(2) I have done causal checking."));
164     SetDlgItemText (dlg, IDC_SIGCLASS_CLASS3, _("(3) I have done very careful checkings."));
165     CheckDlgButton (dlg, IDC_SIGCLASS_CLASS0, BST_CHECKED);
166     SetForegroundWindow (dlg);
167     center_window (dlg, NULL);
168     return TRUE;
169    
170     case WM_COMMAND:
171     switch( LOWORD( wparam ) ) {
172     case IDOK:
173     if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS0))
174     sig_class_choice = 0;
175     else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS1))
176     sig_class_choice = 1;
177     else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS2))
178     sig_class_choice = 2;
179     else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS3))
180     sig_class_choice = 3;
181     else
182     sig_class_choice = 0;
183     EndDialog (dlg, TRUE);
184     return TRUE;
185     }
186     break;
187     }
188    
189     return FALSE;
190     }
191    
192    
193     /* Return the humand friendly expiration date of @key. */
194     static const char*
195     get_expire_date (gpgme_key_t key)
196     {
197     u32 u = key->subkeys->expires;
198     if (!u)
199     return _("never");
200     return get_key_expire_date (u);
201     }
202    
203     /* Display photo of key @key in a separate window. */
204     static void
205     show_photo (winpt_key_t key)
206     {
207     /* XXX: fill it with life. */
208     }
209    
210    
211     /* Dialog box procedure to sign a key. */
212     BOOL CALLBACK
213     keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
214     {
215     static winpt_key_t key;
216     GpgKeyEdit *ke;
217     gpgme_error_t err;
218     gpgme_key_t k;
219     SYSTEMTIME st;
220     HWND h;
221     char keymsg[2048], pwd[256];
222     char *uid = NULL;
223     const char *keyid, *s;
224     int type, expires=0, idx;
225    
226     switch ( msg ) {
227     case WM_INITDIALOG:
228 twoaday 77 if (lparam == 0)
229 werner 36 dlg_fatal_error (dlg, "Could not get dialog param.");
230     #ifndef LANG_DE
231     SetWindowText (dlg, _("Key Signing"));
232     #endif
233     key = (winpt_key_t) lparam;
234     s = key->ctx->uids->uid;
235     uid = utf8_to_wincp (s, strlen (s));
236     _snprintf (keymsg, sizeof keymsg -1,
237     _("pub %d/%s created: %s expires: %s\n\n"
238     "Primary key fingerprint: %s\n\n"
239     "\t%s\n\n"
240     "\nAre you really sure that you want to sign this key with YOUR key?\n"),
241     key->ctx->subkeys->length,
242     key->ctx->subkeys->keyid+8,
243     get_key_created (key->ctx->subkeys->timestamp),
244     get_expire_date (key->ctx),
245     get_printable_fpr (key->ctx->subkeys->fpr),
246     uid);
247     free (uid);
248     s = key->ctx->subkeys->keyid;
249     if (do_fill_seckeylist (dlg, s)) {
250     msg_box (dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR);
251     EndDialog (dlg, FALSE);
252     }
253     SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, keymsg);
254     #ifndef LANG_DE
255     SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)"));
256     SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on"));
257     SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably"));
258     SetDlgItemText (dlg, IDC_KEYSIGN_ASKLEVEL, _("&Ask for certification level"));
259     SetDlgItemText (dlg, IDC_KEYSIGN_PWDINF, _("Passphrase"));
260     #endif
261     CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED);
262     CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED);
263     CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED);
264     EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), FALSE);
265     if (reg_prefs.expert == 0)
266     ShowWindow (GetDlgItem (dlg, IDC_KEYSIGN_NREV), SW_HIDE);
267     if (key->ext && key->ext->attrib.len > 0)
268     EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_SHOWIMG), TRUE);
269 twoaday 41 if (!reg_prefs.gpg.ask_cert_level)
270     EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_ASKLEVEL), FALSE);
271 werner 36 SetForegroundWindow (dlg);
272     h = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE);
273     SetFocus (h);
274     return FALSE;
275    
276     case WM_DESTROY:
277     sig_class_choice = 0;
278     break;
279    
280     case WM_SYSCOMMAND:
281     if( LOWORD( wparam ) == SC_CLOSE ) {
282     SetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, "" );
283     EndDialog( dlg, TRUE );
284     }
285     return FALSE;
286    
287     case WM_COMMAND:
288     if (HIWORD( wparam ) == CBN_SELCHANGE) {
289     do_check_protection (dlg);
290     break;
291     }
292     if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) {
293     int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG);
294     EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE);
295     }
296    
297     switch( LOWORD( wparam ) ) {
298     case IDOK:
299     if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL))
300     dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_SIGCLASS, dlg,
301     sig_class_dlg_proc, (LPARAM)NULL,
302     _("Choose Signature Class"), IDS_WINPT_SIGCLASS);
303     type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL);
304     if (type)
305     type = GPG_EDITKEY_LSIGN;
306     else
307     type = GPG_EDITKEY_SIGN;
308    
309     if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) {
310     type = GPG_EDITKEY_NRSIGN;
311     if (type == GPG_EDITKEY_LSIGN)
312     type = GPG_EDITKEY_NRLSIGN;
313     }
314     if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) {
315     expires = 1;
316     DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st);
317     sprintf (keymsg, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay);
318     }
319    
320     /* XXX: check for --ask-cert-level and --ask-cert-expire in the gpg.conf
321     if an advanced button is checked and offer to add it to the config
322     file. */
323    
324     GetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, pwd, DIM (pwd)-1);
325     keyid = key->ctx->subkeys->keyid;
326     if( !keyid ) {
327     msg_box( dlg, _("Could not get Key ID from key."), _("Key Signing"), MB_ERR );
328     return TRUE;
329     }
330     ke = new GpgKeyEdit (keyid);
331     if (!ke)
332     BUG (NULL);
333     ke->setPassphrase (pwd);
334     idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0);
335     k = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,
336     CB_GETITEMDATA, (WPARAM)idx, 0);
337     if (k)
338     ke->setLocalUser (k);
339    
340     err = ke->signKey (type, sig_class_choice, expires? keymsg : "0");
341     memset (&pwd, 0, sizeof pwd);
342     if (err) {
343     delete ke;
344     msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR);
345     return TRUE;
346     }
347     if (ke->getResult () != 0)
348     msg_box (dlg, _("This key is already signed by your key"), _("Key Signing"), MB_INFO);
349     else {
350     status_box (dlg, _("Key successfully signed."), PGM_NAME);
351     key->update = 1;
352     }
353     delete ke;
354     EndDialog (dlg, TRUE);
355     return TRUE;
356    
357     case IDCANCEL:
358     EndDialog (dlg, FALSE);
359     return TRUE;
360    
361     case IDC_KEYSIGN_SHOWIMG:
362     show_photo (key);
363     return TRUE;
364     }
365     break;
366     }
367    
368     return FALSE;
369     }
370    

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26