]> granicus.if.org Git - neomutt/commitdiff
Add a very simple signature-dumping mode to pgpring. (Not needed
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 26 Jun 2001 10:06:53 +0000 (10:06 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 26 Jun 2001 10:06:53 +0000 (10:06 +0000)
for mutt.)

pgplib.c
pgplib.h
pgppubring.c

index ec7af9b97706c9a17cc3f60e7d543f040e37a46a..dd1b4751fa6fa47cdbeebec3aa98ddb16dcd8dd7 100644 (file)
--- a/pgplib.c
+++ b/pgplib.c
@@ -116,6 +116,22 @@ short pgp_get_abilities (unsigned char type)
   return (pgp_canencrypt (type) << 1) | pgp_cansign (type);
 }
 
+void pgp_free_sig (pgp_sig_t **sigp)
+{
+  pgp_sig_t *sp, *q;
+  
+  if (!sigp || !*sigp)
+    return;
+  
+  for (sp = *sigp; sp; sp = q)
+  {
+    q = sp->next;
+    safe_free ((void **) &sp);
+  }
+  
+  *sigp = NULL;
+}
+
 void pgp_free_uid (pgp_uid_t ** upp)
 {
   pgp_uid_t *up, *q;
@@ -125,6 +141,7 @@ void pgp_free_uid (pgp_uid_t ** upp)
   for (up = *upp; up; up = q)
   {
     q = up->next;
+    pgp_free_sig (&up->sigs);
     safe_free ((void **) &up->addr);
     safe_free ((void **) &up);
   }
index b89b951f820faf3895f996476361078a5488851a..1b4ba4f1eb0599b63c55927479c7fd31cd7e3186 100644 (file)
--- a/pgplib.h
+++ b/pgplib.h
@@ -54,6 +54,15 @@ typedef struct pgp_keyinfo
 }
 pgp_key_t;
 
+typedef struct pgp_signature
+{
+  struct pgp_signature *next;
+  unsigned char sigtype;
+  unsigned long sid1;
+  unsigned long sid2;
+}
+pgp_sig_t;
+
 typedef struct pgp_uid
 {
   char *addr;
@@ -61,6 +70,7 @@ typedef struct pgp_uid
   int flags;
   struct pgp_keyinfo *parent;
   struct pgp_uid *next;
+  struct pgp_signature *sigs;
 }
 pgp_uid_t;
 
index 0181264f3f133e4501eeced014bdeecee3be32ed..6e03919e4e2ef10f98ab44cdc662b9f5bbd2b016 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1997-2000 Thomas Roessler <roessler@guug.de>
+ * Copyright (C) 1997-2001 Thomas Roessler <roessler@does-not-exist.org>
  * 
  *     This program is free software; you can redistribute it
  *     and/or modify it under the terms of the GNU General Public
@@ -64,6 +64,8 @@ extern int optind;
 #endif
 
 
+static short dump_signatures = 0;
+
 
 static void pgpring_find_candidates (char *ringfile, const char *hints[], int nhints);
 static void pgpring_dump_keyblock (pgp_key_t *p);
@@ -81,10 +83,16 @@ int main (int argc, char * const argv[])
   char pgppath[_POSIX_PATH_MAX];
   char kring[_POSIX_PATH_MAX];
 
