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 |
/* 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 |
/* Return a humand readable description for the signature status @sum. */ |
71 |
const char* |
72 |
get_sigstat (gpgme_signature_t sig) |
73 |
{ |
74 |
const char *gpg_sigstat[] = { |
75 |
_("Invalid signature"), |
76 |
_("Good signature"), |
77 |
_("BAD signature"), |
78 |
_("Can't check signature: key not found."), |
79 |
_("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 |
/* Create human readable signature information. */ |
94 |
static void |
95 |
set_sig_info (HWND dlg, gpgme_signature_t sig) |
96 |
{ |
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 |
char buffer[1024]; |
104 |
char date[64] = {0}; |
105 |
|
106 |
err = gpgme_new (&gctx); |
107 |
assert (!err); |
108 |
gpgme_get_key (gctx, sig->fpr, &key, 0); |
109 |
gpgme_release (gctx); |
110 |
|
111 |
keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr+24; |
112 |
stat = get_sigstat (sig); |
113 |
if (!key) |
114 |
uid = xstrdup (_("UserID not found")); |
115 |
else |
116 |
uid = utf8_to_native (key->uids->uid); |
117 |
|
118 |
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 |
if (key) |
130 |
gpgme_key_release (key); |
131 |
free_if_alloc (uid); |
132 |
SetDlgItemText (dlg, IDC_VERIFY_STATUS, buffer); |
133 |
} |
134 |
|
135 |
|
136 |
/* Dialog box procedure for the verify process. */ |
137 |
BOOL CALLBACK |
138 |
verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
139 |
{ |
140 |
gpgme_signature_t sig; |
141 |
|
142 |
switch (msg) { |
143 |
case WM_INITDIALOG: |
144 |
sig = (gpgme_signature_t)lparam; |
145 |
assert (sig); |
146 |
SetDlgItemText (dlg, IDOK, _("&OK")); |
147 |
SetWindowText (dlg, _("Signature Verification")); |
148 |
set_sig_info (dlg, sig); |
149 |
SetForegroundWindow (dlg); |
150 |
break; |
151 |
|
152 |
case WM_COMMAND: |
153 |
switch (LOWORD (wparam )) { |
154 |
case IDOK: |
155 |
EndDialog (dlg, TRUE); |
156 |
return TRUE; |
157 |
} |
158 |
break; |
159 |
} |
160 |
return FALSE; |
161 |
} |