gpg: Print revocation reason for "rev" records.
authorWerner Koch <wk@gnupg.org>
Thu, 21 Jun 2018 18:28:40 +0000 (20:28 +0200)
committerWerner Koch <wk@gnupg.org>
Thu, 21 Jun 2018 18:28:51 +0000 (20:28 +0200)
* g10/main.h: Add prototype.
* g10/keylist.c (list_keyblock_print): Print revocation info.
(list_keyblock_colon): Ditto.

* g10/test-stubs.c (get_revocation_reason): New stub.
* g10/gpgv.c (get_revocation_reason): New stub.
--

GnuPG-bug-id: 1173
Signed-off-by: Werner Koch <wk@gnupg.org>
g10/gpgv.c
g10/keylist.c
g10/main.h
g10/test-stubs.c

index c43067d..c142cef 100644 (file)
@@ -772,3 +772,18 @@ tofu_notice_key_changed (ctrl_t ctrl, kbnode_t kb)
 
   return 0;
 }
+
+
+int
+get_revocation_reason (PKT_signature *sig, char **r_reason,
+                       char **r_comment, size_t *r_commentlen)
+{
+  (void)sig;
+  (void)r_commentlen;
+
+  if (r_reason)
+    *r_reason = NULL;
+  if (r_comment)
+    *r_comment = NULL;
+  return 0;
+}
index 1f501fc..39b87e4 100644 (file)
@@ -1107,6 +1107,9 @@ list_keyblock_print (ctrl_t ctrl, kbnode_t keyblock, int secret, int fpr,
          PKT_signature *sig = node->pkt->pkt.signature;
          int sigrc;
          char *sigstr;
+          char *reason_text = NULL;
+          char *reason_comment = NULL;
+          size_t reason_commentlen;
 
          if (listctx->check_sigs)
            {
@@ -1143,7 +1146,11 @@ list_keyblock_print (ctrl_t ctrl, kbnode_t keyblock, int secret, int fpr,
 
          if (sig->sig_class == 0x20 || sig->sig_class == 0x28
              || sig->sig_class == 0x30)
-           sigstr = "rev";
+            {
+              sigstr = "rev";
+              get_revocation_reason (sig, &reason_text,
+                                     &reason_comment, &reason_commentlen);
+            }
          else if ((sig->sig_class & ~3) == 0x10)
            sigstr = "sig";
          else if (sig->sig_class == 0x18)
@@ -1205,6 +1212,40 @@ list_keyblock_print (ctrl_t ctrl, kbnode_t keyblock, int secret, int fpr,
              && (opt.list_options & LIST_SHOW_KEYSERVER_URLS))
            show_keyserver_url (sig, 3, 0);
 
+          if (reason_text)
+            {
+              es_fprintf (es_stdout, "      %s%s\n",
+                          _("reason for revocation: "), reason_text);
+              if (reason_comment)
+                {
+                  const byte *s, *s_lf;
+                  size_t n, n_lf;
+
+                  s = reason_comment;
+                  n = reason_commentlen;
+                  s_lf = NULL;
+                  do
+                    {
+                      /* We don't want any empty lines, so we skip them.  */
+                      for (;n && *s == '\n'; s++, n--)
+                        ;
+                      if (n)
+                        {
+                          s_lf = memchr (s, '\n', n);
+                          n_lf = s_lf? s_lf - s : n;
+                          es_fprintf (es_stdout, "         %s",
+                                      _("revocation comment: "));
+                          es_write_sanitized (es_stdout, s, n_lf, NULL, NULL);
+                          es_putc ('\n', es_stdout);
+                          s += n_lf; n -= n_lf;
+                        }
+                    } while (s_lf);
+                }
+            }
+
+          xfree (reason_text);
+          xfree (reason_comment);
+
          /* fixme: check or list other sigs here */
        }
     }
@@ -1554,10 +1595,19 @@ list_keyblock_colon (ctrl_t ctrl, kbnode_t keyblock,
           char *siguid;
           size_t siguidlen;
           char *issuer_fpr = NULL;
+          char *reason_text = NULL;
+          char *reason_comment = NULL;
+          size_t reason_commentlen;
+          int reason_code;
 
          if (sig->sig_class == 0x20 || sig->sig_class == 0x28
              || sig->sig_class == 0x30)
-           sigstr = "rev";
+            {
+              sigstr = "rev";
+              reason_code = get_revocation_reason (sig, &reason_text,
+                                                   &reason_comment,
+                                                   &reason_commentlen);
+            }
          else if ((sig->sig_class & ~3) == 0x10)
            sigstr = "sig";
          else if (sig->sig_class == 0x18)
@@ -1651,8 +1701,11 @@ list_keyblock_colon (ctrl_t ctrl, kbnode_t keyblock,
          else if (siguid)
             es_write_sanitized (es_stdout, siguid, siguidlen, ":", NULL);
 
-         es_fprintf (es_stdout, ":%02x%c::", sig->sig_class,
+         es_fprintf (es_stdout, ":%02x%c", sig->sig_class,
                       sig->flags.exportable ? 'x' : 'l');
+          if (reason_text)
+            es_fprintf (es_stdout, ",%02x", reason_code);
+          es_fputs ("::", es_stdout);
 
          if (opt.no_sig_cache && opt.check_sigs && fprokay)
            {
@@ -1662,12 +1715,23 @@ list_keyblock_colon (ctrl_t ctrl, kbnode_t keyblock,
           else if ((issuer_fpr = issuer_fpr_string (sig)))
             es_fputs (issuer_fpr, es_stdout);
 
-         es_fprintf (es_stdout, ":::%d:\n", sig->digest_algo);
+         es_fprintf (es_stdout, ":::%d:", sig->digest_algo);
+
+          if (reason_comment)
+            {
+              es_fputs ("::::", es_stdout);
+              es_write_sanitized (es_stdout, reason_comment, reason_commentlen,
+                                  ":", NULL);
+              es_putc (':', es_stdout);
+            }
+          es_putc ('\n', es_stdout);
 
          if (opt.show_subpackets)
            print_subpackets_colon (sig);
 
          /* fixme: check or list other sigs here */
+          xfree (reason_text);
+          xfree (reason_comment);
           xfree (siguid);
           xfree (issuer_fpr);
        }
index 453d122..768f7cf 100644 (file)
@@ -396,6 +396,9 @@ gpg_error_t transfer_secret_keys (ctrl_t ctrl, struct import_stats_s *stats,
 
 int collapse_uids( KBNODE *keyblock );
 
+int get_revocation_reason (PKT_signature *sig, char **r_reason,
+                           char **r_comment, size_t *r_commentlen);
+
 
 /*-- export.c --*/
 struct export_stats_s;
index e5fd3ae..1e13632 100644 (file)
@@ -535,3 +535,17 @@ tofu_notice_key_changed (ctrl_t ctrl, kbnode_t kb)
 
   return 0;
 }
+
+int
+get_revocation_reason (PKT_signature *sig, char **r_reason,
+                       char **r_comment, size_t *r_commentlen)
+{
+  (void)sig;
+  (void)r_commentlen;
+
+  if (r_reason)
+    *r_reason = NULL;
+  if (r_comment)
+    *r_comment = NULL;
+  return 0;
+}