summaryrefslogtreecommitdiff
path: root/tests/safe-renegotiation/srn3.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2011-04-11 00:02:33 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2011-04-11 00:02:33 +0200
commitd0bb004712e67124c361cdf0be2c273f45a44421 (patch)
tree3998781e3f5be070f3b13184f1719f713443e0ba /tests/safe-renegotiation/srn3.c
parent1f8cd4eebabb8be5acd99a94547fda66b337a7f7 (diff)
downloadgnutls-d0bb004712e67124c361cdf0be2c273f45a44421.tar.gz
Combined the safe renegotiation tests with the again-common lib.
Diffstat (limited to 'tests/safe-renegotiation/srn3.c')
-rw-r--r--tests/safe-renegotiation/srn3.c132
1 files changed, 11 insertions, 121 deletions
diff --git a/tests/safe-renegotiation/srn3.c b/tests/safe-renegotiation/srn3.c
index 71f0ac31ca..45a89802fa 100644
--- a/tests/safe-renegotiation/srn3.c
+++ b/tests/safe-renegotiation/srn3.c
@@ -36,6 +36,8 @@
#include <string.h>
#include <errno.h>
#include <gnutls/gnutls.h>
+#include "../eagain-common.h"
+#include "../utils.h"
static void
tls_log_func (int level, const char *str)
@@ -43,80 +45,6 @@ tls_log_func (int level, const char *str)
fprintf (stderr, "|<%d>| %s", level, str);
}
-static char *to_server;
-static size_t to_server_len;
-
-static char *to_client;
-static size_t to_client_len;
-
-static ssize_t
-client_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
- if (to_client_len < len)
- {
- gnutls_transport_set_global_errno (EAGAIN);
- return -1;
- }
-
- memcpy (data, to_client, len);
-
- memmove (to_client, to_client + len, to_client_len - len);
- to_client_len -= len;
-
- return len;
-}
-
-static ssize_t
-client_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
- size_t newlen = to_server_len + len;
- char *tmp;
-
- tmp = realloc (to_server, newlen);
- if (!tmp)
- abort ();
- to_server = tmp;
-
- memcpy (to_server + to_server_len, data, len);
- to_server_len = newlen;
-
- return len;
-}
-
-static ssize_t
-server_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
-{
- if (to_server_len < len)
- {
- gnutls_transport_set_global_errno (EAGAIN);
- return -1;
- }
-
- memcpy (data, to_server, len);
-
- memmove (to_server, to_server + len, to_server_len - len);
- to_server_len -= len;
-
- return len;
-}
-
-static ssize_t
-server_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
-{
- size_t newlen = to_client_len + len;
- char *tmp;
-
- tmp = realloc (to_client, newlen);
- if (!tmp)
- abort ();
- to_client = tmp;
-
- memcpy (to_client + to_client_len, data, len);
- to_client_len = newlen;
-
- return len;
-}
-
static unsigned char server_cert_pem[] =
"-----BEGIN CERTIFICATE-----\n"
"MIICVjCCAcGgAwIBAgIERiYdMTALBgkqhkiG9w0BAQUwGTEXMBUGA1UEAxMOR251\n"
@@ -158,11 +86,8 @@ const gnutls_datum_t server_key = { server_key_pem,
sizeof (server_key_pem)
};
-int
-main (int argc, char *argv[])
+void doit(void)
{
- int debug_level = argc - 1;
- int exit_code = EXIT_SUCCESS;
/* Server stuff. */
gnutls_certificate_credentials_t serverx509cred;
gnutls_session_t server;
@@ -175,7 +100,7 @@ main (int argc, char *argv[])
/* General init. */
gnutls_global_init ();
gnutls_global_set_log_function (tls_log_func);
- gnutls_global_set_log_level (debug_level);
+ if (debug) gnutls_global_set_log_level (2);
/* Init server */
gnutls_certificate_allocate_credentials (&serverx509cred);
@@ -188,6 +113,7 @@ main (int argc, char *argv[])
NULL);
gnutls_transport_set_push_function (server, server_push);
gnutls_transport_set_pull_function (server, server_pull);
+ gnutls_transport_set_ptr (server, (gnutls_transport_ptr_t)server);
/* Init client */
gnutls_certificate_allocate_credentials (&clientx509cred);
@@ -196,6 +122,7 @@ main (int argc, char *argv[])
gnutls_priority_set_direct (client, "NORMAL:%SAFE_RENEGOTIATION", NULL);
gnutls_transport_set_push_function (client, client_push);
gnutls_transport_set_pull_function (client, client_pull);
+ gnutls_transport_set_ptr (client, (gnutls_transport_ptr_t)client);
/* Check that initially no session use the extension. */
if (gnutls_safe_renegotiation_status (server)
@@ -205,39 +132,7 @@ main (int argc, char *argv[])
abort ();
}
- do
- {
- static int max_iter = 0;
- if (max_iter++ > 10)
- abort ();
-
- if (cret == GNUTLS_E_AGAIN)
- {
- cret = gnutls_handshake (client);
- if (debug_level > 0)
- {
- tls_log_func (0, "gnutls_handshake (client)...\n");
- tls_log_func (0, gnutls_strerror (cret));
- tls_log_func (0, "\n");
- }
- }
-
- if (sret == GNUTLS_E_AGAIN)
- {
- sret = gnutls_handshake (server);
- if (debug_level > 0)
- {
- tls_log_func (0, "gnutls_handshake (server)...\n");
- tls_log_func (0, gnutls_strerror (sret));
- tls_log_func (0, "\n");
- }
- }
- }
- while ((cret == GNUTLS_E_AGAIN || cret == GNUTLS_E_SUCCESS)
- && (sret == GNUTLS_E_AGAIN || sret == GNUTLS_E_SUCCESS));
-
- if (cret != GNUTLS_E_SAFE_RENEGOTIATION_FAILED && sret != GNUTLS_E_SUCCESS)
- exit_code = EXIT_FAILURE;
+ HANDSHAKE_EXPECT(client, server, GNUTLS_E_SAFE_RENEGOTIATION_FAILED, GNUTLS_E_AGAIN);
gnutls_bye (client, GNUTLS_SHUT_RDWR);
gnutls_bye (server, GNUTLS_SHUT_RDWR);
@@ -245,20 +140,15 @@ main (int argc, char *argv[])
gnutls_deinit (client);
gnutls_deinit (server);
- free (to_server);
- free (to_client);
-
gnutls_certificate_free_credentials (serverx509cred);
+ gnutls_certificate_free_credentials (clientx509cred);
gnutls_global_deinit ();
- if (debug_level > 0)
+ if (debug)
{
- if (exit_code == 0)
- puts ("Self-test successful");
- else
- puts ("Self-test failed");
+ puts ("Self-test successful");
}
- return exit_code;
+ return;
}