gnutls-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU gnutls branch, master, updated. gnutls_3_0_13-89-g419ad44


From: Nikos Mavrogiannopoulos
Subject: [SCM] GNU gnutls branch, master, updated. gnutls_3_0_13-89-g419ad44
Date: Thu, 01 Mar 2012 23:24:56 +0000

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 "GNU gnutls".

http://git.savannah.gnu.org/cgit/gnutls.git/commit/?id=419ad44e36f4e087190943ff72e711fc00042dd9

The branch, master has been updated
       via  419ad44e36f4e087190943ff72e711fc00042dd9 (commit)
       via  a1a15422375ad417f3d38acc7b1cff22cb17f870 (commit)
       via  fc1221e77b5378119e811725378b53b5ba96d84d (commit)
      from  517aee329836d13dcf5656a38278e10cd3f0f1f9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 419ad44e36f4e087190943ff72e711fc00042dd9
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Fri Mar 2 00:17:05 2012 +0100

    Added SRP test.

commit a1a15422375ad417f3d38acc7b1cff22cb17f870
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Fri Mar 2 00:16:40 2012 +0100

    Fixes and memory leak elimination in SRP authentication.

commit fc1221e77b5378119e811725378b53b5ba96d84d
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Thu Mar 1 23:33:13 2012 +0100

    Eliminate double free during SRP authentication.

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

Summary of changes:
 .gitignore                                  |    1 +
 NEWS                                        |    3 +
 configure.ac                                |    1 +
 lib/auth/srp.c                              |    2 -
 lib/auth/srp_passwd.c                       |   57 +++++---
 lib/ext/srp.c                               |   43 ++++--
 lib/gnutls_errors.c                         |   14 +-
 tests/Makefile.am                           |    2 +-
 tests/{dtls => srp}/Makefile.am             |    8 +-
 tests/{mini-loss-time.c => srp/mini-srp.c}  |  202 +++++++++++----------------
 {doc/credentials => tests}/srp/tpasswd      |    0
 {doc/credentials => tests}/srp/tpasswd.conf |    0
 12 files changed, 162 insertions(+), 171 deletions(-)
 copy tests/{dtls => srp}/Makefile.am (94%)
 copy tests/{mini-loss-time.c => srp/mini-srp.c} (50%)
 copy {doc/credentials => tests}/srp/tpasswd (100%)
 copy {doc/credentials => tests}/srp/tpasswd.conf (100%)

diff --git a/.gitignore b/.gitignore
index 33632d2..f99f9a2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -591,3 +591,4 @@ doc/gnutls.xml
 tests/mini-tdb
 tests/resume-dtls
 tests/mini-record
+tests/srp/mini-srp
diff --git a/NEWS b/NEWS
index db964f7..87df90e 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,9 @@ system (the full git repository)
 ** command line apps: Link with local libopts if the 
 installed is an old one.
 
+** libgnutls: Eliminate double free during SRP
+authentication. Reported by Peter Penzov.
+
 ** libgnutls: Corrections in record packet parsing.
 Reported by Matthew Hall.
 
