[git] GnuPG - branch, master, updated. gnupg-2.1.9-97-g621afac

by Neal H. Walfield cvs at cvs.gnupg.org
Tue Nov 3 16:34:45 CET 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  621afac37e5555fd68054531e611ead444b62928 (commit)
       via  36326112290b6eef47c9dada30dddbdf408680e4 (commit)
       via  c8ef9f9a64d13ea8b9b4ade62525243abe2976ba (commit)
       via  8ae3946d28c43e30ef692ba6cf1a7fa4ed65ecc5 (commit)
      from  06f3eadb22986d9ebde9efff2794eb1d45d6c6d4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 621afac37e5555fd68054531e611ead444b62928
Author: Neal H. Walfield <neal at g10code.com>
Date:   Tue Nov 3 16:26:25 2015 +0100

    gpg: Also show when the most recently signed message was observed.
    
    * g10/tofu.c (show_statistics): Also show when the most recently
    signed message was observed.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>.
    Suggested-by: MFPA <2014-667rhzu3dc-lists-groups at riseup.net>

diff --git a/g10/tofu.c b/g10/tofu.c
index 06183ed..4dcaa11 100644
--- a/g10/tofu.c
+++ b/g10/tofu.c
@@ -2377,6 +2377,7 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
       char *tail = NULL;
       signed long messages;
       signed long first_seen_ago;
+      signed long most_recent_seen_ago;
 
       assert (strlist_length (strlist) == 3);
 
@@ -2392,7 +2393,10 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
 
       if (messages == 0 && *strlist->next->d == '\0')
 	/* min(NULL) => NULL => "".  */
-	first_seen_ago = -1;
+        {
+          first_seen_ago = -1;
+          most_recent_seen_ago = -1;
+        }
       else
 	{
 	  errno = 0;
@@ -2405,6 +2409,17 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
 			 strlist->next->d, strerror (errno));
 	      first_seen_ago = 0;
 	    }
+
+	  errno = 0;
+	  most_recent_seen_ago = strtol (strlist->next->next->d, &tail, 0);
+	  if (errno || *tail != '\0')
+	    /* Abort.  */
+	    {
+	      log_debug ("%s:%d: Couldn't convert %s (most_recent_seen) to an int: %s.\n",
+			 __func__, __LINE__,
+			 strlist->next->next->d, strerror (errno));
+	      most_recent_seen_ago = 0;
+	    }
 	}
 
       if (messages == -1 || first_seen_ago == 0)
@@ -2428,6 +2443,8 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
 	  else
 	    {
               char *first_seen_ago_str = time_ago_str (first_seen_ago);
+              char *most_recent_seen_ago_str =
+                time_ago_str (most_recent_seen_ago);
 
 	      es_fprintf (fp,
 			  _("Verified %ld messages signed by \"%s\""
@@ -2436,8 +2453,13 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
 			  fingerprint_pp, tofu_policy_str (policy),
                           first_seen_ago_str);
 
+              if (messages > 1)
+                es_fprintf (fp,
+                            _("  The most recent message was verified %s ago."),
+                            most_recent_seen_ago_str);
 
               xfree (first_seen_ago_str);
+              xfree (most_recent_seen_ago_str);
             }
 
 	  es_fputc (0, fp);

commit 36326112290b6eef47c9dada30dddbdf408680e4
Author: Neal H. Walfield <neal at g10code.com>
Date:   Tue Nov 3 16:24:08 2015 +0100

    gpg: Split a utility function out of a large function.
    
    * g10/tofu.c (show_statistics): Break the time delta to string code
    into...
    (time_ago_str): ... this new function.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>

diff --git a/g10/tofu.c b/g10/tofu.c
index b936f68..06183ed 100644
--- a/g10/tofu.c
+++ b/g10/tofu.c
@@ -2184,6 +2184,152 @@ get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
   return trust_level;
 }
 
