1 |
/* wptSignEncDlg.cpp - Sign & encrypt dialog |
/* wptSignEncDlg.cpp - Sign & encrypt dialog |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2006, 2009 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
15 |
*/ |
*/ |
|
|
|
16 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
17 |
#include <config.h> |
#include <config.h> |
18 |
#endif |
#endif |
57 |
return gpg_error (GPG_ERR_NO_PUBKEY); |
return gpg_error (GPG_ERR_NO_PUBKEY); |
58 |
|
|
59 |
gpgme_set_armor (ctx, 1); |
gpgme_set_armor (ctx, 1); |
60 |
|
gpgme_set_textmode (ctx, 1); |
61 |
|
|
62 |
err = gpg_data_new_from_clipboard (&plain, 0); |
err = gpg_data_utf8_new_from_clipboard (&plain, 0, NULL); |
63 |
if (err) |
if (err) |
64 |
goto leave; |
goto leave; |
65 |
err = gpgme_data_new (&ciph); |
err = gpgme_data_new (&ciph); |
75 |
if (err) |
if (err) |
76 |
goto leave; |
goto leave; |
77 |
|
|
78 |
gpg_data_release_and_set_clipboard (ciph, 1); |
gpg_data_release_to_clipboard (ciph, 1); |
79 |
ciph = NULL; |
ciph = NULL; |
80 |
|
|
81 |
leave: |
leave: |
91 |
BOOL CALLBACK |
BOOL CALLBACK |
92 |
clip_signenc_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
clip_signenc_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
93 |
{ |
{ |
94 |
static listview_ctrl_t lv = NULL; |
static keylist_ctrl_t kl = NULL; |
95 |
static keylist_t list = NULL; |
static keylist_t list = NULL; |
96 |
|
static int keys_sortby = 0; |
97 |
gpg_keycache_t kc; |
gpg_keycache_t kc; |
98 |
gpgme_key_t *rset; |
gpgme_key_t *rset; |
99 |
gpgme_error_t err; |
gpgme_error_t err; |
100 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
101 |
passphrase_cb_s pwd; |
passphrase_cb_s pwd; |
102 |
char *signer = NULL; |
char *signer = NULL; |
103 |
int force_trust = 0, opt = 0; |
size_t n; |
104 |
int kmode = reg_prefs.keylist_mode? KEYLIST_ENCRYPT_MIN : KEYLIST_ENCRYPT; |
int force_trust = 0; |
|
int n; |
|
105 |
|
|
106 |
switch( msg ) { |
switch (msg) { |
107 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
108 |
SetWindowText (dlg, _("Sign & Encrypt")); |
SetWindowText (dlg, _("Sign & Encrypt")); |
109 |
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
110 |
kc = keycache_get_ctx( KEYCACHE_PUB ); |
kc = keycache_get_ctx (KEYCACHE_PUB); |
111 |
if( !kc ) |
if (!kc) |
112 |
BUG( NULL ); |
BUG (NULL); |
113 |
lv = keylist_load( GetDlgItem( dlg, IDC_SIGNENC_KEYLIST ), |
|
114 |
kc, NULL, kmode, KEY_SORT_USERID); |
kl = keylist_load (GetDlgItem (dlg, IDC_SIGNENC_KEYLIST), |
115 |
seclist_init( dlg, IDC_SIGNENC_SECLIST, KEYLIST_FLAG_SHORT, &list ); |
kc, NULL, KEYLIST_ENCRYPT_MIN, KEY_SORT_USERID); |
116 |
|
seclist_init (dlg, IDC_SIGNENC_SECLIST, KEYLIST_FLAG_SHORT, &list); |
117 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
|
set_active_window (dlg); |
|
118 |
EnableWindow (GetDlgItem (dlg, IDC_SIGNENC_SECLIST), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_SIGNENC_SECLIST), FALSE); |
119 |
SetDlgItemText (dlg, IDC_SIGNENC_SELKEY, _("Select key for signing")); |
SetDlgItemText (dlg, IDC_SIGNENC_SELKEY, _("Select key for signing")); |
120 |
SetDlgItemText (dlg, IDC_SIGNENC_SECLISTINF, _("Signing key:")); |
SetDlgItemText (dlg, IDC_SIGNENC_SECLISTINF, _("Signing key:")); |
123 |
|
|
124 |
case WM_DESTROY: |
case WM_DESTROY: |
125 |
seclist_destroy (&list); |
seclist_destroy (&list); |
126 |
reset_active_window (); |
if (kl) { |
127 |
if (lv) { |
keylist_delete (kl); |
128 |
keylist_delete (lv); |
kl = NULL; |
|
lv = NULL; |
|
129 |
} |
} |
130 |
return FALSE; |
return FALSE; |
131 |
|
|
132 |
case WM_NOTIFY: |
case WM_NOTIFY: |
133 |
NMHDR * notify; |
/* Wait until the dialog initialization is done */ |
134 |
|
if (kl == NULL) |
135 |
|
break; |
136 |
|
|
137 |
|
int ret; |
138 |
|
ret = keylist_listview_notify (dlg, kl->keys, |
139 |
|
IDC_SIGNENC_KEYLIST, lparam); |
140 |
|
if (ret != 0) { |
141 |
|
SetWindowLong (dlg, DWL_MSGRESULT, ret); |
142 |
|
return TRUE; |
143 |
|
} |
144 |
|
|
145 |
|
NMHDR *notify; |
146 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
147 |
if (notify && notify->code == NM_DBLCLK |
if (notify && notify->code == NM_DBLCLK && |
148 |
&& notify->idFrom == IDC_SIGNENC_KEYLIST) |
notify->idFrom == IDC_SIGNENC_KEYLIST) |
149 |
PostMessage (dlg, WM_COMMAND, MAKEWPARAM (IDOK, 0), NULL); |
PostMessage (dlg, WM_COMMAND, MAKEWPARAM (IDOK, 0), 0); |
150 |
return TRUE; |
|
151 |
|
if (notify && notify->code == LVN_COLUMNCLICK && |
152 |
case WM_SYSCOMMAND: |
notify->idFrom == IDC_SIGNENC_KEYLIST) { |
153 |
if( LOWORD (wparam) == SC_CLOSE ) |
NMLISTVIEW *p = (LPNMLISTVIEW) lparam; |
154 |
EndDialog( dlg, TRUE ); |
int sortby = 0; |
155 |
return FALSE; |
|
156 |
|
switch (p->iSubItem) { |
157 |
|
case 0: sortby = KEY_SORT_USERID; break; |
158 |
|
case 1: sortby = KEY_SORT_KEYID; break; |
159 |
|
case 2: sortby = KEY_SORT_LEN; break; |
160 |
|
case 4: sortby = KEY_SORT_VALIDITY; break; |
161 |
|
default: sortby = KEY_SORT_USERID; break; |
162 |
|
} |
163 |
|
if ((keys_sortby & ~KEYLIST_SORT_DESC) == sortby) |
164 |
|
keys_sortby ^= KEYLIST_SORT_DESC; |
165 |
|
else |
166 |
|
keys_sortby = sortby; |
167 |
|
keylist_sort (kl, keys_sortby); |
168 |
|
return TRUE; |
169 |
|
} |
170 |
|
break; |
171 |
|
|
172 |
case WM_COMMAND: |
case WM_COMMAND: |
173 |
if (HIWORD (wparam) == BN_CLICKED |
if (HIWORD (wparam) == BN_CLICKED && |
174 |
&& LOWORD (wparam) == IDC_SIGNENC_SELKEY) { |
LOWORD (wparam) == IDC_SIGNENC_SELKEY) { |
175 |
int enable = IsDlgButtonChecked (dlg, IDC_SIGNENC_SELKEY); |
int enable = IsDlgButtonChecked (dlg, IDC_SIGNENC_SELKEY); |
176 |
EnableWindow (GetDlgItem (dlg, IDC_SIGNENC_SECLIST), enable? TRUE : FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_SIGNENC_SECLIST), enable? TRUE : FALSE); |
177 |
|
break; |
178 |
} |
} |
179 |
switch( LOWORD( wparam ) ) { |
|
180 |
|
switch (LOWORD (wparam)) { |
181 |
case IDOK: |
case IDOK: |
182 |
rset = keylist_get_recipients( lv, &force_trust, &n ); |
rset = keylist_get_recipients (kl, &force_trust, &n); |
183 |
if (!n) { |
if (!n) { |
184 |
msg_box( dlg, _("You must select at least one key."), _("Sign & Encrypt"), MB_ERR ); |
msg_box (dlg, _("You must select at least one key."), |
185 |
|
_("Sign & Encrypt"), MB_ERR); |
186 |
return FALSE; |
return FALSE; |
187 |
} |
} |
188 |
if( IsDlgButtonChecked( dlg, IDC_SIGNENC_SELKEY ) ) { |
if (IsDlgButtonChecked (dlg, IDC_SIGNENC_SELKEY)) { |
189 |
gpgme_key_t key; |
gpgme_key_t key; |
190 |
const char * s; |
const char *s; |
191 |
|
|
192 |
if( seclist_select_key( dlg, IDC_SIGNENC_SECLIST, &key ) ) { |
if (seclist_select_key (dlg, IDC_SIGNENC_SECLIST, &key)) { |
193 |
msg_box( dlg, _("No key was selected."), _("Signing"), MB_ERR ); |
msg_box (dlg, _("No key was selected."), _("Signing"), MB_ERR); |
194 |
|
safe_free (rset); |
195 |
return FALSE; |
return FALSE; |
196 |
} |
} |
197 |
s = key->subkeys->keyid; |
s = key->subkeys->keyid; |
202 |
signer = get_gnupg_default_key (); |
signer = get_gnupg_default_key (); |
203 |
if (!signer) { |
if (!signer) { |
204 |
msg_box (dlg, _("Could not get default key."), _("Signing"), MB_ERR); |
msg_box (dlg, _("Could not get default key."), _("Signing"), MB_ERR); |
205 |
|
safe_free (rset); |
206 |
return FALSE; |
return FALSE; |
207 |
} |
} |
208 |
} |
} |
213 |
set_gpg_passphrase_cb (&pwd, ctx, GPG_CMD_SIGN, dlg, _("Sign & Encrypt")); |
set_gpg_passphrase_cb (&pwd, ctx, GPG_CMD_SIGN, dlg, _("Sign & Encrypt")); |
214 |
err = gpg_clip_sign_encrypt (ctx, signer, rset, force_trust); |
err = gpg_clip_sign_encrypt (ctx, signer, rset, force_trust); |
215 |
release_gpg_passphrase_cb (&pwd); |
release_gpg_passphrase_cb (&pwd); |
216 |
free (rset); |
safe_free (rset); |
217 |
free_if_alloc (signer); |
free_if_alloc (signer); |
218 |
gpgme_release (ctx); |
gpgme_release (ctx); |
219 |
if (gpgme_err_code (err) == GPG_ERR_BAD_PASSPHRASE) |
if (gpgme_err_code (err) == GPG_ERR_BAD_PASSPHRASE) |
220 |
agent_del_cache (pwd.keyid); |
agent_del_cache (pwd.keyid); |
221 |
if (err) { |
if (err) |
222 |
msg_box (dlg, gpgme_strerror (err), _("Sign & Encrypt"), MB_ERR ); |
msg_box (dlg, gpgme_strerror (err), _("Sign & Encrypt"), MB_ERR); |
223 |
return FALSE; |
else { |
224 |
|
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
225 |
|
EndDialog (dlg, TRUE); |
226 |
} |
} |
|
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
|
|
EndDialog (dlg, TRUE); |
|
227 |
return TRUE; |
return TRUE; |
228 |
|
|
229 |
case IDCANCEL: |
case IDCANCEL: |
230 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
231 |
return FALSE; |
return FALSE; |
232 |
} |
} |
233 |
break; |
break; |