* crypto: improve signature checking code

This commit is contained in:
djcb
2012-09-01 20:03:48 +03:00
parent 7b39d56c99
commit 9d6ef76f5f
7 changed files with 13 additions and 64 deletions

View File

@ -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

View File

@ -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 <gmime/gmime.h>
@ -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,

View File

@ -1,31 +0,0 @@
/*
** Copyright (C) 2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** 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 <glib.h>
#include <mu-msg.h>
struct _MuMsgDecryptedPart;
typedef struct _MuMsgDecryptedPart MuMsgDecryptedPart;
#endif /*__MU_MSG_CRYPTO_H__*/

View File

@ -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*/
}

View File

@ -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);

View File

@ -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
*