[svn] GnuPG - r4822 - in trunk: . agent common doc keyserver po sm tools

svn author wk cvs at cvs.gnupg.org
Wed Sep 3 11:37:38 CEST 2008


Author: wk
Date: 2008-09-03 11:37:32 +0200 (Wed, 03 Sep 2008)
New Revision: 4822

Modified:
   trunk/NEWS
   trunk/THANKS
   trunk/TODO
   trunk/agent/ChangeLog
   trunk/agent/command.c
   trunk/agent/preset-passphrase.c
   trunk/common/ChangeLog
   trunk/common/convert.c
   trunk/common/t-convert.c
   trunk/common/util.h
   trunk/doc/ChangeLog
   trunk/doc/yat2m.c
   trunk/keyserver/ChangeLog
   trunk/keyserver/gpgkeys_kdns.c
   trunk/po/be.po
   trunk/po/ca.po
   trunk/po/cs.po
   trunk/po/da.po
   trunk/po/de.po
   trunk/po/el.po
   trunk/po/eo.po
   trunk/po/es.po
   trunk/po/et.po
   trunk/po/fi.po
   trunk/po/fr.po
   trunk/po/gl.po
   trunk/po/hu.po
   trunk/po/id.po
   trunk/po/it.po
   trunk/po/ja.po
   trunk/po/nb.po
   trunk/po/pl.po
   trunk/po/pt.po
   trunk/po/pt_BR.po
   trunk/po/ro.po
   trunk/po/ru.po
   trunk/po/sk.po
   trunk/po/sv.po
   trunk/po/tr.po
   trunk/po/zh_CN.po
   trunk/po/zh_TW.po
   trunk/sm/ChangeLog
   trunk/sm/sign.c
   trunk/tools/mk-tdata.c
Log:
Fix gpg-preset-passphrase bug.
Cleanups


[The diff below has been truncated]

Modified: trunk/agent/ChangeLog
===================================================================
--- trunk/agent/ChangeLog	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/agent/ChangeLog	2008-09-03 09:37:32 UTC (rev 4822)
@@ -1,3 +1,11 @@
+2008-09-03  Werner Koch  <wk at g10code.com>
+
+	* command.c (parse_keygrip): Use hex2bin.
+	(cmd_preset_passphrase): Decode the passphrase.  Reported by Kiss
+	Gabor.  Fixes #679 again.
+	* preset-passphrase.c (make_hexstring): Remove.
+	(preset_passphrase): Use bin2hex.
+
 2008-05-27  Werner Koch  <wk at g10code.com>
 
 	* trustlist.c (insert_colons): Fix stupidly wrong allocation size
@@ -12,7 +20,7 @@
 
 	* gpg-agent.c (main, agent_deinit_default_ctrl): Always use xfree
 	because our asprintf is mapped to an xmalloc style function in
-	util.h. Replace xtrdup by xtrystrdup.
+	util.h. Replace xstrdup by xtrystrdup.
 	* w32main.c (build_argv): Ditto.
 	* preset-passphrase.c (preset_passphrase): Ditto.
 	* divert-scd.c (ask_for_card): Ditto.

Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/common/ChangeLog	2008-09-03 09:37:32 UTC (rev 4822)
@@ -1,3 +1,9 @@
+2008-09-03  Werner Koch  <wk at g10code.com>
+
+	* convert.c (hex2str): New.
+	(hex2str_alloc): New.
+	* t-convert.c (test_hex2str): New.
+
 2008-08-19  Werner Koch  <wk at g10code.com>
 
 	* iobuf.c: Avoid passing a NULL (iobuf_t)->desc to the log

Modified: trunk/doc/ChangeLog
===================================================================
--- trunk/doc/ChangeLog	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/doc/ChangeLog	2008-09-03 09:37:32 UTC (rev 4822)
@@ -1,3 +1,8 @@
+2008-08-30  Werner Koch  <wk at g10code.com>
+
+	* yat2m.c (write_th): Print a not ethat this is generated source.
+	(VERSION): Bump up to 1.0.
+
 2008-07-30  Werner Koch  <wk at g10code.com>
 
 	* gpgsm.texi (GPGSM Configuration): Mention com-cert.pem.

