1 |
twoaday |
1 |
/* OEDlgVerify.c - OE verify dialog |
2 |
|
|
* Copyright (C) 2001, 2002, 2003, 2006 Timo Schulz |
3 |
|
|
* |
4 |
|
|
* This file is part of GPGOE. |
5 |
|
|
* |
6 |
|
|
* GPGOE is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU Lesser General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2.1 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* GPGOE 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 Lesser General Public License |
17 |
|
|
* along with GPGOE; if not, write to the Free Software Foundation, |
18 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#ifdef HAVE_CONFIG_H |
22 |
|
|
#include <config.h> |
23 |
|
|
#endif |
24 |
|
|
#include <windows.h> |
25 |
|
|
#include <time.h> |
26 |
|
|
#include <assert.h> |
27 |
|
|
#include "resource.h" |
28 |
|
|
#include "gpgme.h" |
29 |
|
|
#include "GPGOE.h" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
/* Map the signature summary in @sum to signature status table index. |
33 |
|
|
Return value: index to table. */ |
34 |
|
|
static int |
35 |
|
|
sigsum_to_index (gpgme_sigsum_t sum) |
36 |
|
|
{ |
37 |
|
|
if ((sum & GPGME_SIGSUM_VALID) && (sum & GPGME_SIGSUM_KEY_REVOKED)) |
38 |
|
|
return 7; |
39 |
|
|
if ((sum & GPGME_SIGSUM_VALID) && (sum & GPGME_SIGSUM_SIG_EXPIRED)) |
40 |
|
|
return 6; |
41 |
|
|
if (sum & GPGME_SIGSUM_GREEN) |
42 |
|
|
return 1; |
43 |
|
|
else if (sum & GPGME_SIGSUM_RED) |
44 |
|
|
return 2; |
45 |
|
|
else if (sum & GPGME_SIGSUM_KEY_MISSING) |
46 |
|
|
return 3; |
47 |
|
|
return 0; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
|
51 |
twoaday |
11 |
/* Return human readable description of the validity. */ |
52 |
|
|
const char* |
53 |
|
|
get_key_validity (gpgme_signature_t sig) |
54 |
|
|
{ |
55 |
|
|
const char *valid; |
56 |
|
|
|
57 |
|
|
switch (sig->validity) { |
58 |
|
|
case GPGME_VALIDITY_UNKNOWN: |
59 |
|
|
case GPGME_VALIDITY_UNDEFINED: valid = _("undefined"); break; |
60 |
|
|
case GPGME_VALIDITY_NEVER: valid = _("NEVER"); break; |
61 |
|
|
case GPGME_VALIDITY_MARGINAL: valid = _("marginal"); break; |
62 |
|
|
case GPGME_VALIDITY_FULL: |
63 |
|
|
case GPGME_VALIDITY_ULTIMATE: valid = _("full"); break; |
64 |
|
|
default: valid = _("undefined"); break; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
return valid; |
68 |
|
|
} |
69 |
|
|
|
70 |
twoaday |
1 |
/* Return a humand readable description for the signature status @sum. */ |
71 |
|
|
const char* |
72 |
twoaday |
11 |
get_sigstat (gpgme_signature_t sig) |
73 |
twoaday |
1 |
{ |
74 |
|
|
const char *gpg_sigstat[] = { |
75 |
|
|
_("Invalid signature"), |
76 |
|
|
_("Good signature"), |
77 |
|
|
_("BAD signature"), |
78 |
twoaday |
11 |
_("Can't check signature: key not found."), |
79 |
twoaday |
1 |
_("Invalid signature"), |
80 |
|
|
_("Invalid signature"), |
81 |
|
|
_("Good signature (Expired Key)"), |
82 |
|
|
_("Good signature (Revoked Key)"), |
83 |
|
|
NULL |
84 |
|
|
}; |
85 |
|
|
const unsigned int mask = 8; |
86 |
|
|
|
87 |
|
|
if (sig->summary == 0 && gpg_err_code (sig->status) == GPG_ERR_NO_ERROR) |
88 |
|
|
return gpg_sigstat[1]; |
89 |
|
|
return gpg_sigstat[sigsum_to_index (sig->summary) % mask]; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
|
93 |
twoaday |
11 |
/* Create human readable signature information. */ |
94 |
twoaday |
1 |
static void |
95 |
twoaday |
11 |
set_sig_info (HWND dlg, gpgme_signature_t sig) |
96 |
twoaday |
1 |
{ |
97 |
|
|
gpgme_key_t key = NULL; |
98 |
|
|
gpgme_ctx_t gctx = NULL; |
99 |
|
|
gpgme_error_t err; |
100 |
|
|
const char *keyid; |
101 |
|
|
const char *stat; |
102 |
|
|
char *uid; |
103 |
twoaday |
11 |
char buffer[1024]; |
104 |
twoaday |
1 |
char date[64] = {0}; |
105 |
|
|
|
106 |
|
|
err = gpgme_new (&gctx); |
107 |
twoaday |
11 |
assert (!err); |
108 |
|
|
gpgme_get_key (gctx, sig->fpr, &key, 0); |
109 |
twoaday |
1 |
gpgme_release (gctx); |
110 |
|
|
|
111 |
|
|
keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr+24; |
112 |
twoaday |
11 |
stat = get_sigstat (sig); |
113 |
twoaday |
1 |
if (!key) |
114 |
|
|
uid = xstrdup (_("UserID not found")); |
115 |
|
|
else |
116 |
|
|
uid = utf8_to_native (key->uids->uid); |
117 |
|
|
|
118 |
twoaday |
11 |
strncpy (date, ctime (&sig->timestamp), sizeof (date)-2); |
119 |
|
|
date[strlen (date)-1]=0; |
120 |
|
|
if (!key) |
121 |
|
|
_snprintf (buffer, sizeof (buffer)-1, |
122 |
|
|
_("Signature made '%s' using key ID 0x%08X\r\n" |
123 |
|
|
"%s\r\n\"%s\""), date, keyid, stat, uid); |
124 |
|
|
else |
125 |
|
|
_snprintf (buffer, sizeof (buffer)-1, |
126 |
|
|
_("Signature made '%s' using key ID 0x%08X\r\n" |
127 |
|
|
"%s from \"%s\"\r\nValidity of the key: %s"), |
128 |
|
|
date, keyid, stat, uid, get_key_validity (sig)); |
129 |
twoaday |
1 |
if (key) |
130 |
|
|
gpgme_key_release (key); |
131 |
|
|
free_if_alloc (uid); |
132 |
twoaday |
11 |
SetDlgItemText (dlg, IDC_VERIFY_STATUS, buffer); |
133 |
twoaday |
1 |
} |
134 |
|
|
|
135 |
|
|
|
136 |
twoaday |
19 |
static void |
137 |
|
|
set_info_fields (HWND dlg, gpgme_data_t text) |
138 |
|
|
{ |
139 |
|
|
gpgme_data_t in; |
140 |
|
|
char date[64], buf[256], *p; |
141 |
|
|
time_t t = time (NULL); |
142 |
|
|
int n; |
143 |
|
|
|
144 |
|
|
strncpy (date, ctime (&t), sizeof (date)-1); |
145 |
|
|
date[strlen (date)-1]=0; |
146 |
|
|
|
147 |
|
|
_snprintf (buf, sizeof (buf)-1, "BEGIN PGP SIGNED MESSAGE [%s]", date); |
148 |
|
|
SetDlgItemText (dlg, IDC_VERIFY_BEGININF, buf); |
149 |
|
|
_snprintf (buf, sizeof (buf)-1, "END PGP SIGNED MESSAGE [%s]", date); |
150 |
|
|
SetDlgItemText (dlg, IDC_VERIFY_ENDINF, buf); |
151 |
|
|
|
152 |
|
|
if (!text) |
153 |
|
|
return; |
154 |
|
|
|
155 |
|
|
gpgme_data_rewind (text); |
156 |
|
|
gpgme_data_new (&in); |
157 |
|
|
for (;;) { |
158 |
|
|
n = gpgme_data_read (text, buf, sizeof (buf)-1); |
159 |
|
|
if (n < 1) |
160 |
|
|
break; |
161 |
|
|
gpgme_data_write (in, buf, n); |
162 |
|
|
} |
163 |
|
|
gpgme_data_write (in, "\0", 1); |
164 |
|
|
p = gpgme_data_release_and_get_mem (in, &n); |
165 |
|
|
SetDlgItemText (dlg, IDC_VERIFY_SIGTEXT, p); |
166 |
|
|
gpgme_free (p); |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
|
170 |
twoaday |
1 |
/* Dialog box procedure for the verify process. */ |
171 |
|
|
BOOL CALLBACK |
172 |
|
|
verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
173 |
|
|
{ |
174 |
twoaday |
19 |
verify_ctx_t ctx; |
175 |
twoaday |
1 |
|
176 |
|
|
switch (msg) { |
177 |
|
|
case WM_INITDIALOG: |
178 |
twoaday |
19 |
ctx = (verify_ctx_t)lparam; |
179 |
|
|
assert (ctx); |
180 |
twoaday |
12 |
SetDlgItemText (dlg, IDOK, _("&OK")); |
181 |
twoaday |
1 |
SetWindowText (dlg, _("Signature Verification")); |
182 |
twoaday |
19 |
set_sig_info (dlg, ctx->sig); |
183 |
|
|
set_info_fields (dlg, ctx->text); |
184 |
twoaday |
1 |
SetForegroundWindow (dlg); |
185 |
|
|
break; |
186 |
|
|
|
187 |
|
|
case WM_COMMAND: |
188 |
|
|
switch (LOWORD (wparam )) { |
189 |
|
|
case IDOK: |
190 |
|
|
EndDialog (dlg, TRUE); |
191 |
|
|
return TRUE; |
192 |
|
|
} |
193 |
|
|
break; |
194 |
|
|
} |
195 |
|
|
return FALSE; |
196 |
|
|
} |