diff --git a/configure.ac b/configure.ac
index 0a24f53..619475c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -461,6 +461,7 @@ AC_CONFIG_FILES([
   tests/cert-tests/Makefile
   tests/dsa/Makefile
   tests/dtls/Makefile
+  tests/srp/Makefile
   tests/ecdsa/Makefile
   tests/key-id/Makefile
   tests/openpgp-certs/Makefile
diff --git a/lib/auth/srp.c b/lib/auth/srp.c
index 539c6b3..2bb6191 100644
--- a/lib/auth/srp.c
+++ b/lib/auth/srp.c
@@ -244,8 +244,6 @@ _gnutls_gen_srp_server_kx (gnutls_session_t session, 
gnutls_buffer_st* data)
 
   _gnutls_mpi_log ("SRP B: ", B);
 
-  _gnutls_srp_entry_free (pwd_entry);
-
   ret = data->length;
 
 cleanup:
diff --git a/lib/auth/srp_passwd.c b/lib/auth/srp_passwd.c
index 78c9b0b..c00a6bb 100644
--- a/lib/auth/srp_passwd.c
+++ b/lib/auth/srp_passwd.c
@@ -206,6 +206,7 @@ pwd_read_conf (const char *pconf_file, SRP_PWD_ENTRY * 
entry, int idx)
   char line[2 * 1024];
   unsigned i, len;
   char indexstr[10];
+  int ret;
 
   snprintf (indexstr, sizeof(indexstr), "%u", (unsigned int)idx);
 
@@ -228,14 +229,22 @@ pwd_read_conf (const char *pconf_file, SRP_PWD_ENTRY * 
entry, int idx)
       if (strncmp (indexstr, line, MAX (i, len)) == 0)
         {
           if ((idx = pwd_put_values2 (entry, line)) >= 0)
-            return 0;
+            {
+              ret = 0;
+              goto cleanup;
+            }
           else
             {
-              return GNUTLS_E_SRP_PWD_ERROR;
+              ret = GNUTLS_E_SRP_PWD_ERROR;
+              goto cleanup;
             }
         }
     }
-  return GNUTLS_E_SRP_PWD_ERROR;
+  ret = GNUTLS_E_SRP_PWD_ERROR;
+  
+cleanup:
+  fclose(fd);
+  return ret;
 
 }
 
@@ -244,12 +253,12 @@ _gnutls_srp_pwd_read_entry (gnutls_session_t state, char 
*username,
                             SRP_PWD_ENTRY ** _entry)
 {
   gnutls_srp_server_credentials_t cred;
-  FILE *fd;
+  FILE *fd = NULL;
   char line[2 * 1024];
   unsigned i, len;
   int ret;
   int idx, last_idx;
-  SRP_PWD_ENTRY *entry;
+  SRP_PWD_ENTRY *entry = NULL;
 
   *_entry = gnutls_calloc (1, sizeof (SRP_PWD_ENTRY));
   if (*_entry == NULL)
@@ -264,8 +273,8 @@ _gnutls_srp_pwd_read_entry (gnutls_session_t state, char 
*username,
   if (cred == NULL)
     {
       gnutls_assert ();
-      _gnutls_srp_entry_free (entry);
-      return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
+      ret = GNUTLS_E_INSUFFICIENT_CREDENTIALS;
+      goto cleanup;
     }
 
   /* if the callback which sends the parameters is
@@ -284,8 +293,7 @@ _gnutls_srp_pwd_read_entry (gnutls_session_t state, char 
*username,
               if (ret < 0)
                 {
                   gnutls_assert ();
-                  _gnutls_srp_entry_free (entry);
-                  return ret;
+                  goto cleanup;
                 }
               return 0;
             }
@@ -299,8 +307,8 @@ _gnutls_srp_pwd_read_entry (gnutls_session_t state, char 
*username,
       if (ret < 0)
         {
           gnutls_assert ();
-          _gnutls_srp_entry_free (entry);
-          return GNUTLS_E_SRP_PWD_ERROR;
+          ret = GNUTLS_E_SRP_PWD_ERROR;
+          goto cleanup;
         }
 
       return 0;
@@ -312,7 +320,8 @@ _gnutls_srp_pwd_read_entry (gnutls_session_t state, char 
*username,
   if (cred->password_file == NULL)
     {
       gnutls_assert ();
-      return GNUTLS_E_SRP_PWD_ERROR;
+      ret = GNUTLS_E_SRP_PWD_ERROR;
+      goto cleanup;
     }
 
   /* Open the selected password file.
@@ -321,8 +330,8 @@ _gnutls_srp_pwd_read_entry (gnutls_session_t state, char 
*username,
   if (fd == NULL)
     {
       gnutls_assert ();
-      _gnutls_srp_entry_free (entry);
-      return GNUTLS_E_SRP_PWD_ERROR;
+      ret = GNUTLS_E_SRP_PWD_ERROR;
+      goto cleanup;
     }
 
   last_idx = 1;                 /* a default value */
@@ -348,20 +357,20 @@ _gnutls_srp_pwd_read_entry (gnutls_session_t state, char 
*username,
               last_idx = idx;
               if (pwd_read_conf (cred->password_conf_file, entry, idx) == 0)
                 {
-                  return 0;
+                  goto found;
                 }
               else
                 {
                   gnutls_assert ();
-                  _gnutls_srp_entry_free (entry);
-                  return GNUTLS_E_SRP_PWD_ERROR;
+                  ret = GNUTLS_E_SRP_PWD_ERROR;
+                  goto cleanup;
                 }
             }
           else
             {
               gnutls_assert ();
-              _gnutls_srp_entry_free (entry);
-              return GNUTLS_E_SRP_PWD_ERROR;
+              ret = GNUTLS_E_SRP_PWD_ERROR;
+              goto cleanup;
             }
         }
     }