Modified: trunk/keyserver/ChangeLog
===================================================================
--- trunk/keyserver/ChangeLog	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/keyserver/ChangeLog	2008-09-03 09:37:32 UTC (rev 4822)
@@ -1,3 +1,7 @@
+2008-08-29  Werner Koch  <wk at g10code.com>
+
+	* gpgkeys_kdns.c: Changed copyright notice to the FSF.
+
 2008-04-21  Werner Koch  <wk at g10code.com>
 
 	* ksutil.c (w32_init_sockets) [HAVE_W32_SYSTEM]: New.

Modified: trunk/sm/ChangeLog
===================================================================
--- trunk/sm/ChangeLog	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/sm/ChangeLog	2008-09-03 09:37:32 UTC (rev 4822)
@@ -1,3 +1,8 @@
+2008-09-03  Werner Koch  <wk at g10code.com>
+
+	* sign.c (MY_GCRY_MD_SHA224): New, so that we don't need libgcrypt
+	1.2. 
+
 2008-08-13  Werner Koch  <wk at g10code.com>
 
 	* keylist.c (list_cert_colon): Print 'f' for validated certs.

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/NEWS	2008-09-03 09:37:32 UTC (rev 4822)
@@ -27,7 +27,9 @@
 
  * gpgsm now uses AES by default.
 
+ * gpg-preset-passphrase works again.
 
+
 Noteworthy changes in version 2.0.9 (2008-03-26)
 ------------------------------------------------
 

Modified: trunk/THANKS
===================================================================
--- trunk/THANKS	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/THANKS	2008-09-03 09:37:32 UTC (rev 4822)
@@ -140,6 +140,7 @@
 Keith Clayton              keith at claytons.org
 Ken Takusagawa             ken.takusagawa.2  at gmail.com
 Kevin Ryde                 user42 at zip.com.au
+Kiss Gabor                 kissg at ssg.ki.iif.hu
 Klaus Singvogel            ks at caldera.de
 Kurt Garloff               garloff at suse.de
 Lars Kellogg-Stedman	   lars at bu.edu

Modified: trunk/TODO
===================================================================
--- trunk/TODO	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/TODO	2008-09-03 09:37:32 UTC (rev 4822)
@@ -104,7 +104,10 @@
    Remove these definitions.
 ** MY_GCRY_PK_ECDSA
    Remove this.
+** MY_GCRY_MD_SHA224
+   Remove this.
 
+
 * Extend selinux support to other modules
 
 * Remove -sat PGP2 compatibility hack

Modified: trunk/agent/command.c
===================================================================
--- trunk/agent/command.c	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/agent/command.c	2008-09-03 09:37:32 UTC (rev 4822)
@@ -271,7 +271,6 @@
 {
   int rc;
   size_t n;
-  const unsigned char *p;
 
   rc = parse_hexstring (ctx, string, &n);
   if (rc)
@@ -280,8 +279,8 @@
   if (n != 20)
     return set_error (GPG_ERR_ASS_PARAMETER, "invalid length of keygrip");
 
-  for (p=(const unsigned char*)string, n=0; n < 20; p += 2, n++)
-    buf[n] = xtoi_2 (p);
+  if (hex2bin (string, buf, 20) < 0)
+    return set_error (GPG_ERR_BUG, "hex2bin");
 
   return 0;
 }
@@ -1100,7 +1099,7 @@
   size_t len;
 
   if (!opt.allow_preset_passphrase)
-    return gpg_error (GPG_ERR_NOT_SUPPORTED);
+    return set_error (GPG_ERR_NOT_SUPPORTED, "no --allow-preset-passphrase");
 
   rc = parse_keygrip (ctx, line, grip);
   if (rc)
@@ -1135,11 +1134,17 @@
   /* If there is a passphrase, use it.  Currently, a passphrase is
      required.  */
   if (*line)
-    passphrase = line;
+    {
+      /* Do in-place conversion.  */
+      passphrase = line;
+      if (!hex2str (passphrase, passphrase, strlen (passphrase)+1, NULL))
+        rc = set_error (GPG_ERR_ASS_PARAMETER, "invalid hexstring");
+    }
   else
-    return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
+    rc = set_error (GPG_ERR_NOT_IMPLEMENTED, "passphrase is required");
 
-  rc = agent_put_cache (grip_clear, CACHE_MODE_ANY, passphrase, ttl);
+  if (!rc)
+    rc = agent_put_cache (grip_clear, CACHE_MODE_ANY, passphrase, ttl);
 
   if (rc)
     log_error ("command preset_passwd failed: %s\n", gpg_strerror (rc));

