Package: gnupg
Version: 1.2.5-3
Severity: grave
Tags: woody, sarge, patch

Hi.

GnuPG 1.2.5 selects wrong encryption keys (e.g. for my key in the debian keyring). Thus, data is encrypted irreversible, i.e. lost.
When discussed on debian-private in February, I was encouraged to file this bug.
According to upstream, this is fixed by newer installments of the GnuPG (>=1.2.7 IIRC).
Simon Richter pointed out that a fix can be found with


cvs -d :pserver:[EMAIL PROTECTED]:/cvs/gnupg login
cvs -d :pserver:[EMAIL PROTECTED]:/cvs/gnupg rdiff -u \
  -D'2004/11/29' -D'2004/11/30' gnupg

The attached patch is a version of the above rdiff that cleanly applies to debianized source of gnupg 1.2.5-3 and with it applied gnupg packages without this bug are build.

Kind regards

T.

P.S.: I really would like to see this bug fixed on db.debian.org (or whereever ud-mailgate runs) and would happily try to come up with a patch for the appropriate version of gnupg if that means that I can hope to be able to read ud-mailgate's encrypted mails.
diff -urN gnupg-1.2.5~/g10/getkey.c gnupg-1.2.5/g10/getkey.c
--- gnupg-1.2.5~/g10/getkey.c	2004-05-01 11:19:03.000000000 +0200
+++ gnupg-1.2.5/g10/getkey.c	2005-03-16 19:15:52.000000000 +0100
@@ -1248,6 +1248,51 @@
     }
 }
 
+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 & 0x20)
+	{
+	  key_usage |= PUBKEY_USAGE_AUTH;
+	  flags&=~0x20;
+	}
+
+      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 +1325,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;
@@ -1486,16 +1521,8 @@
          */
         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 ) {
@@ -1831,7 +1858,6 @@
     u32 keytimestamp = 0;
     u32 key_expire = 0;
     const byte *p;
-    size_t n;
 
     if ( subnode->pkt->pkttype != PKT_PUBLIC_SUBKEY )
         BUG ();
@@ -1890,14 +1916,7 @@
     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;
-    }
+    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 );
     }
diff -urN gnupg-1.2.5~/include/cipher.h gnupg-1.2.5/include/cipher.h
--- gnupg-1.2.5~/include/cipher.h	2003-12-03 11:10:16.000000000 +0100
+++ gnupg-1.2.5/include/cipher.h	2005-03-16 19:10:05.000000000 +0100
@@ -51,6 +51,8 @@
 #define PUBKEY_USAGE_SIG     1	    /* key is good for signatures */
 #define PUBKEY_USAGE_ENC     2	    /* key is good for encryption */
 #define PUBKEY_USAGE_CERT    4      /* key is also good to certify other keys*/
+#define PUBKEY_USAGE_AUTH    8      /* key is good for authentication */
+#define PUBKEY_USAGE_UNKNOWN 128    /* key has an unknown usage bit */
 
 #define DIGEST_ALGO_MD5       1
 #define DIGEST_ALGO_SHA1      2

Reply via email to