@@ -375,17 +384,21 @@ _gnutls_srp_pwd_read_entry (gnutls_session_t state, char 
*username,
       if (ret < 0)
         {
           gnutls_assert ();
-          _gnutls_srp_entry_free (entry);
-          return ret;
+          goto cleanup;
         }
 
-      return 0;
+      goto found;
     }
 
+cleanup:
   gnutls_assert ();
+  if (fd) fclose(fd);
   _gnutls_srp_entry_free (entry);
   return GNUTLS_E_SRP_PWD_ERROR;
 
+found:
+  if (fd) fclose(fd);
+  return 0;
 }
 
 /* Randomizes the given password entry. It actually sets the verifier
diff --git a/lib/ext/srp.c b/lib/ext/srp.c
index 84b25de..54929ca 100644
--- a/lib/ext/srp.c
+++ b/lib/ext/srp.c
@@ -108,7 +108,7 @@ _gnutls_srp_send_params (gnutls_session_t session,
   unsigned len;
   int ret;
   extension_priv_data_t epriv;
-  srp_ext_st *priv;
+  srp_ext_st *priv = NULL;
   char *username = NULL, *password = NULL;
 
   if (_gnutls_kx_priority (session, GNUTLS_KX_SRP) < 0 &&
@@ -129,13 +129,37 @@ _gnutls_srp_send_params (gnutls_session_t session,
       if (cred == NULL)
         return 0;
 
+      priv = gnutls_malloc (sizeof (*priv));
+      if (priv == NULL)
+        return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
+
       if (cred->username != NULL)
         {                       /* send username */
           len = MIN (strlen (cred->username), 255);
 
           ret = _gnutls_buffer_append_data_prefix(extdata, 8, cred->username, 
len);
           if (ret < 0)
-            return gnutls_assert_val(ret);
+            {
+              gnutls_assert();
+              goto cleanup;
+            }
+
+          priv->username = strdup(cred->username);
+          if (priv->username == NULL)
+            {
+              gnutls_assert();
+              goto cleanup;
+            }
+
+          priv->password = strdup(cred->password);
+          if (priv->password == NULL)
+            {
+              gnutls_assert();
+              goto cleanup;
+            }
+
+          epriv.ptr = priv;
+          _gnutls_ext_set_session_data (session, GNUTLS_EXTENSION_SRP, epriv);
 
           return len + 1;
         }
@@ -153,20 +177,9 @@ _gnutls_srp_send_params (gnutls_session_t session,
 
           len = MIN (strlen (username), 255);
 
-          priv = gnutls_malloc (sizeof (*priv));
-          if (priv == NULL)
-            {
-              gnutls_assert ();
-              ret = GNUTLS_E_MEMORY_ERROR;
-              goto cleanup;
-            }
-
           priv->username = username;
           priv->password = password;
 
-          epriv.ptr = priv;
-          _gnutls_ext_set_session_data (session, GNUTLS_EXTENSION_SRP, epriv);
-
           ret = _gnutls_buffer_append_data_prefix(extdata, 8, username, len);
           if (ret < 0)
             {
@@ -174,6 +187,9 @@ _gnutls_srp_send_params (gnutls_session_t session,
               goto cleanup;
             }
 
+          epriv.ptr = priv;
+          _gnutls_ext_set_session_data (session, GNUTLS_EXTENSION_SRP, epriv);
+
           return len + 1;
         }
     }