Modified: trunk/agent/preset-passphrase.c
===================================================================
--- trunk/agent/preset-passphrase.c	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/agent/preset-passphrase.c	2008-09-03 09:37:32 UTC (rev 4822)
@@ -113,38 +113,7 @@
 /* Include the implementation of map_spwq_error.  */
 MAP_SPWQ_ERROR_IMPL
       
-/* Convert the string SRC into HEX encoding.  Caller needs to xfree
-   the returned string.  */
-static char *
-make_hexstring (const char *src)
-{
-  int len = 2 * strlen (src) + 1;
-  char *dst;
-  char *res;
 
-  res = dst = xtrymalloc (len);
-  if (!dst)
-    {
-      log_error ("can not escape string: %s\n",
-		 gpg_strerror (gpg_error_from_syserror ()));
-      return NULL;
-    }
-
-#define _tohex(nr)	((nr) < 10 ? ((nr) + '0') : (((nr) - 10) + 'A'))
-#define tohex1(p)  _tohex (*((unsigned char *) p) & 15)
-#define tohex2(p)  _tohex ((*((unsigned char *) p) >> 4) & 15)
-
-  while (*src)
-    {
-      *(dst++) = tohex2 (src);
-      *(dst++) = tohex1 (src);
-      src++;
-    }
-  *dst = '\0';
-  return res;
-}
-
-
 static void
 preset_passphrase (const char *keygrip)
 {
@@ -175,11 +144,14 @@
       /* FIXME: How to handle empty passwords?  */
     }
 
-  passphrase_esc = make_hexstring (opt_passphrase
-				   ? opt_passphrase : passphrase);
+  {
+    const char *s = opt_passphrase ? opt_passphrase : passphrase;
+    passphrase_esc = bin2hex (s, strlen (s), NULL);
+  }
   if (!passphrase_esc)
     {
-      /* Error message printed by callee.  */
+      log_error ("can not escape string: %s\n",
+		 gpg_strerror (gpg_error_from_syserror ()));
       return;
     }
 

Modified: trunk/common/convert.c
===================================================================
--- trunk/common/convert.c	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/common/convert.c	2008-09-03 09:37:32 UTC (rev 4822)
@@ -1,5 +1,5 @@
 /* convert.c - Hex conversion functions.
- *	Copyright (C) 2006 Free Software Foundation, Inc.
+ *	Copyright (C) 2006, 2008 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -30,7 +30,7 @@
 
 /* Convert STRING consisting of hex characters into its binary
    representation and store that at BUFFER.  BUFFER needs to be of
-   LENGTH bytes.  The function check that the STRING will convert
+   LENGTH bytes.  The function checks that the STRING will convert
    exactly to LENGTH bytes. The string is delimited by either end of
    string or a white space character.  The function returns -1 on
    error or the length of the parsed string.  */
@@ -100,6 +100,7 @@
 }
 
 
+
 static char *
 do_bin2hex (const void *buffer, size_t length, char *stringbuf, int with_colon)
 {
@@ -160,3 +161,87 @@
 }
 
 
