1 |
twoaday |
2 |
/* wptKeyRevokersDlg.cpp - Designated Revoker Keys |
2 |
|
|
* Copyright (C) 2002, 2003, 2005 Timo Schulz |
3 |
twoaday |
24 |
* Copyright (C) 2005 g10 Code GmbH |
4 |
twoaday |
2 |
* |
5 |
|
|
* This file is part of WinPT. |
6 |
|
|
* |
7 |
|
|
* WinPT is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* WinPT is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include <windows.h> |
23 |
|
|
#include <commctrl.h> |
24 |
|
|
|
25 |
|
|
#include "../resource.h" |
26 |
|
|
#include "wptCommonCtl.h" |
27 |
|
|
#include "wptNLS.h" |
28 |
|
|
#include "wptTypes.h" |
29 |
|
|
#include "wptGPG.h" |
30 |
|
|
#include "wptCommonCtl.h" |
31 |
|
|
#include "wptContext.h" |
32 |
|
|
#include "wptDlgs.h" |
33 |
|
|
#include "wptErrors.h" |
34 |
|
|
#include "wptKeyserver.h" |
35 |
twoaday |
20 |
#include "wptW32Api.h" |
36 |
|
|
#include "wptVersion.h" |
37 |
twoaday |
23 |
#include "wptKeyEdit.h" |
38 |
|
|
#include "wptKeyList.h" |
39 |
twoaday |
2 |
|
40 |
|
|
|
41 |
twoaday |
23 |
/* Initialize the listview given in @ctrl and return it in @r_lv. */ |
42 |
twoaday |
2 |
static int |
43 |
twoaday |
20 |
revokelist_build (listview_ctrl_t *r_lv, HWND ctrl) |
44 |
twoaday |
2 |
{ |
45 |
|
|
listview_ctrl_t lv; |
46 |
|
|
struct listview_column_s rlist[] = { |
47 |
|
|
{ 0, 55, (char *)_("Algorithm") }, |
48 |
|
|
{ 1, 80, (char *)_("Key ID") }, |
49 |
|
|
{ 2, 160, (char *)_("Name") }, |
50 |
|
|
{0} |
51 |
|
|
}; |
52 |
|
|
int i, rc; |
53 |
|
|
|
54 |
twoaday |
23 |
rc = listview_new (&lv); |
55 |
|
|
if (rc) |
56 |
twoaday |
2 |
return rc; |
57 |
|
|
lv->ctrl = ctrl; |
58 |
|
|
lv->items = DIM( rlist )-1; |
59 |
twoaday |
23 |
for (i = 0; i < lv->items; i++) |
60 |
|
|
listview_add_column (lv, &rlist[i]); |
61 |
|
|
listview_set_ext_style (lv); |
62 |
twoaday |
2 |
*r_lv = lv; |
63 |
|
|
return 0; |
64 |
twoaday |
23 |
} |
65 |
twoaday |
2 |
|
66 |
|
|
|
67 |
twoaday |
23 |
/* Initialize the listview @ctrl with all designated revokers of the |
68 |
|
|
key @key. @ctx is used to retrieve the rev key from the cache to |
69 |
|
|
show the user-id. |
70 |
|
|
Return value: the initialized listview or NULL on error. */ |
71 |
twoaday |
2 |
static listview_ctrl_t |
72 |
|
|
revokelist_init (HWND ctrl, gpgme_key_t key, gpgme_keycache_t ctx) |
73 |
|
|
{ |
74 |
twoaday |
23 |
gpgme_error_t err; |
75 |
|
|
gpgme_key_t revkey; |
76 |
|
|
GpgKeyEdit *ke; |
77 |
|
|
gpg_desig_rev_t rev=NULL, r; |
78 |
|
|
listview_ctrl_t lv; |
79 |
|
|
const char *id; |
80 |
twoaday |
2 |
|
81 |
twoaday |
23 |
ke = new GpgKeyEdit (key); |
82 |
|
|
if (!ke) |
83 |
|
|
BUG (NULL); |
84 |
|
|
err = ke->getDesignatedRevoker (&rev); |
85 |
|
|
if (err) { |
86 |
|
|
delete ke; |
87 |
|
|
msg_box (NULL, gpgme_strerror (err), _("Designated Key Revokers"), MB_ERR); |
88 |
|
|
return NULL; |
89 |
|
|
} |
90 |
|
|
|
91 |
twoaday |
2 |
if (revokelist_build (&lv, ctrl)) |
92 |
|
|
BUG (0); |
93 |
twoaday |
23 |
for (r = rev; r; r = r->next) { |
94 |
|
|
if (get_pubkey (r->fpr+32, &revkey)) |
95 |
|
|
id = _("user ID not found"); |
96 |
twoaday |
2 |
else |
97 |
twoaday |
23 |
id = revkey->uids->name; |
98 |
twoaday |
2 |
listview_add_item (lv, ""); |
99 |
twoaday |
23 |
listview_add_sub_item (lv, 0, 0, get_key_pubalgo (r->pubkey_algo)); |
100 |
|
|
listview_add_sub_item (lv, 0, 1, r->fpr+32); |
101 |
twoaday |
2 |
listview_add_sub_item (lv, 0, 2, id); |
102 |
|
|
} |
103 |
twoaday |
24 |
|
104 |
|
|
delete ke; |
105 |
twoaday |
23 |
gpg_desig_rev_release (rev); |
106 |
twoaday |
2 |
return lv; |
107 |
twoaday |
23 |
} |
108 |
twoaday |
2 |
|
109 |
|
|
|
110 |
twoaday |
23 |
/* Dialog box procedure to show designated revokers. */ |
111 |
twoaday |
2 |
BOOL CALLBACK |
112 |
twoaday |
20 |
key_revokers_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
113 |
twoaday |
2 |
{ |
114 |
|
|
static listview_ctrl_t lv; |
115 |
|
|
gpgme_key_t key; |
116 |
|
|
char buf[128], keyid[32]; |
117 |
|
|
int rc; |
118 |
|
|
|
119 |
|
|
switch( msg ) { |
120 |
|
|
case WM_INITDIALOG: |
121 |
|
|
gpgme_keycache_t ctx; |
122 |
|
|
key = (gpgme_key_t)lparam; |
123 |
|
|
if( !key ) |
124 |
|
|
dlg_fatal_error( dlg, "Could not get dilaog param" ); |
125 |
twoaday |
23 |
ctx = keycache_get_ctx (1); |
126 |
twoaday |
2 |
if( !ctx ) |
127 |
|
|
BUG( dlg ); |
128 |
|
|
lv = revokelist_init( GetDlgItem( dlg, IDC_KEYREVOKERS_LIST ), key, ctx ); |
129 |
|
|
return TRUE; |
130 |
|
|
|
131 |
|
|
case WM_NOTIFY: |
132 |
|
|
NMHDR *notify; |
133 |
|
|
notify = (NMHDR *)lparam; |
134 |
twoaday |
20 |
if (notify && notify->code == NM_DBLCLK && notify->idFrom == IDC_KEYREVOKERS_LIST) { |
135 |
|
|
int idx = listview_get_curr_pos (lv); |
136 |
|
|
listview_get_item_text (lv, idx, 1, keyid, DIM (keyid)-1); |
137 |
|
|
listview_get_item_text (lv, idx, 2, buf, DIM (buf)-1); |
138 |
twoaday |
23 |
if (!strcmp( buf, _("user ID not found"))) { |
139 |
twoaday |
20 |
int id = log_box (_("Designated Key Revokers"), MB_YESNO|MB_INFO, |
140 |
|
|
_("Do you want to retrieve 0x%s via the default keyserver?"), keyid); |
141 |
|
|
if (id == IDNO) |
142 |
twoaday |
2 |
break; |
143 |
twoaday |
20 |
rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, buf, 0, 0); |
144 |
twoaday |
2 |
if( !rc ) { |
145 |
|
|
const char * s; |
146 |
twoaday |
20 |
keycache_reload (dlg); |
147 |
|
|
if (get_pubkey (keyid, &key)) |
148 |
twoaday |
2 |
BUG( NULL ); |
149 |
twoaday |
23 |
s = key->uids->name; |
150 |
|
|
if (s) |
151 |
|
|
listview_add_sub_item (lv, idx, 2, s); |
152 |
twoaday |
2 |
} |
153 |
|
|
} |
154 |
twoaday |
20 |
else { |
155 |
|
|
struct winpt_key_s k; |
156 |
|
|
memset (&k, 0, sizeof k); |
157 |
|
|
k.keyid = keyid; |
158 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg, |
159 |
|
|
keyprops_dlg_proc, (LPARAM)&k); |
160 |
|
|
} |
161 |
twoaday |
2 |
} |
162 |
|
|
break; |
163 |
|
|
|
164 |
|
|
case WM_DESTROY: |
165 |
twoaday |
23 |
if (lv) { |
166 |
|
|
listview_release (lv); |
167 |
twoaday |
2 |
lv = NULL; |
168 |
|
|
} |
169 |
|
|
return FALSE; |
170 |
|
|
|
171 |
|
|
case WM_COMMAND: |
172 |
twoaday |
23 |
switch (LOWORD (wparam)) { |
173 |
twoaday |
2 |
case IDOK: |
174 |
twoaday |
23 |
EndDialog (dlg, TRUE); |
175 |
twoaday |
2 |
break; |
176 |
|
|
} |
177 |
|
|
break; |
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
return FALSE; |
181 |
twoaday |
23 |
} |