From 9d6ef76f5fba127c123b5320363ae2f5c6340330 Mon Sep 17 00:00:00 2001 From: djcb Date: Sat, 1 Sep 2012 20:03:48 +0300 Subject: [PATCH] * crypto: improve signature checking code --- configure.ac | 2 +- lib/Makefile.am | 2 +- lib/mu-msg-crypto.c | 22 +++++----------------- lib/mu-msg-crypto.h | 31 ------------------------------- lib/mu-msg-file.c | 6 +----- lib/mu-msg-part.c | 13 ++++--------- lib/mu-msg-priv.h | 1 + 7 files changed, 13 insertions(+), 64 deletions(-) delete mode 100644 lib/mu-msg-crypto.h diff --git a/configure.ac b/configure.ac index e1ca882e..c007aa27 100644 --- a/configure.ac +++ b/configure.ac @@ -52,7 +52,7 @@ AC_SYS_LARGEFILE AC_CHECK_LIB([uuid], [uuid_generate_random],[],AC_MSG_ERROR([libuuid not found])) AC_CHECK_LIB([z], [inflateEnd], [],AC_MSG_ERROR([zlib not found])) - + # check for makeinfo AC_CHECK_PROG(have_makeinfo,makeinfo,yes,no) AM_CONDITIONAL(HAVE_MAKEINFO,test "x$have_makeinfo" = "xyes") diff --git a/lib/Makefile.am b/lib/Makefile.am index de9b120e..c00746d2 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -21,7 +21,7 @@ include $(top_srcdir)/gtest.mk SUBDIRS= . tests if BUILD_CRYPTO -crypto=mu-msg-crypto.c mu-msg-crypto.h +crypto=mu-msg-crypto.c else crypto= endif diff --git a/lib/mu-msg-crypto.c b/lib/mu-msg-crypto.c index 826f0fc7..202022e8 100644 --- a/lib/mu-msg-crypto.c +++ b/lib/mu-msg-crypto.c @@ -26,7 +26,6 @@ #include "mu-msg.h" #include "mu-msg-priv.h" #include "mu-msg-part.h" -#include "mu-msg-crypto.h" #include "mu-date.h" #include @@ -206,16 +205,11 @@ get_digestkey_algo_name (GMimeDigestAlgo algo) static char* get_cert_data (GMimeCertificate *cert) { - const char /*issuer_name, *issuer_serial, ,*fprint*/ - *email, *name, - *digest_algo, *pubkey_algo, + const char *email, *name, *digest_algo, *pubkey_algo, *keyid, *trust; - /* issuer_name = g_mime_certificate_get_issuer_name (cert); */ - /* issuer_serial = g_mime_certificate_get_issuer_serial (cert); */ email = g_mime_certificate_get_email (cert); name = g_mime_certificate_get_name (cert); - /* fprint = g_mime_certificate_get_fingerprint (cert); */ keyid = g_mime_certificate_get_key_id (cert); digest_algo = get_digestkey_algo_name @@ -235,10 +229,9 @@ get_cert_data (GMimeCertificate *cert) } return g_strdup_printf ( - "signed by: %s <%s>; " /*; issued by %s (%s); */ + "signed by: %s <%s>; " "algos: <%s,%s>; key-id: %s; trust: %s", name ? name : "?", email ? email : "?", - /* issuer_name, issuer_serial */ pubkey_algo, digest_algo, keyid, trust); } @@ -294,8 +287,7 @@ get_status_report (GMimeSignatureList *sigs) sigstat = g_mime_signature_get_status (msig); switch (sigstat) { - case GMIME_SIGNATURE_STATUS_GOOD: - break; + case GMIME_SIGNATURE_STATUS_GOOD: break; case GMIME_SIGNATURE_STATUS_ERROR: status = MU_MSG_PART_SIG_STATUS_ERROR; break; @@ -306,10 +298,8 @@ get_status_report (GMimeSignatureList *sigs) } rep = get_verdict_report (msig); - report = g_strdup_printf ("%s%s[%d] %s", - report ? report : "", - report ? "; " : "", - i, rep); + report = g_strdup_printf ("%s%s[%d] %s", report ? report : "", + report ? "; " : "", i, rep); g_free (rep); } @@ -364,8 +354,6 @@ mu_msg_crypto_verify_part (GMimeMultipartSigned *sig, MuMsgOptions opts, } - - GMimeObject* /* this is declared in mu-msg-priv.h */ mu_msg_crypto_decrypt_part (GMimeMultipartEncrypted *enc, MuMsgOptions opts, MuMsgPartPasswordFunc func, gpointer user_data, diff --git a/lib/mu-msg-crypto.h b/lib/mu-msg-crypto.h deleted file mode 100644 index 3988decb..00000000 --- a/lib/mu-msg-crypto.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -** Copyright (C) 2012 Dirk-Jan C. Binnema -** -** 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 the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software Foundation, -** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -** -*/ - -/* functions for verifying signatures, decrypting messages */ - -#ifndef __MU_MSG_CRYPTO_H__ -#define __MU_MSG_CRYPTO_H__ - -#include -#include - -struct _MuMsgDecryptedPart; -typedef struct _MuMsgDecryptedPart MuMsgDecryptedPart; - -#endif /*__MU_MSG_CRYPTO_H__*/ diff --git a/lib/mu-msg-file.c b/lib/mu-msg-file.c index 873bae86..9b5da52d 100644 --- a/lib/mu-msg-file.c +++ b/lib/mu-msg-file.c @@ -32,11 +32,6 @@ #include "mu-maildir.h" #include "mu-msg-priv.h" -#ifdef BUILD_CRYPTO -#include "mu-msg-crypto.h" -#endif /*BUILD_CRYPTO*/ - - static gboolean init_file_metadata (MuMsgFile *self, const char* path, const char *mdir, GError **err); static gboolean init_mime_msg (MuMsgFile *msg, const char *path, GError **err); @@ -711,6 +706,7 @@ foreach_cb (GMimeObject *parent, GMimeObject *part, ForeachData *fdata) g_object_unref (dec); } #endif /*BUILD_CRYPTO*/ + } diff --git a/lib/mu-msg-part.c b/lib/mu-msg-part.c index 33039e55..a6b3cf3a 100644 --- a/lib/mu-msg-part.c +++ b/lib/mu-msg-part.c @@ -30,15 +30,10 @@ #include "mu-msg-priv.h" #include "mu-msg-part.h" -#ifdef BUILD_CRYPTO -#include "mu-msg-crypto.h" -#endif /*BUILD_CRYPTO*/ - static gboolean handle_children (MuMsg *msg, GMimeMessage *mime_msg, MuMsgOptions opts, unsigned index, MuMsgPartForeachFunc func, gpointer user_data); - struct _DoData { GMimeObject *mime_obj; unsigned index; @@ -303,6 +298,7 @@ get_disposition (GMimeObject *mobj) static gboolean check_signature (MuMsg *msg, GMimeMultipartSigned *part, MuMsgOptions opts) { +#ifdef BUILD_CRYPTO /* the signature status */ MuMsgPartSigStatusReport *sigrep; GError *err; @@ -319,7 +315,7 @@ check_signature (MuMsg *msg, GMimeMultipartSigned *part, MuMsgOptions opts) (G_OBJECT(part), SIG_STATUS_REPORT, sigrep, (GDestroyNotify)mu_msg_part_sig_status_report_destroy); - +#endif /*BUILD_CRYPTO*/ return TRUE; } @@ -361,10 +357,9 @@ handle_part (MuMsg *msg, GMimePart *part, GMimeObject *parent, msgpart.part_type |= MU_MSG_PART_TYPE_TEXT_HTML; } - /* get the sig status from the parent, but don't set if for - * the signature part itself */ + /* put the verification info in the pgp-signature part */ msgpart.sig_status_report = NULL; - if (g_ascii_strcasecmp (msgpart.subtype, "pgp-signature") != 0) + if (g_ascii_strcasecmp (msgpart.subtype, "pgp-signature") == 0) msgpart.sig_status_report = (MuMsgPartSigStatusReport*) g_object_get_data (G_OBJECT(parent), SIG_STATUS_REPORT); diff --git a/lib/mu-msg-priv.h b/lib/mu-msg-priv.h index efa053cd..e3c0273a 100644 --- a/lib/mu-msg-priv.h +++ b/lib/mu-msg-priv.h @@ -108,6 +108,7 @@ void mu_mime_message_foreach (GMimeMessage *msg, gboolean decrypt, gpointer user_data); #ifdef BUILD_CRYPTO + /** * callback function to retrieve a password from the user *