1 |
/* wptKeyManager.cpp - Handy functions for the Key Manager dialog |
/* wptKeyManager.cpp - Handy functions for the Key Manager dialog |
2 |
* Copyright (C) 2001-2007 Timo Schulz |
* Copyright (C) 2001-2007, 2009 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. |
56 |
char *p = file; |
char *p = file; |
57 |
size_t i; |
size_t i; |
58 |
|
|
59 |
/* XXX: it is possible that the recipient has a different |
/* TODO: it is possible that the recipient has a different |
60 |
charset and thus maybe 8-bit chars should be stripped also. */ |
charset and thus maybe 8-bit chars should be stripped also. */ |
61 |
for (i=0; i < len; i++) { |
for (i=0; i < len; i++) { |
62 |
if (p[i] == ' ' || p[i] == ':' || p[i] == '?' || p[i] == '|' || |
if (p[i] == ' ' || p[i] == ':' || p[i] == '?' || p[i] == '|' || |
99 |
char *inf; |
char *inf; |
100 |
|
|
101 |
pk = key->ctx; |
pk = key->ctx; |
102 |
p = (is_sec? "sec": "pub"); |
p = (is_sec? "sec ": "pub "); |
103 |
p = p + (int)pk->subkeys->length + get_key_pubalgo2 (pk->subkeys->pubkey_algo); |
p = p + (int)pk->subkeys->length + get_key_pubalgo2 (pk->subkeys->pubkey_algo); |
104 |
p = p + "/0x" + (pk->subkeys->keyid+8); |
p = p + "/0x" + (pk->subkeys->keyid+8); |
105 |
p = p + " " + get_key_created (pk->subkeys->timestamp) + "\n"; |
p = p + " " + get_key_created (pk->subkeys->timestamp) + "\n"; |
112 |
/* Retrieve the opaque 32-bit param stored within the list view item |
/* Retrieve the opaque 32-bit param stored within the list view item |
113 |
at position @idx and return the gpgme key context. */ |
at position @idx and return the gpgme key context. */ |
114 |
gpgme_key_t |
gpgme_key_t |
115 |
km_get_key_ptr (listview_ctrl_t lv, int idx, struct keycache_s **r_ctx) |
km_get_key_ptr (keylist_ctrl_t kl, int idx, struct keycache_s **r_ctx) |
116 |
{ |
{ |
117 |
struct keycache_s *ctx; |
listview_ctrl_t lv = kl->lv; |
118 |
|
struct keycache_s *ctx; |
119 |
|
|
120 |
ctx = (struct keycache_s *)listview_get_item2 (lv, idx); |
ctx = (struct keycache_s *)listview_get_item2 (lv, idx); |
121 |
if (!ctx) |
if (!ctx) |
130 |
If utrust is valid, set it to 1 if the key is valid -1 otherwise. |
If utrust is valid, set it to 1 if the key is valid -1 otherwise. |
131 |
Return value: 1 normal key, 2 smart card key. */ |
Return value: 1 normal key, 2 smart card key. */ |
132 |
int |
int |
133 |
km_check_for_seckey (listview_ctrl_t lv, int pos, int *utrust) |
km_check_for_seckey (keylist_ctrl_t kl, int pos, int *utrust) |
134 |
{ |
{ |
135 |
gpgme_key_t key; |
gpgme_key_t key; |
136 |
winpt_key_s sk; |
winpt_key_s sk; |
137 |
int type = 0; |
int type = 0; |
138 |
|
|
139 |
key = km_get_key_ptr (lv, pos, NULL); |
key = km_get_key_ptr (kl, pos, NULL); |
140 |
if (utrust) |
if (utrust) |
141 |
*utrust = 0; |
*utrust = 0; |
142 |
memset (&sk, 0, sizeof (sk)); |
memset (&sk, 0, sizeof (sk)); |
154 |
|
|
155 |
/* Check if the key at position @pos is protected with a passwd. */ |
/* Check if the key at position @pos is protected with a passwd. */ |
156 |
int |
int |
157 |
km_check_if_protected (listview_ctrl_t lv, int pos) |
km_check_if_protected (keylist_ctrl_t kl, int pos) |
158 |
{ |
{ |
159 |
gpgme_key_t key; |
gpgme_key_t key; |
160 |
winpt_key_s k; |
winpt_key_s k; |
161 |
|
|
162 |
key = km_get_key_ptr (lv, pos, NULL); |
key = km_get_key_ptr (kl, pos, NULL); |
163 |
if (!key) |
if (!key) |
164 |
return 1; /* assume yes */ |
return 1; /* assume yes */ |
165 |
winpt_get_pubkey (key->subkeys->keyid, &k); |
winpt_get_pubkey (key->subkeys->keyid, &k); |
170 |
/* Check if the key has a good status. |
/* Check if the key has a good status. |
171 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
172 |
int |
int |
173 |
km_check_key_status (listview_ctrl_t lv, int pos) |
km_check_key_status (keylist_ctrl_t kl, int pos) |
174 |
{ |
{ |
175 |
int flags = km_get_key_status (lv, pos); |
listview_ctrl_t lv = kl->lv; |
176 |
|
int flags = km_get_key_status (kl, pos); |
177 |
|
|
178 |
if (flags & KM_FLAG_EXPIRED) { |
if (flags & KM_FLAG_EXPIRED) { |
179 |
msg_box (lv->ctrl, _("This key has expired!\n" |
msg_box (lv->ctrl, _("This key has expired!\n" |
192 |
|
|
193 |
/* Return all key flags ORed. */ |
/* Return all key flags ORed. */ |
194 |
int |
int |
195 |
km_get_key_status (listview_ctrl_t lv, int pos) |
km_get_key_status (keylist_ctrl_t kl, int pos) |
196 |
{ |
{ |
197 |
gpgme_key_t key; |
gpgme_key_t key; |
198 |
int flags = 0; |
int flags = 0; |
199 |
|
|
200 |
if (pos == -1) |
if (pos == -1) |
201 |
return 0; |
return 0; |
202 |
key = km_get_key_ptr (lv, pos, NULL); |
key = km_get_key_ptr (kl, pos, NULL); |
203 |
if (!key) |
if (!key) |
204 |
return 0; |
return 0; |
205 |
|
|
216 |
/* Interface to enable or disable a key (@enable = 1 then enable). |
/* Interface to enable or disable a key (@enable = 1 then enable). |
217 |
The key is retrieved from a list control @lv at the pos @pos. */ |
The key is retrieved from a list control @lv at the pos @pos. */ |
218 |
int |
int |
219 |
km_enable_disable_key (listview_ctrl_t lv, HWND dlg, int pos, int enable) |
km_enable_disable_key (keylist_ctrl_t kl, HWND dlg, int pos, int enable) |
220 |
{ |
{ |
221 |
gpgme_error_t err; |
gpgme_error_t err; |
222 |
gpgme_key_t key; |
gpgme_key_t key; |
223 |
GpgKeyEdit ke; |
GpgKeyEdit ke; |
224 |
|
|
225 |
key = km_get_key_ptr (lv, pos, NULL); |
key = km_get_key_ptr (kl, pos, NULL); |
226 |
ke.setKeyID (key->subkeys->keyid); |
ke.setKeyID (key->subkeys->keyid); |
227 |
|
|
228 |
err = enable? ke.enable () : ke.disable (); |
err = enable? ke.enable () : ke.disable (); |
256 |
|
|
257 |
/* Export the selected keys in @lv to the clipboard. */ |
/* Export the selected keys in @lv to the clipboard. */ |
258 |
int |
int |
259 |
km_clip_export (HWND dlg, listview_ctrl_t lv) |
km_clip_export (HWND dlg, keylist_ctrl_t kl) |
260 |
{ |
{ |
261 |
gpgme_error_t err; |
gpgme_error_t err; |
262 |
gpgme_key_t *rset; |
gpgme_key_t *rset; |
266 |
size_t n=0; |
size_t n=0; |
267 |
int rc=0; |
int rc=0; |
268 |
|
|
269 |
rset = keylist_enum_recipients (lv, KEYLIST_LIST, &n); |
rset = keylist_enum_recipients (kl, KEYLIST_LIST, &n); |
270 |
if (!n) { |
if (!n) { |
271 |
msg_box (dlg, _("No key was selected for export."), |
msg_box (dlg, _("No key was selected for export."), |
272 |
_("Key Manager"), MB_ERR); |
_("Key Manager"), MB_ERR); |
300 |
/* Export the selected secret key from @lv into @fname. |
/* Export the selected secret key from @lv into @fname. |
301 |
It is only allowed to export a single secret key. */ |
It is only allowed to export a single secret key. */ |
302 |
int |
int |
303 |
km_privkey_export (HWND dlg, listview_ctrl_t lv, const char *fname) |
km_privkey_export (HWND dlg, keylist_ctrl_t kl, const char *fname) |
304 |
{ |
{ |
305 |
gpgme_key_t *rset; |
gpgme_key_t *rset; |
306 |
gpgme_error_t err; |
gpgme_error_t err; |
307 |
size_t n = 0; |
size_t n = 0; |
308 |
|
|
309 |
rset = keylist_enum_recipients (lv, KEYLIST_LIST, &n); |
rset = keylist_enum_recipients (kl, KEYLIST_LIST, &n); |
310 |
if (!n) { |
if (!n) { |
311 |
msg_box (dlg, _("No key was selected for export."), |
msg_box (dlg, _("No key was selected for export."), |
312 |
_("Key Manager"), MB_ERR); |
_("Key Manager"), MB_ERR); |
333 |
|
|
334 |
/* Export the selected recipients from @lv into the file @fname. */ |
/* Export the selected recipients from @lv into the file @fname. */ |
335 |
int |
int |
336 |
km_file_export (HWND dlg, listview_ctrl_t lv, const char *fname) |
km_file_export (HWND dlg, keylist_ctrl_t kl, const char *fname) |
337 |
{ |
{ |
|
GPGME ctx; |
|
338 |
gpgme_key_t *rset; |
gpgme_key_t *rset; |
339 |
gpgme_error_t err; |
gpgme_error_t err; |
340 |
|
GPGME ctx; |
341 |
char **patt; |
char **patt; |
342 |
size_t n; |
size_t n; |
343 |
|
|
344 |
rset = keylist_enum_recipients (lv, KEYLIST_LIST, &n); |
rset = keylist_enum_recipients (kl, KEYLIST_LIST, &n); |
345 |
if (!n) { |
if (!n) { |
346 |
msg_box (dlg, _("No key was selected for export."), |
msg_box (dlg, _("No key was selected for export."), |
347 |
_("Key Manager"), MB_ERR); |
_("Key Manager"), MB_ERR); |
380 |
return -1; |
return -1; |
381 |
} |
} |
382 |
gpg_data_extract_plaintext (inp, &plain); |
gpg_data_extract_plaintext (inp, &plain); |
383 |
gpg_data_release_and_set_clipboard (plain, 0); |
gpg_data_release_to_clipboard (plain, 0); |
384 |
gpgme_data_release (inp); |
gpgme_data_release (inp); |
385 |
|
|
386 |
return 0; |
return 0; |
539 |
if (fm_stat.cancel == 1) { |
if (fm_stat.cancel == 1) { |
540 |
free_if_alloc (fm_stat.opaque); |
free_if_alloc (fm_stat.opaque); |
541 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
542 |
} |
} |
543 |
|
|
544 |
err = gpg.importFromFile (name); |
err = gpg.importFromFile (name); |
545 |
if (err) { |
if (err) { |
546 |
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
634 |
/* Delete the list view items which match a key ptr |
/* Delete the list view items which match a key ptr |
635 |
inside the @rset array. */ |
inside the @rset array. */ |
636 |
static void |
static void |
637 |
lv_del_confirmed_keys (listview_ctrl_t lv, gpgme_key_t *rset, int n_rset) |
lv_del_confirmed_keys (keylist_ctrl_t kl, gpgme_key_t *rset, int n_rset) |
638 |
{ |
{ |
639 |
|
listview_ctrl_t lv = kl->lv; |
640 |
winpt_key_s key2; |
winpt_key_s key2; |
641 |
int j, i, n = listview_count_items (lv, 0); |
int j, i, n = listview_count_items (lv, 0); |
642 |
|
|
643 |
for (i = n; i > -1; i--) { |
for (i = n; i > -1; i--) { |
644 |
if (listview_get_item_state (lv, i)) { |
if (listview_get_item_state (lv, i)) { |
645 |
km_get_key (lv, i, &key2); |
km_get_key (kl, i, &key2); |
646 |
for (j=0; j < n_rset; j++) { |
for (j=0; j < n_rset; j++) { |
647 |
if (rset[j] == key2.ctx) { |
if (rset[j] == key2.ctx) { |
648 |
listview_del_item (lv, i); |
listview_del_item (lv, i); |
655 |
|
|
656 |
/* Delete all selected keys from the list view @lv. */ |
/* Delete all selected keys from the list view @lv. */ |
657 |
int |
int |
658 |
km_delete_keys (listview_ctrl_t lv, HWND dlg) |
km_delete_keys (keylist_ctrl_t kl, HWND dlg) |
659 |
{ |
{ |
660 |
gpgme_error_t err; |
gpgme_error_t err; |
661 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
662 |
gpgme_key_t *rset; |
gpgme_key_t *rset; |
663 |
|
listview_ctrl_t lv = kl->lv; |
664 |
winpt_key_s key2; |
winpt_key_s key2; |
665 |
char *p; |
char *p; |
666 |
int with_seckey=0, seckey_type=0, confirm=0; |
int with_seckey=0, seckey_type=0, confirm=0; |
690 |
BUG (NULL); |
BUG (NULL); |
691 |
for (i = 0; i < n; i++) { |
for (i = 0; i < n; i++) { |
692 |
if (listview_get_item_state(lv, i)) { |
if (listview_get_item_state(lv, i)) { |
693 |
km_get_key (lv, i, &key2); |
km_get_key (kl, i, &key2); |
694 |
|
|
695 |
seckey_type = km_check_for_seckey (lv, i, NULL); |
seckey_type = km_check_for_seckey (kl, i, NULL); |
696 |
if (confirm && !seckey_type) { |
if (confirm && !seckey_type) { |
697 |
p = km_key_get_info (&key2, 0); |
p = km_key_get_info (&key2, 0); |
698 |
rc = log_box (_("Key Manager"), MB_YESNO|MB_ICONWARNING, |
rc = log_box (_("Key Manager"), MB_YESNO|MB_ICONWARNING, |
707 |
rc = log_box (_("Key Manager"), MB_YESNO|MB_ICONWARNING, |
rc = log_box (_("Key Manager"), MB_YESNO|MB_ICONWARNING, |
708 |
_("Do you really want to delete this KEY PAIR?\n\n" |
_("Do you really want to delete this KEY PAIR?\n\n" |
709 |
"Please remember that you are not able to decrypt\n" |
"Please remember that you are not able to decrypt\n" |
710 |
"messages you stored with this key any longer.\n" |
"messages you encrypted with this key any longer;\n" |
711 |
|
"thus it is highly recommend to make a backup first.\n" |
712 |
"\n" |
"\n" |
713 |
"%s"), p); |
"%s"), p); |
714 |
if (rc == IDYES) { |
if (rc == IDYES) { |
750 |
if (n == 0) |
if (n == 0) |
751 |
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
show_msg (dlg, 1500, _("GnuPG Status: Finished")); |
752 |
gpgme_release (ctx); |
gpgme_release (ctx); |
753 |
lv_del_confirmed_keys (lv, rset, k_pos); |
lv_del_confirmed_keys (kl, rset, k_pos); |
754 |
delete_keys_from_cache (rset, k_pos); |
delete_keys_from_cache (rset, k_pos); |
755 |
safe_free (rset); |
safe_free (rset); |
756 |
if (with_seckey) |
if (with_seckey) |
761 |
|
|
762 |
/* Send the select key in @lv to the keyserver @host:@port. */ |
/* Send the select key in @lv to the keyserver @host:@port. */ |
763 |
int |
int |
764 |
km_send_to_keyserver (listview_ctrl_t lv, HWND dlg, |
km_send_to_keyserver (keylist_ctrl_t kl, HWND dlg, |
765 |
const char *host, WORD port) |
const char *host, WORD port) |
766 |
{ |
{ |
767 |
|
listview_ctrl_t lv = kl->lv; |
768 |
winpt_key_s key; |
winpt_key_s key; |
769 |
int id; |
int id; |
770 |
|
|
774 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
775 |
} |
} |
776 |
|
|
777 |
km_get_key (lv, id, &key); |
km_get_key (kl, id, &key); |
778 |
id = log_box (_("Key Manager"), MB_YESNO, |
id = log_box (_("Key Manager"), MB_YESNO, |
779 |
_("Do you really want to send '0x%s' to keyserver %s?"), |
_("Do you really want to send '0x%s' to keyserver %s?"), |
780 |
key.keyid, host); |
key.keyid, host); |
787 |
|
|
788 |
/* Send the selected key in @lv via MAPI to a mail recipient. */ |
/* Send the selected key in @lv via MAPI to a mail recipient. */ |
789 |
int |
int |
790 |
km_send_to_mail_recipient (listview_ctrl_t lv, HWND dlg) |
km_send_to_mail_recipient (keylist_ctrl_t kl, HWND dlg) |
791 |
{ |
{ |
792 |
gpgme_key_t key; |
gpgme_key_t key; |
793 |
gpgme_error_t rc; |
gpgme_error_t rc; |
794 |
|
listview_ctrl_t lv = kl->lv; |
795 |
GPGME ctx; |
GPGME ctx; |
796 |
struct keycache_s *c; |
struct keycache_s *c; |
797 |
char *fname, *uid; |
char *fname, *uid; |
807 |
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
808 |
return WPTERR_GENERAL; |
return WPTERR_GENERAL; |
809 |
} |
} |
810 |
key = km_get_key_ptr (lv, pos, &c); |
key = km_get_key_ptr (kl, pos, &c); |
811 |
uid = m_strdup (c->uids->name); |
uid = m_strdup (c->uids->name); |
812 |
secure_filename (uid, strlen (uid)); |
secure_filename (uid, strlen (uid)); |
813 |
n = strlen (uid) + 1 + MAX_PATH + 5; |
n = strlen (uid) + 1 + MAX_PATH + 5; |
830 |
/* Refresh the selected key in the listview @lv at position @pos. |
/* Refresh the selected key in the listview @lv at position @pos. |
831 |
Legal flags are 0 = single key. */ |
Legal flags are 0 = single key. */ |
832 |
static int |
static int |
833 |
km_refresh_one_key (listview_ctrl_t lv, HWND dlg, int pos, int flags) |
km_refresh_one_key (keylist_ctrl_t kl, HWND dlg, int pos, int flags) |
834 |
{ |
{ |
|
winpt_key_s pk; |
|
835 |
gpgme_key_t key; |
gpgme_key_t key; |
836 |
|
listview_ctrl_t lv = kl->lv; |
837 |
|
winpt_key_s pk; |
838 |
const char *pref_kserv = default_keyserver; |
const char *pref_kserv = default_keyserver; |
839 |
unsigned short pref_kserv_port = default_keyserver_port; |
unsigned short pref_kserv_port = default_keyserver_port; |
840 |
char keyid[16+1]; |
char keyid[16+1]; |
845 |
else |
else |
846 |
idx = listview_get_curr_pos (lv); |
idx = listview_get_curr_pos (lv); |
847 |
if (idx != -1) { |
if (idx != -1) { |
848 |
key = km_get_key_ptr (lv, idx, NULL); |
key = km_get_key_ptr (kl, idx, NULL); |
849 |
|
|
850 |
/* In single refresh mode, try to use the users preferred keyserver. */ |
/* In single refresh mode, try to use the users preferred keyserver. */ |
851 |
if (flags == 0 && |
if (flags == 0 && |
869 |
|
|
870 |
/* Refresh the selected keys from the default keyserver. */ |
/* Refresh the selected keys from the default keyserver. */ |
871 |
int |
int |
872 |
km_refresh_from_keyserver (listview_ctrl_t lv, HWND dlg) |
km_refresh_from_keyserver (keylist_ctrl_t kl, HWND dlg) |
873 |
{ |
{ |
874 |
|
listview_ctrl_t lv = kl->lv; |
875 |
int cnt, id, i; |
int cnt, id, i; |
876 |
int err = 0; |
int err = 0; |
877 |
|
|
888 |
} |
} |
889 |
} |
} |
890 |
if (listview_count_items (lv, 1) == 1) |
if (listview_count_items (lv, 1) == 1) |
891 |
err = km_refresh_one_key (lv, dlg, listview_get_curr_pos (lv), 0); |
err = km_refresh_one_key (kl, dlg, listview_get_curr_pos (lv), 0); |
892 |
else { |
else { |
893 |
for (i=0; i < cnt; i++) { |
for (i=0; i < cnt; i++) { |
894 |
if (listview_get_item_state (lv, i)) |
if (listview_get_item_state (lv, i)) |
895 |
km_refresh_one_key (lv, dlg, i, KM_KS_REFRESH); |
km_refresh_one_key (kl, dlg, i, KM_KS_REFRESH); |
896 |
} |
} |
897 |
} |
} |
898 |
return err; |
return err; |
913 |
/* Return TRUE if the key in the list @lv at pos @pos is an |
/* Return TRUE if the key in the list @lv at pos @pos is an |
914 |
old version 3 key. */ |
old version 3 key. */ |
915 |
int |
int |
916 |
km_key_is_v3 (listview_ctrl_t lv, int pos) |
km_key_is_v3 (keylist_ctrl_t kl, int pos) |
917 |
{ |
{ |
918 |
gpgme_key_t pk; |
gpgme_key_t pk; |
919 |
|
|
920 |
pk = km_get_key_ptr (lv, pos, NULL); |
pk = km_get_key_ptr (kl, pos, NULL); |
921 |
if (strlen (pk->subkeys->fpr) == 32 && |
if (strlen (pk->subkeys->fpr) == 32 && |
922 |
pk->subkeys->pubkey_algo == GPGME_PK_RSA) |
pk->subkeys->pubkey_algo == GPGME_PK_RSA) |
923 |
return -1; |
return -1; |
927 |
|
|
928 |
/* Set trust of selected key in @lv (at @pos) to ultimate. */ |
/* Set trust of selected key in @lv (at @pos) to ultimate. */ |
929 |
int |
int |
930 |
km_set_implicit_trust (HWND dlg, listview_ctrl_t lv, int pos) |
km_set_implicit_trust (HWND dlg, keylist_ctrl_t kl, int pos) |
931 |
{ |
{ |
932 |
gpgme_error_t err; |
gpgme_error_t err; |
933 |
gpgme_key_t key; |
gpgme_key_t key; |
934 |
GpgKeyEdit ke; |
GpgKeyEdit ke; |
935 |
|
|
936 |
key = km_get_key_ptr (lv, pos, NULL); |
key = km_get_key_ptr (kl, pos, NULL); |
937 |
ke.setKeyID (key->subkeys->keyid); |
ke.setKeyID (key->subkeys->keyid); |
938 |
|
|
939 |
err = ke.setTrust (GPGME_VALIDITY_ULTIMATE); |
err = ke.setTrust (GPGME_VALIDITY_ULTIMATE); |
949 |
/* Provide a search dialog and try to find and select |
/* Provide a search dialog and try to find and select |
950 |
the key which matches the entered pattern. */ |
the key which matches the entered pattern. */ |
951 |
void |
void |
952 |
km_find_key (HWND dlg, listview_ctrl_t lv) |
km_find_key (HWND dlg, keylist_ctrl_t kl) |
953 |
{ |
{ |
954 |
|
listview_ctrl_t lv = kl->lv; |
955 |
int oldpos = listview_get_curr_pos (lv); |
int oldpos = listview_get_curr_pos (lv); |
956 |
int n; |
int n; |
957 |
char *name = get_input_dialog (dlg, _("Search"), _("Search for:")); |
char *name = get_input_dialog (dlg, _("Search"), _("Search for:")); |
1001 |
/* Retrieve the GPGME pointer from the selected list view |
/* Retrieve the GPGME pointer from the selected list view |
1002 |
item and return the WinPT specific key context. */ |
item and return the WinPT specific key context. */ |
1003 |
int |
int |
1004 |
km_get_key (listview_ctrl_t lv, int pos, winpt_key_t k) |
km_get_key (keylist_ctrl_t kl, int pos, winpt_key_t k) |
1005 |
{ |
{ |
|
struct keycache_s *c; |
|
1006 |
gpgme_key_t key; |
gpgme_key_t key; |
1007 |
|
struct keycache_s *c; |
1008 |
|
|
1009 |
if (pos == -1) |
if (pos == -1) |
1010 |
return -1; |
return -1; |
1011 |
key = km_get_key_ptr (lv, pos, &c); |
key = km_get_key_ptr (kl, pos, &c); |
1012 |
memset (k, 0, sizeof (*k)); |
memset (k, 0, sizeof (*k)); |
1013 |
strncpy (k->tmp_keyid, key->subkeys->keyid+8, 8); |
strncpy (k->tmp_keyid, key->subkeys->keyid+8, 8); |
1014 |
k->keyid = k->tmp_keyid; |
k->keyid = k->tmp_keyid; |
1015 |
k->is_protected = km_check_if_protected (lv, pos); |
k->is_protected = km_check_if_protected (kl, pos); |
1016 |
k->key_pair = km_check_for_seckey (lv, pos, NULL); |
k->key_pair = km_check_for_seckey (kl, pos, NULL); |
1017 |
k->is_v3 = km_key_is_v3 (lv, pos); |
k->is_v3 = km_key_is_v3 (kl, pos); |
1018 |
k->flags = km_get_key_status (lv, pos); |
k->flags = km_get_key_status (kl, pos); |
1019 |
k->ctx = key; |
k->ctx = key; |
1020 |
k->ext = c; |
k->ext = c; |
1021 |
k->uid = c->uids->uid; |
k->uid = c->uids->uid; |