@@ -182,6 +198,7 @@ _gnutls_srp_send_params (gnutls_session_t session,
 cleanup:
   gnutls_free (username);
   gnutls_free (password);
+  gnutls_free (priv);
   
   return ret;
 }
diff --git a/lib/gnutls_errors.c b/lib/gnutls_errors.c
index 85542ef..c70b3bf 100644
--- a/lib/gnutls_errors.c
+++ b/lib/gnutls_errors.c
@@ -502,11 +502,13 @@ _gnutls_mpi_log (const char *prefix, bigint_t a)
   char *hexbuf;
   int res;
 
+  if (_gnutls_log_level < 2) return;
+
   res = _gnutls_mpi_print (a, NULL, &binlen);
-  if (res != 0)
+  if (res < 0 && res != GNUTLS_E_SHORT_MEMORY_BUFFER)
     {
       gnutls_assert ();
-      _gnutls_hard_log ("MPI: can't print value (%d/%d)\n", res,
+      _gnutls_hard_log ("MPI: %s can't print value (%d/%d)\n", prefix, res,
                         (int) binlen);
       return;
     }
@@ -514,7 +516,7 @@ _gnutls_mpi_log (const char *prefix, bigint_t a)
   if (binlen > 1024 * 1024)
     {
       gnutls_assert ();
-      _gnutls_hard_log ("MPI: too large mpi (%d)\n", (int) binlen);
+      _gnutls_hard_log ("MPI: %s too large mpi (%d)\n", prefix, (int) binlen);
       return;
     }
 
@@ -522,7 +524,7 @@ _gnutls_mpi_log (const char *prefix, bigint_t a)
   if (!binbuf)
     {
       gnutls_assert ();
-      _gnutls_hard_log ("MPI: out of memory (%d)\n", (int) binlen);
+      _gnutls_hard_log ("MPI: %s out of memory (%d)\n", prefix, (int) binlen);
       return;
     }
 
@@ -530,7 +532,7 @@ _gnutls_mpi_log (const char *prefix, bigint_t a)
   if (res != 0)
     {
       gnutls_assert ();
-      _gnutls_hard_log ("MPI: can't print value (%d/%d)\n", res,
+      _gnutls_hard_log ("MPI: %s can't print value (%d/%d)\n", prefix, res,
                         (int) binlen);
       gnutls_free (binbuf);
       return;
@@ -542,7 +544,7 @@ _gnutls_mpi_log (const char *prefix, bigint_t a)
   if (!hexbuf)
     {
       gnutls_assert ();
-      _gnutls_hard_log ("MPI: out of memory (hex %d)\n", (int) hexlen);
+      _gnutls_hard_log ("MPI: %s out of memory (hex %d)\n", prefix, (int) 
hexlen);
       gnutls_free (binbuf);
       return;
     }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 634b6b9..2d78c8c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -21,7 +21,7 @@
 
 SUBDIRS = . rsa-md5-collision pkcs1-padding pkcs8-decode pkcs12-decode \
        userid cert-tests key-id sha2 safe-renegotiation dsa scripts ecdsa \
-       slow dtls
+       slow dtls srp
 
 if ENABLE_OPENPGP
 SUBDIRS += openpgp-certs
diff --git a/tests/dtls/Makefile.am b/tests/srp/Makefile.am
similarity index 94%
copy from tests/dtls/Makefile.am
copy to tests/srp/Makefile.am
index 559a0d4..849b1d9 100644
--- a/tests/dtls/Makefile.am
+++ b/tests/srp/Makefile.am
@@ -19,10 +19,9 @@
 # along with this file; if not, write to the Free Software Foundation,
 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
-dist_check_SCRIPTS = dtls dtls-nb
-
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
 AM_CPPFLAGS = \
+       -I$(top_srcdir)/tests                   \
        -I$(top_srcdir)/gl                      \
        -I$(top_builddir)/gl                    \
        -I$(top_srcdir)/lib/includes            \
@@ -35,13 +34,14 @@ AM_CPPFLAGS = \
 AM_LDFLAGS = -no-install
 LDADD = ../../lib/libgnutls.la \
        ../../gl/libgnu.la \
+       ../libutils.la \
        $(LIBSOCKET) $(INET_NTOP_LIB) $(INET_PTON_LIB) \
        $(LIB_TIMER_TIME)
 
 if !WINDOWS
 
-check_PROGRAMS = dtls-stress
-TESTS = dtls
+check_PROGRAMS = mini-srp
+TESTS = mini-srp
 
 endif
 
diff --git a/tests/mini-loss-time.c b/tests/srp/mini-srp.c
similarity index 50%
copy from tests/mini-loss-time.c
copy to tests/srp/mini-srp.c
index 303e89b..79943ab 100644
--- a/tests/mini-loss-time.c
+++ b/tests/srp/mini-srp.c
@@ -26,7 +26,6 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 
 #if defined(_WIN32)
 
@@ -37,6 +36,7 @@ int main()
 
 #else
 
+#include <string.h>
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
@@ -44,41 +44,13 @@ int main()
 #include <arpa/inet.h>
 #include <unistd.h>
 #include <gnutls/gnutls.h>
-#include <gnutls/dtls.h>
-#include <signal.h>
 
 #include "utils.h"
 
-/* This program tests whether a DTLS handshake would timeout
- * in a minute.
- */
+static void terminate(void);
 
-static void print_type(const unsigned char* buf, int size)
-{
-  if (buf[0] == 22 && size >= 13) {
-    if (buf[13] == 1)
-      fprintf(stderr, "Client Hello\n");
-    else if (buf[13] == 2)
-      fprintf(stderr, "Server Hello\n");
-    else if (buf[13] == 12)
-      fprintf(stderr, "Server Key exchange\n");
-    else if (buf[13] == 14)
-      fprintf(stderr, "Server Hello Done\n");
-    else if (buf[13] == 11)
-      fprintf(stderr, "Certificate\n");
-    else if (buf[13] == 16)
-      fprintf(stderr, "Client Key Exchange\n");
-    else if (buf[4] == 1)
-      fprintf(stderr, "Finished\n");
-    else if (buf[13] == 11)
-      fprintf(stderr, "Server Hello Done\n");
-    else
-      fprintf(stderr, "Unknown handshake\n");
-  } else if (buf[0] == 20) {
-    fprintf(stderr, "Change Cipher Spec\n");
-  } else
-    fprintf(stderr, "Unknown\n");
-}
+/* This program tests the rehandshake in DTLS
+ */
 
 static void
 server_log_func (int level, const char *str)
@@ -95,36 +67,13 @@ client_log_func (int level, const char *str)
 /* A very basic TLS client, with anonymous authentication.
  */
 
-static int counter;
-static int packet_to_lose;
-gnutls_session_t session;
-
-static ssize_t
-push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
-int fd = (long int)tr;
-
-  counter++;
-
-  if (packet_to_lose != -1 && packet_to_lose == counter) {
-    if (debug)
-      {
-        fprintf(stderr, "Discarding packet %d: ", counter);
-        print_type(data, len);
-      }
-      
-    packet_to_lose = 1;
-    counter = 0;
-    return len;
-  }
-  return send(fd, data, len, 0);
-}
 
 static void
-client (int fd, int packet)
+client (int fd)
 {
   int ret;
-  gnutls_anon_client_credentials_t anoncred;
+  gnutls_session_t session;
+  gnutls_srp_client_credentials_t srp_cred;
   /* Need to enable anonymous KX specifically. */
 
   gnutls_global_init ();
@@ -135,25 +84,21 @@ client (int fd, int packet)
       gnutls_global_set_log_level (4711);
     }
 
-  gnutls_anon_allocate_client_credentials (&anoncred);
+  gnutls_srp_allocate_client_credentials (&srp_cred);
+  gnutls_srp_set_client_credentials (srp_cred, "test", "test");
 
   /* Initialize TLS session
    */
-  gnutls_init (&session, GNUTLS_CLIENT|GNUTLS_DATAGRAM);
-  gnutls_dtls_set_mtu( session, 1500);
+  gnutls_init (&session, GNUTLS_CLIENT);
 
   /* Use default priorities */
-  gnutls_priority_set_direct (session, 
"NONE:+VERS-DTLS1.0:+CIPHER-ALL:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ANON-ECDH:+CURVE-ALL",
 NULL);
+  gnutls_priority_set_direct (session, "NORMAL:+SRP", NULL);
 
   /* put the anonymous credentials to the current session
    */
-  gnutls_credentials_set (session, GNUTLS_CRD_ANON, anoncred);
-
-  counter = 0;
-  packet_to_lose = packet;
+  gnutls_credentials_set (session, GNUTLS_CRD_SRP, srp_cred);
 
   gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) fd);
