1 |
twoaday |
2 |
/* wptKeyTrustPathDlg.cpp - List a trust path for a key. |
2 |
|
|
* Copyright (C) 2001, 2002, 2003 Timo Schulz |
3 |
|
|
* |
4 |
|
|
* This file is part of WinPT. |
5 |
|
|
* |
6 |
|
|
* WinPT is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* WinPT is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
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, |
18 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
|
|
*/ |
20 |
|
|
#if 0 |
21 |
|
|
#include <windows.h> |
22 |
|
|
#include <commctrl.h> |
23 |
|
|
|
24 |
|
|
#include "../resource.h" |
25 |
|
|
#include "wptGPGME.h" |
26 |
|
|
#include "wptCommonCtl.h" |
27 |
|
|
#include "wptContext.h" /* for passphrase_s */ |
28 |
|
|
#include "wptDlgs.h" |
29 |
|
|
#include "wptTypes.h" |
30 |
|
|
#include "wptNLS.h" |
31 |
|
|
|
32 |
|
|
struct trust_path_s { |
33 |
|
|
int level; |
34 |
|
|
int type; |
35 |
|
|
char otrust[2]; |
36 |
|
|
char valid[2]; |
37 |
|
|
char keyid[16+1]; |
38 |
|
|
char uid[128]; |
39 |
|
|
}; |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
static void |
43 |
|
|
copy_trust_item(trust_path_s *tp, GpgmeTrustItem ti) |
44 |
|
|
{ |
45 |
|
|
const char *t; |
46 |
|
|
|
47 |
|
|
tp->level = gpgme_trust_item_get_int_attr( ti, GPGME_ATTR_LEVEL, NULL, 0 ); |
48 |
|
|
tp->type = gpgme_trust_item_get_int_attr( ti, GPGME_ATTR_TYPE, NULL, 0 ); |
49 |
|
|
t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_OTRUST, NULL, 0); |
50 |
|
|
strcpy( tp->otrust, t ); |
51 |
|
|
t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_VALIDITY, NULL, 0 ); |
52 |
|
|
strcpy( tp->valid, t ); |
53 |
|
|
t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_KEYID, NULL, 0 ); |
54 |
|
|
strcpy( tp->keyid, t ); |
55 |
|
|
t = gpgme_trust_item_get_string_attr( ti, GPGME_ATTR_USERID, NULL, 0 ); |
56 |
|
|
strcpy( tp->uid, t ); |
57 |
|
|
} /* copy_trust_item */ |
58 |
|
|
|
59 |
|
|
|
60 |
|
|
static HTREEITEM |
61 |
|
|
treeview_insert_item( HWND tree, HTREEITEM parent, const char *text ) |
62 |
|
|
{ |
63 |
|
|
TVINSERTSTRUCT ti; |
64 |
|
|
HTREEITEM node; |
65 |
|
|
|
66 |
|
|
memset( &ti, 0, sizeof ti ); |
67 |
|
|
ti.hParent = parent; |
68 |
|
|
ti.hInsertAfter = TVI_LAST; |
69 |
|
|
ti.item.mask = TVIF_TEXT; |
70 |
|
|
ti.item.pszText = (char *)text; |
71 |
|
|
node = TreeView_InsertItem( tree, &ti ); |
72 |
|
|
return node; |
73 |
|
|
} /* treeview_insert_item */ |
74 |
|
|
|
75 |
|
|
|
76 |
|
|
HTREEITEM |
77 |
|
|
treeview_create_child_item( HWND tree, trust_path_s *tp, HTREEITEM parent ) |
78 |
|
|
{ |
79 |
|
|
char info[1024]; |
80 |
|
|
HTREEITEM node; |
81 |
|
|
|
82 |
|
|
if( tp->type == 0 ) /* root */ |
83 |
|
|
_snprintf( info, sizeof info-1, "%s", tp->uid ); |
84 |
|
|
else if( tp->type == 1 )/* key */ |
85 |
|
|
_snprintf(info, sizeof info -1, "0x%s (otrust=%s, validity=%s)", |
86 |
|
|
tp->keyid, tp->otrust, tp->valid ); |
87 |
|
|
else if( tp->type == 2 ) /* userid */ |
88 |
|
|
_snprintf( info, sizeof info -1, "%s (validity=%s)", tp->uid, tp->valid ); |
89 |
|
|
node = treeview_insert_item( tree, parent, info ); |
90 |
|
|
return node; |
91 |
|
|
} /* treeview_create_child_item */ |
92 |
|
|
|
93 |
|
|
|
94 |
|
|
void |
95 |
|
|
treeview_add_trustpath(HWND tree, HTREEITEM node, trust_path_s c[], int n, int level) |
96 |
|
|
{ |
97 |
|
|
HTREEITEM _node; |
98 |
|
|
int i; |
99 |
|
|
|
100 |
|
|
for( i=0; i<n; i++ ) { |
101 |
|
|
if( c[i].level == level ) { |
102 |
|
|
_node = treeview_create_child_item( tree, &c[i], node ); |
103 |
|
|
treeview_add_trustpath( tree, _node, c, n, i ); |
104 |
|
|
} |
105 |
|
|
} |
106 |
|
|
} /* treeview_add_trustpath */ |
107 |
|
|
|
108 |
|
|
|
109 |
|
|
BOOL CALLBACK |
110 |
|
|
keytrust_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
111 |
|
|
{ |
112 |
|
|
winpt_key_t k; |
113 |
|
|
HWND tree; |
114 |
|
|
GpgmeTrustItem trust_item; |
115 |
|
|
gpgme_ctx_t ctx; |
116 |
|
|
gpgme_error_t ec; |
117 |
|
|
trust_path_s tp[256] = {0}; |
118 |
|
|
int pos = 0; |
119 |
|
|
|
120 |
|
|
switch( msg ) { |
121 |
|
|
case WM_INITDIALOG: |
122 |
|
|
if( !lparam ) |
123 |
|
|
dlg_fatal_error( dlg, "Could not get dialog param!" ); |
124 |
|
|
k = (winpt_key_t )lparam; |
125 |
|
|
#ifndef LANG_DE |
126 |
|
|
SetWindowText( dlg, _("List Trust Path") ); |
127 |
|
|
#endif |
128 |
|
|
tree = GetDlgItem( dlg, IDC_KEYTRUST_TREE ); |
129 |
|
|
ec = gpgme_new( &ctx ); |
130 |
|
|
if( ec ) |
131 |
|
|
BUG( NULL ); |
132 |
|
|
ec = gpgme_op_trustlist_start( ctx, k->keyid, 6 ); |
133 |
|
|
if( ec ) { |
134 |
|
|
msg_box( dlg, gpgme_strerror( err ), _("Trustlist"), MB_ERR ); |
135 |
|
|
gpgme_release( ctx ); |
136 |
|
|
return FALSE; |
137 |
|
|
} |
138 |
|
|
memset( &tp[0], 0, sizeof tp[0] ); |
139 |
|
|
tp[0].level = -1; pos++; |
140 |
|
|
strcpy( tp[0].uid, k->uid ); |
141 |
|
|
strcpy( tp[0].keyid, k->keyid ); |
142 |
|
|
|
143 |
|
|
while( !gpgme_op_trustlist_next( ctx, &trust_item ) ) { |
144 |
|
|
copy_trust_item( &tp[pos++], trust_item ); |
145 |
|
|
if( pos > 256 ) |
146 |
|
|
break; |
147 |
|
|
gpgme_trust_item_release( trust_item ); |
148 |
|
|
} |
149 |
|
|
gpgme_release( ctx ); |
150 |
|
|
treeview_add_trustpath( tree, NULL, tp, pos, -1 ); |
151 |
|
|
return TRUE; |
152 |
|
|
|
153 |
|
|
case WM_SYSCOMMAND: |
154 |
|
|
if( LOWORD( wparam ) == SC_CLOSE ) |
155 |
|
|
EndDialog( dlg, FALSE ); |
156 |
|
|
return FALSE; |
157 |
|
|
|
158 |
|
|
case WM_COMMAND: |
159 |
|
|
switch( LOWORD(wparam) ) { |
160 |
|
|
case IDOK: |
161 |
|
|
EndDialog( dlg, TRUE ); |
162 |
|
|
return TRUE; |
163 |
|
|
} |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
return FALSE; |
167 |
|
|
} /* keytrust_dlg_proc */ |
168 |
|
|
#else |
169 |
|
|
#include <windows.h> |
170 |
|
|
BOOL CALLBACK keytrust_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, |
171 |
|
|
LPARAM lparam ) { return FALSE; } |
172 |
|
|
/* GPG 1.2.x does not support this yet */ |
173 |
|
|
#endif |