STABLE-BRANCH-1-2 gnupg/g10 (ChangeLog getkey.c)

cvs user dshaw cvs at cvs.gnupg.org
Mon Nov 29 21:59:53 CET 2004


    Date: Monday, November 29, 2004 @ 22:07:08
  Author: dshaw
    Path: /cvs/gnupg/gnupg/g10
     Tag: STABLE-BRANCH-1-2

Modified: ChangeLog getkey.c

* getkey.c (parse_key_usage): New function to parse out key usage flags.  
Set PUBKEY_USAGE_UNKNOWN to handle flags (i.e. authentication) that we
don't understand in this branch. (fixup_uidnode, merge_selfsigs_main,
merge_selfsigs_subkey): Call it from here to remove duplicate code.  This
is bug 378.


-----------+
 ChangeLog |   15 ++++++--
 getkey.c  |  103 +++++++++++++++++++++++++++++++++++-------------------------
 2 files changed, 73 insertions(+), 45 deletions(-)


Index: gnupg/g10/ChangeLog
diff -u gnupg/g10/ChangeLog:1.249.2.232 gnupg/g10/ChangeLog:1.249.2.233
--- gnupg/g10/ChangeLog:1.249.2.232	Tue Sep 14 03:55:57 2004
+++ gnupg/g10/ChangeLog	Mon Nov 29 22:07:08 2004
@@ -1,3 +1,11 @@
+2004-11-29  David Shaw  <dshaw at jabberwocky.com>
+
+	* getkey.c (parse_key_usage): New function to parse out key usage
+	flags.  Set PUBKEY_USAGE_UNKNOWN to handle flags
+	(i.e. authentication) that we don't understand in this branch.
+	(fixup_uidnode, merge_selfsigs_main, merge_selfsigs_subkey): Call
+	it from here to remove duplicate code.  This is bug 378.
+
 2004-09-13  David Shaw  <dshaw at jabberwocky.com>
 
 	* getkey.c (premerge_public_with_secret): Fix subkey<->binding sig
@@ -14,9 +22,10 @@
 	* hkp.c (dehtmlize): Understand the quote character
 	(i.e. "&quot;") in HTML responses.
 
-	* keydb.h, getkey.c (get_user_id_printable): Rename to
-	get_user_id_native and remove the printable stuff since we're
-	print-ifying valid utf8 characters.  Change all callers in
+	* keydb.h, getkey.c (get_user_id_printable,
+	get_user_id_string_printable): Rename to get_user_id_native and
+	get_user_id_string_native and remove the printable stuff since
+	we're print-ifying valid utf8 characters.  Change all callers in
 	import.c, sign.c, and encode.c.
 
 2004-08-19  David Shaw  <dshaw at jabberwocky.com>
Index: gnupg/g10/getkey.c
diff -u gnupg/g10/getkey.c:1.78.2.33 gnupg/g10/getkey.c:1.78.2.34
--- gnupg/g10/getkey.c:1.78.2.33	Tue Sep 14 03:55:58 2004
+++ gnupg/g10/getkey.c	Mon Nov 29 22:07:08 2004
@@ -1248,6 +1248,45 @@
     }
 }
 
+static int
+parse_key_usage(PKT_signature *sig)
+{
+  int key_usage=0;
+  const byte *p;
+  size_t n;
+  byte flags;
+
+  p=parse_sig_subpkt(sig->hashed,SIGSUBPKT_KEY_FLAGS,&n);
+  if(p && n)
+    {
+      /* first octet of the keyflags */
+      flags=*p;
+
+      if(flags & 3)
+	{
+	  key_usage |= PUBKEY_USAGE_SIG;
+	  flags&=~3;
+	}
+
+      if(flags & 12)
+	{
+	  key_usage |= PUBKEY_USAGE_ENC;
+	  flags&=~12;
+	}
+
+      if(flags)
+	key_usage |= PUBKEY_USAGE_UNKNOWN;
+    }
+
+  /* We set PUBKEY_USAGE_UNKNOWN to indicate that this key has a
+     capability that we do not handle.  This serves to distinguish
+     between a zero key usage which we handle as the default
+     capabilities for that algorithm, and a usage that we do not
+     handle. */
+
+  return key_usage;
+}
+
 /*
  * Apply information from SIGNODE (which is the valid self-signature
  * associated with that UID) to the UIDNODE:
@@ -1280,17 +1319,7 @@
     uid->expiredate = sig->expiredate;
 
     /* store the key flags in the helper variable for later processing */