-  gnutls_transport_set_push_function (session, push);
 
   /* Perform the TLS handshake
    */
@@ -162,13 +107,9 @@ client (int fd, int packet)
       ret = gnutls_handshake (session);
     }
   while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
-  
-  gnutls_deinit(session);
-  gnutls_global_deinit();
 
   if (ret < 0)
     {
-      if (ret == GNUTLS_E_TIMEDOUT) return;
       fail ("client: Handshake failed\n");
       gnutls_perror (ret);
       exit(1);
@@ -179,12 +120,25 @@ client (int fd, int packet)
         success ("client: Handshake was completed\n");
     }
 
-  exit(1);
+  if (debug)
+    success ("client: TLS version is: %s\n",
+             gnutls_protocol_get_name (gnutls_protocol_get_version
+                                       (session)));
+
+  gnutls_bye (session, GNUTLS_SHUT_WR);
+
+  close (fd);
+
+  gnutls_deinit (session);
+
+  gnutls_srp_free_client_credentials (srp_cred);
+
+  gnutls_global_deinit ();
 }
 
 
 /* These are global */
-gnutls_anon_server_credentials_t anoncred;
+gnutls_srp_server_credentials_t s_srp_cred;
 pid_t child;
 
 static gnutls_session_t
@@ -192,23 +146,33 @@ initialize_tls_session (void)
 {
   gnutls_session_t session;
 
-  gnutls_init (&session, GNUTLS_SERVER|GNUTLS_DATAGRAM);
-  gnutls_dtls_set_mtu( session, 1500);
+  gnutls_init (&session, GNUTLS_SERVER);
 
   /* avoid calling all the priority functions, since the defaults
    * are adequate.
    */
-  gnutls_priority_set_direct (session, 
"NONE:+VERS-DTLS1.0:+CIPHER-ALL:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ANON-ECDH:+CURVE-ALL",
 NULL);
+  gnutls_priority_set_direct (session, "NORMAL:+SRP", NULL);
 
-  gnutls_credentials_set (session, GNUTLS_CRD_ANON, anoncred);
+  gnutls_credentials_set (session, GNUTLS_CRD_SRP, s_srp_cred);
 
   return session;
 }
 
