From 1b21985d64075d0bebe072cb87d7190255ba3a6b Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 29 Mar 2013 20:13:34 +0100 Subject: [PATCH 1/5] Regenerate the Date header after signing Previously the difference to the signature timestamp could be used to estimate the passphrase length for the signing key (if the passphrase wasn't cached). --- src/compose.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/compose.c b/src/compose.c index 77370de..4f88caa 100644 --- a/src/compose.c +++ b/src/compose.c @@ -5609,12 +5609,31 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool } /* sign message if sending */ if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing && - privacy_system_can_sign(compose->privacy_system)) - if (!privacy_sign(compose->privacy_system, mimemsg, - compose->account, from_addr)) { + privacy_system_can_sign(compose->privacy_system)) { + gchar *date; + gchar *end; + gboolean message_signed; + gboolean date_found; + + date = mimemsg->data.mem + strlen("Date: "); + end = strchr(date, '\n'); + + message_signed = privacy_sign(compose->privacy_system, mimemsg, + compose->account, from_addr); + date_found = !strncmp(mimemsg->data.mem, "Date: ", strlen("Date: ")); + + if (!message_signed || !date_found || end == NULL) { g_free(from_name); g_free(from_addr); return -2; + } + /* + * Regenerate the Date header so the difference to the + * signature timestamp can't be used to estimate the + * passphrase length for the signing key. + */ + get_rfc822_date(date, strlen(date)); + *end = '\n'; } g_free(from_name); g_free(from_addr); -- 1.8.2.2 From 29f41f4eb10b11da16e9bbf29474b0e4077e115c Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Mon, 13 May 2013 15:43:08 +0200 Subject: [PATCH 2/5] Fix segfault in nntp_disconnect_all() due to pointer truncation --- src/news.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/news.c b/src/news.c index fcec2ac..48ea4fa 100644 --- a/src/news.c +++ b/src/news.c @@ -36,6 +36,7 @@ #include #include +#include "account.h" #include "nntp-thread.h" #include "news.h" #include "news_gtk.h" -- 1.8.2.2 From 1b3827bfa159ca29f2d82cbe29aa66d0b3e7d64a Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Wed, 10 Oct 2012 20:14:37 +0200 Subject: [PATCH 3/5] In case of multiple matching encryption keys, use the most recent one without bothering the user --- src/plugins/pgpcore/select-keys.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/plugins/pgpcore/select-keys.c b/src/plugins/pgpcore/select-keys.c index f558f4a..5ba6b6f 100644 --- a/src/plugins/pgpcore/select-keys.c +++ b/src/plugins/pgpcore/select-keys.c @@ -278,6 +278,7 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot cm_return_val_if_fail (sk, NULL); clist = sk->clist; cm_return_val_if_fail (clist, NULL); + static int use_most_recent_key = 1; debug_print ("select_keys:fill_clist: pattern '%s' proto %d\n", pattern, proto); @@ -306,7 +307,6 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot if (!key->can_encrypt || key->revoked || key->expired || key->disabled) continue; debug_print ("%% %s:%d: insert\n", __FILE__ ,__LINE__ ); - set_row (clist, key, proto ); for (; uid; uid = uid->next) { gchar *raw_mail = NULL; @@ -322,14 +322,37 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot } g_free(raw_mail); } - num_results++; - last_key = key; + if (use_most_recent_key) { + if (last_key == NULL) { + debug_print ("%s:%d: First matching key for %s has fingerprint %s\n", + __FILE__ ,__LINE__, pattern, key->subkeys->fpr); + last_key = key; + } else if (key->subkeys->timestamp > last_key->subkeys->timestamp) { + debug_print ("%s:%d: Ditching key %s in favor of the more recent %s\n", + __FILE__ ,__LINE__, last_key->subkeys->fpr, key->subkeys->fpr); + last_key = key; + } else { + debug_print ("%s:%d: Not chosing key %s as it's older than the current choice\n", + __FILE__ ,__LINE__, key->subkeys->fpr); + } + } else { + set_row (clist, key, proto ); + num_results++; + last_key = key; + } key = NULL; update_progress (sk, ++running, pattern); while (gtk_events_pending ()) gtk_main_iteration (); } - + + if (use_most_recent_key && last_key) { + debug_print ("%s:%d: The final key for %s has fingerprint %s\n", + __FILE__ ,__LINE__, pattern, last_key->subkeys->fpr); + set_row (clist, last_key, proto ); + num_results++; + } + if (exact_match == TRUE && num_results == 1) { if (last_key->uids->validity < GPGME_VALIDITY_FULL && !use_untrusted(last_key, last_uid, proto)) -- 1.8.2.2 From 37789b31e5080e3480cb66a24314237ac09e96b1 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 8 Feb 2013 09:19:30 +0100 Subject: [PATCH 4/5] Slightly simplify pgpinline_is_signed() by using gpinline_locate_armor_header() --- src/plugins/pgpinline/pgpinline.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/plugins/pgpinline/pgpinline.c b/src/plugins/pgpinline/pgpinline.c index a1ab276..df1d651 100644 --- a/src/plugins/pgpinline/pgpinline.c +++ b/src/plugins/pgpinline/pgpinline.c @@ -222,13 +222,9 @@ static gboolean pgpinline_is_signed(MimeInfo *mimeinfo) textdata = get_part_as_string(mimeinfo); if (!textdata) return FALSE; - - if ((sigpos = strstr(textdata, sig_indicator)) == NULL) { - g_free(textdata); - return FALSE; - } - if (!(sigpos == textdata) && !(sigpos[-1] == '\n')) { + sigpos = pgpinline_locate_armor_header(textdata, sig_indicator); + if (sigpos == NULL) { g_free(textdata); return FALSE; } -- 1.8.2.2 From b44a41678ad486ffa39881a89d5821505c0bfc9d Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 8 Feb 2013 09:26:12 +0100 Subject: [PATCH 5/5] Move a couple of armor headers from the stack to the data section --- src/plugins/pgpinline/pgpinline.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/pgpinline/pgpinline.c b/src/plugins/pgpinline/pgpinline.c index df1d651..a388d3b 100644 --- a/src/plugins/pgpinline/pgpinline.c +++ b/src/plugins/pgpinline/pgpinline.c @@ -192,7 +192,7 @@ static gchar *pgpinline_locate_armor_header(gchar *textdata, const gchar *armor_ static gboolean pgpinline_is_signed(MimeInfo *mimeinfo) { PrivacyDataPGP *data = NULL; - const gchar *sig_indicator = "-----BEGIN PGP SIGNED MESSAGE-----"; + static const gchar sig_indicator[] = "-----BEGIN PGP SIGNED MESSAGE-----"; gchar *textdata, *sigpos; cm_return_val_if_fail(mimeinfo != NULL, FALSE); @@ -351,7 +351,7 @@ static gchar *pgpinline_get_sig_info_full(MimeInfo *mimeinfo) static gboolean pgpinline_is_encrypted(MimeInfo *mimeinfo) { - const gchar *enc_indicator = "-----BEGIN PGP MESSAGE-----"; + static const gchar enc_indicator[] = "-----BEGIN PGP MESSAGE-----"; gchar *textdata; cm_return_val_if_fail(mimeinfo != NULL, FALSE); @@ -400,8 +400,8 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo) gpgme_ctx_t ctx; gchar *chars; size_t len; - const gchar *begin_indicator = "-----BEGIN PGP MESSAGE-----"; - const gchar *end_indicator = "-----END PGP MESSAGE-----"; + static const gchar begin_indicator[] = "-----BEGIN PGP MESSAGE-----"; + static const gchar end_indicator[] = "-----END PGP MESSAGE-----"; gchar *pos; if (gpgme_new(&ctx) != GPG_ERR_NO_ERROR) -- 1.8.2.2