[balsa] Fix confusing signature info



commit fed144d54ceb411b0d94de47216098b7aaaa6a39
Author: Albrecht Dreß <albrecht dress arcor de>
Date:   Fri Nov 30 14:13:42 2018 -0500

    Fix confusing signature info
    
    * libbalsa/gmime-gpgme-signature.c: hide unavailable data if a
      signature is bad, the public key missing, or without signature
      data at all
    * libbalsa/libbalsa-gpgme-widgets.c: find proper subkey even if
      only the end of the fingerprint is given
    * src/balsa-mime-widget-crypto.c: remove useless debug message
    
    Signed-off-by: Peter Bloomfield <PeterBloomfield bellsouth net>

 ChangeLog                         | 11 +++++++++++
 libbalsa/gmime-gpgme-signature.c  |  8 ++++++--
 libbalsa/libbalsa-gpgme-widgets.c | 16 ++++++++++++++--
 src/balsa-mime-widget-crypto.c    |  1 -
 4 files changed, 31 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3b29dae22..d5ca26bd9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2018-11-30  Albrecht Dreß  <albrecht dress arcor de>
+
+       Fix confusing signature info
+
+       * libbalsa/gmime-gpgme-signature.c: hide unavailable data if a
+       signature is bad, the public key missing, or without signature
+       data at all
+       * libbalsa/libbalsa-gpgme-widgets.c: find proper subkey even if
+       only the end of the fingerprint is given
+       * src/balsa-mime-widget-crypto.c: remove useless debug message
+
 2018-11-28  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Pass NULL instead of a stock marshaller to g_signal_new().
diff --git a/libbalsa/gmime-gpgme-signature.c b/libbalsa/gmime-gpgme-signature.c
index 8e2d1ceff..2aec9c647 100644
--- a/libbalsa/gmime-gpgme-signature.c
+++ b/libbalsa/gmime-gpgme-signature.c
@@ -166,8 +166,12 @@ g_mime_gpgme_sigstat_to_gchar(const GMimeGpgmeSigstat *info,
     g_return_val_if_fail(date_string != NULL, NULL);
     msg = g_string_new(g_mime_gpgme_sigstat_protocol_name(info));
     msg = g_string_append(msg, libbalsa_gpgme_sig_stat_to_gchar(info->status));
-    g_string_append_printf(msg, _("\nSignature validity: %s"), libbalsa_gpgme_validity_to_gchar(info-> 
validity));
-    append_time_t(msg, _("\nSigned on: %s"), info->sign_time, date_string);
+    if ((info->status != GPG_ERR_BAD_SIGNATURE) && (info->status != GPG_ERR_NO_DATA)) {
+       if (info->status != GPG_ERR_NO_PUBKEY) {
+               g_string_append_printf(msg, _("\nSignature validity: %s"), 
libbalsa_gpgme_validity_to_gchar(info-> validity));
+       }
+       append_time_t(msg, _("\nSigned on: %s"), info->sign_time, date_string);
+    }
     if (info->fingerprint) {
        g_string_append_printf(msg, _("\nKey fingerprint: %s"), info->fingerprint);
     }
diff --git a/libbalsa/libbalsa-gpgme-widgets.c b/libbalsa/libbalsa-gpgme-widgets.c
index 58747e473..76773e709 100644
--- a/libbalsa/libbalsa-gpgme-widgets.c
+++ b/libbalsa/libbalsa-gpgme-widgets.c
@@ -165,9 +165,11 @@ libbalsa_gpgme_key(gpgme_key_t           key,
                GtkWidget *subkey_expander;
                GtkWidget *subkey_box;
                gpgme_subkey_t subkey;
+               size_t fingerprint_len = 0U;            /* assignment makes gcc happy */
 
                if (fingerprint != NULL) {
                        subkey_expander = gtk_expander_new(_("Subkey used"));
+                       fingerprint_len = strlen(fingerprint);
                } else if (subkey_capa != GPG_SUBKEY_CAP_ALL) {
                        gchar *capa_str;
                        gchar *label_str;
@@ -191,7 +193,11 @@ libbalsa_gpgme_key(gpgme_key_t           key,
 
                for (subkey = key->subkeys; subkey != NULL; subkey = subkey->next) {
                        if (fingerprint != NULL) {
-                               if (strcmp(fingerprint, subkey->fpr) == 0) {
+                               size_t offs;
+
+                               /* if the signature is invalid, the fingerprint only the end of the subkey's 
fingerprint */
+                               offs = strlen(subkey->fpr) - fingerprint_len;
+                               if (strcmp(fingerprint, &subkey->fpr[offs]) == 0) {
                                        gtk_box_pack_end(GTK_BOX(subkey_box), create_subkey_widget(subkey), 
FALSE, FALSE, 2);
                                }
                        } else if ((((subkey_capa & GPG_SUBKEY_CAP_SIGN) != 0U) && (subkey->can_sign != 0)) ||
@@ -284,10 +290,16 @@ libbalsa_gpgme_key_to_gchar(gpgme_key_t  key,
        /* subkey information */
        if (key->subkeys != NULL) {
                gpgme_subkey_t subkey;
+               size_t fingerprint_len;
 
                g_string_append_printf(result, "\n%s", _("Subkey used"));
+               fingerprint_len = strlen(fingerprint);
                for (subkey = key->subkeys; subkey != NULL; subkey = subkey->next) {
-                       if (strcmp(fingerprint, subkey->fpr) == 0) {
+                       size_t offs;
+
+                       /* if the signature is invalid, the fingerprint only the end of the subkey's 
fingerprint */
+                       offs = strlen(subkey->fpr) - fingerprint_len;
+                       if (strcmp(fingerprint, &subkey->fpr[offs]) == 0) {
                                gchar *details_str;
                                gchar *timebuf;
 
diff --git a/src/balsa-mime-widget-crypto.c b/src/balsa-mime-widget-crypto.c
index 73a15dd18..4a9463a9f 100644
--- a/src/balsa-mime-widget-crypto.c
+++ b/src/balsa-mime-widget-crypto.c
@@ -342,7 +342,6 @@ show_public_key_data(GtkExpander *expander,
 {
        LibBalsaMessageBody *body = (LibBalsaMessageBody *) user_data;
 
-       g_message("%s: %p %p %p", __func__, expander, body, body->sig_info);
        if (body->sig_info != NULL) {
                if (body->sig_info->key == NULL) {
                        g_mime_gpgme_sigstat_load_key(body->sig_info);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]