1 |
/* wptFileManager.cpp - File Manager routines |
/* wptFileManager.cpp - File Manager routines |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
* Copyright (C) 2001-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. |
18 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
*/ |
*/ |
|
/* TODO: |
|
|
* check_armor_type: we should check the whole file and not only the first line! |
|
|
*/ |
|
21 |
|
|
22 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
23 |
#include <config.h> |
#include <config.h> |
50 |
#include "wptKeyManager.h" |
#include "wptKeyManager.h" |
51 |
#include "openpgp.h" |
#include "openpgp.h" |
52 |
|
|
|
#define op_begin() SetCursor (LoadCursor (NULL, IDC_WAIT)) |
|
|
#define op_end() SetCursor (LoadCursor (NULL, IDC_ARROW)) |
|
53 |
|
|
54 |
void progress_cleanup (progress_filter_s *pfx); |
void progress_cleanup (progress_filter_s *pfx); |
55 |
BOOL CALLBACK file_secdel_confirm_dlg_proc (HWND dlg, UINT msg, |
BOOL CALLBACK file_secdel_confirm_dlg_proc (HWND dlg, UINT msg, |
58 |
gpgme_error_t sym_passphrase_cb (void *hook, const char *hint, const char *pass_inf, |
gpgme_error_t sym_passphrase_cb (void *hook, const char *hint, const char *pass_inf, |
59 |
int prev_was_bad, int fd); |
int prev_was_bad, int fd); |
60 |
|
|
|
/*-- wptFileVerifyDlg.cpp --*/ |
|
|
void file_verify_add_state (file_sig_ctx_t c); |
|
|
void file_verify_use_event (void); |
|
|
void file_verify_wait (void); |
|
61 |
|
|
62 |
static const char * mm_files[] = {".mov", ".avi", ".mpg", ".mpeg", |
/* Symbolic column IDs. */ |
63 |
|
enum { |
64 |
|
FM_COL_STAT = 0, |
65 |
|
FM_COL_NAME = 1, |
66 |
|
FM_COL_OP = 2 |
67 |
|
}; |
68 |
|
|
69 |
|
static const char *mm_files[] = {".mov", ".avi", ".mpg", ".mpeg", |
70 |
".mp3", ".wav", ".mid", ".wma", |
".mp3", ".wav", ".mid", ".wma", |
71 |
".gif", ".jpg", ".png", ".jpeg", ".dib", 0}; |
".gif", ".jpg", ".png", ".jpeg", ".dib", 0}; |
72 |
|
|
115 |
void |
void |
116 |
remove_crit_file_attrs (const char *fname, int force) |
remove_crit_file_attrs (const char *fname, int force) |
117 |
{ |
{ |
118 |
u32 fattr; |
DWORD fattr; |
119 |
int id = 0; |
int id = 0; |
120 |
|
|
121 |
if (file_exist_check (fname)) |
if (file_exist_check (fname)) |
225 |
|
|
226 |
/* Check the armor type of the file @fname and return |
/* Check the armor type of the file @fname and return |
227 |
a string representation of it. */ |
a string representation of it. */ |
228 |
static const char * |
static const char* |
229 |
fm_check_armor_type (const char *fname, int *r_type) |
fm_check_armor_type (const char *fname, int *r_type) |
230 |
{ |
{ |
231 |
FILE * fp; |
FILE *fp; |
232 |
char header[768], * p; |
char header[768], *p; |
233 |
|
|
234 |
if (r_type) |
if (r_type) |
235 |
*r_type = PGP_NONE; |
*r_type = PGP_NONE; |
375 |
int |
int |
376 |
fm_build (listview_ctrl_t *lv, HWND ctrl) |
fm_build (listview_ctrl_t *lv, HWND ctrl) |
377 |
{ |
{ |
378 |
int i, rc = 0; |
int i; |
379 |
listview_ctrl_t c; |
listview_ctrl_t c; |
380 |
struct listview_column_s col[] = { |
struct listview_column_s col[] = { |
381 |
{0, 80, (char *)_("Status") }, |
{0, 80, (char *)_("Status") }, |
382 |
{1, 256, (char *)_("Name") }, |
{1, 256, (char *)_("Name") }, |
383 |
{2, 128, (char *)_("Operation") }, |
{2, 128, (char *)_("Operation") }, |
384 |
{0, 0, NULL } |
{0, 0, NULL} |
385 |
}; |
}; |
386 |
|
|
387 |
rc = listview_new (&c); |
listview_new (&c, ctrl); |
|
if (rc) |
|
|
BUG (NULL); |
|
|
c->ctrl = ctrl; |
|
388 |
for (i = 0; col[i].width; i++) |
for (i = 0; col[i].width; i++) |
389 |
listview_add_column (c, &col[i]); |
listview_add_column (c, &col[i]); |
390 |
listview_set_ext_style (c); |
listview_set_ext_style (c); |
407 |
int |
int |
408 |
fm_state_new (fm_state_t * ctx) |
fm_state_new (fm_state_t * ctx) |
409 |
{ |
{ |
410 |
gpgme_error_t rc; |
fm_state_s *c; |
|
fm_state_s * c; |
|
411 |
|
|
412 |
c = new fm_state_s; |
c = new fm_state_s; |
413 |
if (!c) |
if (!c) |
414 |
BUG (0); |
BUG (0); |
415 |
memset (c, 0, sizeof *c); |
memset (c, 0, sizeof *c); |
416 |
rc = gpgme_new (&c->ctx); |
if (gpgme_new (&c->ctx)) |
|
if (rc) |
|
417 |
BUG (0); |
BUG (0); |
|
/* XXX rc = gpgme_recipients_new (&c->recp);*/ |
|
|
/* XXX gpgme_set_comment (c->ctx, "Generated by WinPT "PGM_VERSION); */ |
|
418 |
*ctx = c; |
*ctx = c; |
419 |
return 0; |
return 0; |
420 |
} /* fm_state_new */ |
} |
421 |
|
|
422 |
|
|
423 |
/* Release the FM state handle @c. */ |
/* Release the FM state handle @c. */ |
433 |
safe_free (c->recp); |
safe_free (c->recp); |
434 |
free_if_alloc (c->opaque); |
free_if_alloc (c->opaque); |
435 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
436 |
delete c; c = NULL; |
delete c; |
437 |
} |
} |
438 |
|
|
439 |
|
|
440 |
static int |
static int |
441 |
fm_check_for_entry( listview_ctrl_t lv, const char *file ) |
fm_check_for_entry( listview_ctrl_t lv, const char *file ) |
442 |
{ |
{ |
451 |
} |
} |
452 |
|
|
453 |
return 0; |
return 0; |
454 |
} /* fm_check_for_entry */ |
} |
455 |
|
|
456 |
|
|
457 |
static int |
static int |
475 |
} |
} |
476 |
|
|
477 |
|
|
478 |
|
/* Add all files from the directory @path to the list view @lv. */ |
479 |
static int |
static int |
480 |
fm_add_dir_files (listview_ctrl_t lv, char *path) |
fm_add_dir_files (listview_ctrl_t lv, char *path) |
481 |
{ |
{ |
540 |
if (!type) |
if (!type) |
541 |
return WPTERR_FILE_OPEN; |
return WPTERR_FILE_OPEN; |
542 |
if (!strcmp (type, "UNKNOWN")) |
if (!strcmp (type, "UNKNOWN")) |
543 |
type = gnupg_check_file_ext (name, NULL); |
type = gnupg_check_file_ext (name, NULL); |
544 |
rc = listview_add_item (lv, ""); |
rc = listview_add_item (lv, ""); |
545 |
if (!rc) { |
if (!rc) { |
546 |
listview_add_sub_item (lv, 0, 0, type); |
listview_add_sub_item (lv, 0, 0, type); |
547 |
listview_add_sub_item (lv, 0, 1, name); |
listview_add_sub_item (lv, 0, 1, name); |
548 |
} |
} |
594 |
else { |
else { |
595 |
char *p = make_filename (path, name, NULL); |
char *p = make_filename (path, name, NULL); |
596 |
rc = add_single_file (lv, p); |
rc = add_single_file (lv, p); |
597 |
free (p); |
safe_free (p); |
598 |
} |
} |
599 |
n++; |
n++; |
600 |
} |
} |
601 |
if (n == 1) /* single file selected. */ |
if (n == 1) /* single file selected. */ |
602 |
rc = add_single_file (lv, path); |
rc = add_single_file (lv, path); |
603 |
if (path) |
safe_free (path); |
|
free (path); |
|
604 |
return rc; |
return rc; |
605 |
} |
} |
606 |
|
|
607 |
|
|
608 |
int |
int |
609 |
fm_assume_onepass_sig (const char * fname) |
fm_assume_onepass_sig (const char *fname) |
610 |
{ |
{ |
|
gpgme_data_t dat; |
|
611 |
armor_filter_context_t afx; |
armor_filter_context_t afx; |
612 |
gpg_iobuf_t fp; |
gpg_iobuf_t fp; |
613 |
PACKET * pkt = (PACKET *)calloc (1, sizeof *pkt); |
gpgme_data_t dat; |
614 |
|
PACKET *pkt; |
615 |
|
char tmpfile[MAX_PATH+1]; |
616 |
int check = 0; |
int check = 0; |
617 |
|
|
618 |
|
pkt = (PACKET *)calloc (1, sizeof *pkt); |
619 |
if (!fname) { |
if (!fname) { |
620 |
|
get_temp_name (tmpfile, sizeof (tmpfile)-1, "gpgme.tmp"); |
621 |
gpg_data_new_from_clipboard (&dat, 0); |
gpg_data_new_from_clipboard (&dat, 0); |
622 |
gpg_data_release_and_set_file (dat, "gpgme.tmp"); |
gpg_data_release_and_set_file (dat, tmpfile); |
623 |
|
|
624 |
fp = gpg_iobuf_open ("gpgme.tmp"); |
fp = gpg_iobuf_open (tmpfile); |
625 |
if (!fp) |
if (!fp) |
626 |
return 0; |
return 0; |
627 |
gpg_iobuf_ioctl (fp, 3, 1, NULL); |
gpg_iobuf_ioctl (fp, 3, 1, NULL); |
634 |
&& pkt->pkttype == PKT_COMPRESSED) |
&& pkt->pkttype == PKT_COMPRESSED) |
635 |
check = 1; |
check = 1; |
636 |
gpg_free_packet (pkt); |
gpg_free_packet (pkt); |
|
safe_free (pkt); |
|
637 |
gpg_iobuf_close (fp); |
gpg_iobuf_close (fp); |
638 |
remove ("gpgme.tmp"); |
remove (tmpfile); |
639 |
} |
} |
640 |
/* XXX: implement it for real files */ |
/* XXX: implement it for real files */ |
641 |
|
safe_free (pkt); |
642 |
return check; |
return check; |
643 |
} |
} |
644 |
|
|
651 |
items = listview_count_items (lv, 0); |
items = listview_count_items (lv, 0); |
652 |
if (!items) |
if (!items) |
653 |
return -1; |
return -1; |
654 |
else if (items == 1) |
else if (items == 1) { |
|
{ |
|
655 |
listview_select_one (lv, 0); |
listview_select_one (lv, 0); |
656 |
return 0; |
return 0; |
657 |
} |
} |
658 |
else if (items > 1) |
else if (items > 1) { |
|
{ |
|
659 |
i = listview_get_curr_pos (lv); |
i = listview_get_curr_pos (lv); |
660 |
if (i == -1) |
if (i == -1) { |
661 |
{ |
msg_box (lv->ctrl, _("Please select a file."), |
662 |
msg_box (lv->ctrl, _("Please select a file."), _("File Manager"), MB_ERR); |
_("File Manager"), MB_ERR); |
663 |
return -1; |
return -1; |
664 |
} |
} |
665 |
return i; |
return i; |
666 |
} |
} |
667 |
|
|
668 |
return -1; |
return -1; |
669 |
} /* fm_get_current_pos */ |
} |
670 |
|
|
671 |
|
|
672 |
static int |
static int |
673 |
fm_check_detached_sig( listview_ctrl_t lv, int pos ) |
fm_check_detached_sig (listview_ctrl_t lv, int pos) |
674 |
{ |
{ |
675 |
char type[128]; |
char type[128]; |
676 |
|
|
677 |
listview_get_item_text( lv, pos, 0, type, 127 ); |
listview_get_item_text (lv, pos, 0, type, sizeof (type)-1); |
678 |
return !strcmp( type, "SIGNED-DETACH" )? 1 : 0; |
return !strcmp (type, "SIGNED-DETACH")? 1 : 0; |
679 |
} /* fm_check_detached_sig */ |
} |
680 |
|
|
681 |
|
|
682 |
int |
int |
733 |
} |
} |
734 |
|
|
735 |
return rc; |
return rc; |
736 |
} /* fm_check_file_type */ |
} |
737 |
|
|
738 |
|
|
739 |
/* Set the file status of the given command @fm_cmd. |
/* Set the file status of the given command @fm_cmd. |
804 |
if (!cnt) |
if (!cnt) |
805 |
return 0; |
return 0; |
806 |
n = -1; |
n = -1; |
807 |
i = log_box (_("File Manager"), MB_WARN|MB_YESNO, |
i = log_box (_("File Manager"), MB_WARN|MB_YESNO, |
808 |
_("\"%s\" does not seems to be a text file.\n" |
_("\"%s\" does not seems to be a text file.\n" |
809 |
"Do you really want to clearsign it?"), name); |
"Do you really want to clearsign it?"), name); |
810 |
if (i == IDYES) |
if (i == IDYES) |
812 |
return n; |
return n; |
813 |
} |
} |
814 |
|
|
815 |
|
|
816 |
int |
int |
817 |
fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd) |
fm_parse_files (listview_ctrl_t lv, HWND dlg, int cmd) |
818 |
{ |
{ |
941 |
case FM_IMPORT: |
case FM_IMPORT: |
942 |
free_if_alloc (ctx->opaque); |
free_if_alloc (ctx->opaque); |
943 |
ctx->opaque = m_strdup (fname); |
ctx->opaque = m_strdup (fname); |
|
if (!ctx->opaque) |
|
|
BUG (0); |
|
944 |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
945 |
file_import_dlg_proc, (LPARAM)ctx); |
file_import_dlg_proc, (LPARAM)ctx); |
946 |
if (ctx->cancel == 1) |
if (ctx->cancel == 1) |
1022 |
free_if_alloc (*dst); |
free_if_alloc (*dst); |
1023 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1024 |
c->output = m_strdup (s); |
c->output = m_strdup (s); |
|
if (!c->output) |
|
|
BUG (0); |
|
1025 |
if (dst) |
if (dst) |
1026 |
*dst = fm_quote_file (s); |
*dst = fm_quote_file (s); |
1027 |
return 0; |
return 0; |
1089 |
gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0); |
gpgme_key_t sigkey = gpgme_signers_enum (ctx, 0); |
1090 |
if (sigkey && sigkey->subkeys) { |
if (sigkey && sigkey->subkeys) { |
1091 |
keyid = m_strdup (sigkey->subkeys->keyid); |
keyid = m_strdup (sigkey->subkeys->keyid); |
|
if (!keyid) |
|
|
BUG (NULL); |
|
1092 |
} |
} |
1093 |
} |
} |
1094 |
if (!c->init_cb || !c->cache_cb) { |
if (!c->init_cb || !c->cache_cb) { |
1199 |
} |
} |
1200 |
|
|
1201 |
|
|
1202 |
|
char* get_pka_status (gpgme_signature_t sig); |
1203 |
|
|
1204 |
|
|
1205 |
/* Show the human readable verify result from @sigres. */ |
/* Show the human readable verify result from @sigres. */ |
1206 |
static void |
static void |
1207 |
show_verify_result (gpgme_verify_result_t sigres) |
show_verify_result (gpgme_verify_result_t sigres) |
1208 |
{ |
{ |
|
gpgme_key_t key=NULL; |
|
1209 |
gpgme_signature_t sig=sigres->signatures; |
gpgme_signature_t sig=sigres->signatures; |
1210 |
const char *s, *keyid; |
winpt_key_s key; |
1211 |
int sigok = 0; |
const char *s, *keyid, *uid; |
1212 |
int type; |
char *pka_info; |
1213 |
char buf[384]; |
char buf[384]; |
1214 |
|
int sigok = 0; |
1215 |
|
|
1216 |
sig = sigres->signatures; |
sig = sigres->signatures; |
1217 |
sigok = sig->summary & GPGME_SIGSUM_GREEN; |
sigok = sig->summary & GPGME_SIGSUM_GREEN; |
1218 |
s = sigok? _("Good signature") : _("BAD signature"); |
s = sigok? _("Good signature") : _("BAD signature"); |
|
type = sigok? MB_OK: MB_ICONWARNING|MB_OK; |
|
1219 |
keyid = sig->fpr; |
keyid = sig->fpr; |
1220 |
if (!keyid) |
if (!keyid) |
1221 |
return; |
return; |
1222 |
|
pka_info = get_pka_status (sig); |
1223 |
keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr + 24; |
keyid = get_keyid_from_fpr (sig->fpr); |
1224 |
get_pubkey (sig->fpr, &key); |
memset (&key, 0, sizeof (key)); |
1225 |
|
if (!winpt_get_pubkey (sig->fpr, &key)) |
1226 |
|
uid = key.ext->uids->uid; |
1227 |
|
else |
1228 |
|
uid = _("user ID not found"); |
1229 |
_snprintf (buf, sizeof (buf)-1, _("Signature made %s using %s key ID %s\n" |
_snprintf (buf, sizeof (buf)-1, _("Signature made %s using %s key ID %s\n" |
1230 |
"%s from \"%s\""), |
"%s from \"%s\"\n%s"), |
1231 |
strtimestamp (sig->timestamp), |
strtimestamp (sig->timestamp), |
1232 |
get_key_pubalgo (sig->pubkey_algo), |
get_key_pubalgo (sig->pubkey_algo), |
1233 |
keyid, s, key? key->uids->uid : _("user ID not found")); |
keyid, s, uid, pka_info? pka_info : ""); |
1234 |
msg_box (NULL, buf, _("Decrypt Verify"), type); |
msg_box (NULL, buf, _("Decrypt Verify"), sigok? MB_OK: MB_ICONWARNING|MB_OK); |
1235 |
|
free_if_alloc (pka_info); |
1236 |
|
winpt_release_pubkey (&key); |
1237 |
} |
} |
1238 |
|
|
1239 |
|
|
1240 |
/* Check the recipients if we have at least one secret key. */ |
/* Check the recipients if we have at least one secret key. */ |
1241 |
bool |
bool |
1242 |
secret_key_available (gpgme_recipient_t rset) |
is_seckey_available (gpgme_recipient_t rset) |
1243 |
{ |
{ |
1244 |
gpgme_recipient_t r; |
gpgme_recipient_t r; |
1245 |
gpgme_key_t key; |
winpt_key_s key; |
1246 |
|
|
1247 |
for (r=rset; r; r = r->next) { |
for (r=rset; r; r = r->next) { |
1248 |
if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY) |
if (gpgme_err_code (r->status) == GPG_ERR_NO_SECKEY) |
1249 |
continue; |
continue; |
1250 |
else { |
else { |
1251 |
|
memset (&key, 0, sizeof (key)); |
1252 |
/* extra check to make sure the key is available right now. */ |
/* extra check to make sure the key is available right now. */ |
1253 |
if (!get_seckey (r->keyid, &key)) |
if (!winpt_get_seckey (r->keyid, &key)) { |
1254 |
|
winpt_release_pubkey (&key); |
1255 |
return true; |
return true; |
1256 |
|
} |
1257 |
|
winpt_release_pubkey (&key); |
1258 |
} |
} |
1259 |
} |
} |
1260 |
return false; |
return false; |
1261 |
} |
} |
1262 |
|
|
1263 |
|
|
1264 |
|
/* If the decrypt result contains the original file name, |
1265 |
|
we use it instead of the artificial "output - .gpg" string. */ |
1266 |
|
static int |
1267 |
|
restore_original_name (const char *output, const char *file_name) |
1268 |
|
{ |
1269 |
|
char *dir; |
1270 |
|
char *orig; |
1271 |
|
int rc = 0; |
1272 |
|
|
1273 |
|
dir = strrchr (output, '\\'); |
1274 |
|
if (!dir) |
1275 |
|
orig = strdup (file_name); |
1276 |
|
else { |
1277 |
|
orig = (char*)calloc (1, strlen (file_name)+ 1 + |
1278 |
|
strlen (output)+1); |
1279 |
|
if (!orig) |
1280 |
|
BUG (0); |
1281 |
|
memcpy (orig, output, (dir-output)+1); |
1282 |
|
strcat (orig, file_name); |
1283 |
|
} |
1284 |
|
/* XXX: we need to find out if the string needs to be utf8 decoded. */ |
1285 |
|
if (overwrite_file (orig)) { |
1286 |
|
DeleteFile (orig); |
1287 |
|
if (!MoveFile (output, orig)) |
1288 |
|
rc = -1; |
1289 |
|
} |
1290 |
|
safe_free (orig); |
1291 |
|
return rc; |
1292 |
|
} |
1293 |
|
|
1294 |
|
|
1295 |
/* Decrypt the file @name. */ |
/* Decrypt the file @name. */ |
1296 |
int |
int |
1297 |
fm_decrypt (fm_state_t c, const char *name) |
fm_decrypt (fm_state_t c, const char *name) |
1300 |
gpgme_ctx_t ctx = c->ctx; |
gpgme_ctx_t ctx = c->ctx; |
1301 |
gpgme_decrypt_result_t res; |
gpgme_decrypt_result_t res; |
1302 |
gpgme_verify_result_t sigres; |
gpgme_verify_result_t sigres; |
1303 |
file_data_t in =NULL, out=NULL; |
file_data_t in = NULL, out = NULL; |
1304 |
int rc = 0; |
int rc = 0; |
1305 |
|
|
1306 |
if (!c->init_cb || !c->cache_cb) { |
if (!c->init_cb || !c->cache_cb) { |
1310 |
} |
} |
1311 |
|
|
1312 |
c->output = m_strdup (name); |
c->output = m_strdup (name); |
|
if (!c->output) |
|
|
BUG (0); |
|
1313 |
if (is_openpgp_ext (c->output)) |
if (is_openpgp_ext (c->output)) |
1314 |
c->output[strlen (c->output)-4] = '\0'; |
c->output[strlen (c->output)-4] = '\0'; |
1315 |
else { |
else { |
1319 |
if (s) { |
if (s) { |
1320 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1321 |
c->output = m_strdup (s); |
c->output = m_strdup (s); |
|
if (!c->output) |
|
|
BUG (NULL); |
|
1322 |
} |
} |
1323 |
} |
} |
1324 |
|
|
1328 |
goto leave; |
goto leave; |
1329 |
} |
} |
1330 |
|
|
1331 |
|
/* we fetch all recipients here to make sure they list is complete. */ |
1332 |
|
release_gpg_recipients (&c->pass_cb.recipients); |
1333 |
|
gpg_get_recipients (name, &c->pass_cb.recipients); |
1334 |
|
|
1335 |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
1336 |
if (err) |
if (err) |
1337 |
goto leave; |
goto leave; |
1339 |
err = gpg_file_data_new (c->output, F_DATA_WRITE, &out); |
err = gpg_file_data_new (c->output, F_DATA_WRITE, &out); |
1340 |
if (err) |
if (err) |
1341 |
goto leave; |
goto leave; |
1342 |
|
|
1343 |
op_begin (); |
op_begin (); |
1344 |
err = gpgme_op_decrypt_verify (ctx, in->dat, out->dat); |
err = gpgme_op_decrypt_verify (ctx, in->dat, out->dat); |
1345 |
op_end (); |
op_end (); |
1351 |
} |
} |
1352 |
|
|
1353 |
res = gpgme_op_decrypt_result (ctx); |
res = gpgme_op_decrypt_result (ctx); |
1354 |
if (res && res->recipients && !secret_key_available (res->recipients)) { |
if (res && res->recipients && !is_seckey_available (res->recipients)) { |
1355 |
const char *keyid = res->recipients->keyid; |
const char *keyid = res->recipients->keyid; |
1356 |
char *p = get_key_userid (keyid+8); |
char *p = get_key_userid (keyid+8); |
1357 |
gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo; |
gpgme_pubkey_algo_t pkalgo = res->recipients->pubkey_algo; |
1358 |
|
|
1359 |
log_box( _("Decryption"), MB_ERR, |
log_box (_("Decryption"), MB_ERR, |
1360 |
_("Encrypted with %s key, ID %s.%s\n" |
_("Encrypted with %s key, ID %s.%s\n" |
1361 |
"Decryption failed: secret key not available."), |
"Decryption failed: secret key not available."), |
1362 |
get_key_pubalgo (pkalgo), keyid+8, p); |
get_key_pubalgo (pkalgo), keyid+8, p); |
1373 |
log_box ("Decrypt", MB_ERR, |
log_box ("Decrypt", MB_ERR, |
1374 |
_("Decryption failed.\n%s: does not exist."), c->output); |
_("Decryption failed.\n%s: does not exist."), c->output); |
1375 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
1376 |
|
goto leave; |
1377 |
|
} |
1378 |
|
else if (res && res->file_name) { |
1379 |
|
char *file; |
1380 |
|
int id = IDNO; |
1381 |
|
|
1382 |
|
file = strrchr (c->output, '\\'); |
1383 |
|
if (!file) |
1384 |
|
file = c->output; |
1385 |
|
else |
1386 |
|
file++; |
1387 |
|
if (strcmp (res->file_name, file)) |
1388 |
|
id = log_box (_("Decrypt"), MB_QUEST_ASK, |
1389 |
|
_("The original file name is '%s'.\n\n" |
1390 |
|
"Do you want to use this instead of '%s'?"), |
1391 |
|
res->file_name, file); |
1392 |
|
if (id == IDYES) { |
1393 |
|
/* before we can move the file, it needs to be closed first. */ |
1394 |
|
gpg_file_data_release (out); |
1395 |
|
out = NULL; |
1396 |
|
restore_original_name (c->output, res->file_name); |
1397 |
|
} |
1398 |
} |
} |
|
|
|
1399 |
sigres = gpgme_op_verify_result (ctx); |
sigres = gpgme_op_verify_result (ctx); |
1400 |
if (sigres && sigres->signatures) |
if (sigres && sigres->signatures) |
1401 |
show_verify_result (sigres); |
show_verify_result (sigres); |
1474 |
static void |
static void |
1475 |
fm_add_sig_stat (file_sig_ctx_t log) |
fm_add_sig_stat (file_sig_ctx_t log) |
1476 |
{ |
{ |
1477 |
gpgme_key_t key; |
struct winpt_key_s key; |
1478 |
const char *kid; |
const char *kid; |
1479 |
|
|
1480 |
kid = log->sig->fpr; |
memset (&key, 0, sizeof (key)); |
1481 |
if (!kid) |
kid = get_keyid_from_fpr (log->sig->fpr); |
1482 |
BUG (NULL); |
log->use_uid = 0; |
1483 |
if (strlen (kid) == 40) |
if (!winpt_get_pubkey (kid, &key)) { |
1484 |
kid += 32; |
log->user_id = key.ext->uids->uid; |
|
else if (strlen (kid) == 32) |
|
|
kid += 24; |
|
|
if (get_pubkey (kid, &key)) |
|
|
log->use_uid = 0; |
|
|
else { |
|
|
log->user_id = key->uids->uid; |
|
1485 |
log->use_uid = 1; |
log->use_uid = 1; |
1486 |
} |
} |
1487 |
|
winpt_release_pubkey (&key); |
1488 |
file_verify_add_state (log); |
file_verify_add_state (log); |
1489 |
} |
} |
1490 |
|
|
1574 |
else |
else |
1575 |
title = _("Selected Output File"); |
title = _("Selected Output File"); |
1576 |
|
|
1577 |
if (strstr (name, ".sig") |
if (stristr (name, ".sig") || |
1578 |
|| strstr (name, ".asc") |
stristr (name, ".asc") || |
1579 |
|| strstr (name, ".gpg")) { |
stristr (name, ".gpg")) { |
1580 |
_snprintf (fname, sizeof (fname) - 1, "%s", name); |
_snprintf (fname, sizeof (fname) - 1, "%s", name); |
1581 |
fname[strlen (fname) - 4] = '\0'; |
fname[strlen (fname) - 4] = '\0'; |
1582 |
if (file_exist_check (fname) == 0 && detached) |
if (file_exist_check (fname) == 0 && detached) |
1598 |
if (file) { |
if (file) { |
1599 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1600 |
c->output = m_strdup (file); |
c->output = m_strdup (file); |
|
if (!c->output) |
|
|
BUG (NULL); |
|
1601 |
} |
} |
1602 |
else { |
else { |
1603 |
msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR); |
msg_box (c->dlg, _("Invalid file name. Exit"), _("Verify"), MB_ERR); |
1606 |
if (detached) |
if (detached) |
1607 |
c->sigmode = GPGME_SIG_MODE_DETACH; |
c->sigmode = GPGME_SIG_MODE_DETACH; |
1608 |
else { |
else { |
1609 |
if (strstr (name, ".asc")) |
if (stristr (name, ".asc")) |
1610 |
c->sigmode = GPGME_SIG_MODE_CLEAR; |
c->sigmode = GPGME_SIG_MODE_CLEAR; |
1611 |
else |
else |
1612 |
c->sigmode = GPGME_SIG_MODE_NORMAL; |
c->sigmode = GPGME_SIG_MODE_NORMAL; |
1628 |
file_data_t in=NULL, out=NULL; |
file_data_t in=NULL, out=NULL; |
1629 |
int rc = 0; |
int rc = 0; |
1630 |
|
|
1631 |
if (strstr (name, ".sig")) |
if (stristr (name, ".sig")) |
1632 |
detached = 1; |
detached = 1; |
1633 |
|
|
1634 |
if (get_output_file (c, name, detached)) |
if (get_output_file (c, name, detached)) |
1636 |
|
|
1637 |
memset (&log, 0, sizeof (log)); |
memset (&log, 0, sizeof (log)); |
1638 |
log.file = m_strdup (name); |
log.file = m_strdup (name); |
|
if (!log.file) |
|
|
BUG (NULL); |
|
1639 |
file_verify_create_dlg (); |
file_verify_create_dlg (); |
1640 |
|
|
1641 |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
err = gpg_file_data_new (name, F_DATA_READ, &in); |
1689 |
|
|
1690 |
free_if_alloc (c->output); |
free_if_alloc (c->output); |
1691 |
c->output = m_strdup (name); |
c->output = m_strdup (name); |
|
if (!c->output) |
|
|
BUG (NULL); |
|
1692 |
|
|
1693 |
err = gpg_file_data_new (name, F_DATA_READ, &keydata); |
err = gpg_file_data_new (name, F_DATA_READ, &keydata); |
1694 |
if (err) |
if (err) |
1722 |
/* Export the selected keys from the File Manager to a file. */ |
/* Export the selected keys from the File Manager to a file. */ |
1723 |
int |
int |
1724 |
fm_export (fm_state_t c) |
fm_export (fm_state_t c) |
1725 |
{ |
{ |
|
int rc = 0; |
|
1726 |
gpgme_ctx_t ctx = c->ctx; |
gpgme_ctx_t ctx = c->ctx; |
1727 |
gpgme_error_t err; |
gpgme_error_t err; |
1728 |
gpgme_key_t *rset = c->recp; |
gpgme_key_t *rset = c->recp; |
1729 |
file_data_t keydata = NULL; |
file_data_t keydata = NULL; |
1730 |
const char *name; |
const char *name; |
1731 |
char *p = NULL, *patt = NULL; |
char *p = NULL, *patt = NULL; |
1732 |
|
int rc = 0; |
1733 |
|
|
1734 |
if (!rset || !rset[0]) { |
if (!rset || !rset[0]) { |
1735 |
msg_box (c->dlg, _("No key was selected for export."), _("Export"), MB_ERR); |
msg_box (c->dlg, _("No key was selected for export."), _("Export"), MB_ERR); |
1764 |
leave: |
leave: |
1765 |
if (keydata) |
if (keydata) |
1766 |
gpg_file_data_release (keydata); |
gpg_file_data_release (keydata); |
1767 |
if (patt) |
safe_free (patt); |
|
free (patt); |
|
1768 |
free_if_alloc (p); |
free_if_alloc (p); |
1769 |
return rc; |
return rc; |
1770 |
} |
} |
1821 |
|
|
1822 |
case PGP_SIG: |
case PGP_SIG: |
1823 |
case PGP_CLEARSIG: |
case PGP_CLEARSIG: |
|
file_verify_use_event (); |
|
1824 |
if (type == PGP_SIG) |
if (type == PGP_SIG) |
1825 |
detached = 1; |
detached = 1; |
1826 |
fm_verify (ctx, detached, fn); |
fm_verify (ctx, detached, fn); |
1857 |
fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv) |
fm_encrypt_into_zip (fm_state_t ctx, listview_ctrl_t lv) |
1858 |
{ |
{ |
1859 |
PK_FILE_LIST list=NULL; |
PK_FILE_LIST list=NULL; |
1860 |
const char *outfile; |
const char *outfile, *ext; |
1861 |
char *out_enc; |
char *out_enc; |
1862 |
int nitems = listview_count_items (lv, 0); |
int nitems; |
1863 |
int i, idx = -1; |
int i, idx = -1; |
1864 |
int rc; |
int rc; |
1865 |
|
|
1866 |
|
nitems = listview_count_items (lv, 0); |
1867 |
if (!nitems) { |
if (!nitems) { |
1868 |
msg_box (NULL, _("Encrypting into a ZIP archive makes sense with multiple files"), |
msg_box (NULL, _("Encrypting into a ZIP archive makes sense with multiple files"), |
1869 |
_("File Manager"), MB_ERR); |
_("File Manager"), MB_ERR); |
1893 |
if (rc) |
if (rc) |
1894 |
return rc; |
return rc; |
1895 |
|
|
1896 |
out_enc = make_filename (NULL, outfile, "gpg"); |
ext = file_get_extension (ctx->ctx, ctx->sigmode)+1; |
1897 |
|
out_enc = make_filename (NULL, outfile, ext); |
1898 |
fm_set_status (lv, idx, FM_ENCRYPT, (gpgme_sig_mode_t)0, 1, out_enc); |
fm_set_status (lv, idx, FM_ENCRYPT, (gpgme_sig_mode_t)0, 1, out_enc); |
1899 |
free_if_alloc (out_enc); |
free_if_alloc (out_enc); |
1900 |
|
|
1969 |
const char *a = 0; |
const char *a = 0; |
1970 |
const char *b = 0; |
const char *b = 0; |
1971 |
|
|
1972 |
switch( (int)sortby ) { |
switch ((int)sortby) { |
1973 |
case FM_SORT_STAT: |
case FM_SORT_STAT: |
1974 |
break; |
break; |
1975 |
case FM_SORT_NAME: |
case FM_SORT_NAME: |
1985 |
int |
int |
1986 |
fm_sort (listview_ctrl_t lv, int sortby) |
fm_sort (listview_ctrl_t lv, int sortby) |
1987 |
{ |
{ |
1988 |
return listview_sort_items( lv, sortby, fm_cmp_cb ); |
return listview_sort_items (lv, sortby, fm_cmp_cb); |
1989 |
} |
} |
1990 |
|
|
1991 |
|
|