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