[git] Scute - branch, justus/gcrypt-0, created. scute-1.3.0-44-gca96376

by Justus Winter cvs at cvs.gnupg.org
Tue Dec 22 17:15:11 CET 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PKCS#11 token on top of gpg-agent".

The branch, justus/gcrypt-0 has been created
        at  ca963760a998403bb3b24188eb29c5f9774c503b (commit)

- Log -----------------------------------------------------------------
commit ca963760a998403bb3b24188eb29c5f9774c503b
Author: Justus Winter <justus at g10code.com>
Date:   Mon Dec 21 17:37:55 2015 +0100

    Support 4096 bit RSA keys.
    
    * src/agent.c (MAX_SIGNATURE_{BITS,LEN}): Tweak values.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/src/agent.c b/src/agent.c
index 3384980..4127570 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -950,11 +950,11 @@ scute_agent_check_status (void)
 }
 
 

-/* We only support RSA signatures up to 2048 bits.  */
-#define MAX_SIGNATURE_BITS 2048
+/* We only support RSA signatures up to 4096 bits.  */
+#define MAX_SIGNATURE_BITS 4096
 
-/* Enough space to hold a 2048 bit RSA signature in an S-expression.  */
-#define MAX_SIGNATURE_LEN 350
+/* Enough space to hold a 4096 bit RSA signature in an S-expression.  */
+#define MAX_SIGNATURE_LEN 640	/* FIXME: magic value */
 
 struct signature
 {

commit d1219f716f2d1980450f9f00f66eb6bf133a33cf
Author: Justus Winter <justus at g10code.com>
Date:   Mon Dec 21 17:06:47 2015 +0100

    Use a proper s-expression parser.
    
    * README: Document new build dependency.
    * doc/manual/scute.texi: Likewise.
    * configure.ac: Check for libgcrypt.
    * m4/libgcrypt.m4: New file copied from GnuPG.
    * src/Makefile.am: Link against libgcrypt.
    * src/agent.c (scute_agent_sign): Use gcrypts s-expression parser.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/README b/README
index aab45b7..8be98e0 100644
--- a/README
+++ b/README
@@ -36,6 +36,7 @@ Prerequisites
 For the compilation:
 * libgpg-error 1.4
 * libassuan 2.0.0
+* libgcrypt 1.6.0
 
 At runtime:
 * Mozilla (or any other supported application using PKCS #11).
diff --git a/configure.ac b/configure.ac
index 43f1ebd..a523676 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,10 +75,13 @@ VERSION_MINOR=0
 
 NEED_GPG_ERROR_VERSION=1.4
 NEED_LIBASSUAN_VERSION=2.0.0
+NEED_LIBGCRYPT_API=1
+NEED_LIBGCRYPT_VERSION=1.6.0
 NEED_GPGSM_VERSION=1.9.6
 # Some status variables to give feedback at the end of a configure run.
 have_gpg_error=no
 have_libassuan=no
+have_libgcrypt=no
 
 BUILD_REVISION=svn_revision
 PACKAGE=$PACKAGE_NAME
@@ -272,6 +275,10 @@ AM_PATH_GPG_ERROR("$NEED_GPG_ERROR_VERSION",
 AM_PATH_LIBASSUAN("$NEED_LIBASSUAN_VERSION",
                   have_libassuan=yes, have_libassuan=no)
 
+# Libgcrypt is our generic crypto library
+AM_PATH_LIBGCRYPT("$NEED_LIBGCRYPT_API:$NEED_LIBGCRYPT_VERSION",
+        have_libgcrypt=yes,have_libgcrypt=no)
+
 # GPGSM
 NO_OVERRIDE=no
 AC_ARG_WITH(gpgsm,
@@ -450,6 +457,16 @@ if test "$have_libassuan" = "no"; then
 *** (at least version $NEED_LIBASSUAN_VERSION is required).
 ***]])
 fi
+if test "$have_libgcrypt" = "no"; then
+   die=yes
+   AC_MSG_NOTICE([[
+***
+*** You need libgcrypt to build this program.
+**  This library is for example available at
+***   ftp://ftp.gnupg.org/gcrypt/libgcrypt/
+*** (at least version $NEED_LIBGCRYPT_VERSION (API $NEED_LIBGCRYPT_API) is required.)
+***]])
+fi
 
 if test "$die" = "yes"; then
     AC_MSG_ERROR([[
diff --git a/doc/manual/scute.texi b/doc/manual/scute.texi
index 42078a8..2f7ab7f 100644
--- a/doc/manual/scute.texi
+++ b/doc/manual/scute.texi
@@ -247,6 +247,10 @@ the GPG error library.  The minimum version required is 1.4.
 Scute uses the GnuPG 2.0 framework for communication with the GPG Agent,
 so it depends on the Assuan library.  The minimum version required is
 2.0.0.
+
+ at item libgcrypt
+Scute uses the GnuPG 2.0 framework for communication, so it depends on
+the Libgcrypt library.  The minimum version required is 1.6.0.
 @end table
 
 At run-time, in addition to the run-time versions of the above
diff --git a/m4/libgcrypt.m4 b/m4/libgcrypt.m4
new file mode 100644
index 0000000..c67cfec
--- /dev/null
+++ b/m4/libgcrypt.m4
@@ -0,0 +1,143 @@
+# libgcrypt.m4 - Autoconf macros to detect libgcrypt
+# Copyright (C) 2002, 2003, 2004, 2011, 2014 g10 Code GmbH
+#
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This file is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# Last-changed: 2014-10-02
+
+
+dnl AM_PATH_LIBGCRYPT([MINIMUM-VERSION,
+dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
+dnl Test for libgcrypt and define LIBGCRYPT_CFLAGS and LIBGCRYPT_LIBS.
+dnl MINIMUN-VERSION is a string with the version number optionalliy prefixed
+dnl with the API version to also check the API compatibility. Example:
+dnl a MINIMUN-VERSION of 1:1.2.5 won't pass the test unless the installed
+dnl version of libgcrypt is at least 1.2.5 *and* the API number is 1.  Using
+dnl this features allows to prevent build against newer versions of libgcrypt
+dnl with a changed API.
+dnl
+dnl If a prefix option is not used, the config script is first
+dnl searched in $SYSROOT/bin and then along $PATH.  If the used
+dnl config script does not match the host specification the script
+dnl is added to the gpg_config_script_warn variable.
+dnl
+AC_DEFUN([AM_PATH_LIBGCRYPT],
+[ AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_ARG_WITH(libgcrypt-prefix,
+            AC_HELP_STRING([--with-libgcrypt-prefix=PFX],
+                           [prefix where LIBGCRYPT is installed (optional)]),
+     libgcrypt_config_prefix="$withval", libgcrypt_config_prefix="")
+  if test x"${LIBGCRYPT_CONFIG}" = x ; then
+     if test x"${libgcrypt_config_prefix}" != x ; then
+        LIBGCRYPT_CONFIG="${libgcrypt_config_prefix}/bin/libgcrypt-config"
+     else
+       case "${SYSROOT}" in
+         /*)
+           if test -x "${SYSROOT}/bin/libgcrypt-config" ; then
+             LIBGCRYPT_CONFIG="${SYSROOT}/bin/libgcrypt-config"
+           fi
+           ;;
+         '')
+           ;;
+          *)
+           AC_MSG_WARN([Ignoring \$SYSROOT as it is not an absolute path.])
+           ;;
+       esac
+     fi
+  fi
+
+  AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no)
+  tmp=ifelse([$1], ,1:1.2.0,$1)
+  if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then
+     req_libgcrypt_api=`echo "$tmp"     | sed 's/\(.*\):\(.*\)/\1/'`
+     min_libgcrypt_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'`
+  else
+     req_libgcrypt_api=0
+     min_libgcrypt_version="$tmp"
+  fi
+
+  AC_MSG_CHECKING(for LIBGCRYPT - version >= $min_libgcrypt_version)
+  ok=no
+  if test "$LIBGCRYPT_CONFIG" != "no" ; then
+    req_major=`echo $min_libgcrypt_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
+    req_minor=`echo $min_libgcrypt_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
+    req_micro=`echo $min_libgcrypt_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
+    libgcrypt_config_version=`$LIBGCRYPT_CONFIG --version`
+    major=`echo $libgcrypt_config_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
+    minor=`echo $libgcrypt_config_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
+    micro=`echo $libgcrypt_config_version | \
+               sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
+    if test "$major" -gt "$req_major"; then
+        ok=yes
+    else
+        if test "$major" -eq "$req_major"; then
+            if test "$minor" -gt "$req_minor"; then
+               ok=yes
+            else
+               if test "$minor" -eq "$req_minor"; then
+                   if test "$micro" -ge "$req_micro"; then
+                     ok=yes
+                   fi
+               fi
+            fi
+        fi
+    fi
+  fi
+  if test $ok = yes; then
+    AC_MSG_RESULT([yes ($libgcrypt_config_version)])
+  else
+    AC_MSG_RESULT(no)
+  fi
+  if test $ok = yes; then
+     # If we have a recent libgcrypt, we should also check that the
+     # API is compatible
+     if test "$req_libgcrypt_api" -gt 0 ; then
+        tmp=`$LIBGCRYPT_CONFIG --api-version 2>/dev/null || echo 0`
+        if test "$tmp" -gt 0 ; then
+           AC_MSG_CHECKING([LIBGCRYPT API version])
+           if test "$req_libgcrypt_api" -eq "$tmp" ; then
+             AC_MSG_RESULT([okay])
+           else
+             ok=no
+             AC_MSG_RESULT([does not match. want=$req_libgcrypt_api got=$tmp])
+           fi
+        fi
+     fi
+  fi
+  if test $ok = yes; then
+    LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG --cflags`
+    LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG --libs`
+    ifelse([$2], , :, [$2])
+    libgcrypt_config_host=`$LIBGCRYPT_CONFIG --host 2>/dev/null || echo none`
+    if test x"$libgcrypt_config_host" != xnone ; then
+      if test x"$libgcrypt_config_host" != x"$host" ; then
+  AC_MSG_WARN([[
+***
+*** The config script $LIBGCRYPT_CONFIG was
+*** built for $libgcrypt_config_host and thus may not match the
+*** used host $host.
+*** You may want to use the configure option --with-libgcrypt-prefix
+*** to specify a matching config script or use \$SYSROOT.
+***]])
+        gpg_config_script_warn="$gpg_config_script_warn libgcrypt"
+      fi
+    fi
+  else
+    LIBGCRYPT_CFLAGS=""
+    LIBGCRYPT_LIBS=""
+    ifelse([$3], , :, [$3])
+  fi
+  AC_SUBST(LIBGCRYPT_CFLAGS)
+  AC_SUBST(LIBGCRYPT_LIBS)
+])
diff --git a/src/Makefile.am b/src/Makefile.am
index 43fa086..2da31a8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -93,8 +93,9 @@ install-def-file:
 uninstall-def-file:
 	-rm $(DESTDIR)$(libdir)/scute.def
 
-# On Windows targets, link statically to libgpg-error and libassuan.
-scute_deps = $(scute_res) scute.def libgpg-error.a libassuan.a
+# On Windows targets, link statically to libgpg-error, libassuan,
+# and libgcrypt.
+scute_deps = $(scute_res) scute.def libgpg-error.a libassuan.a libgcrypt.a
 
 scute_libadd = -L.
 
@@ -104,8 +105,11 @@ libgpg-error.a:
 libassuan.a:
 	ln -sf $$($(LIBASSUAN_CONFIG) --prefix)/lib/libassuan.a .
 
+libgcrypt.a:
+	ln -sf $$($(LIBCRYPT_CONFIG) --prefix)/lib/libgcrypt.a .
+
 clean-local:
-	rm -f libgpg-error.a libassuan.a
+	rm -f libgpg-error.a libassuan.a libgcrypt.a
 
 else
 
@@ -128,8 +132,8 @@ scute_la_DEPENDENCIES = @LTLIBOBJS@ $(srcdir)/libscute.vers $(scute_deps)
 # scute_libadd must come BEFORE libassuan and gpg-error, because we
 # override it on Windows targets.
 scute_la_LIBADD = $(scute_libadd) \
-	@LTLIBOBJS@ @LIBASSUAN_LIBS@ @GPG_ERROR_LIBS@
+	@LTLIBOBJS@ @LIBASSUAN_LIBS@ @LIBGCRYPT_LIBS@ @GPG_ERROR_LIBS@
 
 scute_la_CPPFLAGS = -I$(srcdir)/../include \
-	@LIBASSUAN_CFLAGS@ @GPG_ERROR_CFLAGS@
+	@LIBASSUAN_CFLAGS@ @LIBGCRYPT_CFLAGS@ @GPG_ERROR_CFLAGS@
 scute_la_SOURCES = $(sources)
diff --git a/src/agent.c b/src/agent.c
index 938edef..3384980 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -47,6 +47,7 @@
 #endif
 
 #include <assuan.h>
+#include <gcrypt.h>
 #include <gpg-error.h>
 
 #include "debug.h"
@@ -949,6 +950,9 @@ scute_agent_check_status (void)
 }
 
 

+/* We only support RSA signatures up to 2048 bits.  */
+#define MAX_SIGNATURE_BITS 2048
+
 /* Enough space to hold a 2048 bit RSA signature in an S-expression.  */
 #define MAX_SIGNATURE_LEN 350
 
@@ -976,14 +980,6 @@ pksign_cb (void *opaque, const void *buffer, size_t length)
 }
 
 
-#define SIG_PREFIX   "(7:sig-val(3:rsa(1:s128:"
-#define SIG_PREFIX_2 "(7:sig-val(3:rsa(1:s256:"
-#define SIG_PREFIX_LEN (sizeof (SIG_PREFIX) - 1)
-#define SIG_POSTFIX ")))"
-#define SIG_POSTFIX_LEN (sizeof (SIG_POSTFIX) - 1)
-#define SIG_LEN 128
-#define SIG_LEN_2 256
-
 /* Call the agent to learn about a smartcard.  */
 gpg_error_t
 scute_agent_sign (char *grip, unsigned char *data, int len,
@@ -995,6 +991,9 @@ scute_agent_sign (char *grip, unsigned char *data, int len,
   unsigned char pretty_data[2 * MAX_DATA_LEN + 1];
   int i;
   struct signature sig;
+  gcry_sexp_t s_sigval = NULL, p;
+  const char *sig_raw;
+  size_t sig_raw_size;
 
   sig.len = 0;
 
@@ -1004,14 +1003,14 @@ scute_agent_sign (char *grip, unsigned char *data, int len,
   if (sig_result == NULL)
     {
       /* FIXME:  We return the largest supported size - is that correct?  */
-      *sig_len = SIG_LEN_2;
+      *sig_len = MAX_SIGNATURE_BITS / 8;
       return 0;
     }
 
   if (len > MAX_DATA_LEN)
     return gpg_error (GPG_ERR_INV_ARG);
 
-  if (grip == NULL || sig_result == NULL || *sig_len < SIG_LEN)
+  if (grip == NULL || sig_result == NULL)
     return gpg_error (GPG_ERR_INV_ARG);
 
   snprintf (cmd, sizeof (cmd), "SIGKEY %s", grip);
@@ -1035,32 +1034,38 @@ scute_agent_sign (char *grip, unsigned char *data, int len,
   if (err)
     return err;
 
-  /* FIXME: we need a real parser to cope with all kind of S-expressions.  */
-  if (sig.len == SIG_PREFIX_LEN + SIG_LEN_2 + SIG_POSTFIX_LEN)
+  err = gcry_sexp_new (&s_sigval, sig.data, sig.len, 0);
+  if (err)
+    return err;
+
+  p = gcry_sexp_find_token (s_sigval, "sig-val", 0);
+  if (! p)
     {
-      if (memcmp (sig.data, SIG_PREFIX_2, SIG_PREFIX_LEN))
-        return gpg_error (GPG_ERR_BAD_SIGNATURE);
-      if (memcmp (sig.data + sig.len - SIG_POSTFIX_LEN,
-                  SIG_POSTFIX, SIG_POSTFIX_LEN))
-        return gpg_error (GPG_ERR_BAD_SIGNATURE);
-      memcpy (sig_result, sig.data + SIG_PREFIX_LEN, SIG_LEN_2);
-      *sig_len = SIG_LEN_2;
+      err = gpg_error (GPG_ERR_BAD_DATA);	/* XXX */
+      goto leave;
     }
-  else
+
+  p = gcry_sexp_find_token (p, "rsa", 0);
+  if (! p)
     {
-      if (sig.len != SIG_PREFIX_LEN + SIG_LEN + SIG_POSTFIX_LEN)
-        return gpg_error (GPG_ERR_BAD_SIGNATURE);
-      if (memcmp (sig.data, SIG_PREFIX, SIG_PREFIX_LEN))
-        return gpg_error (GPG_ERR_BAD_SIGNATURE);
-      if (memcmp (sig.data + sig.len - SIG_POSTFIX_LEN,
-                  SIG_POSTFIX, SIG_POSTFIX_LEN))
-        return gpg_error (GPG_ERR_BAD_SIGNATURE);
-      memcpy (sig_result, sig.data + SIG_PREFIX_LEN, SIG_LEN);
-      *sig_len = SIG_LEN;
+      err = gpg_error (GPG_ERR_BAD_DATA);	/* XXX */
+      goto leave;
     }
-  
-  
-  return 0;
+
+  p = gcry_sexp_find_token (p, "s", 0);
+  if (! p)
+    {
+      err = gpg_error (GPG_ERR_BAD_DATA);	/* XXX */
+      goto leave;
+    }
+
+  sig_raw = gcry_sexp_nth_data (p, 1, &sig_raw_size);
+  *sig_len = (unsigned int) sig_raw_size;
+  memcpy (sig_result, sig_raw, *sig_len);
+
+ leave:
+  gcry_sexp_release (s_sigval);
+  return err;
 }
 
 

-----------------------------------------------------------------------


hooks/post-receive
-- 
PKCS#11 token on top of gpg-agent
http://git.gnupg.org




More information about the Gnupg-commits mailing list