+static void terminate(void)
+{
+int status;
+
+  kill(child, SIGTERM);
+  wait(&status);
+  exit(1);
+}
+
 static void
-server (int fd, int packet)
+server (int fd)
 {
 int ret;
+gnutls_session_t session;
+
   /* this must be called once in the program
    */
   gnutls_global_init ();
@@ -219,41 +183,55 @@ int ret;
       gnutls_global_set_log_level (4711);
     }
 
-  gnutls_anon_allocate_server_credentials (&anoncred);
+  gnutls_srp_allocate_server_credentials (&s_srp_cred);
+  gnutls_srp_set_server_credentials_file (s_srp_cred, "tpasswd",
+                                          "tpasswd.conf");
 
   session = initialize_tls_session ();
 
-  counter = 0;
-  packet_to_lose = packet;
-
   gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) fd);
-  gnutls_transport_set_push_function (session, push);
 
   do 
     {
       ret = gnutls_handshake (session);
     }
   while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
-
-  gnutls_deinit (session);
-  gnutls_global_deinit();
-
   if (ret < 0)
     {
-      return;
+      close (fd);
+      gnutls_deinit (session);
+      fail ("server: Handshake has failed (%s)\n\n", gnutls_strerror (ret));
+      terminate();
     }
+  if (debug)
+    success ("server: Handshake was completed\n");
+
+  if (debug)
+    success ("server: TLS version is: %s\n",
+             gnutls_protocol_get_name (gnutls_protocol_get_version
+                                       (session)));
+
+  /* do not wait for the peer to close the connection.
+   */
+  gnutls_bye (session, GNUTLS_SHUT_WR);
+
+  close (fd);
+  gnutls_deinit (session);
+
+  gnutls_srp_free_server_credentials (s_srp_cred);
+
+  gnutls_global_deinit ();
+
+  if (debug)
+    success ("server: finished\n");
 }
 
