1 |
/* wptSignEncDlg.cpp - Sign & encrypt dialog |
/* wptSignEncDlg.cpp - Sign & encrypt dialog |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
*/ |
|
|
|
20 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
21 |
#include <config.h> |
#include <config.h> |
22 |
#endif |
#endif |
61 |
return gpg_error (GPG_ERR_NO_PUBKEY); |
return gpg_error (GPG_ERR_NO_PUBKEY); |
62 |
|
|
63 |
gpgme_set_armor (ctx, 1); |
gpgme_set_armor (ctx, 1); |
64 |
|
gpgme_set_textmode (ctx, 1); |
65 |
|
|
66 |
err = gpg_data_new_from_clipboard (&plain, 0); |
err = gpg_data_new_from_clipboard (&plain, 0); |
67 |
if (err) |
if (err) |
103 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
104 |
passphrase_cb_s pwd; |
passphrase_cb_s pwd; |
105 |
char *signer = NULL; |
char *signer = NULL; |
106 |
|
size_t n; |
107 |
int force_trust = 0; |
int force_trust = 0; |
|
int kmode = reg_prefs.keylist_mode? KEYLIST_ENCRYPT_MIN : KEYLIST_ENCRYPT; |
|
|
int n; |
|
108 |
|
|
109 |
switch( msg ) { |
switch (msg) { |
110 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
111 |
SetWindowText (dlg, _("Sign & Encrypt")); |
SetWindowText (dlg, _("Sign & Encrypt")); |
112 |
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
113 |
kc = keycache_get_ctx( KEYCACHE_PUB ); |
kc = keycache_get_ctx (KEYCACHE_PUB); |
114 |
if( !kc ) |
lv = keylist_load (GetDlgItem (dlg, IDC_SIGNENC_KEYLIST), |
115 |
BUG( NULL ); |
kc, NULL, KEYLIST_ENCRYPT_MIN, KEY_SORT_USERID); |
116 |
lv = keylist_load( GetDlgItem( dlg, IDC_SIGNENC_KEYLIST ), |
seclist_init (dlg, IDC_SIGNENC_SECLIST, KEYLIST_FLAG_SHORT, &list); |
|
kc, NULL, kmode, KEY_SORT_USERID); |
|
|
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); |
|
reset_active_window (); |
|
126 |
if (lv) { |
if (lv) { |
127 |
keylist_delete (lv); |
keylist_delete (lv); |
128 |
lv = NULL; |
lv = NULL; |
130 |
return FALSE; |
return FALSE; |
131 |
|
|
132 |
case WM_NOTIFY: |
case WM_NOTIFY: |
133 |
NMHDR * notify; |
NMHDR *notify; |
134 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
135 |
if (notify && notify->code == NM_DBLCLK |
if (notify && notify->code == NM_DBLCLK |
136 |
&& notify->idFrom == IDC_SIGNENC_KEYLIST) |
&& notify->idFrom == IDC_SIGNENC_KEYLIST) |
137 |
PostMessage (dlg, WM_COMMAND, MAKEWPARAM (IDOK, 0), 0); |
PostMessage (dlg, WM_COMMAND, MAKEWPARAM (IDOK, 0), 0); |
138 |
return TRUE; |
return TRUE; |
139 |
|
|
|
case WM_SYSCOMMAND: |
|
|
if( LOWORD (wparam) == SC_CLOSE ) |
|
|
EndDialog( dlg, TRUE ); |
|
|
return FALSE; |
|
|
|
|
140 |
case WM_COMMAND: |
case WM_COMMAND: |
141 |
if (HIWORD (wparam) == BN_CLICKED |
if (HIWORD (wparam) == BN_CLICKED |
142 |
&& LOWORD (wparam) == IDC_SIGNENC_SELKEY) { |
&& LOWORD (wparam) == IDC_SIGNENC_SELKEY) { |
143 |
int enable = IsDlgButtonChecked (dlg, IDC_SIGNENC_SELKEY); |
int enable = IsDlgButtonChecked (dlg, IDC_SIGNENC_SELKEY); |
144 |
EnableWindow (GetDlgItem (dlg, IDC_SIGNENC_SECLIST), enable? TRUE : FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_SIGNENC_SECLIST), enable? TRUE : FALSE); |
145 |
} |
} |
146 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
147 |
case IDOK: |
case IDOK: |
148 |
rset = keylist_get_recipients( lv, &force_trust, &n ); |
rset = keylist_get_recipients (lv, &force_trust, &n); |
149 |
if (!n) { |
if (!n) { |
150 |
msg_box( dlg, _("You must select at least one key."), _("Sign & Encrypt"), MB_ERR ); |
msg_box (dlg, _("You must select at least one key."), |
151 |
|
_("Sign & Encrypt"), MB_ERR); |
152 |
return FALSE; |
return FALSE; |
153 |
} |
} |
154 |
if( IsDlgButtonChecked( dlg, IDC_SIGNENC_SELKEY ) ) { |
if (IsDlgButtonChecked (dlg, IDC_SIGNENC_SELKEY)) { |
155 |
gpgme_key_t key; |
gpgme_key_t key; |
156 |
const char * s; |
const char *s; |
157 |
|
|
158 |
if( seclist_select_key( dlg, IDC_SIGNENC_SECLIST, &key ) ) { |
if (seclist_select_key (dlg, IDC_SIGNENC_SECLIST, &key)) { |
159 |
msg_box( dlg, _("No key was selected."), _("Signing"), MB_ERR ); |
msg_box (dlg, _("No key was selected."), _("Signing"), MB_ERR); |
160 |
|
safe_free (rset); |
161 |
return FALSE; |
return FALSE; |
162 |
} |
} |
163 |
s = key->subkeys->keyid; |
s = key->subkeys->keyid; |
168 |
signer = get_gnupg_default_key (); |
signer = get_gnupg_default_key (); |
169 |
if (!signer) { |
if (!signer) { |
170 |
msg_box (dlg, _("Could not get default key."), _("Signing"), MB_ERR); |
msg_box (dlg, _("Could not get default key."), _("Signing"), MB_ERR); |
171 |
|
safe_free (rset); |
172 |
return FALSE; |
return FALSE; |
173 |
} |
} |
174 |
} |
} |
179 |
set_gpg_passphrase_cb (&pwd, ctx, GPG_CMD_SIGN, dlg, _("Sign & Encrypt")); |
set_gpg_passphrase_cb (&pwd, ctx, GPG_CMD_SIGN, dlg, _("Sign & Encrypt")); |
180 |
err = gpg_clip_sign_encrypt (ctx, signer, rset, force_trust); |
err = gpg_clip_sign_encrypt (ctx, signer, rset, force_trust); |
181 |
release_gpg_passphrase_cb (&pwd); |
release_gpg_passphrase_cb (&pwd); |
182 |
free (rset); |
safe_free (rset); |
183 |
free_if_alloc (signer); |
free_if_alloc (signer); |
184 |
gpgme_release (ctx); |
gpgme_release (ctx); |
185 |
if (gpgme_err_code (err) == GPG_ERR_BAD_PASSPHRASE) |
if (gpgme_err_code (err) == GPG_ERR_BAD_PASSPHRASE) |
186 |
agent_del_cache (pwd.keyid); |
agent_del_cache (pwd.keyid); |
187 |
if (err) { |
if (err) |
188 |
msg_box (dlg, gpgme_strerror (err), _("Sign & Encrypt"), MB_ERR ); |
msg_box (dlg, gpgme_strerror (err), _("Sign & Encrypt"), MB_ERR); |
189 |
return FALSE; |
else { |
190 |
|
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
191 |
|
EndDialog (dlg, TRUE); |
192 |
} |
} |
|
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
|
|
EndDialog (dlg, TRUE); |
|
193 |
return TRUE; |
return TRUE; |
194 |
|
|
195 |
case IDCANCEL: |
case IDCANCEL: |
196 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
197 |
return FALSE; |
return FALSE; |
198 |
} |
} |
199 |
break; |
break; |