+
+/* Convert HEXSTRING consisting of hex characters into string and
+   store that at BUFFER.  HEXSTRING is either delimited by end of
+   string or a white space character.  The function makes sure that
+   the resulting string in BUFFER is terminated by a Nul character.
+   BUFSIZE is the availabe length of BUFFER; if the converted result
+   plus a possible required Nul character does not fit into this
+   buffer, the function returns NULL and won't change the existing
+   conent of buffer.  In-place conversion is possible as long as
+   BUFFER points to HEXSTRING.
+   
+   If BUFFER is NULL and bufsize is 0 the function scans HEXSTRING but
+   does not store anything.  This may be used to find the end of
+   hexstring.
+
+   On sucess the function returns a pointer to the next character
+   after HEXSTRING (which is either end-of-string or a the next white
+   space).  If BUFLEN is not NULL the strlen of buffer is stored
+   there; this will even be done if BUFFER has been passed as NULL. */
+const char *
+hex2str (const char *hexstring, char *buffer, size_t bufsize, size_t *buflen)
+{
+  const char *s = hexstring;
+  int idx, count;
+  int need_nul = 0;
+
+  if (buflen)
+    *buflen = 0;
+
+  for (s=hexstring, count=0; hexdigitp (s) && hexdigitp (s+1); s += 2, count++)
+    ;
+  if (*s && (!isascii (*s) || !isspace (*s)) )
+    return NULL;   /* Not followed by Nul or white space.  */
+  need_nul = !(s[-2] == '0' && s[-1] == '0');
+  if (need_nul)
+    count++;
+
+  if (buffer)
+    {
+      if (count > bufsize)
+        return NULL; /* Too long.  */
+      
+      for (s=hexstring, idx=0; hexdigitp (s) && hexdigitp (s+1); s += 2)
+        ((unsigned char*)buffer)[idx++] = xtoi_2 (s);
+      if (need_nul)
+        buffer[idx] = 0;
+    }
+
+  if (buflen)
+    *buflen = count - 1;
+  return s;
+}
+
+
+/* Same as hex2str but this function allocated a new string.  Returns
+   NULL on error.  If R_COUNT is not NULL, the number of scanned bytes
+   will be stored there.  ERRNO is set on error. */
+char *
+hex2str_alloc (const char *hexstring, size_t *r_count)
+{
+  const char *tail;
+  size_t nbytes;
+  char *result;
+
+  tail = hex2str (hexstring, NULL, 0, &nbytes);
+  if (!tail)
+    {
+      if (r_count)
+        *r_count = 0;
+      errno = EINVAL;
+      return NULL;
+    }
+  if (r_count)
+    *r_count = tail - hexstring;
+  result = xtrymalloc (nbytes+1);
+  if (!result)
+    return NULL;
+  if (!hex2str (hexstring, result, nbytes+1, NULL))
+    BUG ();
+  return result;
+}
+
+
+

Modified: trunk/common/t-convert.c
===================================================================
--- trunk/common/t-convert.c	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/common/t-convert.c	2008-09-03 09:37:32 UTC (rev 4822)
@@ -1,5 +1,5 @@
 /* t-convert.c - Module test for convert.c
- *	Copyright (C) 2006 Free Software Foundation, Inc.
+ *	Copyright (C) 2006, 2008 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -20,6 +20,7 @@
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <assert.h>
 
 #include "util.h"
 
@@ -275,7 +276,174 @@
 
 
 
+static void
+test_hex2str (void)
+{
+  static struct {
+    const char *hex;
+    const char *str;
+    int off;
+    int no_alloc_test;
+  } tests[] = {
+    /* Simple tests.  */
+    { "112233445566778899aabbccddeeff1122",
+      "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x11\x22",
+      34 },
+    { "112233445566778899aabbccddeeff1122 blah",
+      "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x11\x22",
+      34 },
+    { "112233445566778899aabbccddeeff1122\tblah",
+      "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x11\x22",
+      34 },
+    { "112233445566778899aabbccddeeff1122\nblah",
+      "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x11\x22",
+      34 },
+    /* Valid tests yielding an empty string.  */
+    { "00",
+      "",
+      2 },
+    { "00 x",
+      "",
+      2 },
+    { "",
+      "",
+      0 },
+    { " ",
+      "",
+      0 },
+    /* Test trailing Nul feature.  */
+    { "112233445566778899aabbccddeeff112200",
+      "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x11\x22",
+      36 },
+    { "112233445566778899aabbccddeeff112200 ",
+      "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff\x11\x22",
+      36 },
+    /* Test buffer size. (buffer is of length 20)  */
+    { "6162636465666768696A6b6c6D6e6f70717273",
+      "abcdefghijklmnopqrs",
+      38 },
+    { "6162636465666768696A6b6c6D6e6f7071727300",
+      "abcdefghijklmnopqrs",
+      40 },
+    { "6162636465666768696A6b6c6D6e6f7071727374",
+      NULL,
+      0, 1 },
+    { "6162636465666768696A6b6c6D6e6f707172737400",
+      NULL,
+      0, 1 },
+    { "6162636465666768696A6b6c6D6e6f707172737475",
+      NULL,
+      0, 1 },
 
