[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gnutls 2.11.1
From: |
Ludovic Courtès |
Subject: |
Re: gnutls 2.11.1 |
Date: |
Sat, 18 Sep 2010 23:35:51 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
Hi,
Nikos Mavrogiannopoulos <address@hidden> writes:
> On 09/15/2010 11:59 AM, Ludovic Courtès wrote:
>> Hi,
>>
>> Nikos Mavrogiannopoulos <address@hidden> writes:
>>
>>> On 09/14/2010 11:05 PM, Arfrever Frehtes Taifersar Arahesis wrote:
>>>> When GnuTLS 2.11.1 has been built with support for Nettle, then 1 test
>>>> fails:
>>>> PASS: openpgp-keyring.scm
>>>> /bin/sh: line 5: 23938 Segmentation fault GUILE_AUTO_COMPILE=0
>>>> ../../guile/pre-inst-guile -L . ${dir}$tst
>>>> FAIL: openpgp-auth.scm
>>> [...]
>>>> This problem doesn't occur when GnuTLS 2.11.1 has been built with support
>>>> for libgcrypt.
OK, I’ve reproduced it. The ‘openpgp-auth.scm’ programs spawns a client
and server that authenticate using OpenPGP keys. The server either
hangs or segfaults this way:
--8<---------------cut here---------------start------------->8---
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff762956c in __gmpz_set () from
/nix/store/00fbkpgn2g1xrp39crrvnyjb2kj3m6js-gmp-4.3.2/lib/libgmp.so.3
(gdb) bt
#0 0x00007ffff762956c in __gmpz_set () from
/nix/store/00fbkpgn2g1xrp39crrvnyjb2kj3m6js-gmp-4.3.2/lib/libgmp.so.3
#1 0x00007ffff76230dd in __gmpz_invert () from
/nix/store/00fbkpgn2g1xrp39crrvnyjb2kj3m6js-gmp-4.3.2/lib/libgmp.so.3
#2 0x00007ffff5bbda41 in wrap_nettle_pk_fixup (algo=<value optimized out>,
direction=<value optimized out>, params=0x7fffffffc200) at pk.c:564
#3 0x00007ffff5ba05ea in _gnutls_pk_fixup (pkey=<value optimized out>,
keyid=<value optimized out>, params=0x7fffffffc2d0, params_size=0x7fffffffc36c)
at ../gnutls_pk.h:42
#4 _gnutls_openpgp_privkey_get_mpis (pkey=<value optimized out>, keyid=<value
optimized out>, params=0x7fffffffc2d0, params_size=0x7fffffffc36c) at
privkey.c:765
#5 0x00007ffff5ba37c9 in gnutls_openpgp_privkey_sign_hash (key=0x6666f0,
hash=0x7fffffffc4c0, signature=0x7fffffffc530) at gnutls_openpgp.c:885
#6 0x00007ffff5b56729 in _gnutls_handshake_sign_data (session=0x6754f0,
cert=0x676430, pkey=0x669680, params=<value optimized out>,
signature=0x7fffffffc530, sign_algo=<value optimized out>) at gnutls_sig.c:221
#7 0x00007ffff5b579be in gen_dhe_server_kx (session=0x6754f0,
data=0x7fffffffc5a8) at auth_dhe.c:151
#8 0x00007ffff5b44a8e in _gnutls_send_server_kx_message (session=0x6754f0,
again=<value optimized out>) at gnutls_kx.c:180
#9 0x00007ffff5b41f1f in _gnutls_handshake_server (session=0x6754f0) at
gnutls_handshake.c:2971
#10 0x00007ffff5b4253d in gnutls_handshake (session=0x6754f0) at
gnutls_handshake.c:2634
#11 0x00007ffff5e191c2 in scm_gnutls_handshake (session=<value optimized out>)
at core.c:161
#12 0x00007ffff7b3ef98 in vm_debug_engine (vm=0x6bc370, program=0x1,
argv=0x6be320, nargs=0) at vm-i-system.c:860
#13 0x00007ffff7b3ef98 in vm_debug_engine (vm=0x6bc370, program=0x1,
argv=0x6be260, nargs=0) at vm-i-system.c:860
#14 0x00007ffff7ac8fa3 in scm_primitive_eval (exp=0x95c6e0) at eval.c:844
#15 0x00007ffff7ac9003 in scm_eval (exp=0x95c6e0, module_or_state=0x6bd090) at
eval.c:878
#16 0x00007ffff7b0d3af in scm_shell (argc=2, argv=0x7fffffffcca8) at
script.c:760
#17 0x00007ffff7ae0ecf in invoke_main_func (body_data=<value optimized out>) at
init.c:383
#18 0x00007ffff7abfb2a in c_body (d=0x7fffffffcad0) at continuations.c:473
#19 0x00007ffff7b3ed1b in vm_debug_engine (vm=0x6bc370, program=0x8e3520,
argv=0x6be0b8, nargs=1) at vm-i-system.c:928
#20 0x00007ffff7ac8e63 in scm_call_4 (proc=0x659090, arg1=<value optimized
out>, arg2=<value optimized out>, arg3=<value optimized out>, arg4=<value
optimized out>) at eval.c:582
#21 0x00007ffff7ac0173 in scm_i_with_continuation_barrier (body=0x7ffff7abfb20
<c_body>, body_data=0x7fffffffcad0, handler=0x7ffff7abfb40 <c_handler>,
handler_data=0x7fffffffcad0,
pre_unwind_handler=<value optimized out>, pre_unwind_handler_data=<value
optimized out>) at continuations.c:450
#22 0x00007ffff7ac0210 in scm_c_with_continuation_barrier (func=<value
optimized out>, data=<value optimized out>) at continuations.c:491
#23 0x00007ffff7b30822 in scm_i_with_guile_and_parent (func=0x7ffff7ae0eb0
<invoke_main_func>, data=0x7fffffffcba0, parent=<value optimized out>) at
threads.c:741
#24 0x00007ffff7ae0f85 in scm_boot_guile (argc=<value optimized out>,
argv=<value optimized out>, main_func=<value optimized out>, closure=<value
optimized out>) at init.c:366
#25 0x0000000000400c70 in main (argc=<value optimized out>, argv=<value
optimized out>) at guile.c:70
(gdb) frame 5
#5 0x00007ffff5ba37c9 in gnutls_openpgp_privkey_sign_hash (key=0x6666f0,
hash=0x7fffffffc4c0, signature=0x7fffffffc530) at gnutls_openpgp.c:885
885 result = _gnutls_openpgp_privkey_get_mpis (key, NULL,
(gdb) p *key
$1 = {knode = 0x6670d0, preferred_keyid = "\000\000\000\000\000\000\000",
preferred_set = 0}
(gdb) p *key->knode
$2 = {next = 0x6671d0, pkt = 0x679780, is_deleted = 0, is_cloned = 0}
--8<---------------cut here---------------end--------------->8---
This Guile test is the only unit test for OpenPGP authentication in
GnuTLS, and I feel that the issue is more closely related to the
CDK/Nettle integration than to Guile.
So, here’s a patch that adds a similar unit test in C. The test hangs
while the server generates DH parameters, apparently stuck in the second
loop of ‘gen_prime’. After some time the stack looks scrambled:
--8<---------------cut here---------------start------------->8---
(gdb) bt
#0 0x00007ffff78eef73 in __gmpn_redc_1 () from
/nix/store/ms38kzmhai2xfzvzyvzdfdcpdays942x-user-environment/lib/libgmp.so.3
#1 0x000000000000000e in ?? ()
#2 0x000000000000000b in ?? ()
#3 0x000000000000000e in ?? ()
#4 0x0000000000000008 in ?? ()
#5 0x0000000000000011 in ?? ()
#6 0x00007fffffffcf50 in ?? ()
#7 0x00007ffff78c85ac in __gmpz_powm () from
/nix/store/ms38kzmhai2xfzvzyvzdfdcpdays942x-user-environment/lib/libgmp.so.3
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
--8<---------------cut here---------------end--------------->8---
Unfortunately Valgrind doesn’t reveal anything interesting.
Any idea what to look at now?
Thanks,
Ludo’.
PS: The code in lib/nettle ought to go through ‘indent’ IMO.
pgpe2ImhpTu7V.pgp
Description: PGP signature
>From e0100f82a1bcec4ad25aee7dee28fbfadc876f0a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <address@hidden>
Date: Sat, 18 Sep 2010 15:56:28 +0200
Subject: [PATCH] Add an OpenPGP authentication unit test.
* tests/Makefile.am (ctests)[ENABLE_OPENPGP]: Add `openpgp-auth'.
(TESTS_ENVIRONMENT): Add `srcdir'.
* tests/openpgp-auth.c: New file.
---
.gitignore | 1 +
tests/Makefile.am | 13 ++-
tests/openpgp-auth.c | 282 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 290 insertions(+), 6 deletions(-)
create mode 100644 tests/openpgp-auth.c
diff --git a/.gitignore b/.gitignore
index 5b8643f..101187d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -434,3 +434,4 @@ m4/
po/
lib/m4
lgl/
+/tests/openpgp-auth
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b14f4fd..875173e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -68,7 +68,7 @@ openssl_LDADD = $(LDADD) ../libextra/libgnutls-openssl.la
endif
if ENABLE_OPENPGP
-ctests += openpgp-keyring pgps2kgnu
+ctests += openpgp-auth openpgp-keyring pgps2kgnu
openpgp_keyring_LDADD = $(LDADD) ../libextra/libgnutls-extra.la
endif
@@ -88,10 +88,11 @@ dist_check_SCRIPTS = rfc2253-escape-test
TESTS = $(ctests) $(dist_check_SCRIPTS)
-TESTS_ENVIRONMENT = \
- PKCS12FILE=$(srcdir)/pkcs12-decode/client.p12 \
- PKCS12PASSWORD=foobar \
+TESTS_ENVIRONMENT = \
+ PKCS12FILE=$(srcdir)/pkcs12-decode/client.p12 \
+ PKCS12PASSWORD=foobar \
PKCS12FILE_2=$(srcdir)/pkcs12-decode/pkcs12_2certs.p12 \
- PKCS12PASSWORD_2="" \
- EXEEXT=$(EXEEXT) \
+ PKCS12PASSWORD_2="" \
+ EXEEXT=$(EXEEXT) \
+ srcdir="$(srcdir)" \
$(VALGRIND)
diff --git a/tests/openpgp-auth.c b/tests/openpgp-auth.c
new file mode 100644
index 0000000..92d8eb9
--- /dev/null
+++ b/tests/openpgp-auth.c
@@ -0,0 +1,282 @@
+/*
+ * Copyright (C) 2010 Free Software Foundation
+ * Author: Ludovic Courtès
+ *
+ * This file is part of GNUTLS.
+ *
+ * GNUTLS is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GNUTLS is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNUTLS; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <gnutls/gnutls.h>
+#include <gnutls/openpgp.h>
+
+#include "utils.h"
+#include <read-file.h>
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+
+static const char message[] = "Hello, brave GNU world!";
+
+/* The OpenPGP key pair for use and the key ID in those keys. */
+static const char pub_key_file[] = "../guile/tests/openpgp-pub.asc";
+static const char priv_key_file[] = "../guile/tests/openpgp-sec.asc";
+static const char *key_id =
+ NULL
+ /* FIXME: The values below don't work as expected. */
+ /* "auto" */
+ /* "bd572cdcccc07c35" */;
+
+static const char rsa_params_file[] = "../guile/tests/rsa-parameters.pem";
+
+static const int protocols[] = { GNUTLS_TLS1_0, 0 };
+static const int cert_types[] = { GNUTLS_CRT_OPENPGP, 0 };
+static const int ciphers[] =
+ {
+ GNUTLS_CIPHER_NULL, GNUTLS_CIPHER_ARCFOUR,
+ GNUTLS_CIPHER_AES_128_CBC, GNUTLS_CIPHER_AES_256_CBC,
+ 0
+ };
+static const int kx[] =
+ {
+ GNUTLS_KX_RSA, GNUTLS_KX_RSA_EXPORT,
+ GNUTLS_KX_DHE_RSA, GNUTLS_KX_DHE_DSS,
+ 0
+ };
+static const int macs[] =
+ {
+ GNUTLS_MAC_SHA1, GNUTLS_MAC_RMD160, GNUTLS_MAC_MD5,
+ 0
+ };
+
+static void
+log_message (int level, const char *message)
+{
+ fprintf (stderr, "[%5d|%2d] %s", getpid (), level, message);
+}
+
+
+void
+doit ()
+{
+ int err;
+ int sockets[2];
+ const char *srcdir;
+ char *pub_key_path, *priv_key_path;
+ pid_t child;
+
+ gnutls_global_init ();
+
+ srcdir = getenv ("srcdir") ?: ".";
+
+ if (debug)
+ {
+ gnutls_global_set_log_level (10);
+ gnutls_global_set_log_function (log_message);
+ }
+
+ err = socketpair (PF_UNIX, SOCK_STREAM, 0, sockets);
+ if (err != 0)
+ fail ("socketpair %s\n", strerror (errno));
+
+ pub_key_path = alloca (strlen (srcdir) + strlen (pub_key_file) + 2);
+ strcpy (pub_key_path, srcdir);
+ strcat (pub_key_path, "/");
+ strcat (pub_key_path, pub_key_file);
+
+ priv_key_path = alloca (strlen (srcdir) + strlen (priv_key_file) + 2);
+ strcpy (priv_key_path, srcdir);
+ strcat (priv_key_path, "/");
+ strcat (priv_key_path, priv_key_file);
+
+ child = fork ();
+ if (child == -1)
+ fail ("fork %s\n", strerror (errno));
+
+ if (child == 0)
+ {
+ /* Child process (client). */
+ gnutls_session_t session;
+ gnutls_certificate_credentials_t cred;
+ ssize_t sent;
+
+ if (debug)
+ printf ("client process %i\n", getpid ());
+
+ err = gnutls_init (&session, GNUTLS_CLIENT);
+ if (err != 0)
+ fail ("client session %d\n", err);
+
+ gnutls_set_default_priority (session);
+ gnutls_transport_set_ptr (session,
+ (gnutls_transport_ptr_t)(intptr_t) sockets[0]);
+
+ err = gnutls_certificate_allocate_credentials (&cred);
+ if (err != 0)
+ fail ("client credentials %d\n", err);
+
+ err =
+ gnutls_certificate_set_openpgp_key_file2 (cred,
+ pub_key_file, priv_key_file,
+ key_id,
+ GNUTLS_OPENPGP_FMT_BASE64);
+ if (err != 0)
+ fail ("client openpgp keys %d\n", err);
+
+ err = gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, cred);
+ if (err != 0)
+ fail ("client credential_set %d\n", err);
+
+ gnutls_protocol_set_priority (session, protocols);
+ gnutls_certificate_type_set_priority (session, cert_types);
+ gnutls_cipher_set_priority (session, ciphers);
+ gnutls_kx_set_priority (session, kx);
+ gnutls_mac_set_priority (session, macs);
+ gnutls_dh_set_prime_bits (session, 1024);
+
+ err = gnutls_handshake (session);
+ if (err != 0)
+ fail ("client handshake %d\n", err);
+ else if (debug)
+ printf ("client handshake successful\n");
+
+ sent = gnutls_record_send (session, message, sizeof (message));
+ if (sent != sizeof (message))
+ fail ("client sent %li vs. %li\n", sent, sizeof (message));
+
+ err = gnutls_bye (session, GNUTLS_SHUT_RDWR);
+ if (err != 0)
+ fail ("client bye %d\n", err);
+
+ if (debug)
+ printf ("client done\n");
+ }
+ else
+ {
+ /* Parent process (server). */
+ gnutls_session_t session;
+ gnutls_dh_params_t dh_params;
+ gnutls_rsa_params_t rsa_params;
+ gnutls_certificate_credentials_t cred;
+ char greetings[sizeof (message) * 2];
+ ssize_t received;
+ pid_t done;
+ int status;
+ size_t rsa_size;
+ gnutls_datum_t rsa_data;
+
+ if (debug)
+ printf ("server process %i (child %i)\n", getpid (), child);
+
+ err = gnutls_init (&session, GNUTLS_SERVER);
+ if (err != 0)
+ fail ("server session %d\n", err);
+
+ gnutls_set_default_priority (session);
+ gnutls_transport_set_ptr (session,
+ (gnutls_transport_ptr_t)(intptr_t) sockets[1]);
+
+ err = gnutls_certificate_allocate_credentials (&cred);
+ if (err != 0)
+ fail ("server credentials %d\n", err);
+
+ err =
+ gnutls_certificate_set_openpgp_key_file2 (cred,
+ pub_key_file, priv_key_file,
+ key_id,
+ GNUTLS_OPENPGP_FMT_BASE64);
+ if (err != 0)
+ fail ("server openpgp keys %d\n", err);
+
+ err = gnutls_dh_params_init (&dh_params);
+ if (err)
+ fail ("server DH params init %d\n", err);
+
+ err = gnutls_dh_params_generate2 (dh_params, 1024);
+ if (err)
+ fail ("server DH params generate %d\n", err);
+
+ gnutls_certificate_set_dh_params (cred, dh_params);
+
+ rsa_data.data =
+ (unsigned char *) read_binary_file (rsa_params_file, &rsa_size);
+ rsa_data.size = rsa_size;
+
+ err = gnutls_rsa_params_init (&rsa_params);
+ if (err)
+ fail ("server RSA params init %d\n", err);
+
+ err = gnutls_rsa_params_import_pkcs1 (rsa_params, &rsa_data,
+ GNUTLS_X509_FMT_PEM);
+ if (err)
+ fail ("server RSA params import %d\n", err);
+
+ gnutls_certificate_set_rsa_export_params (cred, rsa_params);
+
+ err = gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, cred);
+ if (err != 0)
+ fail ("server credential_set %d\n", err);
+
+ gnutls_protocol_set_priority (session, protocols);
+ gnutls_certificate_type_set_priority (session, cert_types);
+ gnutls_cipher_set_priority (session, ciphers);
+ gnutls_kx_set_priority (session, kx);
+ gnutls_mac_set_priority (session, macs);
+ gnutls_certificate_server_set_request (session, GNUTLS_CERT_REQUIRE);
+
+ err = gnutls_handshake (session);
+ if (err != 0)
+ fail ("server handshake %d\n", err);
+
+ received = gnutls_record_recv (session, greetings, sizeof (greetings));
+ if (received != sizeof (message)
+ || memcmp (greetings, message, sizeof (message)))
+ fail ("server received %li vs. %li\n", received, sizeof (message));
+
+ err = gnutls_bye (session, GNUTLS_SHUT_RDWR);
+ if (err != 0)
+ fail ("server bye %d\n", err);
+
+ if (debug)
+ printf ("server done\n");
+
+ done = wait (&status);
+ if (done < 0)
+ fail ("wait %s\n", strerror (errno));
+
+ if (done != child)
+ fail ("who's that?! %d\n", done);
+
+ if (WIFEXITED (status))
+ {
+ if (WEXITSTATUS (status) != 0)
+ fail ("child exited with status %d\n", WEXITSTATUS (status));
+ }
+ else if (WIFSIGNALED (status))
+ fail ("child stopped by signal %d\n", WTERMSIG (status));
+ else
+ fail ("child failed: %d\n", status);
+ }
+}
--
1.7.0
- gnutls 2.11.1, Nikos Mavrogiannopoulos, 2010/09/14
- Re: gnutls 2.11.1, Arfrever Frehtes Taifersar Arahesis, 2010/09/14
- Re: gnutls 2.11.1, Nikos Mavrogiannopoulos, 2010/09/15
- Re: gnutls 2.11.1, Ludovic Courtès, 2010/09/15
- Re: gnutls 2.11.1, Nikos Mavrogiannopoulos, 2010/09/17
- Re: gnutls 2.11.1, Ludovic Courtès, 2010/09/17
- Re: gnutls 2.11.1,
Ludovic Courtès <=
- Re: gnutls 2.11.1, Nikos Mavrogiannopoulos, 2010/09/19
- Re: gnutls 2.11.1, Ludovic Courtès, 2010/09/19