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

Annotation of /trunk/Src/wptClipSignDlg.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: 7065 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 /* wptClipSignDlg.cpp - WinPT clipboard sign dialog
2 twoaday 23 * Copyright (C) 2000, 2001, 2002, 2003, 2005 Timo Schulz
3     * Copyright (C) 2005 g10 Code GmbH
4 twoaday 2 *
5     * This file is part of WinPT.
6     *
7     * WinPT is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * WinPT is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with WinPT; if not, write to the Free Software Foundation,
19     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20     */
21    
22     #include <windows.h>
23     #include <commctrl.h>
24    
25     #include "../resource.h"
26     #include "wptTypes.h"
27     #include "wptAgent.h"
28     #include "wptNLS.h"
29 twoaday 32 #include "wptCrypto.h"
30 twoaday 2 #include "wptGPG.h"
31     #include "wptCommonCtl.h"
32     #include "wptRegistry.h"
33     #include "wptKeylist.h"
34     #include "wptErrors.h"
35     #include "wptW32API.h"
36     #include "wptVersion.h"
37     #include "wptContext.h" /* for passphrase_s */
38     #include "wptDlgs.h"
39    
40 twoaday 30
41 twoaday 23 /* Sign the clipboard contents with the key @keyid and wrap
42     text lines to @wraplen (0 disable line wrapping).
43     Return value: 0 on success. */
44     gpgme_error_t
45     gpg_clip_sign (gpgme_ctx_t ctx, const char *keyid, int wraplen)
46     {
47     gpgme_error_t err;
48     gpgme_data_t plain = NULL;
49     gpgme_data_t sig = NULL;
50     gpgme_key_t key = NULL;
51    
52     if (!keyid)
53     return gpg_error (GPG_ERR_INV_ARG);
54    
55     gpgme_set_armor (ctx, 1);
56    
57     err = gpg_data_new_from_clipboard (&plain, wraplen);
58     if (err)
59     return err;
60 twoaday 2
61 twoaday 23 get_pubkey (keyid, &key);
62     if (key)
63     err = gpgme_signers_add (ctx, key);
64     else {
65     err = gpg_error (GPG_ERR_NO_PUBKEY);
66     goto leave;
67     }
68     err = gpgme_data_new (&sig);
69     if (err)
70     goto leave;
71     err = gpgme_op_sign (ctx, plain, sig, GPGME_SIG_MODE_CLEAR);
72     if (err)
73     goto leave;
74    
75     gpg_data_release_and_set_clipboard (sig, 1);
76     sig = NULL;
77    
78     leave:
79     if (plain)
80     gpgme_data_release (plain);
81     if (sig)
82     gpgme_data_release (sig);
83     return err;
84     }
85    
86    
87 twoaday 2 /* This function is used when only one secret key is available.
88     * it doesn't make sense to offer a dialog for this case.
89     */
90     void
91     one_key_proc (HWND dlg)
92     {
93     char * signer;
94     gpgme_ctx_t ctx;
95     gpgme_error_t err;
96     passphrase_cb_s pwd;
97 twoaday 23 int rc = 0;
98     int n = reg_prefs.word_wrap;
99 twoaday 2
100     signer = get_gnupg_default_key ();
101 twoaday 23 if (!signer) {
102     msg_box (dlg, _("Could not get default key."), _("Signing"), MB_ERR);
103 twoaday 2 return;
104     }
105    
106 twoaday 23 err = gpgme_new (&ctx);
107     if (err)
108     BUG (dlg);
109 twoaday 2
110 twoaday 23 set_gpg_passphrase_cb (&pwd, ctx, GPG_CMD_SIGN, dlg, _("Signing"));
111     err = gpg_clip_sign (ctx, signer, n );
112 twoaday 30 wipememory (pwd.pwd, sizeof (pwd.pwd));
113 twoaday 25 if (gpgme_err_code (err) == GPG_ERR_BAD_PASSPHRASE)
114 twoaday 23 agent_del_cache (pwd.keyid);
115     if (err)
116     msg_box (dlg, gpgme_strerror (err), _("Signing"), MB_ERR);
117 twoaday 2 else
118 twoaday 23 show_msg (dlg, 1500, _("GnuPG Status: Finished"));
119     gpgme_release (ctx);
120     free_if_alloc (signer);
121     }
122 twoaday 2
123    
124 twoaday 23 /* Dialog box procedure for clipboard signing. */
125 twoaday 2 BOOL CALLBACK
126 twoaday 23 clip_sign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
127 twoaday 2 {
128     static listview_ctrl_t lv = NULL;
129 twoaday 25 gpg_keycache_t kc, sec_kc;
130 twoaday 2 gpgme_ctx_t ctx;
131     gpgme_error_t err;
132     passphrase_cb_s pwd;
133     int lv_idx = 0;
134     int rc = 0, no_signer = 0;
135     char * signer = NULL;
136    
137     switch( msg ) {
138     case WM_INITDIALOG:
139 twoaday 23 #ifndef LANG_DE
140 twoaday 2 SetWindowText( dlg, _("Signing") );
141 twoaday 23 #endif
142     kc = keycache_get_ctx (KEYCACHE_PUB);
143     if (!kc)
144 twoaday 2 BUG( NULL );
145 twoaday 23 sec_kc = keycache_get_ctx (KEYCACHE_PRV);
146     if (!sec_kc)
147     BUG (dlg);
148 twoaday 25 if (gpg_keycache_get_size (sec_kc) == 1) {
149 twoaday 23 one_key_proc (dlg);
150     EndDialog (dlg, TRUE);
151 twoaday 2 return FALSE;
152     }
153 twoaday 23 lv = keylist_load (GetDlgItem (dlg, IDC_SIGN_KEYLIST), kc, sec_kc,
154     KEYLIST_SIGN, KEY_SORT_USERID);
155     center_window (dlg, NULL);
156     SetForegroundWindow (dlg);
157     set_active_window (dlg);
158 twoaday 2 return FALSE;
159    
160     case WM_DESTROY:
161 twoaday 23 reset_active_window ();
162     if (lv) {
163     keylist_delete (lv);
164 twoaday 2 lv = NULL;
165     }
166     return FALSE;
167    
168     case WM_NOTIFY:
169     NMHDR * notify;
170     notify = (NMHDR *)lparam;
171     if( notify && notify->code == NM_DBLCLK
172     && notify->idFrom == IDC_SIGN_KEYLIST )
173     PostMessage( dlg, WM_COMMAND, MAKEWPARAM(IDOK, 0), NULL );
174     return TRUE;
175    
176     case WM_SYSCOMMAND:
177     if( LOWORD (wparam) == SC_CLOSE )
178     EndDialog(dlg, TRUE);
179     return FALSE;
180    
181     case WM_COMMAND:
182 twoaday 23 switch (LOWORD (wparam)) {
183 twoaday 2 case IDOK:
184     signer = get_gnupg_default_key ();
185 twoaday 23 if (!signer) {
186 twoaday 2 msg_box( dlg, _("Could not get default key."), _("Signing"), MB_ERR );
187     return FALSE;
188     }
189 twoaday 23 if (listview_count_items (lv, 0) == 1) {
190     listview_get_item_text (lv, 0, 1, signer, sizeof signer-1);
191 twoaday 2 no_signer = 0;
192     }
193 twoaday 23 else if ((lv_idx = listview_get_curr_pos (lv)) == -1) {
194     rc = log_box (_("Signing"), MB_YESNO,
195 twoaday 2 _("No key was chosen.\nUse the GPG default key '%s'?"),
196 twoaday 23 signer);
197     if (rc == IDNO) {
198 twoaday 2 free_if_alloc (signer);
199     return FALSE;
200     }
201     no_signer = 1;
202     }
203 twoaday 23 if (!no_signer) {
204 twoaday 2 free_if_alloc (signer);
205     signer = new char[32+1];
206     if (!signer)
207     BUG (NULL);
208     listview_get_item_text (lv, lv_idx, 1, signer, 32);
209     }
210     err = gpgme_new (&ctx);
211 twoaday 23 if (err)
212     BUG (dlg);
213     set_gpg_passphrase_cb (&pwd, ctx, GPG_CMD_SIGN, dlg, _("Signing"));
214     err = gpg_clip_sign (ctx, signer, reg_prefs.word_wrap);
215     free_if_alloc (signer);
216 twoaday 25 release_gpg_passphrase_cb (&pwd);
217 twoaday 23
218 twoaday 24 if (pwd.cancel && gpgme_err_code(err) == GPG_ERR_BAD_PASSPHRASE) {
219 twoaday 23 /* The user hit the cancel button or bad passphrase */
220     gpgme_release (ctx);
221     EndDialog (dlg, TRUE);
222 twoaday 2 return TRUE;
223     }
224 twoaday 23 if (err) {
225     msg_box (dlg, gpgme_strerror (err), _("Signing"), MB_ERR);
226 twoaday 25 gpgme_release (ctx);
227 twoaday 2 return FALSE;
228     }
229     else
230     show_msg( dlg, 1500, _("GnuPG Status: Finished") );
231 twoaday 23 gpgme_release (ctx);
232     EndDialog (dlg, TRUE);
233 twoaday 2 return TRUE;
234    
235     case IDCANCEL:
236 twoaday 23 EndDialog (dlg, FALSE);
237 twoaday 2 return FALSE;
238     }
239     break;
240     }
241    
242     return FALSE;
243 twoaday 23 }
244    

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26