+    /* Invalid tests. */
+    { "112233445566778899aabbccddeeff1122334",      NULL, 0 },
+    { "112233445566778899AABBCCDDEEFF1122334",      NULL, 0 },
+    { "112233445566778899AABBCCDDEEFG11223344",     NULL, 0 },
+    { "0:0112233445566778899aabbccddeeff11223344",  NULL, 0 },
+    { "112233445566778899aabbccddeeff11223344:",    NULL, 0 },
+    { "112233445566778899aabbccddeeff112233445",    NULL, 0 },
+    { "112233445566778899aabbccddeeff1122334455",   NULL, 0, 1 },
+    { "112233445566778899aabbccddeeff11223344blah", NULL, 0 },
+    { "0",    NULL, 0 },
+    { "00:",  NULL, 0 },
+    { "00x",  NULL, 0 },
+
+    { NULL, NULL, 0 }
+  };
+
+  int idx;
+  char buffer[20];
+  const char *tail;
+  size_t count;
+  char *result;
+
+  for (idx=0; tests[idx].hex; idx++)
+    {
+      tail = hex2str (tests[idx].hex, buffer, sizeof buffer, &count);
+      if (tests[idx].str)
+        {
+          /* Good case test.  */
+          if (!tail)
+            fail (idx);
+          else if (strcmp (tests[idx].str, buffer))
+            fail (idx);
+          else if (tail - tests[idx].hex != tests[idx].off)
+            fail (idx);
+          else if (strlen (buffer) != count)
+            fail (idx);
+        }
+      else
+        {
+          /* Bad case test.  */
+          if (tail)
+            fail (idx);
+        }
+    }
+
+  /* Same tests again using in-place conversion.  */
+  for (idx=0; tests[idx].hex; idx++)
+    {
+      char tmpbuf[100];
+      
+      assert (strlen (tests[idx].hex)+1 < sizeof tmpbuf);
+      strcpy (tmpbuf, tests[idx].hex);
+      
+      /* Note: we still need to use 20 as buffer length because our
+         tests assume that. */
+      tail = hex2str (tmpbuf, tmpbuf, 20, &count);
+      if (tests[idx].str)
+        {
+          /* Good case test.  */
+          if (!tail)
+            fail (idx);
+          else if (strcmp (tests[idx].str, tmpbuf))
+            fail (idx);
+          else if (tail - tmpbuf != tests[idx].off)
+            fail (idx);
+          else if (strlen (tmpbuf) != count)
+            fail (idx);
+        }
+      else
+        {
+          /* Bad case test.  */
+          if (tail)
+            fail (idx);
+          if (strcmp (tmpbuf, tests[idx].hex))
+            fail (idx); /* Buffer was modified.  */
+        }
+    }
+
+  /* Test the allocation variant.  */
+  for (idx=0; tests[idx].hex; idx++)
+    {
+      if (tests[idx].no_alloc_test)
+        continue;
+
+      result = hex2str_alloc (tests[idx].hex, &count);
+      if (tests[idx].str)
+        {
+          /* Good case test.  */
+          if (!result)
+            fail (idx);
+          else if (strcmp (tests[idx].str, result))
+            fail (idx);
+          else if (count != tests[idx].off)
+            fail (idx);
+        }
+      else
+        {
+          /* Bad case test.  */
+          if (result)
+            fail (idx);
+        }
+      xfree (result);
+    }
+}
+
+
+
+
+
 int
 main (int argc, char **argv)
 {
@@ -284,6 +452,7 @@
   test_hexcolon2bin ();
   test_bin2hex ();
   test_bin2hexcolon ();
+  test_hex2str ();
 
   return 0;
 }

Modified: trunk/common/util.h
===================================================================
--- trunk/common/util.h	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/common/util.h	2008-09-03 09:37:32 UTC (rev 4822)
@@ -189,6 +189,9 @@
 int hexcolon2bin (const char *string, void *buffer, size_t length);
 char *bin2hex (const void *buffer, size_t length, char *stringbuf);
 char *bin2hexcolon (const void *buffer, size_t length, char *stringbuf);
+const char *hex2str (const char *hexstring,
+                     char *buffer, size_t bufsize, size_t *buflen);
+char *hex2str_alloc (const char *hexstring, size_t *r_count);
 
 
 /*-- homedir.c --*/

Modified: trunk/doc/yat2m.c
===================================================================
--- trunk/doc/yat2m.c	2008-08-31 11:55:09 UTC (rev 4821)
+++ trunk/doc/yat2m.c	2008-09-03 09:37:32 UTC (rev 4822)
@@ -1,6 +1,6 @@




More information about the Gnupg-commits mailing list