]> granicus.if.org Git - mutt/commitdiff
Fix classic gpg date parsing in list-keys.
authorKevin McCarthy <kevin@8t8.us>
Fri, 7 Dec 2018 03:22:59 +0000 (19:22 -0800)
committerKevin McCarthy <kevin@8t8.us>
Fri, 7 Dec 2018 03:22:59 +0000 (19:22 -0800)
GnuPG changed the format of their --with-colons output in 2.0.10.
Dates are now seconds since epoch.  Update the parse_pub_line() code
to detect the new format.

The GnuPG changes also separated pub and the first uid.  Since mutt
allows an empty uid field, the output is a bit less friendly now, with
an initial key without an uid.  I think that's acceptable, but
eventually we'll want to change the parsing behavior.

gnupgparse.c

index fd754a006895b41055bd09aa0aedf3e585ff252d..9a2e0cb719d067743f9ed8ac8ed7e90a6295a95a 100644 (file)
@@ -246,37 +246,46 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k)
       }
       case 6:                  /* timestamp (1998-02-28) */
       {
-       char tstr[11];
-       struct tm time;
-
        dprint (2, (debugfile, "time stamp: %s\n", p));
 
-       if (!p)
-         break;
-       time.tm_sec = 0;
-       time.tm_min = 0;
-       time.tm_hour = 12;
-       strncpy (tstr, p, 11);
-       tstr[4] = '\0';
-       tstr[7] = '\0';
-       if (mutt_atoi (tstr, &time.tm_year) < 0)
-       {
-         p = tstr;
-         goto bail;
-       }
-       time.tm_year -= 1900;
-       if (mutt_atoi (tstr+5, &time.tm_mon) < 0)
-       {
-         p = tstr+5;
-         goto bail;
-       }
-       time.tm_mon -= 1;
-       if (mutt_atoi (tstr+8, &time.tm_mday) < 0)
-       {
-         p = tstr+8;
-         goto bail;
-       }
-       tmp.gen_time = mutt_mktime (&time, 0);
+        if (strchr (p, '-'))   /* gpg pre-2.0.10 used format (yyyy-mm-dd) */
+        {
+          char tstr[11];
+          struct tm time;
+
+          time.tm_sec = 0;
+          time.tm_min = 0;
+          time.tm_hour = 12;
+          strncpy (tstr, p, 11);
+          tstr[4] = '\0';
+          tstr[7] = '\0';
+          if (mutt_atoi (tstr, &time.tm_year) < 0)
+          {
+            p = tstr;
+            goto bail;
+          }
+          time.tm_year -= 1900;
+          if (mutt_atoi (tstr+5, &time.tm_mon) < 0)
+          {
+            p = tstr+5;
+            goto bail;
+          }
+          time.tm_mon -= 1;
+          if (mutt_atoi (tstr+8, &time.tm_mday) < 0)
+          {
+            p = tstr+8;
+            goto bail;
+          }
+          tmp.gen_time = mutt_mktime (&time, 0);
+        }
+        else                  /* gpg 2.0.10+ uses seconds since 1970-01-01 */
+        {
+          unsigned long long secs;
+
+          if (mutt_atoull (p, &secs) < 0)
+            goto bail;
+          tmp.gen_time = (time_t)secs;
+        }
         break;
       }
       case 7:                  /* valid for n days */