+static char *
+time_ago_str (long long int t)
+{
+  estream_t fp;
+  int years = 0;
+  int months = 0;
+  int days = 0;
+  int hours = 0;
+  int minutes = 0;
+  int seconds = 0;
+
+  /* The number of units that we've printed so far.  */
+  int count = 0;
+  /* The first unit that we printed (year = 0, month = 1,
+     etc.).  */
+  int first = -1;
+  /* The current unit.  */
+  int i = 0;
+
+  char *str;
+
+  /* It would be nice to use a macro to do this, but gettext
+     works on the unpreprocessed code.  */
+#define MIN_SECS (60)
+#define HOUR_SECS (60 * MIN_SECS)
+#define DAY_SECS (24 * HOUR_SECS)
+#define MONTH_SECS (30 * DAY_SECS)
+#define YEAR_SECS (365 * DAY_SECS)
+
+  if (t > YEAR_SECS)
+    {
+      years = t / YEAR_SECS;
+      t -= years * YEAR_SECS;
+    }
+  if (t > MONTH_SECS)
+    {
+      months = t / MONTH_SECS;
+      t -= months * MONTH_SECS;
+    }
+  if (t > DAY_SECS)
+    {
+      days = t / DAY_SECS;
+      t -= days * DAY_SECS;
+    }
+  if (t > HOUR_SECS)
+    {
+      hours = t / HOUR_SECS;
+      t -= hours * HOUR_SECS;
+    }
+  if (t > MIN_SECS)
+    {
+      minutes = t / MIN_SECS;
+      t -= minutes * MIN_SECS;
+    }
+  seconds = t;
+
+#undef MIN_SECS
+#undef HOUR_SECS
+#undef DAY_SECS
+#undef MONTH_SECS
+#undef YEAR_SECS
+
+  fp = es_fopenmem (0, "rw,samethread");
+  if (! fp)
+    log_fatal ("error creating memory stream\n");
+
+  if (years)
+    {
+      if (years > 1)
+        es_fprintf (fp, _("%d years"), years);
+      else
+        es_fprintf (fp, _("%d year"), years);
+      count ++;
+      first = i;
+    }
+  i ++;
+  if ((first == -1 || i - first <= 3) && months)
+    {
+      if (count)
+        es_fprintf (fp, _(", "));
+
+      if (months > 1)
+        es_fprintf (fp, _("%d months"), months);
+      else
+        es_fprintf (fp, _("%d month"), months);
+      count ++;
+      first = i;
+    }
+  i ++;
+  if ((first == -1 || i - first <= 3) && count < 2 && days)
+    {
+      if (count)
+        es_fprintf (fp, _(", "));
+
+      if (days > 1)
+        es_fprintf (fp, _("%d days"), days);
+      else
+        es_fprintf (fp, _("%d day"), days);
+      count ++;
+      first = i;
+    }
+  i ++;
+  if ((first == -1 || i - first <= 3) && count < 2 && hours)
+    {
+      if (count)
+        es_fprintf (fp, _(", "));
+
+      if (hours > 1)
+        es_fprintf (fp, _("%d hours"), hours);
+      else
+        es_fprintf (fp, _("%d hour"), hours);
+      count ++;
+      first = i;
+    }
+  i ++;
+  if ((first == -1 || i - first <= 3) && count < 2 && minutes)
+    {
+      if (count)
+        es_fprintf (fp, _(", "));
+
+      if (minutes > 1)
+        es_fprintf (fp, _("%d minutes"), minutes);
+      else
+        es_fprintf (fp, _("%d minute"), minutes);
+      count ++;
+      first = i;
+    }
+  i ++;
+  if ((first == -1 || i - first <= 3) && count < 2)
+    {
+      if (count)
+        es_fprintf (fp, _(", "));
+
+      if (seconds > 1)
+        es_fprintf (fp, _("%d seconds"), seconds);
+      else
+        es_fprintf (fp, _("%d second"), seconds);
+    }
+
+  es_fputc (0, fp);
+  if (es_fclose_snatch (fp, (void **) &str, NULL))
+    log_fatal ("error snatching memory stream\n");
+
+  return str;
+}
+
 static void
 show_statistics (struct dbs *dbs, const char *fingerprint,
 		 const char *email, const char *user_id,
@@ -2203,7 +2349,8 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
 
   rc = sqlite3_exec_printf
     (db->db, strings_collect_cb, &strlist, &err,
-     "select count (*), strftime('%%s','now') - min (signatures.time)\n"
+     "select count (*), strftime('%%s','now') - min (signatures.time),\n"
+     "  strftime('%%s','now') - max (signatures.time)\n"
      " from signatures\n"
      " left join bindings on signatures.binding = bindings.oid\n"
      " where fingerprint = %Q and email = %Q and sig_digest %s%s%s;",
@@ -2231,7 +2378,7 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
       signed long messages;
       signed long first_seen_ago;
 
-      assert (strlist_length (strlist) == 2);
+      assert (strlist_length (strlist) == 3);
 
       errno = 0;
       messages = strtol (strlist->d, &tail, 0);
@@ -2253,7 +2400,7 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
 	  if (errno || *tail != '\0')
 	    /* Abort.  */
 	    {
-	      log_debug ("%s:%d: Cound't convert %s (first_seen) to an int: %s.\n",
+	      log_debug ("%s:%d: Couldn't convert %s (first_seen) to an int: %s.\n",
 			 __func__, __LINE__,
 			 strlist->next->d, strerror (errno));
 	      first_seen_ago = 0;
@@ -2280,149 +2427,25 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
                         user_id, fingerprint_pp, tofu_policy_str (policy));
 	  else
 	    {
-	      int years = 0;
-	      int months = 0;
-	      int days = 0;
-	      int hours = 0;
-	      int minutes = 0;
-	      int seconds = 0;
-
-	      /* The number of units that we've printed so far.  */
-	      int count = 0;
-	      /* The first unit that we printed (year = 0, month = 1,
-		 etc.).  */
-	      int first = -1;
-	      /* The current unit.  */
-	      int i = 0;
+              char *first_seen_ago_str = time_ago_str (first_seen_ago);
 
 	      es_fprintf (fp,
 			  _("Verified %ld messages signed by \"%s\""
-			    " (key: %s, policy: %s) in the past "),
+			    " (key: %s, policy: %s) in the past %s."),
 			  messages, user_id,
-			  fingerprint_pp, tofu_policy_str (policy));
-
-	      /* It would be nice to use a macro to do this, but gettext
-		 works on the unpreprocessed code.  */
-#define MIN_SECS (60)
-#define HOUR_SECS (60 * MIN_SECS)
-#define DAY_SECS (24 * HOUR_SECS)
-#define MONTH_SECS (30 * DAY_SECS)
-#define YEAR_SECS (365 * DAY_SECS)
+			  fingerprint_pp, tofu_policy_str (policy),
+                          first_seen_ago_str);
 
-	      if (first_seen_ago > YEAR_SECS)
-		{
-		  years = first_seen_ago / YEAR_SECS;
-		  first_seen_ago -= years * YEAR_SECS;
-		}
-	      if (first_seen_ago > MONTH_SECS)
-		{
-		  months = first_seen_ago / MONTH_SECS;
-		  first_seen_ago -= months * MONTH_SECS;
-		}
-	      if (first_seen_ago > DAY_SECS)
-		{
-		  days = first_seen_ago / DAY_SECS;
-		  first_seen_ago -= days * DAY_SECS;
-		}
-	      if (first_seen_ago > HOUR_SECS)
-		{
-		  hours = first_seen_ago / HOUR_SECS;
-		  first_seen_ago -= hours * HOUR_SECS;
-		}
-	      if (first_seen_ago > MIN_SECS)
-		{
-		  minutes = first_seen_ago / MIN_SECS;
-		  first_seen_ago -= minutes * MIN_SECS;
-		}
-	      seconds = first_seen_ago;
 
-#undef MIN_SECS
-#undef HOUR_SECS
-#undef DAY_SECS
-#undef MONTH_SECS
-#undef YEAR_SECS
-
-	      if (years)
-		{
-		  if (years > 1)
-		    es_fprintf (fp, _("%d years"), years);
-		  else
-		    es_fprintf (fp, _("%d year"), years);
-		  count ++;
-		  first = i;
-		}
-	      i ++;
-	      if ((first == -1 || i - first <= 3) && months)
-		{
-		  if (count)
-		    es_fprintf (fp, _(", "));
-
-		  if (months > 1)
-		    es_fprintf (fp, _("%d months"), months);
-		  else
-		    es_fprintf (fp, _("%d month"), months);
-		  count ++;
-		  first = i;
-		}
-	      i ++;
-	      if ((first == -1 || i - first <= 3) && count < 2 && days)
-		{
-		  if (count)
-		    es_fprintf (fp, _(", "));
-
-		  if (days > 1)
-		    es_fprintf (fp, _("%d days"), days);
-		  else
-		    es_fprintf (fp, _("%d day"), days);
-		  count ++;
-		  first = i;
-		}
-	      i ++;
-	      if ((first == -1 || i - first <= 3) && count < 2 && hours)
-		{
-		  if (count)
-		    es_fprintf (fp, _(", "));
-
-		  if (hours > 1)
-		    es_fprintf (fp, _("%d hours"), hours);
-		  else
-		    es_fprintf (fp, _("%d hour"), hours);
-		  count ++;
-		  first = i;
-		}
-	      i ++;
-	      if ((first == -1 || i - first <= 3) && count < 2 && minutes)
-		{
-		  if (count)
-		    es_fprintf (fp, _(", "));
-
-		  if (minutes > 1)
-		    es_fprintf (fp, _("%d minutes"), minutes);
-		  else
-		    es_fprintf (fp, _("%d minute"), minutes);
-		  count ++;
-		  first = i;
-		}
-	      i ++;
-	      if ((first == -1 || i - first <= 3) && count < 2)
-		{
-		  if (count)
-		    es_fprintf (fp, _(", "));
-
-		  if (seconds > 1)
-		    es_fprintf (fp, _("%d seconds"), seconds);
-		  else
-		    es_fprintf (fp, _("%d second"), seconds);
-		}
-
-	      es_fprintf (fp, _("."));
-	    }
+              xfree (first_seen_ago_str);
+            }
 
 	  es_fputc (0, fp);
 	  if (es_fclose_snatch (fp, (void **) &msg, NULL))
 	    log_fatal ("error snatching memory stream\n");
 
 	  log_info ("%s\n", msg);
