25 |
|
|
26 |
#include <windows.h> |
#include <windows.h> |
27 |
#include <sys/stat.h> |
#include <sys/stat.h> |
28 |
|
#include <string.h> |
29 |
|
#include <errno.h> |
30 |
|
|
31 |
#include "gpgme.h" |
#include "gpgme.h" |
32 |
#include "wptTypes.h" |
#include "wptTypes.h" |
33 |
#include "wptErrors.h" |
#include "wptErrors.h" |
34 |
#include "wptW32API.h" |
#include "wptW32API.h" |
35 |
|
#include "wptGPG.h" |
36 |
|
#include "openpgp.h" |
37 |
|
|
38 |
|
|
39 |
#define NROFHEXDIGITS 2 |
#define NROFHEXDIGITS 2 |
706 |
} |
} |
707 |
|
|
708 |
|
|
709 |
#if 0 |
static gpgme_error_t |
710 |
|
clip_store_data (char *tmp_outname, DWORD outlen) |
711 |
|
{ |
712 |
|
gpgme_data_t in; |
713 |
|
gpgme_error_t err; |
714 |
|
|
715 |
|
get_temp_name (tmp_outname, outlen-1, NULL); |
716 |
|
err = gpg_data_new_from_clipboard (&in, 0); |
717 |
|
if (err) |
718 |
|
return err; |
719 |
|
err = gpg_data_release_and_set_file (in, tmp_outname); |
720 |
|
return err; |
721 |
|
} |
722 |
|
|
723 |
|
|
724 |
/* Extract all recipients from the file @file. |
/* Extract all recipients from the file @file. |
725 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
726 |
static int |
static gpgme_error_t |
727 |
do_get_recipients (const char *file, gpgme_recipient_t *r_list) |
file_extract_recipient (const char *file, gpgme_recipient_t *r_list) |
728 |
{ |
{ |
|
gpgme_recipient_t l; |
|
729 |
PACKET *pkt; |
PACKET *pkt; |
730 |
|
PKT_pubkey_enc *enc; |
731 |
gpg_iobuf_t inp = NULL; |
gpg_iobuf_t inp = NULL; |
732 |
armor_filter_context_t afx; |
armor_filter_context_t afx; |
733 |
|
gpgme_recipient_t l; |
734 |
int rc = 0, quit=0; |
int rc = 0, quit=0; |
735 |
|
|
736 |
if (!file || !r_list) { |
if (!file || !r_list) { |
737 |
log_debug ("do_list_packets: !r_list || !file"); |
log_debug ("do_list_packets: !r_list || !file"); |
738 |
return -1; |
return gpgme_error (GPG_ERR_INV_ARG); |
739 |
} |
} |
740 |
|
|
741 |
*r_list=NULL; |
*r_list=NULL; |
742 |
inp = gpg_iobuf_open (file); |
inp = gpg_iobuf_open (file); |
743 |
if (!inp) |
if (!inp) |
744 |
return WPTERR_FILE_OPEN; |
return gpgme_err_code_from_errno (errno); |
745 |
gpg_iobuf_ioctl (inp, 3, 1, NULL); /* disable cache */ |
gpg_iobuf_ioctl (inp, 3, 1, NULL); /* disable cache */ |
746 |
if (gpg_use_armor_filter (inp)) { |
if (gpg_use_armor_filter (inp)) { |
747 |
memset (&afx, 0, sizeof (afx)); |
memset (&afx, 0, sizeof (afx)); |
752 |
while (!quit && (rc = gpg_parse_packet (inp, pkt)) != -1) { |
while (!quit && (rc = gpg_parse_packet (inp, pkt)) != -1) { |
753 |
switch (pkt->pkttype) { |
switch (pkt->pkttype) { |
754 |
case PKT_PUBKEY_ENC: |
case PKT_PUBKEY_ENC: |
755 |
{PKT_pubkey_enc *enc = pkt->pkt.pubkey_enc; |
enc = pkt->pkt.pubkey_enc; |
756 |
if (!enc) |
if (!enc) |
757 |
break; |
break; |
758 |
l = calloc (1, sizeof *l); |
l = (gpgme_recipient_t)calloc (1, sizeof *l); |
759 |
l->keyid = calloc (1, 16+1); |
if (!l) |
760 |
|
BUG (NULL); |
761 |
|
l->keyid = (char*)calloc (1, 16+1); |
762 |
_snprintf (l->keyid, 16, "%08lX%08lX", enc->keyid[0], enc->keyid[1]); |
_snprintf (l->keyid, 16, "%08lX%08lX", enc->keyid[0], enc->keyid[1]); |
763 |
l->pubkey_algo = enc->pubkey_algo; |
l->pubkey_algo = (gpgme_pubkey_algo_t)enc->pubkey_algo; |
764 |
l->status = 0; |
l->status = 0; |
765 |
l->next = (*r_list); |
l->next = (*r_list); |
766 |
*r_list = l; |
*r_list = l; |
767 |
break;} |
break; |
768 |
|
|
769 |
case PKT_ENCRYPTED: |
case PKT_ENCRYPTED: |
770 |
case PKT_ENCRYPTED_MDC: |
case PKT_ENCRYPTED_MDC: |
773 |
case PKT_SECRET_KEY: |
case PKT_SECRET_KEY: |
774 |
quit = 1; |
quit = 1; |
775 |
break; |
break; |
776 |
|
|
777 |
|
default: |
778 |
|
break; |
779 |
} |
} |
780 |
gpg_free_packet (pkt); |
gpg_free_packet (pkt); |
781 |
gpg_init_packet (pkt); |
gpg_init_packet (pkt); |
784 |
safe_free (pkt); |
safe_free (pkt); |
785 |
return 0; |
return 0; |
786 |
} |
} |
787 |
#endif |
|
788 |
|
|
789 |
|
/* Either extract the list of recipients from the file @file or |
790 |
|
if the string is NULL, try to extract them from the clipboard. |
791 |
|
Return value: 0 on success. */ |
792 |
|
gpgme_error_t |
793 |
|
gpg_get_recipients (const char *file, gpgme_recipient_t *r_list) |
794 |
|
{ |
795 |
|
gpgme_error_t err; |
796 |
|
char tmp[MAX_PATH+1]; |
797 |
|
|
798 |
|
if (!file) { |
799 |
|
clip_store_data (tmp, DIM (tmp)-2); |
800 |
|
err = file_extract_recipient (tmp, r_list); |
801 |
|
DeleteFile (tmp); |
802 |
|
} |
803 |
|
else |
804 |
|
err = file_extract_recipient (file, r_list); |
805 |
|
return err; |
806 |
|
} |
807 |
|
|
808 |
|
|
809 |
|
/* Try to find a subpacket with the given id @subpktid |
810 |
|
inside the key @key. |
811 |
|
Return value: 0 on success. */ |
812 |
|
gpgme_error_t |
813 |
|
gpg_find_key_subpacket (const char *key, int subpktid, |
814 |
|
char **value) |
815 |
|
{ |
816 |
|
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
817 |
|
const char *fmt; |
818 |
|
const char *spk; |
819 |
|
char *p, *cmd; |
820 |
|
HANDLE out; |
821 |
|
|
822 |
|
*value = NULL; |
823 |
|
p = read_gpg_program (); |
824 |
|
fmt = "%s --with-colons --list-options show-sig-subpackets=%d --list-sigs %s"; |
825 |
|
cmd = (char*)calloc (1, strlen (fmt) + strlen (p) + strlen (key) + 32 + 1); |
826 |
|
sprintf (cmd, fmt, p, subpktid, key); |
827 |
|
|
828 |
|
out = create_tmpfile ("gpg_subpackets"); |
829 |
|
if (create_process (cmd, NULL, out, NULL)) |
830 |
|
err = gpg_error (GPG_ERR_INTERNAL); |
831 |
|
|
832 |
|
free (p); |
833 |
|
free (cmd); |
834 |
|
|
835 |
|
p = map_tmpfile (out, NULL); |
836 |
|
if (p && (spk=strstr (p, "spk"))) { |
837 |
|
char *end = strstr (spk, "\n"); |
838 |
|
if (end) { |
839 |
|
*value = (char*)calloc (1, (end-spk)+1); |
840 |
|
memcpy (*value, spk, (end-spk)-1); |
841 |
|
} |
842 |
|
} |
843 |
|
|
844 |
|
free (p); |
845 |
|
CloseHandle (out); |
846 |
|
return err; |
847 |
|
} |