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