1 |
/* wptSigList.cpp - Listview for key signatures |
/* wptSigList.cpp - Listview for key signatures |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
* Copyright (C) 2001-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 |
* WinPT is free software; you can redistribute it and/or |
8 |
* modify it under the terms of the GNU General Public License |
* modify it under the terms of the GNU General Public License |
9 |
* as published by the Free Software Foundation; either version 2 |
* as published by the Free Software Foundation; either version 2 |
10 |
* of the License, or (at your option) any later version. |
* of the License, or (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 GNU |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
* General Public License for more details. |
* 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 <time.h> |
#include <config.h> |
24 |
|
#endif |
25 |
#include "wptGPG.h" |
|
26 |
#include "wptCommonCtl.h" |
#include <windows.h> |
27 |
#include "wptKeylist.h" |
#include <windows.h> |
28 |
#include "wptNLS.h" |
#include <time.h> |
29 |
#include "wptUTF8.h" |
|
30 |
#include "wptErrors.h" |
#include "wptGPG.h" |
31 |
#include "wptTypes.h" |
#include "wptCommonCtl.h" |
32 |
#include "wptW32API.h" |
#include "wptKeylist.h" |
33 |
|
#include "wptNLS.h" |
34 |
|
#include "wptUTF8.h" |
35 |
/* Is the given signature an user-id signature? */ |
#include "wptErrors.h" |
36 |
#define IS_UID_CERT(_class) ((_class) >= 0x10 && (_class) <= 0x13) |
#include "wptTypes.h" |
37 |
|
#include "wptW32API.h" |
38 |
|
|
39 |
/* Create a signature list control in @lv with the parent window |
|
40 |
given in @ctrl. |
/* Is the given signature an user-id signature? */ |
41 |
Return value: 0 on success. */ |
#define IS_UID_CERT(_class) ((_class) >= 0x10 && (_class) <= 0x13) |
42 |
static int |
|
43 |
siglist_build (listview_ctrl_t * lv, HWND ctrl) |
|
44 |
{ |
/* Create a signature list control in @lv with the parent window |
45 |
struct listview_ctrl_s *c; |
given in @ctrl. |
46 |
struct listview_column_s implist[] = { |
Return value: 0 on success. */ |
47 |
{0, 240, (char *)_("User ID")}, |
static int |
48 |
{1, 50, (char *)_("Valid")}, |
siglist_build (listview_ctrl_t * lv, HWND ctrl) |
49 |
{2, 40, (char *)_("Class")}, |
{ |
50 |
{3, 68, (char *)_("Creation")}, |
struct listview_ctrl_s *c; |
51 |
{4, 80, (char *)_("Key ID")}, |
struct listview_column_s implist[] = { |
52 |
{5, 68, (char *)_("Expiration")}, |
{0, 240, (char *)_("User ID")}, |
53 |
{6, 56, (char *)_("Algorithm")}, |
{1, 50, (char *)_("Valid")}, |
54 |
{0, 0, NULL} |
{2, 40, (char *)_("Class")}, |
55 |
}; |
{3, 68, (char *)_("Creation")}, |
56 |
int j, rc = 0; |
{4, 80, (char *)_("Key ID")}, |
57 |
|
{5, 68, (char *)_("Expiration")}, |
58 |
rc = listview_new (&c); |
{6, 56, (char *)_("Algorithm")}, |
59 |
if (rc) |
{0, 0, NULL} |
60 |
return rc; |
}; |
61 |
c->ctrl = ctrl; |
int j, rc = 0; |
62 |
for ( j=0; implist[j].fieldname != NULL; j++ ) |
|
63 |
listview_add_column( c, &implist[j] ); |
rc = listview_new (&c); |
64 |
listview_set_ext_style( c ); |
if (rc) |
65 |
*lv = c; |
return rc; |
66 |
return 0; |
c->ctrl = ctrl; |
67 |
} |
for ( j=0; implist[j].fieldname != NULL; j++ ) |
68 |
|
listview_add_column( c, &implist[j] ); |
69 |
|
listview_set_ext_style( c ); |
70 |
/* Delete the signature control in @lv. */ |
*lv = c; |
71 |
void |
return 0; |
72 |
siglist_delete( listview_ctrl_t lv ) |
} |
73 |
{ |
|
74 |
if( lv ) { |
|
75 |
listview_release( lv ); |
/* Delete the signature control in @lv. */ |
76 |
} |
void |
77 |
} |
siglist_delete( listview_ctrl_t lv ) |
78 |
|
{ |
79 |
|
if( lv ) { |
80 |
/* Indent the string in @old with the level @ilvl. |
listview_release( lv ); |
81 |
Return value: indented string. */ |
} |
82 |
static char * |
} |
83 |
indent_string (const char * old, int ilvl) |
|
84 |
{ |
|
85 |
char * p; |
/* Indent the string in @old with the level @ilvl. |
86 |
int i; |
Return value: indented string. */ |
87 |
|
static char * |
88 |
p = new char[strlen (old) + 1 + ilvl]; |
indent_string (const char * old, int ilvl) |
89 |
if (!p) |
{ |
90 |
BUG (NULL); |
char * p; |
91 |
for (i = 0; i < ilvl; i++) |
int i; |
92 |
p[i] = ' '; |
|
93 |
strcpy (p+i, old); |
p = new char[strlen (old) + 1 + ilvl]; |
94 |
return p; |
if (!p) |
95 |
} |
BUG (NULL); |
96 |
|
for (i = 0; i < ilvl; i++) |
97 |
|
p[i] = ' '; |
98 |
/* Add an userid signature @ks from the userid @uid to the sig list |
strcpy (p+i, old); |
99 |
control @lv. |
return p; |
100 |
Return value: 0 on success. */ |
} |
101 |
static int |
|
102 |
siglist_add_key (listview_ctrl_t lv, gpgme_user_id_t uid, gpgme_key_sig_t ks) |
|
103 |
{ |
/* Add an userid signature @ks from the userid @uid to the sig list |
104 |
gpgme_key_t key=NULL; |
control @lv. |
105 |
char t[128]; |
Return value: 0 on success. */ |
106 |
const char *attr; |
static int |
107 |
const char *s; |
siglist_add_key (listview_ctrl_t lv, gpgme_user_id_t uid, gpgme_key_sig_t ks) |
108 |
int rc = 0, key_attr; |
{ |
109 |
|
gpgme_key_t key=NULL; |
110 |
if (ks && !IS_UID_CERT (ks->sig_class)) |
char t[128]; |
111 |
return 0; |
const char *attr; |
112 |
|
const char *s; |
113 |
rc = listview_add_item (lv, " "); |
int rc = 0, key_attr; |
114 |
if( rc ) |
|
115 |
return rc; |
if (ks && !IS_UID_CERT (ks->sig_class)) |
116 |
|
return 0; |
117 |
attr = NULL; |
|
118 |
if (!uid) { |
rc = listview_add_item (lv, " "); |
119 |
get_pubkey (ks->keyid, &key); |
if( rc ) |
120 |
if (key) |
return rc; |
121 |
attr = key->uids->uid; |
|
122 |
} |
attr = NULL; |
123 |
else |
if (!uid) { |
124 |
attr = uid->uid; |
get_pubkey (ks->keyid, &key); |
125 |
if (attr && strlen (attr)) { |
if (key) |
126 |
char *uid_utf8 = utf8_to_wincp (attr, strlen (attr)); |
attr = key->uids->uid; |
127 |
char *p = uid? m_strdup (uid_utf8) : indent_string (uid_utf8, 2); |
} |
128 |
listview_add_sub_item (lv, 0, 0, p); |
else |
129 |
free (uid_utf8); |
attr = uid->uid; |
130 |
free_if_alloc (p); |
if (attr && strlen (attr)) { |
131 |
} |
char *uid_utf8 = utf8_to_wincp (attr, strlen (attr)); |
132 |
else |
char *p = uid? m_strdup (uid_utf8) : indent_string (uid_utf8, 2); |
133 |
listview_add_sub_item (lv, 0, 0, _(" user ID not found")); |
listview_add_sub_item (lv, 0, 0, p); |
134 |
|
free (uid_utf8); |
135 |
if (uid) |
free_if_alloc (p); |
136 |
return 0; |
} |
137 |
|
else |
138 |
switch (gpgme_err_code (ks->status)) { |
listview_add_sub_item (lv, 0, 0, _(" user ID not found")); |
139 |
case GPG_ERR_NO_ERROR: s = "YES"; break; |
|
140 |
case GPG_ERR_NO_PUBKEY: s = "NOKEY"; break; |
if (uid) |
141 |
case GPG_ERR_BAD_SIGNATURE:s = "NO"; break; |
return 0; |
142 |
default: s = "ERROR"; break; |
|
143 |
} |
switch (gpgme_err_code (ks->status)) { |
144 |
listview_add_sub_item( lv, 0, 1, s ); |
case GPG_ERR_NO_ERROR: s = "YES"; break; |
145 |
|
case GPG_ERR_NO_PUBKEY: s = "NOKEY"; break; |
146 |
switch (ks->sig_class) { |
case GPG_ERR_BAD_SIGNATURE:s = "NO"; break; |
147 |
case 0x10: strcpy (t, " "); break; |
default: s = "ERROR"; break; |
148 |
case 0x11: strcpy (t, "1"); break; |
} |
149 |
case 0x12: strcpy (t, "2"); break; |
listview_add_sub_item( lv, 0, 1, s ); |
150 |
case 0x13: strcpy (t, "3"); break; |
|
151 |
} |
switch (ks->sig_class) { |
152 |
|
case 0x10: strcpy (t, " "); break; |
153 |
strcat (t, " "); |
case 0x11: strcpy (t, "1"); break; |
154 |
if (!ks->exportable) |
case 0x12: strcpy (t, "2"); break; |
155 |
strcat (t, "L"); |
case 0x13: strcpy (t, "3"); break; |
156 |
/*if (key_attr & GPGME_SIGF_NREV) |
} |
157 |
strcat (t, "R");*/ |
|
158 |
listview_add_sub_item (lv, 0, 2, t); |
strcat (t, " "); |
159 |
|
if (!ks->exportable) |
160 |
key_attr = ks->timestamp; |
strcat (t, "L"); |
161 |
if( key_attr ) { |
/*if (key_attr & GPGME_SIGF_NREV) |
162 |
s = get_key_created( key_attr ); |
strcat (t, "R");*/ |
163 |
listview_add_sub_item( lv, 0, 3, s ); |
listview_add_sub_item (lv, 0, 2, t); |
164 |
} |
|
165 |
|
key_attr = ks->timestamp; |
166 |
attr = ks->keyid; |
if( key_attr ) { |
167 |
if( attr && strlen( attr ) == 16 ) { |
s = get_key_created( key_attr ); |
168 |
_snprintf (t, sizeof t -1, "0x%s", attr + 8); |
listview_add_sub_item( lv, 0, 3, s ); |
169 |
listview_add_sub_item( lv, 0, 4, t ); |
} |
170 |
} |
|
171 |
|
attr = ks->keyid; |
172 |
key_attr = ks->expires; |
if( attr && strlen( attr ) == 16 ) { |
173 |
if (key_attr) { |
_snprintf (t, sizeof t -1, "0x%s", attr + 8); |
174 |
s = get_key_created (key_attr); |
listview_add_sub_item( lv, 0, 4, t ); |
175 |
listview_add_sub_item (lv, 0, 5, s); |
} |
176 |
} |
|
177 |
|
key_attr = ks->expires; |
178 |
attr = get_key_pubalgo (ks->pubkey_algo); |
if (key_attr) { |
179 |
if( attr ) |
s = get_key_created (key_attr); |
180 |
listview_add_sub_item( lv, 0, 6, (char *)attr ); |
listview_add_sub_item (lv, 0, 5, s); |
181 |
|
} |
182 |
return 0; |
|
183 |
} |
attr = get_key_pubalgo (ks->pubkey_algo); |
184 |
|
if( attr ) |
185 |
|
listview_add_sub_item( lv, 0, 6, (char *)attr ); |
186 |
/* Load a signature list with the signatures of the key with |
|
187 |
the keyID @keyid. The parent window is in @ctrl. |
return 0; |
188 |
Return value is the handle to the listview control. */ |
} |
189 |
listview_ctrl_t |
|
190 |
siglist_load (HWND ctrl, const char *keyid) |
|
191 |
{ |
/* Load a signature list with the signatures of the key with |
192 |
gpgme_key_t key; |
the keyID @keyid. The parent window is in @ctrl. |
193 |
gpgme_user_id_t u; |
Return value is the handle to the listview control. */ |
194 |
gpgme_key_sig_t s; |
listview_ctrl_t |
195 |
listview_ctrl_t lv; |
siglist_load (HWND ctrl, const char *keyid) |
196 |
int rc, i=0; |
{ |
197 |
|
gpgme_key_t key; |
198 |
if (siglist_build (&lv, ctrl)) |
gpgme_user_id_t u; |
199 |
BUG (NULL); |
gpgme_key_sig_t s; |
200 |
rc = get_pubkey(keyid, &key); |
listview_ctrl_t lv; |
201 |
if (rc) |
int rc, i=0; |
202 |
BUG (NULL); |
|
203 |
|
if (siglist_build (&lv, ctrl)) |
204 |
/* XXX: the root item is at the end but should come first. */ |
BUG (NULL); |
205 |
for (u=key->uids; u; u = u->next) { |
rc = get_pubkey(keyid, &key); |
206 |
siglist_add_key (lv, u, NULL); |
if (rc) |
207 |
for (s = u->signatures; s; s = s->next) { |
BUG (NULL); |
208 |
rc = siglist_add_key (lv, NULL, s); |
|
209 |
if (rc) |
/* XXX: the root item is at the end but should come first. */ |
210 |
break; |
for (u=key->uids; u; u = u->next) { |
211 |
} |
siglist_add_key (lv, u, NULL); |
212 |
} |
for (s = u->signatures; s; s = s->next) { |
213 |
if (rc) { |
rc = siglist_add_key (lv, NULL, s); |
214 |
siglist_delete (lv); |
if (rc) |
215 |
lv = NULL; |
break; |
216 |
} |
} |
217 |
return lv; |
} |
218 |
} |
if (rc) { |
219 |
|
siglist_delete (lv); |
220 |
|
lv = NULL; |
221 |
|
} |
222 |
|
return lv; |
223 |
|
} |