-static void start (int server_packet, int client_packet)
+static void start (void)
 {
   int fd[2];
   int ret;
   
-  if (debug)
-    fprintf(stderr, "\nWill discard %s packet %d\n", 
-      (client_packet!=-1)?"client":"server", 
(client_packet!=-1)?client_packet:server_packet);
-  
-  ret = socketpair(AF_LOCAL, SOCK_DGRAM, 0, fd);
+  ret = socketpair(AF_LOCAL, SOCK_STREAM, 0, fd);
   if (ret < 0)
     {
       perror("socketpair");
@@ -270,46 +248,24 @@ static void start (int server_packet, int client_packet)
 
   if (child)
     {
+      int status;
       /* parent */
-      close(fd[1]);
-      server (fd[0], server_packet);
-      close(fd[0]);
-      kill(child, SIGTERM);
+      server (fd[0]);
+      wait (&status);
+      if (WEXITSTATUS(status) != 0)
+        fail("Child died with status %d\n", WEXITSTATUS(status));
     }
   else 
     {
-      close(fd[0]);
-      client (fd[1], client_packet);
-      close(fd[1]);
+      client (fd[1]);
       exit(0);
     }
 }
 
-static void ch_handler(int sig)
-{
-int status;
-  wait(&status);
-  if (WEXITSTATUS(status) != 0)
-    fail("Child died with status %d\n", WEXITSTATUS(status));
-  return;
-}
-
 void
 doit (void)
 {
-time_t tstart, tstop;
-
-  signal(SIGCHLD, ch_handler);
-
-  tstart = time(0);
-  start(2, -1);
-
-  tstop = time(0);
-  
-  tstop = tstop - tstart;
-
-  if (!(tstop < 70 && tstop > 55))
-    fail("Time difference: %u\n", (unsigned)tstop);
+  start();
 }
 
 #endif /* _WIN32 */
diff --git a/doc/credentials/srp/tpasswd b/tests/srp/tpasswd
similarity index 100%
copy from doc/credentials/srp/tpasswd
copy to tests/srp/tpasswd
diff --git a/doc/credentials/srp/tpasswd.conf b/tests/srp/tpasswd.conf
similarity index 100%
copy from doc/credentials/srp/tpasswd.conf
copy to tests/srp/tpasswd.conf


hooks/post-receive
-- 
GNU gnutls



reply via email to

[Prev in Thread] Current Thread [Next in Thread]