+          xfree (msg);
 
 	  if (policy == TOFU_POLICY_AUTO && messages < 10)
 	    {

commit c8ef9f9a64d13ea8b9b4ade62525243abe2976ba
Author: Neal H. Walfield <neal at g10code.com>
Date:   Tue Nov 3 15:51:29 2015 +0100

    gpg: Fix message formatting.
    
    * g10/tofu.c (get_trust): Fix message formatting.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>

diff --git a/g10/tofu.c b/g10/tofu.c
index 37ae8c6..b936f68 100644
--- a/g10/tofu.c
+++ b/g10/tofu.c
@@ -1876,7 +1876,7 @@ get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
         char *conflict_pp = fingerprint_format (conflict);
 	es_fprintf (fp,
 		    _("The key %s raised a conflict with this binding (%s)."
-                      "  Since this binding's policy was 'auto', it was"
+                      "  Since this binding's policy was 'auto', it was "
                       "changed to 'ask'.  "),
 		    conflict_pp, binding);
         xfree (conflict_pp);
@@ -2069,7 +2069,7 @@ get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
 	    "Normally, there is only a single key associated with an email "
 	    "address.  However, people sometimes generate a new key if "
 	    "their key is too old or they think it might be compromised.  "
-	    "Alternatively, a new key may indicate a man-in-the-middle"
+	    "Alternatively, a new key may indicate a man-in-the-middle "
 	    "attack!  Before accepting this key, you should talk to or "
 	    "call the person to make sure this new key is legitimate.";
 	es_fprintf (fp, "\n%s\n", text);

commit 8ae3946d28c43e30ef692ba6cf1a7fa4ed65ecc5
Author: Neal H. Walfield <neal at g10code.com>
Date:   Tue Nov 3 15:43:03 2015 +0100

    gpg: Don't store formatting fingerprints in the TOFU DB.
    
    * g10/tofu.c (fingerprint_pp): Split this function into...
    (fingerprint_str): ... this function...
    (fingerprint_format): ... and this function.
    (record_binding): Store the unformatted fingerprint in the DB.  Only
    use the formatting fingerprint when displaying a message to the user.
    (get_trust): Likewise.
    (show_statistics): Likewise.
    (tofu_register): Likewise.
    (tofu_get_validity): Likewise.
    (tofu_set_policy): Likewise.
    (tofu_get_policy): Likewise.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>

diff --git a/g10/tofu.c b/g10/tofu.c
index 6dda873..37ae8c6 100644
--- a/g10/tofu.c
+++ b/g10/tofu.c
@@ -167,9 +167,56 @@ tofu_cache_dump (struct db *db)
 #  define TIME_AGO_UNIT_LARGE_NAME _("month")
 #  define TIME_AGO_UNIT_LARGE_NAME_PLURAL _("months")
 #endif
+

+static char *
+fingerprint_str (const byte *fingerprint_bin)
+{
+  char *fingerprint = bin2hex (fingerprint_bin, MAX_FINGERPRINT_LEN, NULL);
+  if (! fingerprint)
+    log_fatal ("Out of memory.\n");
+  return fingerprint;
+}
+
+/* Pretty print a MAX_FINGERPRINT_LEN-byte binary fingerprint into a
+   malloc'd string.  */
+static char *
+fingerprint_format (const byte *fingerprint)
+{
+  char *fingerprint_pretty;
+  int space = (/* The characters and the NUL.  */
+	       2 * MAX_FINGERPRINT_LEN + 1
+	       /* After every fourth character, we add a space (except
+		  the last).  */
+	       + 2 * MAX_FINGERPRINT_LEN / 4 - 1
+	       /* Half way through we add a second space.  */
+	       + 1);
+  int i;
+  int j;
+
+  if (strlen (fingerprint) != 2 * MAX_FINGERPRINT_LEN)
+    {
+      log_info (_("Fingerprint with unexpected length (%zd chars)\n"),
+                strlen (fingerprint));
+      return xstrdup (fingerprint);
+    }
 
+  fingerprint_pretty = xmalloc (space);
+
+  for (i = 0, j = 0; i < MAX_FINGERPRINT_LEN * 2; i ++)
+    {
+      if (i && i % 4 == 0)
+	fingerprint_pretty[j ++] = ' ';
+      if (i == MAX_FINGERPRINT_LEN * 2 / 2)
+	fingerprint_pretty[j ++] = ' ';
 
+      fingerprint_pretty[j ++] = fingerprint[i];
+    }
+  fingerprint_pretty[j ++] = 0;
+  assert (j == space);
 
+  return fingerprint_pretty;
+}
+

 const char *
 tofu_policy_str (enum tofu_policy policy)
 {
@@ -1074,6 +1121,7 @@ static gpg_error_t
 record_binding (struct dbs *dbs, const char *fingerprint, const char *email,
 		const char *user_id, enum tofu_policy policy, int show_old)
 {
+  char *fingerprint_pp = fingerprint_format (fingerprint);
   struct db *db_email = NULL, *db_key = NULL;
   int rc;
   char *err = NULL;
@@ -1132,7 +1180,7 @@ record_binding (struct dbs *dbs, const char *fingerprint, const char *email,
 	{
 	  log_debug ("TOFU: Error reading from binding database"
 		     " (reading policy for <%s, %s>): %s\n",
-		     fingerprint, email, err);
+		     fingerprint_pp, email, err);
 	  sqlite3_free (err);
 	}
     }
@@ -1142,12 +1190,12 @@ record_binding (struct dbs *dbs, const char *fingerprint, const char *email,
       if (policy_old != TOFU_POLICY_NONE)
 	log_debug ("Changing TOFU trust policy for binding <%s, %s>"
 		   " from %s to %s.\n",
-		   fingerprint, email,
+		   fingerprint_pp, email,
 		   tofu_policy_str (policy_old),
 		   tofu_policy_str (policy));
       else
 	log_debug ("Set TOFU trust policy for binding <%s, %s> to %s.\n",
-		   fingerprint, email,
+		   fingerprint_pp, email,
 		   tofu_policy_str (policy));
     }
 
@@ -1173,7 +1221,7 @@ record_binding (struct dbs *dbs, const char *fingerprint, const char *email,
     {
       log_error (_("error updating TOFU binding database"
 		   " (inserting <%s, %s> = %s): %s\n"),
-		 fingerprint, email, tofu_policy_str (policy),
+		 fingerprint_pp, email, tofu_policy_str (policy),
 		 err);
       sqlite3_free (err);
       goto out;
@@ -1201,7 +1249,7 @@ record_binding (struct dbs *dbs, const char *fingerprint, const char *email,
 	{
 	  log_error (_("error updating TOFU binding database"
 		       " (inserting <%s, %s>): %s\n"),
-		     fingerprint, email, err);
+		     fingerprint_pp, email, err);
 	  sqlite3_free (err);
 	  goto out;
 	}
@@ -1239,6 +1287,8 @@ record_binding (struct dbs *dbs, const char *fingerprint, const char *email,
 	}
     }
 
+  xfree (fingerprint_pp);
+
   if (rc)
     return gpg_error (GPG_ERR_GENERAL);
   return 0;
@@ -1568,6 +1618,7 @@ static enum tofu_policy
 get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
 	   const char *user_id, int may_ask)
 {
+  char *fingerprint_pp;
   struct db *db;
   enum tofu_policy policy;
   char *conflict = NULL;
@@ -1595,38 +1646,33 @@ get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
   if (! db)
     return _tofu_GET_TRUST_ERROR;
 
+  fingerprint_pp = fingerprint_format (fingerprint);
+
   policy = get_policy (dbs, fingerprint, email, &conflict);
   if (policy == TOFU_POLICY_AUTO || policy == TOFU_POLICY_NONE)
     /* See if the key is ultimately trusted.  If so, we're done.  */
     {
-      int i, j;
-      char keyid[17];
+      const char *keyid;
       KEYDB_SEARCH_DESC desc;
 
       /* We need to convert the fingerprint as a string to a long
          keyid.
 
-         FINGERPRINT has the form:
+         FINGERPRINT is stored as follows:
 
-           362D 3527 F53A AD19 71AA  FDE6 5885 9975 EE37 CF96
-                                          -------------------
+           362D3527F53AAD1971AAFDE658859975EE37CF96
+                                -------------------
 
          The last 16 characters are the long keyid.
       */
-      assert (strlen (fingerprint) > 4 * 4 + 3);
-      for (i = strlen (fingerprint) - (4 * 4 + 3), j = 0; j < 16; i ++, j ++)
-        {
-          if (fingerprint[i] == ' ')
-            i ++;
-          keyid[j] = fingerprint[i];
-        }
-      keyid[j] = 0;
+      assert (strlen (fingerprint) > 4 * 4);
+      keyid = &fingerprint[strlen (fingerprint) - 16];
 
       rc = classify_user_id (keyid, &desc, 1);
       if (rc || desc.mode != KEYDB_SEARCH_MODE_LONG_KID)
         {
           log_error (_("'%s' is not a valid long keyID\n"), keyid);
-          return _tofu_GET_TRUST_ERROR;
+          goto out;
         }
 
       if (tdb_keyid_is_utk (desc.u.kid))
@@ -1653,7 +1699,7 @@ get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
       policy = opt.tofu_default_policy;
       if (DBG_TRUST)
 	log_debug ("TOFU: binding <%s, %s>'s policy is auto (default: %s).\n",
-		   fingerprint, email,
+		   fingerprint_pp, email,
 		   tofu_policy_str (opt.tofu_default_policy));
     }
   switch (policy)
@@ -1666,7 +1712,7 @@ get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
 	 We don't need to ask the user anything.  */
       if (DBG_TRUST)
 	log_debug ("TOFU: Known binding <%s, %s>'s policy: %s\n",
-		   fingerprint, email, tofu_policy_str (policy));
+		   fingerprint_pp, email, tofu_policy_str (policy));
       trust_level = tofu_policy_to_trust_level (policy);
       goto out;
 
@@ -1745,7 +1791,7 @@ get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
 
       if (DBG_TRUST)
 	log_debug ("TOFU: New binding <%s, %s>, no conflict.\n",
-		   email, fingerprint);
+		   email, fingerprint_pp);
 
       if (record_binding (dbs, fingerprint, email, user_id,
 			  TOFU_POLICY_AUTO, 0) != 0)
@@ -1814,7 +1860,7 @@ get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
     if (! fp)
       log_fatal ("Error creating memory stream\n");
 
-    binding = xasprintf ("<%s, %s>", fingerprint, email);
+    binding = xasprintf ("<%s, %s>", fingerprint_pp, email);
     binding_shown = 0;
 
     if (policy == TOFU_POLICY_NONE)
@@ -1827,11 +1873,13 @@ get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
 		display this message.  */
 	     && conflict && strcmp (conflict, fingerprint) != 0)
       {
+        char *conflict_pp = fingerprint_format (conflict);
 	es_fprintf (fp,
 		    _("The key %s raised a conflict with this binding (%s)."
                       "  Since this binding's policy was 'auto', it was"
                       "changed to 'ask'.  "),
-		    conflict, binding);
+		    conflict_pp, binding);
+        xfree (conflict_pp);
 	binding_shown = 1;
       }
     es_fprintf (fp,
@@ -1979,13 +2027,16 @@ get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
 	    if (! key || strcmp (key, stats_iter->fingerprint) != 0)
 	      {
 		int this_key;
+                char *key_pp;
 		key = stats_iter->fingerprint;
 		this_key = strcmp (key, fingerprint) == 0;
+                key_pp = fingerprint_format (key);
 		if (this_key)
-		  es_fprintf (fp, _("  %s (this key):"), key);
+		  es_fprintf (fp, _("  %s (this key):"), key_pp);
 		else
 		  es_fprintf (fp, _("  %s (policy: %s):"),
-			      key, tofu_policy_str (stats_iter->policy));
+			      key_pp, tofu_policy_str (stats_iter->policy));
+                xfree (key_pp);
 		es_fprintf (fp, "\n");
 	      }
 