-  while ((c = getopt (argc, argv, "25sk:")) != EOF)
+  while ((c = getopt (argc, argv, "25sk:S")) != EOF)
   {
     switch (c)
     {
+      case 'S':
+      {
+       dump_signatures = 1;
+       break;
+      }
+
       case 'k':
       {
        _kring = optarg;
@@ -319,11 +327,12 @@ static pgp_key_t *pgp_parse_keyinfo (unsigned char *buff, size_t l)
   }
 }
 
-static int pgp_parse_pgp2_sig (unsigned char *buff, size_t l, pgp_key_t * p)
+static int pgp_parse_pgp2_sig (unsigned char *buff, size_t l, pgp_key_t * p, pgp_sig_t *s)
 {
   unsigned char sigtype;
   time_t sig_gen_time;
-  unsigned long signerid;
+  unsigned long signerid1;
+  unsigned long signerid2;
   size_t j;
   int i;
 
@@ -337,18 +346,28 @@ static int pgp_parse_pgp2_sig (unsigned char *buff, size_t l, pgp_key_t * p)
   for (i = 0; i < 4; i++)
     sig_gen_time = (sig_gen_time << 8) + buff[j++];
 
-  j += 4;
-  signerid = 0;
+  signerid1 = signerid2 = 0;
+  for (i = 0; i < 4; i++)
+    signerid1 = (signerid1 << 8) + buff[j++];
+
   for (i = 0; i < 4; i++)
-    signerid = (signerid << 8) + buff[j++];
+    signerid2 = (signerid2 << 8) + buff[j++];
 
+  
   if (sigtype == 0x20 || sigtype == 0x28)
     p->flags |= KEYFLAG_REVOKED;
 
+  if (s)
+  {
+    s->sigtype = sigtype;
+    s->sid1    = signerid1;
+    s->sid2    = signerid2;
+  }
+  
   return 0;
 }
 
-static int pgp_parse_pgp3_sig (unsigned char *buff, size_t l, pgp_key_t * p)
+static int pgp_parse_pgp3_sig (unsigned char *buff, size_t l, pgp_key_t * p, pgp_sig_t *s)
 {
   unsigned char sigtype;
   unsigned char pkalg;
@@ -357,7 +376,8 @@ static int pgp_parse_pgp3_sig (unsigned char *buff, size_t l, pgp_key_t * p)
   time_t sig_gen_time = -1;
   long validity = -1;
   long key_validity = -1;
-  long signerid = 0;
+  unsigned long signerid1 = 0;
+  unsigned long signerid2 = 0;
   size_t ml;
   size_t j;
   int i;
@@ -440,10 +460,13 @@ static int pgp_parse_pgp3_sig (unsigned char *buff, size_t l, pgp_key_t * p)
        {
          if (skl < 8)
            break;
-         j += 4;
-         signerid = 0;
+         signerid1 = 0;
+         for (i = 0; i < 4; i++)
+           signerid1 = (signerid1 << 8) + buff[j++];
+         signerid2 = 0;
          for (i = 0; i < 4; i++)
-           signerid = (signerid << 8) + buff[j++];
+           signerid2 = (signerid2 << 8) + buff[j++];
+         
          break;
        }
        case 10:                        /* CMR key */
@@ -476,12 +499,20 @@ static int pgp_parse_pgp3_sig (unsigned char *buff, size_t l, pgp_key_t * p)
   if (have_critical_spks)
     p->flags |= KEYFLAG_CRITICAL;
 
+  if (s)
+  {
+    s->sigtype = sigtype;
+    s->sid1    = signerid1;
+    s->sid2    = signerid2;
+  }
+
+  
   return 0;
 
 }
 
 
-static int pgp_parse_sig (unsigned char *buff, size_t l, pgp_key_t * p)
+static int pgp_parse_sig (unsigned char *buff, size_t l, pgp_key_t * p, pgp_sig_t *sig)
 {
   if (!buff || l < 2 || !p)
     return -1;
@@ -490,9 +521,9 @@ static int pgp_parse_sig (unsigned char *buff, size_t l, pgp_key_t * p)
   {
   case 2:
   case 3:
-    return pgp_parse_pgp2_sig (buff, l, p);
+    return pgp_parse_pgp2_sig (buff, l, p, sig);      
   case 4:
-    return pgp_parse_pgp3_sig (buff, l, p);
+    return pgp_parse_pgp3_sig (buff, l, p, sig);
   default:
     return -1;
   }
@@ -519,6 +550,7 @@ static pgp_key_t *pgp_parse_keyblock (FILE * fp)
   pgp_key_t *p = NULL;
   pgp_uid_t *uid = NULL;
   pgp_uid_t **addr = NULL;
+  pgp_sig_t **lsig = NULL;
 
   FGETPOS(fp,pos);
   
@@ -570,7 +602,14 @@ static pgp_key_t *pgp_parse_keyblock (FILE * fp)
 
       case PT_SIG:
       {
-       pgp_parse_sig (buff, l, p);
+       if (lsig)
+       {
+         pgp_sig_t *signature = safe_calloc (sizeof (pgp_sig_t), 1);
+         *lsig = signature;
+         lsig = &signature->next;
+         
+         pgp_parse_sig (buff, l, p, signature);
+       }
        break;
       }
 
@@ -608,7 +647,8 @@ static pgp_key_t *pgp_parse_keyblock (FILE * fp)
        uid->parent = p;
        uid->trust = 0;
        addr = &uid->next;
-
+       lsig = &uid->sigs;
+       
        /* the following tags are generated by
         * pgp 2.6.3in.
         */
@@ -746,6 +786,7 @@ static char gnupg_trustletter (int t)
 static void pgpring_dump_keyblock (pgp_key_t *p)
 {
   pgp_uid_t *uid;
+  pgp_sig_t *sig;
   short first;
   struct tm *tp;
   time_t t;
@@ -800,6 +841,18 @@ static void pgpring_dump_keyblock (pgp_key_t *p)
        print_userid (uid->addr);
        printf (":\n");
       }
+      
+      if (dump_signatures)
+      {
+       for (sig = uid->sigs; sig; sig = sig->next)
+       {
+         if (sig->sigtype == 0x10 || sig->sigtype == 0x11 ||
+             sig->sigtype == 0x12 || sig->sigtype == 0x13)
+           printf ("sig::::%08lX%08lX:::::::\n",
+                   sig->sid1, sig->sid2);
+           
+       }
+      }
     }
   }
 }