-    uid->help_key_usage = 0;
-    p = parse_sig_subpkt (sig->hashed, SIGSUBPKT_KEY_FLAGS, &n );
-    if ( p && n ) {
-        /* first octet of the keyflags */   
-        if ( (*p & 3) )
-            uid->help_key_usage |= PUBKEY_USAGE_SIG;
-        if ( (*p & 12) )    
-            uid->help_key_usage |= PUBKEY_USAGE_ENC;
-        /* Note: we do not set the CERT flag here because it can be assumed
-         * that thre is no real policy to set it. */
-    }
+    uid->help_key_usage=parse_key_usage(sig);
 
     /* ditto or the key expiration */
     uid->help_key_expire = 0;
@@ -1480,33 +1509,27 @@
 			       pk->numrevkeys*sizeof(struct revocation_key));
       }
 
-    if ( signode ) {
+    if ( signode )
+      {
         /* some information from a direct key signature take precedence
          * over the same information given in UID sigs.
          */
         PKT_signature *sig = signode->pkt->pkt.signature;
         const byte *p;
-        size_t n;
-        
-        p = parse_sig_subpkt (sig->hashed, SIGSUBPKT_KEY_FLAGS, &n );
-        if ( p && n ) {
-            /* first octet of the keyflags */   
-            if ( (*p & 3) )
-                key_usage |= PUBKEY_USAGE_SIG;
-            if ( (*p & 12) )    
-                key_usage |= PUBKEY_USAGE_ENC;
-        }
+
+	key_usage=parse_key_usage(sig);
 
 	p = parse_sig_subpkt (sig->hashed, SIGSUBPKT_KEY_EXPIRE, NULL);
-	if ( p ) {
-	  key_expire = keytimestamp + buffer_to_u32(p);
-	  key_expire_seen = 1;
-        }
+	if ( p )
+	  {
+	    key_expire = keytimestamp + buffer_to_u32(p);
+	    key_expire_seen = 1;
+	  }
 
         /* mark that key as valid: one direct key signature should 
          * render a key as valid */
         pk->is_valid = 1;
-    }
+      }
 
     /* pass 1.5: look for key revocation signatures that were not made
        by the key (i.e. did a revocation key issue a revocation for
@@ -1831,7 +1854,6 @@
     u32 keytimestamp = 0;
     u32 key_expire = 0;
     const byte *p;
-    size_t n;
 
     if ( subnode->pkt->pkttype != PKT_PUBLIC_SUBKEY )
         BUG ();
@@ -1889,23 +1911,20 @@
     subpk->is_valid = 1;
     sig = signode->pkt->pkt.signature;
     sig->flags.chosen_selfsig=1; /* so we know which selfsig we chose later */
-        
-    p = parse_sig_subpkt (sig->hashed, SIGSUBPKT_KEY_FLAGS, &n );
-    if ( p && n ) {
-        /* first octet of the keyflags */   
-        if ( (*p & 3) )
-            key_usage |= PUBKEY_USAGE_SIG;
-        if ( (*p & 12) )    
-            key_usage |= PUBKEY_USAGE_ENC;
-    }
-    if ( !key_usage ) { /* no key flags at all: get it from the algo */
+
+    key_usage=parse_key_usage(sig);
+    if ( !key_usage )
+      {
+	/* no key flags at all: get it from the algo */
         key_usage = openpgp_pk_algo_usage ( subpk->pubkey_algo );
-    }
-    else { /* check that the usage matches the usage as given by the algo */
+      }
+    else
+      {
+	/* check that the usage matches the usage as given by the algo */
         int x = openpgp_pk_algo_usage ( subpk->pubkey_algo );
         if ( x ) /* mask it down to the actual allowed usage */
-            key_usage &= x; 
-    }
+	  key_usage &= x; 
+      }
 
     /* Type 20 Elgamal subkeys, any subkey on a type 20 primary, or
        any subkey on an old v3 Elgamal(e) primary are not usable. */




More information about the Gnupg-commits mailing list