21 |
/* TODO: |
/* TODO: |
22 |
* check_armor_type: we should check the whole file and not only the first line! |
* check_armor_type: we should check the whole file and not only the first line! |
23 |
*/ |
*/ |
24 |
|
|
25 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
26 |
#include <config.h> |
#include <config.h> |
27 |
#endif |
#endif |
50 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
51 |
#include "wptImport.h" |
#include "wptImport.h" |
52 |
#include "wptCrypto.h" |
#include "wptCrypto.h" |
53 |
|
#include "wptKeyManager.h" |
54 |
#include "openpgp.h" |
#include "openpgp.h" |
55 |
|
|
56 |
#define op_begin() SetCursor (LoadCursor (NULL, IDC_WAIT)) |
#define op_begin() SetCursor (LoadCursor (NULL, IDC_WAIT)) |
114 |
|
|
115 |
/* Removes 'critical' attributes from the file @fname. |
/* Removes 'critical' attributes from the file @fname. |
116 |
If @force is 1, the user is not asked for permission. */ |
If @force is 1, the user is not asked for permission. */ |
117 |
static void |
void |
118 |
remove_crit_file_attrs (const char *fname, int force) |
remove_crit_file_attrs (const char *fname, int force) |
119 |
{ |
{ |
120 |
u32 fattr; |
u32 fattr; |
529 |
if (rc == -1) |
if (rc == -1) |
530 |
break; /* XXX: fixme? */ |
break; /* XXX: fixme? */ |
531 |
} |
} |
532 |
|
DragFinish (dd_files); |
533 |
return rc; |
return rc; |
534 |
} |
} |
535 |
|
|
573 |
open.lStructSize = sizeof (OPENFILENAME); |
open.lStructSize = sizeof (OPENFILENAME); |
574 |
open.hInstance = glob_hinst; |
open.hInstance = glob_hinst; |
575 |
open.lpstrTitle = _("File Open"); |
open.lpstrTitle = _("File Open"); |
576 |
open.lpstrFilter = _("All Files (*.*)\0*.*\0\0"); |
open.lpstrFilter = "All Files (*.*)\0*.*\0\0"; |
577 |
open.hwndOwner = dlg; |
open.hwndOwner = dlg; |
578 |
open.lpstrFile = file; |
open.lpstrFile = file; |
579 |
open.nMaxFile = sizeof (file) - 1; |
open.nMaxFile = sizeof (file) - 1; |
766 |
case FM_SIGN: |
case FM_SIGN: |
767 |
if (sigmode == GPGME_SIG_MODE_DETACH) |
if (sigmode == GPGME_SIG_MODE_DETACH) |
768 |
strcpy (status, "SIGNED-DETACH"); |
strcpy (status, "SIGNED-DETACH"); |
769 |
|
else if (sigmode == GPGME_SIG_MODE_CLEAR) |
770 |
|
strcpy (status, "SIGNED-CLEAR"); |
771 |
else |
else |
772 |
strcpy (status, "SIGNED"); |
strcpy (status, "SIGNED"); |
773 |
break; |
break; |
778 |
default: strcpy (status, "UNKNOWN"); break; |
default: strcpy (status, "UNKNOWN"); break; |
779 |
} |
} |
780 |
|
|
781 |
if (success) { |
if (success && update) { |
782 |
if (update) { |
listview_add_sub_item (lv, pos, 0, status); |
783 |
listview_add_sub_item (lv, pos, 0, status); |
listview_add_sub_item (lv, pos, 1, output); |
|
listview_add_sub_item (lv, pos, 1, output); |
|
|
} |
|
784 |
} |
} |
785 |
listview_add_sub_item( lv, pos, 2, operat ); |
listview_add_sub_item( lv, pos, 2, operat ); |
786 |
} |
} |
916 |
if (!confirm.yes) |
if (!confirm.yes) |
917 |
goto leave; |
goto leave; |
918 |
} |
} |
919 |
|
|
920 |
if (fm_cmd == FM_ENCRYPT_ZIP) |
if (fm_cmd == FM_ENCRYPT_ZIP) |
921 |
fm_encrypt_into_zip (ctx, lv); |
fm_encrypt_into_zip (ctx, lv); |
922 |
|
|
923 |
for (i = 0; i < listview_count_items (lv, 0); i++) { |
for (i = 0; i < listview_count_items (lv, 0); i++) { |
924 |
if( !listview_get_item_state( lv, i ) ) |
if (!listview_get_item_state (lv, i)) |
925 |
continue; |
continue; |
926 |
listview_get_item_text( lv, i, 1, fname, sizeof (fname) - 1 ); |
listview_get_item_text (lv, i, 1, fname, sizeof (fname) - 1); |
927 |
if( file_exist_check( fname ) && !is_directory( fname ) ) { |
if( file_exist_check (fname) && !is_directory (fname)) { |
928 |
log_box( _("File Manager"), MB_ERR, _("\"%s\" does not exist"), fname ); |
log_box (_("File Manager"), MB_ERR, |
929 |
|
_("\"%s\" does not exist"), fname); |
930 |
continue; |
continue; |
931 |
} |
} |
932 |
if( is_directory( fname ) ) |
if (is_directory (fname)) |
933 |
fm_cmd = FM_ENCRYPT_DIR; |
fm_cmd = FM_ENCRYPT_DIR; |
934 |
if( !fm_check_file_type( lv, i, fm_cmd ) ) |
if (!fm_check_file_type (lv, i, fm_cmd)) |
935 |
continue; |
continue; |
936 |
sig_detached = fm_check_detached_sig( lv, i ); |
sig_detached = fm_check_detached_sig (lv, i); |
937 |
switch (fm_cmd) { |
switch (fm_cmd) { |
938 |
case FM_LIST: rc = fm_list( fname, dlg ); break; |
case FM_LIST: rc = fm_list( fname, dlg ); break; |
939 |
case FM_WIPE: rc = fm_wipe( fname ); break; |
case FM_WIPE: rc = fm_wipe( fname ); break; |
942 |
case FM_SIGNENCRYPT: rc = fm_encrypt( ctx, fname, 1 ); break; |
case FM_SIGNENCRYPT: rc = fm_encrypt( ctx, fname, 1 ); break; |
943 |
case FM_DECRYPT: rc = fm_decrypt( ctx, fname ); break; |
case FM_DECRYPT: rc = fm_decrypt( ctx, fname ); break; |
944 |
case FM_SIGN: rc = fm_sign( ctx, fname ); break; |
case FM_SIGN: rc = fm_sign( ctx, fname ); break; |
945 |
case FM_SYMENC: rc = fm_sym_encrypt( ctx, fname );break; |
case FM_SYMENC: rc = fm_sym_encrypt (ctx, fname); break; |
946 |
case FM_VERIFY: rc = fm_verify (ctx, sig_detached, fname);break; |
case FM_VERIFY: rc = fm_verify (ctx, sig_detached, fname);break; |
947 |
case FM_IMPORT: |
case FM_IMPORT: |
948 |
free_if_alloc (ctx->opaque); |
free_if_alloc (ctx->opaque); |
949 |
ctx->opaque = m_strdup (fname); |
ctx->opaque = m_strdup (fname); |
950 |
if (!ctx->opaque) |
if (!ctx->opaque) |
951 |
BUG (0); |
BUG (0); |
952 |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT, dlg, |
953 |
file_import_dlg_proc, (LPARAM)ctx ); |
file_import_dlg_proc, (LPARAM)ctx); |
954 |
if (ctx->cancel == 1) |
if (ctx->cancel == 1) |
955 |
continue; |
continue; |
956 |
rc = fm_import (ctx, fname); |
rc = fm_import (ctx, fname); |
957 |
break; |
break; |
958 |
} |
} |
959 |
|
if (ctx->cancel == 1) { |
960 |
|
ctx->cancel = 0; |
961 |
|
continue; |
962 |
|
} |
963 |
fm_set_status (lv, i, fm_cmd, ctx->sigmode, !rc, ctx->output); |
fm_set_status (lv, i, fm_cmd, ctx->sigmode, !rc, ctx->output); |
964 |
free_if_alloc (ctx->output); |
free_if_alloc (ctx->output); |
965 |
progress_cleanup (&pfx); |
progress_cleanup (&pfx); |
1160 |
char ext[5], * pass; |
char ext[5], * pass; |
1161 |
|
|
1162 |
pass = request_passphrase2 (_("Symmetric"), 0, &cancel); |
pass = request_passphrase2 (_("Symmetric"), 0, &cancel); |
1163 |
if (cancel) |
if (cancel) { |
1164 |
|
c->cancel = 1; |
1165 |
return 0; |
return 0; |
1166 |
|
} |
1167 |
|
|
1168 |
/* XXX gpgme_control (ctx, GPGME_CTRL_CIPHER, -1);*/ |
/* XXX gpgme_control (ctx, GPGME_CTRL_CIPHER, -1);*/ |
1169 |
c->output = new char[strlen (name) + 5 + 1]; |
c->output = new char[strlen (name) + 5 + 1]; |
1273 |
int rc = 0; |
int rc = 0; |
1274 |
|
|
1275 |
if (!c->init_cb || !c->cache_cb) { |
if (!c->init_cb || !c->cache_cb) { |
1276 |
set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_DECRYPT, |
set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_DECRYPT, |
1277 |
c->dlg, _("Decryption")); |
c->dlg, _("Decryption")); |
1278 |
c->init_cb = 1; |
c->init_cb = 1; |
1279 |
} |
} |
1280 |
|
|
1281 |
c->output = m_strdup (name); |
c->output = m_strdup (name); |
1282 |
if (!c->output) |
if (!c->output) |
1353 |
gpg_file_data_release (in); |
gpg_file_data_release (in); |
1354 |
if (out) |
if (out) |
1355 |
gpg_file_data_release (out); |
gpg_file_data_release (out); |
1356 |
|
|
1357 |
return rc; |
return rc; |
1358 |
} |
} |
1359 |
|
|
1368 |
int rc = 0; |
int rc = 0; |
1369 |
|
|
1370 |
if (!c->init_cb || !c->cache_cb) { |
if (!c->init_cb || !c->cache_cb) { |
1371 |
set_gpg_passphrase_cb (&c->pass_cb, c->ctx, GPG_CMD_SIGN, c->dlg, _("Signing")); |
set_gpg_passphrase_cb (&c->pass_cb, c->ctx, |
1372 |
|
GPG_CMD_SIGN, c->dlg, _("Signing")); |
1373 |
c->init_cb = 1; |
c->init_cb = 1; |
1374 |
} |
} |
1375 |
|
|
1678 |
} |
} |
1679 |
|
|
1680 |
|
|
|
/* Generate a user friendly file name based on the key @k. */ |
|
|
static char* |
|
|
gen_key_outname (gpgme_key_t k) |
|
|
{ |
|
|
char *p; |
|
|
size_t i; |
|
|
|
|
|
p = new char[strlen (k->uids->name)+1+8]; |
|
|
if (!p) |
|
|
BUG (NULL); |
|
|
sprintf (p, "%s.asc", k->uids->name); |
|
|
for (i=0; i < strlen (p); i++) { |
|
|
if (p[i] == ' ') |
|
|
p[i] = '_'; |
|
|
} |
|
|
return p; |
|
|
} |
|
|
|
|
|
|
|
1681 |
/* Export the selected keys from the File Manager to a file. */ |
/* Export the selected keys from the File Manager to a file. */ |
1682 |
int |
int |
1683 |
fm_export (fm_state_t c) |
fm_export (fm_state_t c) |
1697 |
} |
} |
1698 |
|
|
1699 |
if (rset[1] == NULL) /* count == 1*/ |
if (rset[1] == NULL) /* count == 1*/ |
1700 |
p = gen_key_outname (rset[0]); |
p = km_gen_export_filename (rset[0]->subkeys->keyid+8, 0); |
1701 |
|
|
1702 |
name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"), |
name = get_filesave_dlg (c->dlg, _("Choose Name for Key File"), |
1703 |
NULL, p? p : NULL); |
NULL, p? p : NULL); |