/*
* Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 the Claws Mail team
+ * Copyright (C) 1999-2009 the Claws Mail team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#ifndef G_OS_WIN32
# include <sys/wait.h>
#endif
-#if (defined(__DragonFly__) || defined (__NetBSD__) || defined (__FreeBSD__) || defined (__OpenBSD__))
+#if (defined(__DragonFly__) || defined(SOLARIS) || defined (__NetBSD__) || defined (__FreeBSD__) || defined (__OpenBSD__))
# include <sys/signal.h>
#endif
#ifndef G_OS_WIN32
debug_print("op_verify err %s\n", gpgme_strerror(err));
privacy_set_error("%s", gpgme_strerror(err));
return GINT_TO_POINTER(-GPG_ERR_SYSTEM_ERROR);
-
}
status = gpgme_op_verify_result(ctx);
if (status && status->signatures == NULL) {
return SIGNATURE_CHECK_FAILED;
}
case GPG_ERR_SIG_EXPIRED:
- case GPG_ERR_KEY_EXPIRED:
+ case GPG_ERR_CERT_REVOKED:
return SIGNATURE_WARN;
+ case GPG_ERR_KEY_EXPIRED:
+ return SIGNATURE_KEY_EXPIRED;
case GPG_ERR_BAD_SIGNATURE:
return SIGNATURE_INVALID;
case GPG_ERR_NO_PUBKEY:
else
g_warning(_("PGP Core: Can't get key - no gpg-agent running."));
warned = TRUE;
+ } else if (gpg_err_code(err) != GPG_ERR_NO_ERROR && gpg_err_code(err) != GPG_ERR_EOF) {
+ return g_strdup_printf(_("The signature can't be checked - %s"),
+ gpgme_strerror(err));
}
if (key)
uname = extract_name(key->uids->uid);
gint i = 0;
gchar *ret;
GString *siginfo;
- gpgme_signature_t sig = status->signatures;
-
+ gpgme_signature_t sig = NULL;
+
siginfo = g_string_sized_new(64);
+ if (status == NULL) {
+ g_string_append_printf(siginfo,
+ _("Error checking signature: no status\n"));
+ goto bail;
+ }
+
+ sig = status->signatures;
+
while (sig) {
gpgme_user_id_t user = NULL;
gpgme_key_t key;
-
+ gpgme_error_t err;
const gchar *keytype, *keyid, *uid;
- gpgme_get_key(ctx, sig->fpr, &key, 0);
+ err = gpgme_get_key(ctx, sig->fpr, &key, 0);
+ if (err != GPG_ERR_NO_ERROR) {
+ key = NULL;
+ g_string_append_printf(siginfo,
+ _("Error checking signature: %s\n"),
+ gpgme_strerror(err));
+ goto bail;
+ }
if (key) {
user = key->uids;
keytype = gpgme_pubkey_algo_name(
case GPG_ERR_NO_ERROR:
case GPG_ERR_KEY_EXPIRED:
g_string_append_printf(siginfo,
- _("Good signature from \"%s\" (Trust: %s)\n"),
- uid, get_validity_str(sig->validity));
+ _("Good signature from uid \"%s\" (Validity: %s)\n"),
+ uid, get_validity_str(user?user->validity:GPGME_VALIDITY_UNKNOWN));
break;
case GPG_ERR_SIG_EXPIRED:
g_string_append_printf(siginfo,
- _("Expired signature from \"%s\"\n"),
- uid);
+ _("Expired signature from uid \"%s\" (Validity: %s)\n"),
+ uid, get_validity_str(user?user->validity:GPGME_VALIDITY_UNKNOWN));
break;
case GPG_ERR_BAD_SIGNATURE:
g_string_append_printf(siginfo,
user = user ? user->next : NULL;
while (user != NULL) {
g_string_append_printf(siginfo,
- _(" aka \"%s\"\n"),
- user->uid);
+ _(" uid \"%s\" (Validity: %s)\n"),
+ user->uid,
+ get_validity_str(user->validity));
j++;
user = user->next;
}
g_string_append_printf(siginfo,
- _("Primary key fingerprint: %s\n"),
- sig ? sig->fpr: "?");
+ _("Primary key fingerprint:"));
+ const char* primary_fpr = NULL;
+ if (key && key->subkeys && key->subkeys->fpr)
+ primary_fpr = key->subkeys->fpr;
+ else
+ g_string_append(siginfo, " ?");
+ int idx; /* now pretty-print the fingerprint */
+ for (idx=0; primary_fpr && *primary_fpr!='\0'; idx++, primary_fpr++) {
+ if (idx%4==0)
+ g_string_append_c(siginfo, ' ');
+ if (idx%20==0)
+ g_string_append_c(siginfo, ' ');
+ g_string_append_c(siginfo, (gchar)*primary_fpr);
+ }
+ g_string_append_c(siginfo, '\n');
#ifdef HAVE_GPGME_PKA_TRUST
if (sig->pka_trust == 1 && sig->pka_address) {
g_string_append_printf(siginfo,
i++;
sig = sig->next;
}
-
+bail:
ret = siginfo->str;
g_string_free(siginfo, FALSE);
return ret;
return NULL;
}
- err = gpgme_data_rewind(plain);
+ err = cm_gpgme_data_rewind(plain);
if (err) {
debug_print("can't seek (%d %d %s)\n", err, errno, strerror(errno));
}
return NULL;
}
- err = gpgme_data_rewind(plain);
+ err = cm_gpgme_data_rewind(plain);
if (err) {
debug_print("can't seek (%d %d %s)\n", err, errno, strerror(errno));
}
return ret;
}
-gboolean sgpgme_setup_signers(gpgme_ctx_t ctx, PrefsAccount *account)
+gboolean sgpgme_setup_signers(gpgme_ctx_t ctx, PrefsAccount *account,
+ const gchar *from_addr)
{
GPGAccountConfig *config;
+ const gchar *signer_addr = account->address;
gpgme_signers_clear(ctx);
+ if (from_addr)
+ signer_addr = from_addr;
config = prefs_gpg_account_get_config(account);
switch(config->sign_key) {
debug_print("using default gnupg key\n");
break;
case SIGN_KEY_BY_FROM:
- debug_print("using key for %s\n", account->address);
+ debug_print("using key for %s\n", signer_addr);
break;
case SIGN_KEY_CUSTOM:
debug_print("using key for %s\n", config->sign_key_id);
}
if (config->sign_key != SIGN_KEY_DEFAULT) {
- gchar *keyid;
+ const gchar *keyid;
gpgme_key_t key, key2;
gpgme_error_t err;
if (config->sign_key == SIGN_KEY_BY_FROM)
- keyid = account->address;
+ keyid = signer_addr;
else if (config->sign_key == SIGN_KEY_CUSTOM)
keyid = config->sign_key_id;
else
goto bail;
err = gpgme_op_keylist_start(ctx, keyid, 1);
- if (!err)
- err = gpgme_op_keylist_next(ctx, &key);
+ if (!err) {
+ do {
+ err = gpgme_op_keylist_next(ctx, &key);
+ if (!err && key && key->protocol == gpgme_get_protocol(ctx) &&
+ !key->expired && !key->revoked && !key->disabled)
+ break;
+ if (!err && key && key->protocol != gpgme_get_protocol(ctx)) {
+ debug_print("skipping a key (wrong protocol %d)\n", key->protocol);
+ gpgme_key_release(key);
+ }
+ if (!err && key && (key->expired || key->revoked || key->disabled)) {
+
+ debug_print("skipping a key");
+ if (key->expired)
+ debug_print(" expired");
+ if (key->revoked)
+ debug_print(" revoked");
+ if (key->disabled)
+ debug_print(" disabled");
+ debug_print("\n");
+ gpgme_key_release(key);
+ }
+ } while (!err);
+ }
if (err) {
g_warning("setup_signers start: %s", gpgme_strerror(err));
privacy_set_error(_("Secret key not found (%s)"), gpgme_strerror(err));
goto bail;
}
- err = gpgme_op_keylist_next(ctx, &key2);
+ do {
+ err = gpgme_op_keylist_next(ctx, &key2);
+ if (!err && key2 && key2->protocol == gpgme_get_protocol(ctx) &&
+ !key2->expired && !key2->revoked && !key2->disabled)
+ break;
+ if (!err && key2 && key2->protocol != gpgme_get_protocol(ctx)) {
+ debug_print("skipping a key (wrong protocol %d)\n", key2->protocol);
+ gpgme_key_release(key2);
+ }
+ if (!err && key2 && (key2->expired || key2->revoked || key2->disabled)) {
+ debug_print("skipping a key");
+ if (key2->expired)
+ debug_print(" expired");
+ if (key2->revoked)
+ debug_print(" revoked");
+ if (key2->disabled)
+ debug_print(" disabled");
+ debug_print("\n");
+ gpgme_key_release(key2);
+ }
+ } while (!err);
if (!err) {
+ gpgme_key_release(key2);
g_warning("ambiguous specification of secret key '%s'\n",
keyid);
privacy_set_error(_("Secret key specification is ambiguous"));
gpgme_op_keylist_end(ctx);
err = gpgme_signers_add(ctx, key);
+ debug_print("got key (proto %d (pgp %d, smime %d).\n", key->protocol,
+ GPGME_PROTOCOL_OpenPGP, GPGME_PROTOCOL_CMS);
gpgme_key_release(key);
if (err) {
#endif
if (!gpgme_get_engine_info(&engineInfo)) {
while (engineInfo) {
+#ifndef G_OS_WIN32
debug_print("GpgME Protocol: %s\n"
"Version: %s (req %s)\n"
"Executable: %s\n",
- gpgme_get_protocol_name(engineInfo->protocol),
+ gpgme_get_protocol_name(engineInfo->protocol) ? gpgme_get_protocol_name(engineInfo->protocol):"???",
engineInfo->version ? engineInfo->version:"???",
engineInfo->req_version ? engineInfo->req_version:"???",
engineInfo->file_name ? engineInfo->file_name:"???");
+#endif
if (engineInfo->protocol == GPGME_PROTOCOL_OpenPGP
&& gpgme_engine_check_version(engineInfo->protocol) !=
GPG_ERR_NO_ERROR) {
debug_print("err : %s\n", gpgme_strerror(err));
return TRUE;
}
+check_again:
err = gpgme_op_keylist_start(ctx, NULL, TRUE);
if (!err)
err = gpgme_op_keylist_next(ctx, &key);
gpgme_op_keylist_end(ctx);
- gpgme_release(ctx);
- if (gpg_err_code(err) == GPG_ERR_EOF)
+ if (gpg_err_code(err) == GPG_ERR_EOF) {
+ if (gpgme_get_protocol(ctx) != GPGME_PROTOCOL_CMS) {
+ gpgme_set_protocol(ctx, GPGME_PROTOCOL_CMS);
+ goto check_again;
+ }
+ gpgme_release(ctx);
return FALSE;
- else
+ } else {
+ gpgme_release(ctx);
return TRUE;
+ }
}
void sgpgme_check_create_key(void)
return NULL;
/* I know it's deprecated, but we don't compile with _LARGEFILE */
- gpgme_data_rewind(data);
+ cm_gpgme_data_rewind(data);
while ((r = gpgme_data_read(data, buf, BUFSIZ)) > 0) {
result = realloc(result, r + w);
memcpy(result+w, buf, r);
}
return result;
}
+
+gpgme_error_t cm_gpgme_data_rewind(gpgme_data_t dh)
+{
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
+ if (gpgme_data_seek(dh, (off_t)0, SEEK_SET) == -1)
+ return gpg_error_from_errno(errno);
+ else
+ return 0;
+#else
+ return gpgme_data_rewind(dh);
+#endif
+}
+
#endif /* USE_GPGME */