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