1 |
twoaday |
2 |
/* wptClipVerifyDlg.cpp - WinPT verify dialog |
2 |
|
|
* Copyright (C) 2001-2005 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 |
|
|
|
21 |
|
|
#include <windows.h> |
22 |
|
|
|
23 |
|
|
#include "../resource.h" |
24 |
|
|
#include "wptGPG.h" |
25 |
|
|
#include "wptTypes.h" |
26 |
|
|
#include "wptCommonCtl.h" |
27 |
|
|
#include "wptKeylist.h" |
28 |
|
|
#include "wptW32API.h" |
29 |
|
|
#include "wptKeyserver.h" |
30 |
|
|
#include "wptNLS.h" |
31 |
|
|
#include "wptContext.h" /* for passwd_s */ |
32 |
|
|
#include "wptDlgs.h" |
33 |
|
|
#include "wptErrors.h" |
34 |
|
|
#include "wptVersion.h" |
35 |
|
|
|
36 |
|
|
BOOL CALLBACK |
37 |
|
|
clip_verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
38 |
|
|
{ |
39 |
|
|
static listview_ctrl_t lv = NULL; |
40 |
|
|
static text_input_s *ctx = NULL; |
41 |
|
|
const char *ndat, *nurl; |
42 |
|
|
gpgme_error_t err; |
43 |
|
|
gpgme_sig_t sig = NULL; |
44 |
|
|
gpgme_keycache_t kc = NULL; |
45 |
|
|
char keyid[16+1]; |
46 |
|
|
u16 port = HKP_PORT; |
47 |
|
|
int rc = 0, tt, algo; |
48 |
|
|
size_t i; |
49 |
|
|
|
50 |
|
|
switch( msg ) { |
51 |
|
|
case WM_INITDIALOG: |
52 |
|
|
#ifndef LANG_DE |
53 |
|
|
SetWindowText( dlg, _("Verify") ); |
54 |
|
|
#endif |
55 |
|
|
kc = keycache_get_ctx( KEYCACHE_PUB ); |
56 |
|
|
if( !kc ) |
57 |
|
|
BUG( NULL ); |
58 |
|
|
ctx = (text_input_s *)lparam; |
59 |
|
|
if( ctx && ctx->length ) |
60 |
|
|
err = gpgme_op_clip_verify_detached( kc, &sig, ctx->data, ctx->length ); |
61 |
|
|
else |
62 |
|
|
err = gpgme_op_clip_verify (kc, &sig); |
63 |
|
|
if (err) { |
64 |
|
|
if (err == GPGME_Interal_GPG_Problem) |
65 |
|
|
gnupg_display_error (); |
66 |
|
|
else |
67 |
|
|
msg_box( dlg, gpgme_strerror( err ), _("Verify"), MB_ERR ); |
68 |
|
|
gpgme_sig_release( sig ); |
69 |
|
|
EndDialog( dlg, FALSE ); |
70 |
|
|
return FALSE; |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
tt = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_VALIDITY ); |
74 |
|
|
if( tt == GPGME_SIG_STAT_NOKEY ) { |
75 |
|
|
const char * kserv; |
76 |
|
|
u32 kid = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_KEYID ); |
77 |
|
|
if( kid == 0 ) |
78 |
|
|
kid = 0xDEADBEEF; |
79 |
|
|
tt = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_CREATED ); |
80 |
|
|
algo = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_ALGO ); |
81 |
|
|
_snprintf( keyid, sizeof keyid - 1, "%X", kid ); |
82 |
|
|
rc = log_box( _("Verify"), MB_INFO|MB_YESNO, |
83 |
|
|
_("Signature made %s using %s key ID 0x%s\n" |
84 |
|
|
"Cannot check signature: public key not found\n\n" |
85 |
|
|
"Do you want to try to retrieve the key from the keyserver?"), |
86 |
|
|
strtimestamp( tt ), |
87 |
|
|
gpgme_key_expand_attr( GPGME_ATTR_ALGO, algo ), |
88 |
|
|
keyid ); |
89 |
|
|
if( rc == IDNO ) { |
90 |
|
|
msg_box( dlg, gpg_sigstat[GPGME_SIG_STAT_NOKEY], _("Verify"), MB_ERR ); |
91 |
|
|
gpgme_sig_release( sig ); |
92 |
|
|
EndDialog( dlg, FALSE ); |
93 |
|
|
return FALSE; |
94 |
|
|
} |
95 |
|
|
kserv = gpgme_sig_get_string_attr (sig, GPGME_ATTR_KEYSERVER); |
96 |
|
|
if (kserv && strncmp (kserv, "hkp://", 6)) { |
97 |
|
|
rc = log_box (_("Verify"), MB_INFO|MB_YESNO, |
98 |
|
|
_("The users preferred keyserver is '%s'.\n" |
99 |
|
|
"Do you want to use it to fetch the key?"), kserv); |
100 |
|
|
if (rc == IDNO) { |
101 |
|
|
kserv = default_keyserver; |
102 |
|
|
port = default_keyserver_port; |
103 |
|
|
} |
104 |
|
|
} |
105 |
|
|
else { |
106 |
|
|
kserv = default_keyserver; |
107 |
|
|
port = default_keyserver_port; |
108 |
|
|
} |
109 |
|
|
if (!hkp_recv_key (dlg, kserv, port, keyid, 0, 0)) { |
110 |
|
|
keycache_reload (dlg); |
111 |
|
|
kc = keycache_get_ctx (KEYCACHE_PUB); |
112 |
|
|
if (!kc) |
113 |
|
|
BUG (dlg); |
114 |
|
|
gpgme_sig_set_key_ctx (sig, kc); |
115 |
|
|
} |
116 |
|
|
} |
117 |
|
|
else if( tt == GPGME_SIG_STAT_BAD && |
118 |
|
|
!gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_CREATED ) ) |
119 |
|
|
; |
120 |
|
|
else if( !gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_TYPE ) |
121 |
|
|
|| !gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_CREATED ) |
122 |
|
|
|| !gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_VALIDITY ) ) { |
123 |
|
|
msg_box( dlg, _("Invalid signature state."), _("Verify"), MB_ERR ); |
124 |
|
|
gpgme_sig_release( sig ); |
125 |
|
|
EndDialog( dlg, FALSE ); |
126 |
|
|
return FALSE; |
127 |
|
|
} |
128 |
|
|
verlist_build( &lv, GetDlgItem( dlg, IDC_VERIFY_SIGLIST ), 0 ); |
129 |
|
|
|
130 |
|
|
for( i = 0; i < gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_LEVEL ); i++ ) { |
131 |
|
|
gpgme_sig_t _sig; |
132 |
|
|
_sig = (gpgme_sig_t)gpgme_sig_get_ulong_attr( sig, i, GPGME_ATTR_OPAQUE ); |
133 |
|
|
rc = verlist_add_sig( lv, _sig ); |
134 |
|
|
if( rc ) |
135 |
|
|
msg_box( dlg, _("Could not extract key or signature information."), |
136 |
|
|
_("Verify"), MB_ERR ); |
137 |
|
|
} |
138 |
|
|
if( gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_EXPIRE ) ) |
139 |
|
|
SetDlgItemText( dlg, IDC_VERIFY_INFO, _("The signature is expired!") ); |
140 |
|
|
ndat = gpgme_sig_get_string_attr( sig, GPGME_ATTR_NOTATION ); |
141 |
|
|
nurl = gpgme_sig_get_string_attr( sig, GPGME_ATTR_POLICY_URL ); |
142 |
|
|
if( ndat || nurl ) { |
143 |
|
|
size_t n; |
144 |
|
|
char * p; |
145 |
|
|
n = ndat? strlen( ndat ) + 1 : 0; |
146 |
|
|
n += nurl? strlen( nurl ) + 1 : 0; |
147 |
|
|
p = new char[n+40]; |
148 |
|
|
if( !p ) |
149 |
|
|
BUG( NULL ); |
150 |
|
|
sprintf( p, "%s%s%s%s%s", |
151 |
|
|
ndat? _("Notation Data: ") : "", ndat? ndat : "", ndat? "\n" : "", |
152 |
|
|
nurl? _("Policy URL: ") : "", nurl? nurl : "" ); |
153 |
|
|
msg_box( dlg, p, _("Signature Information"), MB_INFO ); |
154 |
|
|
free_if_alloc( p ); |
155 |
|
|
} |
156 |
|
|
gpgme_sig_release( sig ); |
157 |
|
|
SetForegroundWindow( dlg ); |
158 |
|
|
set_active_window( dlg ); |
159 |
|
|
return TRUE; |
160 |
|
|
|
161 |
|
|
case WM_DESTROY: |
162 |
|
|
reset_active_window(); |
163 |
|
|
if( lv ) { |
164 |
|
|
listview_release( lv ); |
165 |
|
|
lv = NULL; |
166 |
|
|
} |
167 |
|
|
return FALSE; |
168 |
|
|
|
169 |
|
|
case WM_SYSCOMMAND: |
170 |
|
|
if( LOWORD( wparam ) == SC_CLOSE ) |
171 |
|
|
EndDialog( dlg, TRUE ); |
172 |
|
|
return FALSE; |
173 |
|
|
|
174 |
|
|
case WM_COMMAND: |
175 |
|
|
switch( LOWORD( wparam ) ) { |
176 |
|
|
case IDOK: |
177 |
|
|
EndDialog( dlg, TRUE ); |
178 |
|
|
return FALSE; |
179 |
|
|
|
180 |
|
|
case IDC_VERIFY_SAVE: |
181 |
|
|
dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg, |
182 |
|
|
file_save_dlg_proc, NULL, _("Save Plaintext"), |
183 |
|
|
IDS_WINPT_FILE_SAVE ); |
184 |
|
|
break; |
185 |
|
|
} |
186 |
|
|
break; |
187 |
|
|
} |
188 |
|
|
|
189 |
|
|
return FALSE; |
190 |
|
|
} /* clip_verify_dlg_proc */ |