12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
|
* along with GPGOE; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
15 |
*/ |
*/ |
16 |
|
|
17 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
44 |
} |
} |
45 |
|
|
46 |
|
|
47 |
|
/* 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 |
/* Return a humand readable description for the signature status @sum. */ |
/* Return a humand readable description for the signature status @sum. */ |
67 |
const char* |
const char* |
68 |
get_gpg_sigstat (gpgme_signature_t sig) |
get_sigstat (gpgme_signature_t sig) |
69 |
{ |
{ |
70 |
const char *gpg_sigstat[] = { |
const char *gpg_sigstat[] = { |
71 |
_("Invalid signature"), |
_("Invalid signature"), |
72 |
_("Good signature"), |
_("Good signature"), |
73 |
_("BAD signature"), |
_("BAD signature"), |
74 |
_("Invalid signature"), |
_("Can't check signature: key not found."), |
75 |
_("Invalid signature"), |
_("Invalid signature"), |
76 |
_("Invalid signature"), |
_("Invalid signature"), |
77 |
_("Good signature (Expired Key)"), |
_("Good signature (Expired Key)"), |
86 |
} |
} |
87 |
|
|
88 |
|
|
89 |
/* Put all signature information into the buffer @buffer. */ |
/* Create human readable signature information. */ |
90 |
static void |
static void |
91 |
sig_get_info_buffer (gpgme_signature_t sig, char *buffer, DWORD buflen) |
set_sig_info (HWND dlg, gpgme_signature_t sig) |
92 |
{ |
{ |
93 |
gpgme_key_t key = NULL; |
gpgme_key_t key = NULL; |
94 |
gpgme_ctx_t gctx = NULL; |
gpgme_ctx_t gctx = NULL; |
96 |
const char *keyid; |
const char *keyid; |
97 |
const char *stat; |
const char *stat; |
98 |
char *uid; |
char *uid; |
99 |
|
char buffer[1024]; |
100 |
char date[64] = {0}; |
char date[64] = {0}; |
101 |
|
|
102 |
err = gpgme_new (&gctx); |
err = gpgme_new (&gctx); |
103 |
if (!err) |
assert (!err); |
104 |
err = gpgme_get_key (gctx, sig->fpr, &key, 0); |
gpgme_get_key (gctx, sig->fpr, &key, 0); |
|
|
|
105 |
gpgme_release (gctx); |
gpgme_release (gctx); |
|
if (err) { |
|
|
_snprintf (buffer, buflen-1, |
|
|
_("Error during verification: %s"), gpgme_strerror (err)); |
|
|
return; |
|
|
} |
|
106 |
|
|
107 |
keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr+24; |
keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr+24; |
108 |
stat = get_gpg_sigstat (sig); |
stat = get_sigstat (sig); |
109 |
if (!key) |
if (!key) |
110 |
uid = xstrdup (_("UserID not found")); |
uid = xstrdup (_("UserID not found")); |
111 |
else |
else |
112 |
uid = utf8_to_native (key->uids->uid); |
uid = utf8_to_native (key->uids->uid); |
113 |
|
|
114 |
if (sig->summary & GPGME_SIGSUM_KEY_MISSING) |
strncpy (date, ctime (&sig->timestamp), sizeof (date)-2); |
115 |
_snprintf (buffer, buflen, "%s", stat); |
date[strlen (date)-1]=0; |
116 |
else { |
if (!key) |
117 |
strncpy (date, ctime (&sig->timestamp), sizeof (date)-2); |
_snprintf (buffer, sizeof (buffer)-1, |
118 |
date[strlen (date)-1]=0; |
_("Signature made '%s' using key ID 0x%08X\r\n" |
119 |
_snprintf (buffer, buflen, |
"%s\r\n\"%s\""), date, keyid, stat, uid); |
120 |
_("Signature made '%s' using key ID 0x%08X\r\n" |
else |
121 |
"%s from \"%s\"\r\n"), date, keyid, stat, uid); |
_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 |
if (key) |
if (key) |
126 |
gpgme_key_release (key); |
gpgme_key_release (key); |
127 |
free_if_alloc (uid); |
free_if_alloc (uid); |
128 |
|
SetDlgItemText (dlg, IDC_VERIFY_STATUS, buffer); |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
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 |
|
|
167 |
BOOL CALLBACK |
BOOL CALLBACK |
168 |
verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
169 |
{ |
{ |
170 |
gpgme_signature_t sig; |
verify_ctx_t ctx; |
|
char siginfo[2048] = {0}; |
|
171 |
|
|
172 |
switch (msg) { |
switch (msg) { |
173 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
174 |
sig = (gpgme_signature_t)lparam; |
ctx = (verify_ctx_t)lparam; |
175 |
assert (sig); |
assert (ctx); |
176 |
|
SetDlgItemText (dlg, IDOK, _("&OK")); |
177 |
SetWindowText (dlg, _("Signature Verification")); |
SetWindowText (dlg, _("Signature Verification")); |
178 |
sig_get_info_buffer (sig, siginfo, sizeof (siginfo)-1); |
set_sig_info (dlg, ctx->sig); |
179 |
SetDlgItemText (dlg, IDC_VERIFY_STATUS, siginfo); |
set_info_fields (dlg, ctx->text); |
180 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
181 |
break; |
break; |
182 |
|
|