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

Annotation of /trunk/Src/wptClipSignEncDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 129 - (hide annotations)
Fri Dec 30 13:56:10 2005 UTC (19 years, 2 months ago) by twoaday
File size: 6066 byte(s)
2005-12-27  Timo Schulz  <ts@g10code.com>
                                                                                
        * wptListView.cpp (listview_set_view): New.
        (listview_del_column): New.
        * wptW32API.cpp (get_locale_date): New.
        (get_menu_state): New.
        (force_foreground_window): New.
        * wptVerifyList.cpp (strtimestamp): Support for
        locale date formats.
        * wptGPGUtil.cpp (gpg_revoke_cert): Handle bad
        passphrases.
        * wptKeyEditCB.cpp (editkey_command_handler): Immediately
        return when a bad passphrase was submitted.
        * wptKeyRevokersDlg.cpp (keyrevokers_dlg_proc): Change
        column order.
        * wptKeylist.cpp (keylist_upd_col): New.
        * wptKeyManagerDlg.cpp (update_ui_items): Deactivate
        'Revocation' for public keys.
        (translate_menu_strings): s/Revoke/Revoke Cert.
        (modify_listview_columns): New.


1 werner 36 /* wptSignEncDlg.cpp - Sign & encrypt dialog
2     * Copyright (C) 2000-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     #ifdef HAVE_CONFIG_H
21     #include <config.h>
22     #endif
23    
24     #include <windows.h>
25     #include <commctrl.h>
26    
27 werner 47 #include "resource.h"
28 werner 36 #include "wptErrors.h"
29     #include "wptAgent.h"
30     #include "wptCrypto.h"
31     #include "wptGPG.h"
32     #include "wptCommonCtl.h"
33     #include "wptKeylist.h"
34     #include "wptTypes.h"
35     #include "wptNLS.h"
36     #include "wptContext.h" /* for passphrase_s */
37     #include "wptDlgs.h"
38     #include "wptW32API.h"
39     #include "wptKeylist.h"
40     #include "wptVersion.h"
41     #include "wptGPG.h"
42     #include "wptRegistry.h"
43     #include "wptUTF8.h"
44    
45    
46     /* Encrypt the clipboard data with the recipients from @rset and
47     additionally sign the data before @signer as the keyID.
48     Return value: 0 on success. */
49     gpgme_error_t
50     gpg_clip_sign_encrypt (gpgme_ctx_t ctx, const char *signer,
51     gpgme_key_t *rset, int opts)
52     {
53     gpgme_error_t err;
54     gpgme_data_t plain = NULL;
55     gpgme_data_t ciph = NULL;
56     gpgme_key_t key = NULL;
57    
58     if (!signer)
59     return gpg_error (GPG_ERR_INV_ARG);
60     if (get_pubkey (signer, &key))
61     return gpg_error (GPG_ERR_NO_PUBKEY);
62    
63     gpgme_set_armor (ctx, 1);
64    
65     err = gpg_data_new_from_clipboard (&plain, 0);
66     if (err)
67     goto leave;
68     err = gpgme_data_new (&ciph);
69     if (err)
70     goto leave;
71     err = gpgme_signers_add (ctx, key);
72     if (err)
73     goto leave;
74    
75     err = gpgme_op_encrypt_sign (ctx, rset,
76     opts? GPGME_ENCRYPT_ALWAYS_TRUST : (gpgme_encrypt_flags_t)0,
77     plain, ciph);
78     if (err)
79     goto leave;
80    
81     gpg_data_release_and_set_clipboard (ciph, 1);
82     ciph = NULL;
83    
84     leave:
85     if (plain)
86     gpgme_data_release (plain);
87     if (ciph)
88     gpgme_data_release (ciph);
89     return err;
90     }
91    
92    
93     /* Dialog procedure for clipboard sign + encrypt. */
94     BOOL CALLBACK
95     clip_signenc_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
96     {
97     static listview_ctrl_t lv = NULL;
98     static keylist_t list = NULL;
99     gpg_keycache_t kc;
100     gpgme_key_t *rset;
101     gpgme_error_t err;
102     gpgme_ctx_t ctx;
103     passphrase_cb_s pwd;
104     char *signer = NULL;
105 twoaday 68 int force_trust = 0;
106 werner 36 int kmode = reg_prefs.keylist_mode? KEYLIST_ENCRYPT_MIN : KEYLIST_ENCRYPT;
107     int n;
108    
109     switch( msg ) {
110     case WM_INITDIALOG:
111     SetWindowText (dlg, _("Sign & Encrypt"));
112 twoaday 105 SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
113     kc = keycache_get_ctx (KEYCACHE_PUB);
114     if (!kc)
115     BUG (NULL);
116     lv = keylist_load (GetDlgItem (dlg, IDC_SIGNENC_KEYLIST),
117 werner 36 kc, NULL, kmode, KEY_SORT_USERID);
118 twoaday 105 seclist_init (dlg, IDC_SIGNENC_SECLIST, KEYLIST_FLAG_SHORT, &list);
119 werner 36 center_window (dlg, NULL);
120     EnableWindow (GetDlgItem (dlg, IDC_SIGNENC_SECLIST), FALSE);
121     SetDlgItemText (dlg, IDC_SIGNENC_SELKEY, _("Select key for signing"));
122     SetDlgItemText (dlg, IDC_SIGNENC_SECLISTINF, _("Signing key:"));
123     SetForegroundWindow (dlg);
124     return TRUE;
125    
126     case WM_DESTROY:
127     seclist_destroy (&list);
128     if (lv) {
129     keylist_delete (lv);
130     lv = NULL;
131     }
132     return FALSE;
133    
134     case WM_NOTIFY:
135     NMHDR * notify;
136     notify = (NMHDR *)lparam;
137     if (notify && notify->code == NM_DBLCLK
138     && notify->idFrom == IDC_SIGNENC_KEYLIST)
139 twoaday 65 PostMessage (dlg, WM_COMMAND, MAKEWPARAM (IDOK, 0), 0);
140 werner 36 return TRUE;
141    
142     case WM_SYSCOMMAND:
143 twoaday 105 if (LOWORD (wparam) == SC_CLOSE)
144     EndDialog (dlg, TRUE);
145 werner 36 return FALSE;
146    
147     case WM_COMMAND:
148     if (HIWORD (wparam) == BN_CLICKED
149     && LOWORD (wparam) == IDC_SIGNENC_SELKEY) {
150     int enable = IsDlgButtonChecked (dlg, IDC_SIGNENC_SELKEY);
151     EnableWindow (GetDlgItem (dlg, IDC_SIGNENC_SECLIST), enable? TRUE : FALSE);
152     }
153 twoaday 105 switch (LOWORD (wparam)) {
154 werner 36 case IDOK:
155 twoaday 105 rset = keylist_get_recipients (lv, &force_trust, &n);
156 werner 36 if (!n) {
157 twoaday 105 msg_box (dlg, _("You must select at least one key."),
158     _("Sign & Encrypt"), MB_ERR);
159 werner 36 return FALSE;
160     }
161     if( IsDlgButtonChecked( dlg, IDC_SIGNENC_SELKEY ) ) {
162     gpgme_key_t key;
163     const char * s;
164    
165     if( seclist_select_key( dlg, IDC_SIGNENC_SECLIST, &key ) ) {
166 twoaday 105 msg_box (dlg, _("No key was selected."), _("Signing"), MB_ERR);
167 werner 36 return FALSE;
168     }
169     s = key->subkeys->keyid;
170     if (s)
171     signer = m_strdup(s+8);
172     }
173     else {
174     signer = get_gnupg_default_key ();
175     if (!signer) {
176     msg_box (dlg, _("Could not get default key."), _("Signing"), MB_ERR);
177     return FALSE;
178     }
179     }
180    
181     err = gpgme_new (&ctx);
182     if (err)
183     BUG (NULL);
184 twoaday 105
185 werner 36 set_gpg_passphrase_cb (&pwd, ctx, GPG_CMD_SIGN, dlg, _("Sign & Encrypt"));
186     err = gpg_clip_sign_encrypt (ctx, signer, rset, force_trust);
187     release_gpg_passphrase_cb (&pwd);
188     free (rset);
189     free_if_alloc (signer);
190     gpgme_release (ctx);
191     if (gpgme_err_code (err) == GPG_ERR_BAD_PASSPHRASE)
192     agent_del_cache (pwd.keyid);
193     if (err) {
194     msg_box (dlg, gpgme_strerror (err), _("Sign & Encrypt"), MB_ERR );
195     return FALSE;
196     }
197     show_msg (dlg, 1500, _("GnuPG Status: Finished"));
198     EndDialog (dlg, TRUE);
199     return TRUE;
200    
201     case IDCANCEL:
202     EndDialog( dlg, FALSE );
203     return FALSE;
204     }
205     break;
206     }
207    
208     return FALSE;
209     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26