/[gpgoe]/trunk/src/OEDlgVerify.c
ViewVC logotype

Contents of /trunk/src/OEDlgVerify.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Fri Mar 24 13:36:54 2006 UTC (19 years, 1 month ago) by twoaday
File MIME type: text/plain
File size: 3895 byte(s)
Initial checkin of the GPGOE code.


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 a humand readable description for the signature status @sum. */
52 const char*
53 get_gpg_sigstat (gpgme_signature_t sig)
54 {
55 const char *gpg_sigstat[] = {
56 _("Invalid signature"),
57 _("Good signature"),
58 _("BAD signature"),
59 _("Invalid signature"),
60 _("Invalid signature"),
61 _("Invalid signature"),
62 _("Good signature (Expired Key)"),
63 _("Good signature (Revoked Key)"),
64 NULL
65 };
66 const unsigned int mask = 8;
67
68 if (sig->summary == 0 && gpg_err_code (sig->status) == GPG_ERR_NO_ERROR)
69 return gpg_sigstat[1];
70 return gpg_sigstat[sigsum_to_index (sig->summary) % mask];
71 }
72
73
74 /* Put all signature information into the buffer @buffer. */
75 static void
76 sig_get_info_buffer (gpgme_signature_t sig, char *buffer, DWORD buflen)
77 {
78 gpgme_key_t key = NULL;
79 gpgme_ctx_t gctx = NULL;
80 gpgme_error_t err;
81 const char *keyid;
82 const char *stat;
83 char *uid;
84 char date[64] = {0};
85 int rc = 0;
86
87 err = gpgme_new (&gctx);
88 if (!err)
89 err = gpgme_get_key (gctx, sig->fpr, &key, 0);
90
91 gpgme_release (gctx);
92 if (err) {
93 _snprintf (buffer, buflen-1,
94 _("Error during verification: %s"), gpgme_strerror (err));
95 return;
96 }
97
98 keyid = strlen (sig->fpr) == 40? sig->fpr+32 : sig->fpr+24;
99 stat = get_gpg_sigstat (sig);
100 if (!key)
101 uid = xstrdup (_("UserID not found"));
102 else
103 uid = utf8_to_native (key->uids->uid);
104
105 if (sig->summary & GPGME_SIGSUM_KEY_MISSING)
106 _snprintf (buffer, buflen, "%s", stat);
107 else {
108 strncpy (date, ctime (&sig->timestamp), sizeof (date)-2);
109 date[strlen (date)-1]=0;
110 _snprintf (buffer, buflen,
111 _("Signature made '%s' using key ID 0x%08X\r\n"
112 "%s from \"%s\"\r\n"), date, keyid, stat, uid);
113 }
114 if (key)
115 gpgme_key_release (key);
116 free_if_alloc (uid);
117 }
118
119
120 /* Dialog box procedure for the verify process. */
121 BOOL CALLBACK
122 verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
123 {
124 gpgme_signature_t sig;
125 char siginfo[2048] = {0};
126
127 switch (msg) {
128 case WM_INITDIALOG:
129 sig = (gpgme_signature_t)lparam;
130 assert (sig);
131
132 SetWindowText (dlg, _("Signature Verification"));
133 sig_get_info_buffer (sig, siginfo, sizeof (siginfo)-1);
134 SetDlgItemText (dlg, IDC_VERIFY_STATUS, siginfo);
135 SetForegroundWindow (dlg);
136 break;
137
138 case WM_COMMAND:
139 switch (LOWORD (wparam )) {
140 case IDOK:
141 EndDialog (dlg, TRUE);
142 return TRUE;
143 }
144 break;
145 }
146 return FALSE;
147 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26