[svn] GnuPG - r3989 - trunk/g10

svn author dshaw cvs at cvs.gnupg.org
Tue Jan 17 21:55:56 CET 2006


Author: dshaw
Date: 2006-01-17 21:55:53 +0100 (Tue, 17 Jan 2006)
New Revision: 3989

Modified:
   trunk/g10/ChangeLog
   trunk/g10/keydb.h
   trunk/g10/passphrase.c
   trunk/g10/pubkey-enc.c
Log:
* keydb.h, passphrase.c (next_to_last_passphrase): New.  "Touch" a
passphrase as if it was used (move from next_pw to last_pw).

* pubkey-enc.c (get_session_key): Use it here to handle the case where a
passphrase happens to be correct for a secret key, but yet that key isn't
the anonymous recipient (i.e. the secret key could be decrypted, but not
the session key).  This also handles the case where a secret key is
located on a card and a secret key with no passphrase.  Note this does not
fix bug 594 (anonymous recipients on smartcard do not work) - it just
prevents the anonymous search from stopping when the card is encountered.


Modified: trunk/g10/ChangeLog
===================================================================
--- trunk/g10/ChangeLog	2006-01-17 16:03:51 UTC (rev 3988)
+++ trunk/g10/ChangeLog	2006-01-17 20:55:53 UTC (rev 3989)
@@ -1,3 +1,17 @@
+2006-01-17  David Shaw  <dshaw at jabberwocky.com>
+
+	* keydb.h, passphrase.c (next_to_last_passphrase): New.  "Touch" a
+	passphrase as if it was used (move from next_pw to last_pw).
+
+	* pubkey-enc.c (get_session_key): Use it here to handle the case
+	where a passphrase happens to be correct for a secret key, but yet
+	that key isn't the anonymous recipient (i.e. the secret key could
+	be decrypted, but not the session key).  This also handles the
+	case where a secret key is located on a card and a secret key with
+	no passphrase.  Note this does not fix bug 594 (anonymous
+	recipients on smartcard do not work) - it just prevents the
+	anonymous search from stopping when the card is encountered.
+
 2006-01-07  David Shaw  <dshaw at jabberwocky.com>
 
 	* keyserver.c (keyserver_refresh): Fix problem when more than one

Modified: trunk/g10/keydb.h
===================================================================
--- trunk/g10/keydb.h	2006-01-17 16:03:51 UTC (rev 3988)
+++ trunk/g10/keydb.h	2006-01-17 20:55:53 UTC (rev 3989)
@@ -211,6 +211,7 @@
                         const char *tryagain_text, int *canceled);
 void set_next_passphrase( const char *s );
 char *get_last_passphrase(void);
+void next_to_last_passphrase(void);
 
 /*-- getkey.c --*/
 int classify_user_id( const char *name, KEYDB_SEARCH_DESC *desc);

Modified: trunk/g10/passphrase.c
===================================================================
--- trunk/g10/passphrase.c	2006-01-17 16:03:51 UTC (rev 3988)
+++ trunk/g10/passphrase.c	2006-01-17 20:55:53 UTC (rev 3989)
@@ -55,24 +55,6 @@
 #include "assuan.h"
 #endif /*ENABLE_AGENT_SUPPORT*/
 
-
-#define buftou32( p )  ((*(byte*)(p) << 24) | (*((byte*)(p)+1)<< 16) | \
-		       (*((byte*)(p)+2) << 8) | (*((byte*)(p)+3)))
-#define u32tobuf( p, a ) do { 			                \
-			    ((byte*)p)[0] = (byte)((a) >> 24);	\
-			    ((byte*)p)[1] = (byte)((a) >> 16);	\
-			    ((byte*)p)[2] = (byte)((a) >>  8);	\
-			    ((byte*)p)[3] = (byte)((a) 	    );	\
-			} while(0)
-
-#define digitp(p)   (*(p) >= '0' && *(p) <= '9')
-#define hexdigitp(a) (digitp (a)                     \
-                      || (*(a) >= 'A' && *(a) <= 'F')  \
-                      || (*(a) >= 'a' && *(a) <= 'f'))
-#define xtoi_1(p)   (*(p) <= '9'? (*(p)- '0'): \
-                     *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
-#define xtoi_2(p)   ((xtoi_1(p) * 16) + xtoi_1((p)+1))
-
 static char *fd_passwd = NULL;
 static char *next_pw = NULL;
 static char *last_pw = NULL;
@@ -115,6 +97,17 @@
     return p;
 }
 
+/* As if we had used the passphrase - make it the last_pw. */
+void
+next_to_last_passphrase(void)
+{
+  if(next_pw)
+    {
+      last_pw=next_pw;
+      next_pw=NULL;
+    }
+}
+
 /* Here's an interesting question: since this passphrase was passed in
    on the command line, is there really any point in using secure
    memory for it?  I'm going with 'yes', since it doesn't hurt, and

Modified: trunk/g10/pubkey-enc.c
===================================================================
--- trunk/g10/pubkey-enc.c	2006-01-17 16:03:51 UTC (rev 3988)
+++ trunk/g10/pubkey-enc.c	2006-01-17 20:55:53 UTC (rev 3989)
@@ -115,11 +115,26 @@
 								      only
 								      once */
 	    if( !rc )
+	      {
 		rc = get_it( k, dek, sk, keyid );
-	    if( !rc ) {
+		/* Successfully checked the secret key (either it was
+		   a card, had no passphrase, or had the right
+		   passphrase) but couldn't decrypt the session key,
+		   so thus that key is not the anonymous recipient.
+		   Move the next passphrase into last for the next
+		   round.  We only do this if the secret key was
+		   successfully checked as in the normal case,
+		   check_secret_key handles this for us via
+		   passphrase_to_dek */
+		if(rc)
+		  next_to_last_passphrase();
+	      }
+
+	    if( !rc )
+	      {
 		log_info(_("okay, we are the anonymous recipient.\n") );
 		break;
-	    }
+	      }
 	}
 	enum_secret_keys( &enum_context, NULL, 0, 0 ); /* free context */
     }




More information about the Gnupg-commits mailing list