@@ -2128,6 +2179,7 @@ get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
 
   xfree (conflict);
   free_strlist (bindings_with_this_email);
+  xfree (fingerprint_pp);
 
   return trust_level;
 }
@@ -2138,6 +2190,7 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
 		 const char *sig_exclude)
 {
   struct db *db;
+  char *fingerprint_pp;
   int rc;
   strlist_t strlist = NULL;
   char *err = NULL;
@@ -2146,6 +2199,8 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
   if (! db)
     return;
 
+  fingerprint_pp = fingerprint_format (fingerprint);
+
   rc = sqlite3_exec_printf
     (db->db, strings_collect_cb, &strlist, &err,
      "select count (*), strftime('%%s','now') - min (signatures.time)\n"
@@ -2169,7 +2224,7 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
 
   if (! strlist)
     log_info (_("Have never verified a message signed by key %s!\n"),
-	      fingerprint);
+              fingerprint_pp);
   else
     {
       char *tail = NULL;
@@ -2206,8 +2261,8 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
 	}
 
       if (messages == -1 || first_seen_ago == 0)
-	log_info (_("Failed to collect signature statistics for \"%s\" (key %s)\n"),
-		  user_id, fingerprint);
+        log_info (_("Failed to collect signature statistics for \"%s\" (key %s)\n"),
+                  user_id, fingerprint_pp);
       else
 	{
 	  enum tofu_policy policy = get_policy (dbs, fingerprint, email, NULL);
@@ -2219,10 +2274,10 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
 	    log_fatal ("error creating memory stream\n");
 
 	  if (messages == 0)
-	    es_fprintf (fp,
-			_("Verified 0 messages signed by \"%s\""
-			  " (key: %s, policy %s)."),
-			user_id, fingerprint, tofu_policy_str (policy));
+            es_fprintf (fp,
+                        _("Verified 0 messages signed by \"%s\""
+                          " (key: %s, policy %s)."),
+                        user_id, fingerprint_pp, tofu_policy_str (policy));
 	  else
 	    {
 	      int years = 0;
@@ -2244,7 +2299,7 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
 			  _("Verified %ld messages signed by \"%s\""
 			    " (key: %s, policy: %s) in the past "),
 			  messages, user_id,
-			  fingerprint, tofu_policy_str (policy));
+			  fingerprint_pp, tofu_policy_str (policy));
 
 	      /* It would be nice to use a macro to do this, but gettext
 		 works on the unpreprocessed code.  */
@@ -2402,6 +2457,7 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
 
  out:
   free_strlist (strlist);
+  xfree (fingerprint_pp);
 
   return;
 }
