2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 Hiroyuki Yamamoto & the Sylpheed-Claws team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include "prefs_common.h"
34 #include "alertpanel.h"
35 #include "passphrase.h"
38 static void idle_function_for_gpgme(void)
40 while (gtk_events_pending())
44 static void sgpgme_disable_all(void)
46 /* FIXME: set a flag, so that we don't bother the user with failed
50 GpgmeSigStat sgpgme_verify_signature(GpgmeCtx ctx, GpgmeData sig,
55 if (gpgme_op_verify(ctx, sig, plain, &status) != GPGME_No_Error)
56 return GPGME_SIG_STAT_ERROR;
61 SignatureStatus sgpgme_sigstat_gpgme_to_privacy(GpgmeSigStat status)
64 case GPGME_SIG_STAT_GOOD:
66 case GPGME_SIG_STAT_GOOD_EXP:
67 case GPGME_SIG_STAT_GOOD_EXPKEY:
68 case GPGME_SIG_STAT_DIFF:
69 return SIGNATURE_WARN;
70 case GPGME_SIG_STAT_BAD:
71 return SIGNATURE_INVALID;
72 case GPGME_SIG_STAT_NOKEY:
73 case GPGME_SIG_STAT_NOSIG:
74 case GPGME_SIG_STAT_ERROR:
75 return SIGNATURE_CHECK_FAILED;
76 case GPGME_SIG_STAT_NONE:
77 return SIGNATURE_UNCHECKED;
79 return SIGNATURE_CHECK_FAILED;
82 static const gchar *get_validity_str(unsigned long validity)
85 case GPGME_VALIDITY_UNKNOWN:
87 case GPGME_VALIDITY_UNDEFINED:
88 return _("Undefined");
89 case GPGME_VALIDITY_NEVER:
91 case GPGME_VALIDITY_MARGINAL:
93 case GPGME_VALIDITY_FULL:
95 case GPGME_VALIDITY_ULTIMATE:
102 gchar *sgpgme_sigstat_info_short(GpgmeCtx ctx, GpgmeSigStat status)
105 case GPGME_SIG_STAT_GOOD:
108 unsigned long validity = 0;
110 if (gpgme_get_sig_key(ctx, 0, &key) != GPGME_No_Error)
111 return g_strdup(_("Error"));
113 validity = gpgme_get_sig_ulong_attr(ctx, 0,
114 GPGME_ATTR_VALIDITY, 0);
116 return g_strdup_printf(_("Valid signature by %s (Trust: %s)"),
117 gpgme_key_get_string_attr(key, GPGME_ATTR_NAME, NULL, 0),
118 get_validity_str(validity));
120 case GPGME_SIG_STAT_GOOD_EXP:
121 return g_strdup(_("The signature of this part has expired"));
122 case GPGME_SIG_STAT_GOOD_EXPKEY:
123 return g_strdup(_("The key that was used to sign this part has expired"));
124 case GPGME_SIG_STAT_DIFF:
125 return g_strdup(_("Not all signatures are valid"));
126 case GPGME_SIG_STAT_BAD:
127 return g_strdup(_("This signature is invalid"));
128 case GPGME_SIG_STAT_NOKEY:
129 return g_strdup(_("You have no key to verify this signature"));
130 case GPGME_SIG_STAT_NOSIG:
131 return g_strdup(_("Bo signature found"));
132 case GPGME_SIG_STAT_ERROR:
133 return g_strdup(_("An error occured"));
134 case GPGME_SIG_STAT_NONE:
135 return g_strdup(_("The signature of this part has not been checked"));
137 return g_strdup(_("Error"));
140 gchar *sgpgme_sigstat_info_full(GpgmeCtx ctx, GpgmeSigStat status)
147 siginfo = g_string_sized_new(64);
148 while (gpgme_get_sig_key(ctx, i, &key) != GPGME_EOF) {
149 time_t sigtime, expiretime;
150 GpgmeSigStat sigstatus;
152 const gchar *keytype, *keyid;
154 sigtime = gpgme_get_sig_ulong_attr(ctx, i, GPGME_ATTR_CREATED, 0);
155 strftime(time, 64, "%c", gmtime(&sigtime));
156 keytype = gpgme_key_get_string_attr(key, GPGME_ATTR_ALGO, NULL, 0);
157 keyid = gpgme_key_get_string_attr(key, GPGME_ATTR_KEYID, NULL, 0);
158 g_string_sprintfa(siginfo,
159 _("Signature made %s using %s key ID %s\n"),
160 time, keytype, keyid);
162 sigstatus = gpgme_get_sig_ulong_attr(ctx, i, GPGME_ATTR_SIG_STATUS, 0);
164 case GPGME_SIG_STAT_GOOD:
165 case GPGME_SIG_STAT_GOOD_EXP:
166 case GPGME_SIG_STAT_GOOD_EXPKEY:
171 g_string_sprintfa(siginfo,
172 _("Good signature from \"%s\"\n"),
173 gpgme_key_get_string_attr(key, GPGME_ATTR_USERID, NULL, 0));
174 while (uid = gpgme_key_get_string_attr(key, GPGME_ATTR_USERID, NULL, j)) {
175 g_string_sprintfa(siginfo,
180 g_string_sprintfa(siginfo,
181 _("Primary key fingerprint: %s\n"),
182 gpgme_key_get_string_attr(key, GPGME_ATTR_FPR, NULL, 0));
185 case GPGME_SIG_STAT_BAD:
186 g_string_sprintfa(siginfo,
187 _("BAD signature from \"%s\"\n"),
188 gpgme_key_get_string_attr(key, GPGME_ATTR_USERID, NULL, 0));
194 expiretime = gpgme_get_sig_ulong_attr(ctx, i, GPGME_ATTR_EXPIRE, 0);
195 if (expiretime > 0) {
196 strftime(time, 64, "%c", gmtime(&expiretime));
197 g_string_sprintfa(siginfo,
198 _("Signature expires %s\n"),
202 g_string_append(siginfo, "\n");
207 g_string_free(siginfo, FALSE);
213 if (gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP) !=
214 GPGME_No_Error) { /* Also does some gpgme init */
215 sgpgme_disable_all();
216 debug_print("gpgme_engine_version:\n%s\n",
217 gpgme_get_engine_info());
219 if (prefs_common.gpg_warning) {
222 val = alertpanel_message_with_disable
224 _("GnuPG is not installed properly, or needs to be upgraded.\n"
225 "OpenPGP support disabled."));
226 if (val & G_ALERTDISABLE)
227 prefs_common.gpg_warning = FALSE;
231 gpgme_register_idle(idle_function_for_gpgme);
236 gpgmegtk_free_passphrase();
239 #endif /* USE_GPGME */