1 |
/* wptClipEncryptDlg.cpp - Clipboard encrypt dialog |
/* wptClipEncryptDlg.cpp - Clipboard encrypt dialog |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2006 Timo Schulz |
3 |
* Copyright (C) 2005 g10 Code GmbH |
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
38 |
#include "wptContext.h" /* for passphrase_s */ |
#include "wptContext.h" /* for passphrase_s */ |
39 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
40 |
#include "wptDlgs.h" |
#include "wptDlgs.h" |
41 |
|
#include "wptUTF8.h" |
42 |
|
|
43 |
|
|
44 |
/* Encrypt the contents of the clipboard with the keys in @rset. |
/* Encrypt the contents of the clipboard with the keys in @rset. |
58 |
return err; |
return err; |
59 |
|
|
60 |
gpgme_set_armor (ctx, 1); |
gpgme_set_armor (ctx, 1); |
61 |
|
gpgme_set_textmode (ctx, 1); |
62 |
|
|
63 |
err = gpg_data_new_from_clipboard (&plain, 0); |
err = gpg_data_new_from_clipboard (&plain, 0); |
64 |
if (err) |
if (err) |
95 |
gpgme_invalid_key_t k; |
gpgme_invalid_key_t k; |
96 |
gpgme_key_t key; |
gpgme_key_t key; |
97 |
size_t len=0; |
size_t len=0; |
98 |
char *p; |
const char *keyid; |
99 |
|
const char *warn = _("key not found"); |
100 |
|
char *uid, *p; |
101 |
|
|
102 |
if (!ctx) |
if (!ctx) |
103 |
return -1; |
return -1; |
106 |
return -1; |
return -1; |
107 |
|
|
108 |
for (k=res->invalid_recipients; k; k = k->next) { |
for (k=res->invalid_recipients; k; k = k->next) { |
109 |
get_pubkey (k->fpr, &key); |
if (!get_pubkey (k->fpr, &key)) |
110 |
len += (32 + 16 + strlen (key->uids->name) + 2) + 4; |
len += (32 + strlen (k->fpr)+8 + strlen (key->uids->name) + 2) + 4; |
111 |
|
else |
112 |
|
len += strlen (warn) + strlen (k->fpr)+8 + 2 + 4; |
113 |
} |
} |
114 |
|
|
115 |
p = (char *)calloc (1, len+64); |
p = (char *)calloc (1, len+64); |
116 |
if (!p) |
if (!p) |
117 |
BUG (NULL); |
BUG (NULL); |
118 |
sprintf (p, _("Recipients unsuable for encryption:\n")); |
strcpy (p, _("Recipients unsuable for encryption:\n")); |
119 |
for (k = res->invalid_recipients; k; k = k->next) { |
for (k = res->invalid_recipients; k; k = k->next) { |
120 |
get_pubkey (k->fpr, &key); |
if (!get_pubkey (k->fpr, &key)) { |
121 |
strcat (p, key->subkeys->keyid+8); |
uid = utf8_to_native (key->uids->name); |
122 |
|
keyid = key->subkeys->keyid+8; |
123 |
|
} |
124 |
|
else { |
125 |
|
uid = strdup (warn); |
126 |
|
keyid = k->fpr; |
127 |
|
} |
128 |
|
strcat (p, keyid); |
129 |
strcat (p, " : "); |
strcat (p, " : "); |
130 |
strcat (p, key->uids->name); |
strcat (p, uid); |
131 |
strcat (p, "\n"); |
strcat (p, "\n"); |
132 |
|
safe_free (uid); |
133 |
} |
} |
134 |
msg_box (dlg, p, _("Encryption"), MB_ERR); |
msg_box (dlg, p, _("Encryption"), MB_ERR); |
135 |
free (p); |
safe_free (p); |
136 |
return 0; |
return 0; |
137 |
} |
} |
138 |
|
|
142 |
clip_encrypt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
clip_encrypt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
143 |
{ |
{ |
144 |
static listview_ctrl_t lv = NULL; |
static listview_ctrl_t lv = NULL; |
145 |
|
static int keys_sortby = 0; |
146 |
gpg_keycache_t kc; |
gpg_keycache_t kc; |
147 |
gpgme_key_t *rset; |
gpgme_key_t *rset; |
148 |
gpgme_ctx_t ctx=NULL; |
gpgme_ctx_t ctx=NULL; |
149 |
gpgme_error_t err; |
gpgme_error_t err; |
150 |
refresh_cache_s rcs = {0}; |
int force_trust = 0; |
|
int force_trust = 0, opt = 0; |
|
|
int kmode = reg_prefs.keylist_mode? KEYLIST_ENCRYPT_MIN : KEYLIST_ENCRYPT; |
|
151 |
int n; |
int n; |
152 |
|
|
153 |
switch( msg ) { |
switch (msg) { |
154 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
155 |
SetWindowText( dlg, _("Encryption") ); |
SetWindowText (dlg, _("Encryption")); |
156 |
kc = keycache_get_ctx( KEYCACHE_PUB ); |
SetDlgItemText (dlg, IDC_ENCRYPT_FNDCMD, _("&Find")); |
157 |
if( !kc ) |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
158 |
BUG( NULL ); |
kc = keycache_get_ctx (KEYCACHE_PUB); |
159 |
lv = keylist_load (GetDlgItem( dlg, IDC_ENCRYPT_KEYLIST ), kc, NULL, |
lv = keylist_load (GetDlgItem (dlg, IDC_ENCRYPT_KEYLIST), kc, NULL, |
160 |
kmode, KEY_SORT_USERID); |
KEYLIST_ENCRYPT_MIN, KEY_SORT_USERID); |
161 |
center_window( dlg, NULL ); |
center_window (dlg, NULL); |
162 |
SetForegroundWindow( dlg ); |
SetForegroundWindow (dlg); |
|
set_active_window( dlg ); |
|
163 |
return TRUE; |
return TRUE; |
164 |
|
|
165 |
case WM_DESTROY: |
case WM_DESTROY: |
166 |
reset_active_window( ); |
if (lv) { |
167 |
if( lv ) { |
keylist_delete (lv); |
|
keylist_delete( lv ); |
|
168 |
lv = NULL; |
lv = NULL; |
169 |
} |
} |
170 |
return FALSE; |
return FALSE; |
175 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
176 |
if (notify && notify->code == NM_DBLCLK && |
if (notify && notify->code == NM_DBLCLK && |
177 |
notify->idFrom == IDC_ENCRYPT_KEYLIST) |
notify->idFrom == IDC_ENCRYPT_KEYLIST) |
178 |
PostMessage( dlg, WM_COMMAND, MAKEWPARAM( IDOK, 0 ), 0); |
PostMessage( dlg, WM_COMMAND, MAKEWPARAM( IDOK, 0 ), 0 ); |
179 |
if (notify && notify->code == LVN_COLUMNCLICK && |
if (notify && notify->code == LVN_COLUMNCLICK && |
180 |
notify->idFrom == IDC_ENCRYPT_KEYLIST ) { |
notify->idFrom == IDC_ENCRYPT_KEYLIST) { |
181 |
NMLISTVIEW *p = (LPNMLISTVIEW) lparam; |
NMLISTVIEW *p = (LPNMLISTVIEW) lparam; |
182 |
int sortby = 0; |
int sortby = 0; |
183 |
|
|
184 |
switch( p->iSubItem ) { |
switch (p->iSubItem) { |
185 |
case 0: sortby = KEY_SORT_USERID; break; |
case 0: sortby = KEY_SORT_USERID; break; |
186 |
case 1: sortby = KEY_SORT_KEYID; break; |
case 1: sortby = KEY_SORT_KEYID; break; |
187 |
case 2: sortby = KEY_SORT_LEN; break; |
case 2: sortby = KEY_SORT_LEN; break; |
188 |
case 4: sortby = KEY_SORT_VALIDITY; break; |
case 4: sortby = KEY_SORT_VALIDITY; break; |
189 |
default: sortby = KEY_SORT_USERID; break; |
default: sortby = KEY_SORT_USERID; break; |
190 |
} |
} |
191 |
keylist_sort( lv, sortby ); |
if ((keys_sortby & ~KEYLIST_SORT_DESC) == sortby) |
192 |
|
keys_sortby ^= KEYLIST_SORT_DESC; |
193 |
|
else |
194 |
|
keys_sortby = sortby; |
195 |
|
keylist_sort (lv, keys_sortby); |
196 |
} |
} |
197 |
return TRUE; |
return TRUE; |
198 |
|
|
|
case WM_SYSCOMMAND: |
|
|
if( LOWORD( wparam ) == SC_CLOSE ) |
|
|
EndDialog( dlg, TRUE ); |
|
|
return FALSE; |
|
|
|
|
199 |
case WM_COMMAND: |
case WM_COMMAND: |
200 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
201 |
case IDOK: |
case IDOK: |
202 |
rset = keylist_get_recipients (lv, &force_trust, &n); |
rset = keylist_get_recipients (lv, &force_trust, &n); |
203 |
if (!n) { |
if (!n) { |
204 |
msg_box (dlg, _("You must select at least one key."), _("Encryption"), MB_ERR); |
msg_box (dlg, _("You must select at least one key."), |
205 |
free (rset); |
_("Encryption"), MB_ERR); |
206 |
|
safe_free (rset); |
207 |
return FALSE; |
return FALSE; |
208 |
} |
} |
209 |
err = gpg_clip_encrypt (rset, force_trust, &ctx); |
err = gpg_clip_encrypt (rset, force_trust, &ctx); |
210 |
if (err) { |
if (err) { |
211 |
if (show_invalid_recipients (dlg, ctx)) |
if (show_invalid_recipients (dlg, ctx)) |
212 |
msg_box (dlg, gpgme_strerror (err), _("Encryption"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Encryption"), MB_ERR); |
|
if (ctx) |
|
|
gpgme_release (ctx); |
|
|
free (rset); |
|
|
return FALSE; |
|
213 |
} |
} |
214 |
else |
else |
215 |
show_msg( dlg, 1500, _("GnuPG Status: Finished") ); |
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
216 |
free (rset); |
safe_free (rset); |
217 |
gpgme_release (ctx); |
if (ctx) |
218 |
EndDialog (dlg, TRUE); |
gpgme_release (ctx); |
219 |
|
if (!err) |
220 |
|
EndDialog (dlg, TRUE); |
221 |
return TRUE; |
return TRUE; |
222 |
|
|
223 |
case IDCANCEL: |
case IDCANCEL: |
224 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
225 |
return FALSE; |
return FALSE; |
226 |
|
|
227 |
case IDC_ENCRYPT_FNDCMD: |
case IDC_ENCRYPT_FNDCMD: |
228 |
{ |
{ |
229 |
char tmpbuf[64]; |
char tmpbuf[64]; |
|
int n; |
|
230 |
|
|
231 |
n = GetDlgItemText (dlg, IDC_ENCRYPT_FIND, tmpbuf, DIM (tmpbuf)-1); |
n = GetDlgItemText (dlg, IDC_ENCRYPT_FIND, tmpbuf, DIM (tmpbuf)-1); |
232 |
if (!n) |
if (!n) |