@@ -2422,42 +2478,6 @@ email_from_user_id (const char *user_id)
   return email;
 }
 
-/* Pretty print a MAX_FINGERPRINT_LEN-byte binary fingerprint into a
-   malloc'd string.  */
-static char *
-fingerprint_pp (const byte *fingerprint_bin)
-{
-  char fingerprint[MAX_FINGERPRINT_LEN * 2 + 1];
-  char *fingerprint_pretty;
-  int space = (/* The characters and the NUL.  */
-	       sizeof (fingerprint)
-	       /* After every fourth character, we add a space (except
-		  the last).  */
-	       + (sizeof (fingerprint) - 1) / 4 - 1
-	       /* Half way through we add a second space.  */
-	       + 1);
-  int i;
-  int j;
-
-  bin2hex (fingerprint_bin, MAX_FINGERPRINT_LEN, fingerprint);
-
-  fingerprint_pretty = xmalloc (space);
-
-  for (i = 0, j = 0; i < MAX_FINGERPRINT_LEN * 2; i ++)
-    {
-      if (i && i % 4 == 0)
-	fingerprint_pretty[j ++] = ' ';
-      if (i == MAX_FINGERPRINT_LEN * 2 / 2)
-	fingerprint_pretty[j ++] = ' ';
-
-      fingerprint_pretty[j ++] = fingerprint[i];
-    }
-  fingerprint_pretty[j ++] = 0;
-  assert (j == space);
-
-  return fingerprint_pretty;
-}
-
 /* Register the signature with the binding <FINGERPRINT_BIN, USER_ID>.
    FINGERPRINT must be MAX_FINGERPRINT_LEN bytes long.
 
@@ -2485,6 +2505,7 @@ tofu_register (const byte *fingerprint_bin, const char *user_id,
   struct dbs *dbs;
   struct db *db;
   char *fingerprint = NULL;
+  char *fingerprint_pp = NULL;
   char *email = NULL;
   char *err = NULL;
   int rc;
@@ -2502,7 +2523,8 @@ tofu_register (const byte *fingerprint_bin, const char *user_id,
       goto die;
     }
 
-  fingerprint = fingerprint_pp (fingerprint_bin);
+  fingerprint = fingerprint_str (fingerprint_bin);
+  fingerprint_pp = fingerprint_format (fingerprint);
 
   if (! *user_id)
     {
@@ -2568,7 +2590,7 @@ tofu_register (const byte *fingerprint_bin, const char *user_id,
     log_debug ("SIGNATURES DB contains duplicate records"
 	       " <key: %s, %s, time: 0x%lx, sig: %s, %s>."
 	       "  Please report.\n",
-	       fingerprint, email, (unsigned long) sig_time,
+	       fingerprint_pp, email, (unsigned long) sig_time,
 	       sig_digest, origin);
   else if (c == 1)
     {
@@ -2576,7 +2598,7 @@ tofu_register (const byte *fingerprint_bin, const char *user_id,
       if (DBG_TRUST)
 	log_debug ("Already observed the signature"
 		   " <key: %s, %s, time: 0x%lx, sig: %s, %s>\n",
-		   fingerprint, email, (unsigned long) sig_time,
+		   fingerprint_pp, email, (unsigned long) sig_time,
 		   sig_digest, origin);
     }
   else
@@ -2585,7 +2607,7 @@ tofu_register (const byte *fingerprint_bin, const char *user_id,
     {
       if (DBG_TRUST)
 	log_debug ("TOFU: Saving signature <%s, %s, %s>\n",
-		   fingerprint, email, sig_digest);
+		   fingerprint_pp, email, sig_digest);
 
       assert (c == 0);
 
@@ -2631,6 +2653,7 @@ tofu_register (const byte *fingerprint_bin, const char *user_id,
 		     already_verified ? NULL : sig_digest);
 
   xfree (email);
+  xfree (fingerprint_pp);
   xfree (fingerprint);
   if (dbs)
     closedbs (dbs);
@@ -2715,7 +2738,7 @@ tofu_get_validity (const byte *fingerprint_bin, const char *user_id,
       goto die;
     }
 
-  fingerprint = fingerprint_pp (fingerprint_bin);
+  fingerprint = fingerprint_str (fingerprint_bin);
 
   if (! *user_id)
     {
@@ -2778,7 +2801,7 @@ tofu_set_policy (kbnode_t kb, enum tofu_policy policy)
   fingerprint_from_pk (pk, fingerprint_bin, &fingerprint_bin_len);
   assert (fingerprint_bin_len == sizeof (fingerprint_bin));
 
-  fingerprint = fingerprint_pp (fingerprint_bin);
+  fingerprint = fingerprint_str (fingerprint_bin);
 
   for (; kb; kb = kb->next)
     {
@@ -2855,7 +2878,7 @@ tofu_get_policy (PKT_public_key *pk, PKT_user_id *user_id,
   fingerprint_from_pk (pk, fingerprint_bin, &fingerprint_bin_len);
   assert (fingerprint_bin_len == sizeof (fingerprint_bin));
 
-  fingerprint = fingerprint_pp (fingerprint_bin);
+  fingerprint = fingerprint_str (fingerprint_bin);
 
   email = email_from_user_id (user_id->name);
 

-----------------------------------------------------------------------

Summary of changes:
 g10/tofu.c | 494 +++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 281 insertions(+), 213 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list