[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r26658 - libmicrohttpd/src/testcurl/https
From: |
gnunet |
Subject: |
[GNUnet-SVN] r26658 - libmicrohttpd/src/testcurl/https |
Date: |
Fri, 29 Mar 2013 17:16:02 +0100 |
Author: grothoff
Date: 2013-03-29 17:16:02 +0100 (Fri, 29 Mar 2013)
New Revision: 26658
Added:
libmicrohttpd/src/testcurl/https/test_https_get.c
libmicrohttpd/src/testcurl/https/test_https_get_parallel.c
libmicrohttpd/src/testcurl/https/test_https_get_parallel_threads.c
libmicrohttpd/src/testcurl/https/test_https_get_select.c
libmicrohttpd/src/testcurl/https/test_https_multi_daemon.c
libmicrohttpd/src/testcurl/https/test_https_session_info.c
libmicrohttpd/src/testcurl/https/test_https_time_out.c
libmicrohttpd/src/testcurl/https/test_tls_authentication.c
libmicrohttpd/src/testcurl/https/test_tls_extensions.c
libmicrohttpd/src/testcurl/https/test_tls_options.c
Removed:
libmicrohttpd/src/testcurl/https/mhds_get_test.c
libmicrohttpd/src/testcurl/https/mhds_get_test_select.c
libmicrohttpd/src/testcurl/https/mhds_multi_daemon_test.c
libmicrohttpd/src/testcurl/https/mhds_session_info_test.c
libmicrohttpd/src/testcurl/https/tls_authentication_test.c
libmicrohttpd/src/testcurl/https/tls_daemon_options_test.c
libmicrohttpd/src/testcurl/https/tls_extension_test.c
libmicrohttpd/src/testcurl/https/tls_multi_thread_mode_test.c
libmicrohttpd/src/testcurl/https/tls_session_time_out_test.c
libmicrohttpd/src/testcurl/https/tls_thread_mode_test.c
Modified:
libmicrohttpd/src/testcurl/https/Makefile.am
Log:
-renaming for consistency
Modified: libmicrohttpd/src/testcurl/https/Makefile.am
===================================================================
--- libmicrohttpd/src/testcurl/https/Makefile.am 2013-03-29 15:59:58 UTC
(rev 26657)
+++ libmicrohttpd/src/testcurl/https/Makefile.am 2013-03-29 16:16:02 UTC
(rev 26658)
@@ -15,53 +15,52 @@
$(LIBCURL_CPPFLAGS)
check_PROGRAMS = \
- tls_daemon_options_test \
- tls_authentication_test \
- mhds_multi_daemon_test \
- mhds_get_test \
- mhds_get_test_select \
- mhds_session_info_test \
- tls_thread_mode_test \
- tls_multi_thread_mode_test \
- tls_session_time_out_test \
+ test_tls_options \
+ test_tls_authentication \
+ test_https_multi_daemon \
+ test_https_get \
+ test_https_get_select \
+ test_https_get_parallel \
+ test_https_get_parallel_threads \
+ test_https_session_info \
+ test_https_time_out \
test_empty_response
EXTRA_DIST = cert.pem key.pem tls_test_keys.h tls_test_common.h
-# tls_authentication_test currently fails for unknown reasons
TESTS = \
- tls_daemon_options_test \
- mhds_multi_daemon_test \
- mhds_get_test \
- mhds_get_test_select \
- mhds_session_info_test \
- tls_thread_mode_test \
- tls_multi_thread_mode_test \
- tls_session_time_out_test \
- tls_authentication_test \
+ test_tls_options \
+ test_https_multi_daemon \
+ test_https_get \
+ test_https_get_select \
+ test_https_get_parallel \
+ test_https_get_parallel_threads \
+ test_https_session_info \
+ test_https_time_out \
+ test_tls_authentication \
test_empty_response
-# cURL dependent tests
-tls_session_time_out_test_SOURCES = \
- tls_session_time_out_test.c \
+
+test_https_time_out_SOURCES = \
+ test_https_time_out.c \
tls_test_common.c
-tls_session_time_out_test_LDADD = \
+test_https_time_out_LDADD = \
$(top_builddir)/src/testcurl/libcurl_version_check.a \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@ -lgnutls @LIBGCRYPT_LIBS@
-tls_daemon_options_test_SOURCES = \
- tls_daemon_options_test.c \
+test_tls_options_SOURCES = \
+ test_tls_options.c \
tls_test_common.c
-tls_daemon_options_test_LDADD = \
+test_tls_options_LDADD = \
$(top_builddir)/src/testcurl/libcurl_version_check.a \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@ -lgnutls @LIBGCRYPT_LIBS@
-tls_thread_mode_test_SOURCES = \
- tls_thread_mode_test.c \
+test_https_get_parallel_SOURCES = \
+ test_https_get_parallel.c \
tls_test_common.c
-tls_thread_mode_test_LDADD = \
+test_https_get_parallel_LDADD = \
$(top_builddir)/src/testcurl/libcurl_version_check.a \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@ -lgnutls @LIBGCRYPT_LIBS@
@@ -74,51 +73,50 @@
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@ -lgnutls @LIBGCRYPT_LIBS@
-tls_multi_thread_mode_test_SOURCES = \
- tls_multi_thread_mode_test.c \
+test_https_get_parallel_threads_SOURCES = \
+ test_https_get_parallel_threads.c \
tls_test_common.c
-tls_multi_thread_mode_test_LDADD = \
+test_https_get_parallel_threads_LDADD = \
$(top_builddir)/src/testcurl/libcurl_version_check.a \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@ -lgnutls @LIBGCRYPT_LIBS@
-tls_authentication_test_SOURCES = \
- tls_authentication_test.c \
+test_tls_authentication_SOURCES = \
+ test_tls_authentication.c \
tls_test_common.c
-tls_authentication_test_LDADD = \
+test_tls_authentication_LDADD = \
$(top_builddir)/src/testcurl/libcurl_version_check.a \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@ -lgnutls @LIBGCRYPT_LIBS@
-mhds_session_info_test_SOURCES = \
- mhds_session_info_test.c \
+test_https_session_info_SOURCES = \
+ test_https_session_info.c \
tls_test_common.c
-mhds_session_info_test_LDADD = \
+test_https_session_info_LDADD = \
$(top_builddir)/src/testcurl/libcurl_version_check.a \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@ -lgnutls @LIBGCRYPT_LIBS@
-mhds_multi_daemon_test_SOURCES = \
- mhds_multi_daemon_test.c \
+test_https_multi_daemon_SOURCES = \
+ test_https_multi_daemon.c \
tls_test_common.c
-mhds_multi_daemon_test_LDADD = \
+test_https_multi_daemon_LDADD = \
$(top_builddir)/src/testcurl/libcurl_version_check.a \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@ -lgnutls @LIBGCRYPT_LIBS@
-mhds_get_test_SOURCES = \
- mhds_get_test.c \
+test_https_get_SOURCES = \
+ test_https_get.c \
tls_test_common.c
-mhds_get_test_LDADD = \
+test_https_get_LDADD = \
$(top_builddir)/src/testcurl/libcurl_version_check.a \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@ -lgnutls @LIBGCRYPT_LIBS@
-
-mhds_get_test_select_SOURCES = \
- mhds_get_test_select.c \
+test_https_get_select_SOURCES = \
+ test_https_get_select.c \
tls_test_common.c
-mhds_get_test_select_LDADD = \
+test_https_get_select_LDADD = \
$(top_builddir)/src/testcurl/libcurl_version_check.a \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@ -lgnutls @LIBGCRYPT_LIBS@
Deleted: libmicrohttpd/src/testcurl/https/mhds_get_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/mhds_get_test.c 2013-03-29 15:59:58 UTC
(rev 26657)
+++ libmicrohttpd/src/testcurl/https/mhds_get_test.c 2013-03-29 16:16:02 UTC
(rev 26658)
@@ -1,127 +0,0 @@
-/*
- This file is part of libmicrohttpd
- (C) 2007 Christian Grothoff
-
- libmicrohttpd 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 2, or (at your
- option) any later version.
-
- libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file mhds_get_test.c
- * @brief Testcase for libmicrohttpd HTTPS GET operations
- * @author Sagie Amir
- */
-
-#include "platform.h"
-#include "microhttpd.h"
-#include <limits.h>
-#include <sys/stat.h>
-#include <curl/curl.h>
-#include <gcrypt.h>
-#include "tls_test_common.h"
-
-extern const char srv_key_pem[];
-extern const char srv_self_signed_cert_pem[];
-extern const char srv_signed_cert_pem[];
-extern const char srv_signed_key_pem[];
-
-static int
-test_cipher_option (FILE * test_fd, char *cipher_suite, int proto_version)
-{
-
- int ret;
- struct MHD_Daemon *d;
- d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
- MHD_USE_DEBUG, 4233,
- NULL, NULL, &http_ahc, NULL,
- MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
- MHD_OPTION_END);
-
- if (d == NULL)
- {
- fprintf (stderr, MHD_E_SERVER_INIT);
- return -1;
- }
-
- ret = test_https_transfer (test_fd, cipher_suite, proto_version);
-
- MHD_stop_daemon (d);
- return ret;
-}
-
-/* perform a HTTP GET request via SSL/TLS */
-int
-test_secure_get (FILE * test_fd, char *cipher_suite, int proto_version)
-{
- int ret;
- struct MHD_Daemon *d;
-
- d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
- MHD_USE_DEBUG, 4233,
- NULL, NULL, &http_ahc, NULL,
- MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
- MHD_OPTION_END);
-
- if (d == NULL)
- {
- fprintf (stderr, MHD_E_SERVER_INIT);
- return -1;
- }
-
- ret = test_https_transfer (test_fd, cipher_suite, proto_version);
-
- MHD_stop_daemon (d);
- return ret;
-}
-
-int
-main (int argc, char *const *argv)
-{
- unsigned int errorCount = 0;
-
- if (!gcry_check_version (GCRYPT_VERSION))
- abort ();
- if (0 != curl_global_init (CURL_GLOBAL_ALL))
- {
- fprintf (stderr, "Error: %s\n", strerror (errno));
- return -1;
- }
-
- char *aes256_sha_tlsv1 = "AES256-SHA";
- char *aes256_sha_sslv3 = "AES256-SHA";
- char *des_cbc3_sha_tlsv1 = "DES-CBC3-SHA";
-
- if (curl_uses_nss_ssl() == 0)
- {
- aes256_sha_tlsv1 = "rsa_aes_256_sha";
- aes256_sha_sslv3 = "rsa_aes_256_sha";
- des_cbc3_sha_tlsv1 = "rsa_aes_128_sha";
- }
-
- errorCount +=
- test_secure_get (NULL, aes256_sha_tlsv1, CURL_SSLVERSION_TLSv1);
- errorCount +=
- test_secure_get (NULL, aes256_sha_sslv3, CURL_SSLVERSION_SSLv3);
- errorCount +=
- test_cipher_option (NULL, des_cbc3_sha_tlsv1, CURL_SSLVERSION_TLSv1);
-
- print_test_result (errorCount, argv[0]);
-
- curl_global_cleanup ();
-
- return errorCount != 0;
-}
Deleted: libmicrohttpd/src/testcurl/https/mhds_get_test_select.c
===================================================================
--- libmicrohttpd/src/testcurl/https/mhds_get_test_select.c 2013-03-29
15:59:58 UTC (rev 26657)
+++ libmicrohttpd/src/testcurl/https/mhds_get_test_select.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -1,229 +0,0 @@
-/*
- This file is part of libmicrohttpd
- (C) 2007 Christian Grothoff
-
- libmicrohttpd 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 2, or (at your
- option) any later version.
-
- libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file mhds_get_test.c
- * @brief Testcase for libmicrohttpd HTTPS GET operations
- * @author Sagie Amir
- */
-
-#include "platform.h"
-#include "microhttpd.h"
-#include <limits.h>
-#include <sys/stat.h>
-#include <curl/curl.h>
-#include <gcrypt.h>
-#include "tls_test_common.h"
-
-extern const char srv_key_pem[];
-extern const char srv_self_signed_cert_pem[];
-extern const char srv_signed_cert_pem[];
-extern const char srv_signed_key_pem[];
-
-static int oneone;
-
-static int
-ahc_echo (void *cls,
- struct MHD_Connection *connection,
- const char *url,
- const char *method,
- const char *version,
- const char *upload_data, size_t *upload_data_size,
- void **unused)
-{
- static int ptr;
- const char *me = cls;
- struct MHD_Response *response;
- int ret;
-
- if (0 != strcmp (me, method))
- return MHD_NO; /* unexpected method */
- if (&ptr != *unused)
- {
- *unused = &ptr;
- return MHD_YES;
- }
- *unused = NULL;
- response = MHD_create_response_from_buffer (strlen (url),
- (void *) url,
- MHD_RESPMEM_MUST_COPY);
- ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
- MHD_destroy_response (response);
- if (ret == MHD_NO)
- abort ();
- return ret;
-}
-
-static int
-testExternalGet ()
-{
- struct MHD_Daemon *d;
- CURL *c;
- char buf[2048];
- struct CBC cbc;
- CURLM *multi;
- CURLMcode mret;
- fd_set rs;
- fd_set ws;
- fd_set es;
- int max;
- int running;
- struct CURLMsg *msg;
- time_t start;
- struct timeval tv;
-
- multi = NULL;
- cbc.buf = buf;
- cbc.size = 2048;
- cbc.pos = 0;
- d = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL,
- 1082, NULL, NULL, &ahc_echo, "GET",
- MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
- MHD_OPTION_END);
- if (d == NULL)
- return 256;
-
- char *aes256_sha = "AES256-SHA";
- if (curl_uses_nss_ssl() == 0)
- {
- aes256_sha = "rsa_aes_256_sha";
- }
-
- c = curl_easy_init ();
- curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1:1082/hello_world");
- curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
- curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
- /* TLS options */
- curl_easy_setopt (c, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3);
- curl_easy_setopt (c, CURLOPT_SSL_CIPHER_LIST, aes256_sha);
- curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0);
- curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0);
- curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
- if (oneone)
- curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
- else
- curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
- curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
- curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
- /* NOTE: use of CONNECTTIMEOUT without also
- setting NOSIGNAL results in really weird
- crashes on my system! */
- curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
-
-
- multi = curl_multi_init ();
- if (multi == NULL)
- {
- curl_easy_cleanup (c);
- MHD_stop_daemon (d);
- return 512;
- }
- mret = curl_multi_add_handle (multi, c);
- if (mret != CURLM_OK)
- {
- curl_multi_cleanup (multi);
- curl_easy_cleanup (c);
- MHD_stop_daemon (d);
- return 1024;
- }
- start = time (NULL);
- while ((time (NULL) - start < 5) && (multi != NULL))
- {
- max = 0;
- FD_ZERO (&rs);
- FD_ZERO (&ws);
- FD_ZERO (&es);
- mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
- if (mret != CURLM_OK)
- {
- curl_multi_remove_handle (multi, c);
- curl_multi_cleanup (multi);
- curl_easy_cleanup (c);
- MHD_stop_daemon (d);
- return 2048;
- }
- if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
- {
- curl_multi_remove_handle (multi, c);
- curl_multi_cleanup (multi);
- curl_easy_cleanup (c);
- MHD_stop_daemon (d);
- return 4096;
- }
- tv.tv_sec = 0;
- tv.tv_usec = 1000;
- select (max + 1, &rs, &ws, &es, &tv);
- curl_multi_perform (multi, &running);
- if (running == 0)
- {
- msg = curl_multi_info_read (multi, &running);
- if (msg == NULL)
- break;
- if (msg->msg == CURLMSG_DONE)
- {
- if (msg->data.result != CURLE_OK)
- printf ("%s failed at %s:%d: `%s'\n",
- "curl_multi_perform",
- __FILE__,
- __LINE__, curl_easy_strerror (msg->data.result));
- curl_multi_remove_handle (multi, c);
- curl_multi_cleanup (multi);
- curl_easy_cleanup (c);
- c = NULL;
- multi = NULL;
- }
- }
- MHD_run (d);
- }
- if (multi != NULL)
- {
- curl_multi_remove_handle (multi, c);
- curl_easy_cleanup (c);
- curl_multi_cleanup (multi);
- }
- MHD_stop_daemon (d);
- if (cbc.pos != strlen ("/hello_world"))
- return 8192;
- if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
- return 16384;
- return 0;
-}
-
-GCRY_THREAD_OPTION_PTHREAD_IMPL;
-
-int
-main (int argc, char *const *argv)
-{
- unsigned int errorCount = 0;
-
- gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
- if (!gcry_check_version (GCRYPT_VERSION))
- abort ();
- if (0 != curl_global_init (CURL_GLOBAL_ALL))
- {
- fprintf (stderr, "Error: %s\n", strerror (errno));
- return -1;
- }
- if (0 != (errorCount = testExternalGet ()))
- fprintf (stderr, "Fail: %d\n", errorCount);
- curl_global_cleanup ();
- return errorCount != 0;
-}
Deleted: libmicrohttpd/src/testcurl/https/mhds_multi_daemon_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/mhds_multi_daemon_test.c 2013-03-29
15:59:58 UTC (rev 26657)
+++ libmicrohttpd/src/testcurl/https/mhds_multi_daemon_test.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -1,124 +0,0 @@
-/*
- This file is part of libmicrohttpd
- (C) 2007 Christian Grothoff
-
- libmicrohttpd 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 2, or (at your
- option) any later version.
-
- libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file mhds_multi_daemon_test.c
- * @brief Testcase for libmicrohttpd multiple HTTPS daemon scenario
- * @author Sagie Amir
- */
-
-#include "platform.h"
-#include "microhttpd.h"
-#include <curl/curl.h>
-#include <limits.h>
-#include <sys/stat.h>
-
-#include "tls_test_common.h"
-
-extern int curl_check_version (const char *req_version, ...);
-extern const char srv_key_pem[];
-extern const char srv_self_signed_cert_pem[];
-
-/*
- * assert initiating two separate daemons and having one shut down
- * doesn't affect the other
- */
-int
-test_concurent_daemon_pair (void * cls, char *cipher_suite,
- int proto_version)
-{
-
- int ret;
- struct MHD_Daemon *d1;
- struct MHD_Daemon *d2;
- d1 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
- MHD_USE_DEBUG, DEAMON_TEST_PORT,
- NULL, NULL, &http_ahc, NULL,
- MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
- MHD_OPTION_END);
-
- if (d1 == NULL)
- {
- fprintf (stderr, MHD_E_SERVER_INIT);
- return -1;
- }
-
- d2 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
- MHD_USE_DEBUG, DEAMON_TEST_PORT + 1,
- NULL, NULL, &http_ahc, NULL,
- MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
- MHD_OPTION_END);
-
- if (d2 == NULL)
- {
- MHD_stop_daemon (d1);
- fprintf (stderr, MHD_E_SERVER_INIT);
- return -1;
- }
-
- ret =
- test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT, 0);
- ret +=
- test_daemon_get (NULL, cipher_suite, proto_version,
- DEAMON_TEST_PORT + 1, 0);
-
- MHD_stop_daemon (d2);
- ret +=
- test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT, 0);
- MHD_stop_daemon (d1);
- return ret;
-}
-
-int
-main (int argc, char *const *argv)
-{
- unsigned int errorCount = 0;
- FILE *cert;
-
- if (0 != curl_global_init (CURL_GLOBAL_ALL))
- {
- fprintf (stderr, "Error (code: %u). l:%d f:%s\n", errorCount, __LINE__,
- __FUNCTION__);
- return -1;
- }
- if ((cert = setup_ca_cert ()) == NULL)
- {
- fprintf (stderr, MHD_E_TEST_FILE_CREAT);
- return -1;
- }
-
- char *aes256_sha = "AES256-SHA";
- if (curl_uses_nss_ssl() == 0)
- {
- aes256_sha = "rsa_aes_256_sha";
- }
-
- errorCount +=
- test_concurent_daemon_pair (NULL, aes256_sha, CURL_SSLVERSION_SSLv3);
-
- print_test_result (errorCount, "concurent_daemon_pair");
-
- curl_global_cleanup ();
- fclose (cert);
- remove (ca_cert_file_name);
- return errorCount != 0;
-}
Deleted: libmicrohttpd/src/testcurl/https/mhds_session_info_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/mhds_session_info_test.c 2013-03-29
15:59:58 UTC (rev 26657)
+++ libmicrohttpd/src/testcurl/https/mhds_session_info_test.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -1,170 +0,0 @@
-/*
- This file is part of libmicrohttpd
- (C) 2007 Christian Grothoff
-
- libmicrohttpd 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 2, or (at your
- option) any later version.
-
- libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file mhds_session_info_test.c
- * @brief Testcase for libmicrohttpd HTTPS connection querying operations
- * @author Sagie Amir
- */
-
-#include "platform.h"
-#include "microhttpd.h"
-#include <curl/curl.h>
-
-#include "tls_test_common.h"
-
-extern int curl_check_version (const char *req_version, ...);
-extern const char srv_key_pem[];
-extern const char srv_self_signed_cert_pem[];
-
-struct MHD_Daemon *d;
-
-/*
- * HTTP access handler call back
- * used to query negotiated security parameters
- */
-static int
-query_session_ahc (void *cls, struct MHD_Connection *connection,
- const char *url, const char *method,
- const char *upload_data, const char *version,
- size_t *upload_data_size, void **ptr)
-{
- struct MHD_Response *response;
- int ret;
-
- if (NULL == *ptr)
- {
- *ptr = &query_session_ahc;
- return MHD_YES;
- }
-
- if (GNUTLS_SSL3 !=
- (ret = MHD_get_connection_info
- (connection,
- MHD_CONNECTION_INFO_PROTOCOL)->protocol))
- {
- fprintf (stderr, "Error: requested protocol mismatch (wanted %d, got
%d)\n",
- GNUTLS_SSL3,
- ret);
- return -1;
- }
-
- response = MHD_create_response_from_buffer (strlen (EMPTY_PAGE),
- (void *) EMPTY_PAGE,
- MHD_RESPMEM_PERSISTENT);
- ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
- MHD_destroy_response (response);
- return ret;
-}
-
-
-/**
- * negotiate a secure connection with server & query negotiated security
parameters
- */
-static int
-test_query_session ()
-{
- CURL *c;
- struct CBC cbc;
- CURLcode errornum;
- char url[256];
-
- if (NULL == (cbc.buf = malloc (sizeof (char) * 255)))
- return 16;
- cbc.size = 255;
- cbc.pos = 0;
-
- gen_test_file_url (url, DEAMON_TEST_PORT);
-
- /* setup test */
- d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
- MHD_USE_DEBUG, DEAMON_TEST_PORT,
- NULL, NULL, &query_session_ahc, NULL,
- MHD_OPTION_HTTPS_PRIORITIES, "NORMAL:+ARCFOUR-128",
- MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
- MHD_OPTION_END);
-
- if (d == NULL)
- return 2;
-
- const char *aes256_sha = "AES256-SHA";
- if (curl_uses_nss_ssl() == 0)
- {
- aes256_sha = "rsa_aes_256_sha";
- }
-
- c = curl_easy_init ();
-#if DEBUG_HTTPS_TEST
- curl_easy_setopt (c, CURLOPT_VERBOSE, 1);
-#endif
- curl_easy_setopt (c, CURLOPT_URL, url);
- curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
- curl_easy_setopt (c, CURLOPT_TIMEOUT, 10L);
- curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 10L);
- curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
- curl_easy_setopt (c, CURLOPT_FILE, &cbc);
- /* TLS options */
- curl_easy_setopt (c, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3);
- curl_easy_setopt (c, CURLOPT_SSL_CIPHER_LIST, aes256_sha);
- /* currently skip any peer authentication */
- curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0);
- curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0);
- curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
-
- // NOTE: use of CONNECTTIMEOUT without also
- // setting NOSIGNAL results in really weird
- // crashes on my system!
- curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
- if (CURLE_OK != (errornum = curl_easy_perform (c)))
- {
- fprintf (stderr, "curl_easy_perform failed: `%s'\n",
- curl_easy_strerror (errornum));
-
- MHD_stop_daemon (d);
- curl_easy_cleanup (c);
- free (cbc.buf);
- return -1;
- }
-
- curl_easy_cleanup (c);
- MHD_stop_daemon (d);
- free (cbc.buf);
- return 0;
-}
-
-
-int
-main (int argc, char *const *argv)
-{
- unsigned int errorCount = 0;
-
- if (0 != curl_global_init (CURL_GLOBAL_ALL))
- {
- fprintf (stderr, "Error (code: %u)\n", errorCount);
- return -1;
- }
- errorCount += test_query_session ();
- print_test_result (errorCount, argv[0]);
- curl_global_cleanup ();
- if (errorCount > 0)
- fprintf (stderr, "Error (code: %u)\n", errorCount);
- return errorCount;
-}
Copied: libmicrohttpd/src/testcurl/https/test_https_get.c (from rev 26652,
libmicrohttpd/src/testcurl/https/mhds_get_test.c)
===================================================================
--- libmicrohttpd/src/testcurl/https/test_https_get.c
(rev 0)
+++ libmicrohttpd/src/testcurl/https/test_https_get.c 2013-03-29 16:16:02 UTC
(rev 26658)
@@ -0,0 +1,127 @@
+/*
+ This file is part of libmicrohttpd
+ (C) 2007 Christian Grothoff
+
+ libmicrohttpd 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 2, or (at your
+ option) any later version.
+
+ libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file mhds_get_test.c
+ * @brief Testcase for libmicrohttpd HTTPS GET operations
+ * @author Sagie Amir
+ */
+
+#include "platform.h"
+#include "microhttpd.h"
+#include <limits.h>
+#include <sys/stat.h>
+#include <curl/curl.h>
+#include <gcrypt.h>
+#include "tls_test_common.h"
+
+extern const char srv_key_pem[];
+extern const char srv_self_signed_cert_pem[];
+extern const char srv_signed_cert_pem[];
+extern const char srv_signed_key_pem[];
+
+static int
+test_cipher_option (FILE * test_fd, char *cipher_suite, int proto_version)
+{
+
+ int ret;
+ struct MHD_Daemon *d;
+ d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
+ MHD_USE_DEBUG, 4233,
+ NULL, NULL, &http_ahc, NULL,
+ MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
+ MHD_OPTION_END);
+
+ if (d == NULL)
+ {
+ fprintf (stderr, MHD_E_SERVER_INIT);
+ return -1;
+ }
+
+ ret = test_https_transfer (test_fd, cipher_suite, proto_version);
+
+ MHD_stop_daemon (d);
+ return ret;
+}
+
+/* perform a HTTP GET request via SSL/TLS */
+int
+test_secure_get (FILE * test_fd, char *cipher_suite, int proto_version)
+{
+ int ret;
+ struct MHD_Daemon *d;
+
+ d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
+ MHD_USE_DEBUG, 4233,
+ NULL, NULL, &http_ahc, NULL,
+ MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
+ MHD_OPTION_END);
+
+ if (d == NULL)
+ {
+ fprintf (stderr, MHD_E_SERVER_INIT);
+ return -1;
+ }
+
+ ret = test_https_transfer (test_fd, cipher_suite, proto_version);
+
+ MHD_stop_daemon (d);
+ return ret;
+}
+
+int
+main (int argc, char *const *argv)
+{
+ unsigned int errorCount = 0;
+
+ if (!gcry_check_version (GCRYPT_VERSION))
+ abort ();
+ if (0 != curl_global_init (CURL_GLOBAL_ALL))
+ {
+ fprintf (stderr, "Error: %s\n", strerror (errno));
+ return -1;
+ }
+
+ char *aes256_sha_tlsv1 = "AES256-SHA";
+ char *aes256_sha_sslv3 = "AES256-SHA";
+ char *des_cbc3_sha_tlsv1 = "DES-CBC3-SHA";
+
+ if (curl_uses_nss_ssl() == 0)
+ {
+ aes256_sha_tlsv1 = "rsa_aes_256_sha";
+ aes256_sha_sslv3 = "rsa_aes_256_sha";
+ des_cbc3_sha_tlsv1 = "rsa_aes_128_sha";
+ }
+
+ errorCount +=
+ test_secure_get (NULL, aes256_sha_tlsv1, CURL_SSLVERSION_TLSv1);
+ errorCount +=
+ test_secure_get (NULL, aes256_sha_sslv3, CURL_SSLVERSION_SSLv3);
+ errorCount +=
+ test_cipher_option (NULL, des_cbc3_sha_tlsv1, CURL_SSLVERSION_TLSv1);
+
+ print_test_result (errorCount, argv[0]);
+
+ curl_global_cleanup ();
+
+ return errorCount != 0;
+}
Copied: libmicrohttpd/src/testcurl/https/test_https_get_parallel.c (from rev
26652, libmicrohttpd/src/testcurl/https/tls_thread_mode_test.c)
===================================================================
--- libmicrohttpd/src/testcurl/https/test_https_get_parallel.c
(rev 0)
+++ libmicrohttpd/src/testcurl/https/test_https_get_parallel.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -0,0 +1,162 @@
+/*
+ This file is part of libmicrohttpd
+ (C) 2007 Christian Grothoff
+
+ libmicrohttpd 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 2, or (at your
+ option) any later version.
+
+ libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file tls_thread_mode_test.c
+ * @brief Testcase for libmicrohttpd HTTPS GET operations
+ * @author Sagie Amir
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "microhttpd.h"
+#include <sys/stat.h>
+#include <limits.h>
+#include <curl/curl.h>
+#include <gcrypt.h>
+#include "tls_test_common.h"
+
+extern const char srv_key_pem[];
+extern const char srv_self_signed_cert_pem[];
+
+int curl_check_version (const char *req_version, ...);
+
+/**
+ * used when spawning multiple threads executing curl server requests
+ *
+ */
+static void *
+https_transfer_thread_adapter (void *args)
+{
+ static int nonnull;
+ struct https_test_data *cargs = args;
+ int ret;
+
+ /* time spread incomming requests */
+ usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX));
+ ret = test_https_transfer (NULL,
+ cargs->cipher_suite, cargs->proto_version);
+ if (ret == 0)
+ return NULL;
+ return &nonnull;
+}
+
+/**
+ * Test non-parallel requests.
+ *
+ * @return: 0 upon all client requests returning '0', -1 otherwise.
+ *
+ * TODO : make client_count a parameter - number of curl client threads to
spawn
+ */
+static int
+test_single_client (void *cls, const char *cipher_suite,
+ int curl_proto_version)
+{
+ void *client_thread_ret;
+ struct https_test_data client_args =
+ { NULL, cipher_suite, curl_proto_version };
+
+ client_thread_ret = https_transfer_thread_adapter (&client_args);
+ if (client_thread_ret != NULL)
+ return -1;
+ return 0;
+}
+
+/**
+ * Test parallel request handling.
+ *
+ * @return: 0 upon all client requests returning '0', -1 otherwise.
+ *
+ * TODO : make client_count a parameter - numver of curl client threads to
spawn
+ */
+static int
+test_parallel_clients (void * cls, const char *cipher_suite,
+ int curl_proto_version)
+{
+ int i;
+ int client_count = 3;
+ void *client_thread_ret;
+ pthread_t client_arr[client_count];
+ struct https_test_data client_args =
+ { NULL, cipher_suite, curl_proto_version };
+
+ for (i = 0; i < client_count; ++i)
+ {
+ if (pthread_create (&client_arr[i], NULL,
+ &https_transfer_thread_adapter, &client_args) != 0)
+ {
+ fprintf (stderr, "Error: failed to spawn test client threads.\n");
+ return -1;
+ }
+ }
+
+ /* check all client requests fulfilled correctly */
+ for (i = 0; i < client_count; ++i)
+ {
+ if ((pthread_join (client_arr[i], &client_thread_ret) != 0) ||
+ (client_thread_ret != NULL))
+ return -1;
+ }
+
+ return 0;
+}
+
+GCRY_THREAD_OPTION_PTHREAD_IMPL;
+
+int
+main (int argc, char *const *argv)
+{
+ unsigned int errorCount = 0;
+
+ /* initialize random seed used by curl clients */
+ unsigned int iseed = (unsigned int) time (NULL);
+ srand (iseed);
+ gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
+ if (0 != curl_global_init (CURL_GLOBAL_ALL))
+ {
+ fprintf (stderr, "Error: %s\n", strerror (errno));
+ return -1;
+ }
+
+ char *aes256_sha = "AES256-SHA";
+ if (curl_uses_nss_ssl() == 0)
+ {
+ aes256_sha = "rsa_aes_256_sha";
+ }
+
+ errorCount +=
+ test_wrap ("single threaded daemon, single client", &test_single_client,
+ NULL,
+ MHD_USE_SELECT_INTERNALLY | MHD_USE_SSL | MHD_USE_DEBUG,
+ aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
+ srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
+ srv_self_signed_cert_pem, MHD_OPTION_END);
+
+ errorCount +=
+ test_wrap ("single threaded daemon, parallel clients",
+ &test_parallel_clients, NULL,
+ MHD_USE_SELECT_INTERNALLY | MHD_USE_SSL | MHD_USE_DEBUG,
+ aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
+ srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
+ srv_self_signed_cert_pem, MHD_OPTION_END);
+
+ curl_global_cleanup ();
+ return errorCount != 0;
+}
Copied: libmicrohttpd/src/testcurl/https/test_https_get_parallel_threads.c
(from rev 26652, libmicrohttpd/src/testcurl/https/tls_multi_thread_mode_test.c)
===================================================================
--- libmicrohttpd/src/testcurl/https/test_https_get_parallel_threads.c
(rev 0)
+++ libmicrohttpd/src/testcurl/https/test_https_get_parallel_threads.c
2013-03-29 16:16:02 UTC (rev 26658)
@@ -0,0 +1,178 @@
+/*
+ This file is part of libmicrohttpd
+ (C) 2007 Christian Grothoff
+
+ libmicrohttpd 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 2, or (at your
+ option) any later version.
+
+ libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file tls_thread_mode_test.c
+ * @brief Testcase for libmicrohttpd HTTPS GET operations
+ * @author Sagie Amir
+ * @author Christian Grothoff
+ *
+ * TODO: add test for external select!
+ */
+
+#include "platform.h"
+#include "microhttpd.h"
+#include <sys/stat.h>
+#include <limits.h>
+#include <curl/curl.h>
+#include "tls_test_common.h"
+
+extern const char srv_key_pem[];
+extern const char srv_self_signed_cert_pem[];
+
+int curl_check_version (const char *req_version, ...);
+
+/**
+ * used when spawning multiple threads executing curl server requests
+ *
+ */
+static void *
+https_transfer_thread_adapter (void *args)
+{
+ static int nonnull;
+ struct https_test_data *cargs = args;
+ int ret;
+
+ /* time spread incomming requests */
+ usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX));
+ ret = test_https_transfer (cargs->cls,
+ cargs->cipher_suite, cargs->proto_version);
+ if (ret == 0)
+ return NULL;
+ return &nonnull;
+}
+
+/**
+ * Test non-parallel requests.
+ *
+ * @return: 0 upon all client requests returning '0', -1 otherwise.
+ *
+ * TODO : make client_count a parameter - numver of curl client threads to
spawn
+ */
+static int
+test_single_client (void *cls, const char *cipher_suite,
+ int curl_proto_version)
+{
+ void *client_thread_ret;
+ struct https_test_data client_args =
+ { NULL, cipher_suite, curl_proto_version };
+
+ client_thread_ret = https_transfer_thread_adapter (&client_args);
+ if (client_thread_ret != NULL)
+ return -1;
+ return 0;
+}
+
+
+/**
+ * Test parallel request handling.
+ *
+ * @return: 0 upon all client requests returning '0', -1 otherwise.
+ *
+ * TODO : make client_count a parameter - numver of curl client threads to
spawn
+ */
+static int
+test_parallel_clients (void *cls, const char *cipher_suite,
+ int curl_proto_version)
+{
+ int i;
+ int client_count = 3;
+ void *client_thread_ret;
+ pthread_t client_arr[client_count];
+ struct https_test_data client_args =
+ { NULL, cipher_suite, curl_proto_version };
+
+ for (i = 0; i < client_count; ++i)
+ {
+ if (pthread_create (&client_arr[i], NULL,
+ &https_transfer_thread_adapter, &client_args) != 0)
+ {
+ fprintf (stderr, "Error: failed to spawn test client threads.\n");
+
+ return -1;
+ }
+ }
+
+ /* check all client requests fulfilled correctly */
+ for (i = 0; i < client_count; ++i)
+ {
+ if ((pthread_join (client_arr[i], &client_thread_ret) != 0) ||
+ (client_thread_ret != NULL))
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int
+main (int argc, char *const *argv)
+{
+ unsigned int errorCount = 0;
+ const char *ssl_version;
+
+ /* initialize random seed used by curl clients */
+ unsigned int iseed = (unsigned int) time (NULL);
+ srand (iseed);
+ ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version;
+ if (NULL == ssl_version)
+ {
+ fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n");
+ return 0;
+ }
+ if (NULL != strcasestr (ssl_version, "openssl"))
+ {
+ fprintf (stderr, "Refusing to run test with OpenSSL. Please install
libcurl-gnutls\n");
+ return 0;
+ }
+ if (0 != curl_global_init (CURL_GLOBAL_ALL))
+ {
+ fprintf (stderr, "Error: %s\n", strerror (errno));
+ return -1;
+ }
+
+ char *aes256_sha = "AES256-SHA";
+ if (curl_uses_nss_ssl() == 0)
+ {
+ aes256_sha = "rsa_aes_256_sha";
+ }
+
+ errorCount +=
+ test_wrap ("multi threaded daemon, single client", &test_single_client,
+ NULL,
+ MHD_USE_SSL | MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION,
+ aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
+ srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
+ srv_self_signed_cert_pem, MHD_OPTION_END);
+
+ errorCount +=
+ test_wrap ("multi threaded daemon, parallel client",
+ &test_parallel_clients, NULL,
+ MHD_USE_SSL | MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION,
+ aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
+ srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
+ srv_self_signed_cert_pem, MHD_OPTION_END);
+
+ if (errorCount != 0)
+ fprintf (stderr, "Failed test: %s.\n", argv[0]);
+
+ curl_global_cleanup ();
+ return errorCount != 0;
+}
Copied: libmicrohttpd/src/testcurl/https/test_https_get_select.c (from rev
26652, libmicrohttpd/src/testcurl/https/mhds_get_test_select.c)
===================================================================
--- libmicrohttpd/src/testcurl/https/test_https_get_select.c
(rev 0)
+++ libmicrohttpd/src/testcurl/https/test_https_get_select.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -0,0 +1,229 @@
+/*
+ This file is part of libmicrohttpd
+ (C) 2007 Christian Grothoff
+
+ libmicrohttpd 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 2, or (at your
+ option) any later version.
+
+ libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file mhds_get_test.c
+ * @brief Testcase for libmicrohttpd HTTPS GET operations
+ * @author Sagie Amir
+ */
+
+#include "platform.h"
+#include "microhttpd.h"
+#include <limits.h>
+#include <sys/stat.h>
+#include <curl/curl.h>
+#include <gcrypt.h>
+#include "tls_test_common.h"
+
+extern const char srv_key_pem[];
+extern const char srv_self_signed_cert_pem[];
+extern const char srv_signed_cert_pem[];
+extern const char srv_signed_key_pem[];
+
+static int oneone;
+
+static int
+ahc_echo (void *cls,
+ struct MHD_Connection *connection,
+ const char *url,
+ const char *method,
+ const char *version,
+ const char *upload_data, size_t *upload_data_size,
+ void **unused)
+{
+ static int ptr;
+ const char *me = cls;
+ struct MHD_Response *response;
+ int ret;
+
+ if (0 != strcmp (me, method))
+ return MHD_NO; /* unexpected method */
+ if (&ptr != *unused)
+ {
+ *unused = &ptr;
+ return MHD_YES;
+ }
+ *unused = NULL;
+ response = MHD_create_response_from_buffer (strlen (url),
+ (void *) url,
+ MHD_RESPMEM_MUST_COPY);
+ ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
+ MHD_destroy_response (response);
+ if (ret == MHD_NO)
+ abort ();
+ return ret;
+}
+
+static int
+testExternalGet ()
+{
+ struct MHD_Daemon *d;
+ CURL *c;
+ char buf[2048];
+ struct CBC cbc;
+ CURLM *multi;
+ CURLMcode mret;
+ fd_set rs;
+ fd_set ws;
+ fd_set es;
+ int max;
+ int running;
+ struct CURLMsg *msg;
+ time_t start;
+ struct timeval tv;
+
+ multi = NULL;
+ cbc.buf = buf;
+ cbc.size = 2048;
+ cbc.pos = 0;
+ d = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL,
+ 1082, NULL, NULL, &ahc_echo, "GET",
+ MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
+ MHD_OPTION_END);
+ if (d == NULL)
+ return 256;
+
+ char *aes256_sha = "AES256-SHA";
+ if (curl_uses_nss_ssl() == 0)
+ {
+ aes256_sha = "rsa_aes_256_sha";
+ }
+
+ c = curl_easy_init ();
+ curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1:1082/hello_world");
+ curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
+ curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
+ /* TLS options */
+ curl_easy_setopt (c, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3);
+ curl_easy_setopt (c, CURLOPT_SSL_CIPHER_LIST, aes256_sha);
+ curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0);
+ curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
+ if (oneone)
+ curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
+ else
+ curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
+ curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
+ curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
+ /* NOTE: use of CONNECTTIMEOUT without also
+ setting NOSIGNAL results in really weird
+ crashes on my system! */
+ curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
+
+
+ multi = curl_multi_init ();
+ if (multi == NULL)
+ {
+ curl_easy_cleanup (c);
+ MHD_stop_daemon (d);
+ return 512;
+ }
+ mret = curl_multi_add_handle (multi, c);
+ if (mret != CURLM_OK)
+ {
+ curl_multi_cleanup (multi);
+ curl_easy_cleanup (c);
+ MHD_stop_daemon (d);
+ return 1024;
+ }
+ start = time (NULL);
+ while ((time (NULL) - start < 5) && (multi != NULL))
+ {
+ max = 0;
+ FD_ZERO (&rs);
+ FD_ZERO (&ws);
+ FD_ZERO (&es);
+ mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
+ if (mret != CURLM_OK)
+ {
+ curl_multi_remove_handle (multi, c);
+ curl_multi_cleanup (multi);
+ curl_easy_cleanup (c);
+ MHD_stop_daemon (d);
+ return 2048;
+ }
+ if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
+ {
+ curl_multi_remove_handle (multi, c);
+ curl_multi_cleanup (multi);
+ curl_easy_cleanup (c);
+ MHD_stop_daemon (d);
+ return 4096;
+ }
+ tv.tv_sec = 0;
+ tv.tv_usec = 1000;
+ select (max + 1, &rs, &ws, &es, &tv);
+ curl_multi_perform (multi, &running);
+ if (running == 0)
+ {
+ msg = curl_multi_info_read (multi, &running);
+ if (msg == NULL)
+ break;
+ if (msg->msg == CURLMSG_DONE)
+ {
+ if (msg->data.result != CURLE_OK)
+ printf ("%s failed at %s:%d: `%s'\n",
+ "curl_multi_perform",
+ __FILE__,
+ __LINE__, curl_easy_strerror (msg->data.result));
+ curl_multi_remove_handle (multi, c);
+ curl_multi_cleanup (multi);
+ curl_easy_cleanup (c);
+ c = NULL;
+ multi = NULL;
+ }
+ }
+ MHD_run (d);
+ }
+ if (multi != NULL)
+ {
+ curl_multi_remove_handle (multi, c);
+ curl_easy_cleanup (c);
+ curl_multi_cleanup (multi);
+ }
+ MHD_stop_daemon (d);
+ if (cbc.pos != strlen ("/hello_world"))
+ return 8192;
+ if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
+ return 16384;
+ return 0;
+}
+
+GCRY_THREAD_OPTION_PTHREAD_IMPL;
+
+int
+main (int argc, char *const *argv)
+{
+ unsigned int errorCount = 0;
+
+ gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
+ if (!gcry_check_version (GCRYPT_VERSION))
+ abort ();
+ if (0 != curl_global_init (CURL_GLOBAL_ALL))
+ {
+ fprintf (stderr, "Error: %s\n", strerror (errno));
+ return -1;
+ }
+ if (0 != (errorCount = testExternalGet ()))
+ fprintf (stderr, "Fail: %d\n", errorCount);
+ curl_global_cleanup ();
+ return errorCount != 0;
+}
Copied: libmicrohttpd/src/testcurl/https/test_https_multi_daemon.c (from rev
26652, libmicrohttpd/src/testcurl/https/mhds_multi_daemon_test.c)
===================================================================
--- libmicrohttpd/src/testcurl/https/test_https_multi_daemon.c
(rev 0)
+++ libmicrohttpd/src/testcurl/https/test_https_multi_daemon.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -0,0 +1,124 @@
+/*
+ This file is part of libmicrohttpd
+ (C) 2007 Christian Grothoff
+
+ libmicrohttpd 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 2, or (at your
+ option) any later version.
+
+ libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file mhds_multi_daemon_test.c
+ * @brief Testcase for libmicrohttpd multiple HTTPS daemon scenario
+ * @author Sagie Amir
+ */
+
+#include "platform.h"
+#include "microhttpd.h"
+#include <curl/curl.h>
+#include <limits.h>
+#include <sys/stat.h>
+
+#include "tls_test_common.h"
+
+extern int curl_check_version (const char *req_version, ...);
+extern const char srv_key_pem[];
+extern const char srv_self_signed_cert_pem[];
+
+/*
+ * assert initiating two separate daemons and having one shut down
+ * doesn't affect the other
+ */
+int
+test_concurent_daemon_pair (void * cls, char *cipher_suite,
+ int proto_version)
+{
+
+ int ret;
+ struct MHD_Daemon *d1;
+ struct MHD_Daemon *d2;
+ d1 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
+ MHD_USE_DEBUG, DEAMON_TEST_PORT,
+ NULL, NULL, &http_ahc, NULL,
+ MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
+ MHD_OPTION_END);
+
+ if (d1 == NULL)
+ {
+ fprintf (stderr, MHD_E_SERVER_INIT);
+ return -1;
+ }
+
+ d2 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
+ MHD_USE_DEBUG, DEAMON_TEST_PORT + 1,
+ NULL, NULL, &http_ahc, NULL,
+ MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
+ MHD_OPTION_END);
+
+ if (d2 == NULL)
+ {
+ MHD_stop_daemon (d1);
+ fprintf (stderr, MHD_E_SERVER_INIT);
+ return -1;
+ }
+
+ ret =
+ test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT, 0);
+ ret +=
+ test_daemon_get (NULL, cipher_suite, proto_version,
+ DEAMON_TEST_PORT + 1, 0);
+
+ MHD_stop_daemon (d2);
+ ret +=
+ test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT, 0);
+ MHD_stop_daemon (d1);
+ return ret;
+}
+
+int
+main (int argc, char *const *argv)
+{
+ unsigned int errorCount = 0;
+ FILE *cert;
+
+ if (0 != curl_global_init (CURL_GLOBAL_ALL))
+ {
+ fprintf (stderr, "Error (code: %u). l:%d f:%s\n", errorCount, __LINE__,
+ __FUNCTION__);
+ return -1;
+ }
+ if ((cert = setup_ca_cert ()) == NULL)
+ {
+ fprintf (stderr, MHD_E_TEST_FILE_CREAT);
+ return -1;
+ }
+
+ char *aes256_sha = "AES256-SHA";
+ if (curl_uses_nss_ssl() == 0)
+ {
+ aes256_sha = "rsa_aes_256_sha";
+ }
+
+ errorCount +=
+ test_concurent_daemon_pair (NULL, aes256_sha, CURL_SSLVERSION_SSLv3);
+
+ print_test_result (errorCount, "concurent_daemon_pair");
+
+ curl_global_cleanup ();
+ fclose (cert);
+ remove (ca_cert_file_name);
+ return errorCount != 0;
+}
Copied: libmicrohttpd/src/testcurl/https/test_https_session_info.c (from rev
26652, libmicrohttpd/src/testcurl/https/mhds_session_info_test.c)
===================================================================
--- libmicrohttpd/src/testcurl/https/test_https_session_info.c
(rev 0)
+++ libmicrohttpd/src/testcurl/https/test_https_session_info.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -0,0 +1,170 @@
+/*
+ This file is part of libmicrohttpd
+ (C) 2007 Christian Grothoff
+
+ libmicrohttpd 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 2, or (at your
+ option) any later version.
+
+ libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file mhds_session_info_test.c
+ * @brief Testcase for libmicrohttpd HTTPS connection querying operations
+ * @author Sagie Amir
+ */
+
+#include "platform.h"
+#include "microhttpd.h"
+#include <curl/curl.h>
+
+#include "tls_test_common.h"
+
+extern int curl_check_version (const char *req_version, ...);
+extern const char srv_key_pem[];
+extern const char srv_self_signed_cert_pem[];
+
+struct MHD_Daemon *d;
+
+/*
+ * HTTP access handler call back
+ * used to query negotiated security parameters
+ */
+static int
+query_session_ahc (void *cls, struct MHD_Connection *connection,
+ const char *url, const char *method,
+ const char *upload_data, const char *version,
+ size_t *upload_data_size, void **ptr)
+{
+ struct MHD_Response *response;
+ int ret;
+
+ if (NULL == *ptr)
+ {
+ *ptr = &query_session_ahc;
+ return MHD_YES;
+ }
+
+ if (GNUTLS_SSL3 !=
+ (ret = MHD_get_connection_info
+ (connection,
+ MHD_CONNECTION_INFO_PROTOCOL)->protocol))
+ {
+ fprintf (stderr, "Error: requested protocol mismatch (wanted %d, got
%d)\n",
+ GNUTLS_SSL3,
+ ret);
+ return -1;
+ }
+
+ response = MHD_create_response_from_buffer (strlen (EMPTY_PAGE),
+ (void *) EMPTY_PAGE,
+ MHD_RESPMEM_PERSISTENT);
+ ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
+ MHD_destroy_response (response);
+ return ret;
+}
+
+
+/**
+ * negotiate a secure connection with server & query negotiated security
parameters
+ */
+static int
+test_query_session ()
+{
+ CURL *c;
+ struct CBC cbc;
+ CURLcode errornum;
+ char url[256];
+
+ if (NULL == (cbc.buf = malloc (sizeof (char) * 255)))
+ return 16;
+ cbc.size = 255;
+ cbc.pos = 0;
+
+ gen_test_file_url (url, DEAMON_TEST_PORT);
+
+ /* setup test */
+ d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
+ MHD_USE_DEBUG, DEAMON_TEST_PORT,
+ NULL, NULL, &query_session_ahc, NULL,
+ MHD_OPTION_HTTPS_PRIORITIES, "NORMAL:+ARCFOUR-128",
+ MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
+ MHD_OPTION_END);
+
+ if (d == NULL)
+ return 2;
+
+ const char *aes256_sha = "AES256-SHA";
+ if (curl_uses_nss_ssl() == 0)
+ {
+ aes256_sha = "rsa_aes_256_sha";
+ }
+
+ c = curl_easy_init ();
+#if DEBUG_HTTPS_TEST
+ curl_easy_setopt (c, CURLOPT_VERBOSE, 1);
+#endif
+ curl_easy_setopt (c, CURLOPT_URL, url);
+ curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
+ curl_easy_setopt (c, CURLOPT_TIMEOUT, 10L);
+ curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 10L);
+ curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
+ curl_easy_setopt (c, CURLOPT_FILE, &cbc);
+ /* TLS options */
+ curl_easy_setopt (c, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3);
+ curl_easy_setopt (c, CURLOPT_SSL_CIPHER_LIST, aes256_sha);
+ /* currently skip any peer authentication */
+ curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0);
+ curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
+
+ // NOTE: use of CONNECTTIMEOUT without also
+ // setting NOSIGNAL results in really weird
+ // crashes on my system!
+ curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
+ if (CURLE_OK != (errornum = curl_easy_perform (c)))
+ {
+ fprintf (stderr, "curl_easy_perform failed: `%s'\n",
+ curl_easy_strerror (errornum));
+
+ MHD_stop_daemon (d);
+ curl_easy_cleanup (c);
+ free (cbc.buf);
+ return -1;
+ }
+
+ curl_easy_cleanup (c);
+ MHD_stop_daemon (d);
+ free (cbc.buf);
+ return 0;
+}
+
+
+int
+main (int argc, char *const *argv)
+{
+ unsigned int errorCount = 0;
+
+ if (0 != curl_global_init (CURL_GLOBAL_ALL))
+ {
+ fprintf (stderr, "Error (code: %u)\n", errorCount);
+ return -1;
+ }
+ errorCount += test_query_session ();
+ print_test_result (errorCount, argv[0]);
+ curl_global_cleanup ();
+ if (errorCount > 0)
+ fprintf (stderr, "Error (code: %u)\n", errorCount);
+ return errorCount;
+}
Copied: libmicrohttpd/src/testcurl/https/test_https_time_out.c (from rev 26652,
libmicrohttpd/src/testcurl/https/tls_session_time_out_test.c)
===================================================================
--- libmicrohttpd/src/testcurl/https/test_https_time_out.c
(rev 0)
+++ libmicrohttpd/src/testcurl/https/test_https_time_out.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -0,0 +1,130 @@
+/*
+ This file is part of libmicrohttpd
+ (C) 2007 Christian Grothoff
+
+ libmicrohttpd 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 2, or (at your
+ option) any later version.
+
+ libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file mhds_get_test.c
+ * @brief: daemon TLS alert response test-case
+ *
+ * @author Sagie Amir
+ */
+
+#include "platform.h"
+#include "microhttpd.h"
+#include "internal.h"
+#include "tls_test_common.h"
+
+extern const char srv_key_pem[];
+extern const char srv_self_signed_cert_pem[];
+
+static const int TIME_OUT = 3;
+
+char *http_get_req = "GET / HTTP/1.1\r\n\r\n";
+
+static int
+test_tls_session_time_out (gnutls_session_t session)
+{
+ int sd, ret;
+ struct sockaddr_in sa;
+
+ sd = socket (AF_INET, SOCK_STREAM, 0);
+ if (sd == -1)
+ {
+ fprintf (stderr, "Failed to create socket: %s\n", strerror (errno));
+ return -1;
+ }
+
+ memset (&sa, '\0', sizeof (struct sockaddr_in));
+ sa.sin_family = AF_INET;
+ sa.sin_port = htons (DEAMON_TEST_PORT);
+ inet_pton (AF_INET, "127.0.0.1", &sa.sin_addr);
+
+ gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) (long) sd);
+
+ ret = connect (sd, &sa, sizeof (struct sockaddr_in));
+
+ if (ret < 0)
+ {
+ fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT);
+ return -1;
+ }
+
+ ret = gnutls_handshake (session);
+ if (ret < 0)
+ {
+ fprintf (stderr, "Handshake failed\n");
+ return -1;
+ }
+
+ sleep (TIME_OUT + 1);
+
+ /* check that server has closed the connection */
+ /* TODO better RST trigger */
+ if (send (sd, "", 1, 0) == 0)
+ {
+ fprintf (stderr, "Connection failed to time-out\n");
+ return -1;
+ }
+
+ close (sd);
+ return 0;
+}
+
+int
+main (int argc, char *const *argv)
+{
+ int errorCount = 0;;
+ struct MHD_Daemon *d;
+ gnutls_session_t session;
+ gnutls_datum_t key;
+ gnutls_datum_t cert;
+ gnutls_certificate_credentials_t xcred;
+
+ gnutls_global_init ();
+ gnutls_global_set_log_level (11);
+
+ d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
+ MHD_USE_DEBUG, DEAMON_TEST_PORT,
+ NULL, NULL, &http_dummy_ahc, NULL,
+ MHD_OPTION_CONNECTION_TIMEOUT, TIME_OUT,
+ MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
+ MHD_OPTION_END);
+
+ if (d == NULL)
+ {
+ fprintf (stderr, MHD_E_SERVER_INIT);
+ return -1;
+ }
+
+ if (0 != setup_session (&session, &key, &cert, &xcred))
+ {
+ fprintf (stderr, "failed to setup session\n");
+ return 1;
+ }
+ errorCount += test_tls_session_time_out (session);
+ teardown_session (session, &key, &cert, xcred);
+
+ print_test_result (errorCount, argv[0]);
+
+ MHD_stop_daemon (d);
+ gnutls_global_deinit ();
+
+ return errorCount != 0;
+}
Copied: libmicrohttpd/src/testcurl/https/test_tls_authentication.c (from rev
26652, libmicrohttpd/src/testcurl/https/tls_authentication_test.c)
===================================================================
--- libmicrohttpd/src/testcurl/https/test_tls_authentication.c
(rev 0)
+++ libmicrohttpd/src/testcurl/https/test_tls_authentication.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -0,0 +1,103 @@
+/*
+ This file is part of libmicrohttpd
+ (C) 2007 Christian Grothoff
+
+ libmicrohttpd 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 2, or (at your
+ option) any later version.
+
+ libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file tls_authentication_test.c
+ * @brief Testcase for libmicrohttpd HTTPS GET operations
+ * @author Sagie Amir
+ */
+
+#include "platform.h"
+#include "microhttpd.h"
+#include <curl/curl.h>
+#include <limits.h>
+#include <sys/stat.h>
+
+#include "tls_test_common.h"
+
+extern int curl_check_version (const char *req_version, ...);
+extern const char test_file_data[];
+
+extern const char ca_key_pem[];
+extern const char ca_cert_pem[];
+extern const char srv_signed_cert_pem[];
+extern const char srv_signed_key_pem[];
+
+
+
+/* perform a HTTP GET request via SSL/TLS */
+static int
+test_secure_get (void * cls, char *cipher_suite, int proto_version)
+{
+ int ret;
+ struct MHD_Daemon *d;
+
+ d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
+ MHD_USE_DEBUG, DEAMON_TEST_PORT,
+ NULL, NULL, &http_ahc, NULL,
+ MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
+ MHD_OPTION_END);
+
+ if (d == NULL)
+ {
+ fprintf (stderr, MHD_E_SERVER_INIT);
+ return -1;
+ }
+
+ ret = test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT,
0);
+
+ MHD_stop_daemon (d);
+ return ret;
+}
+
+
+int
+main (int argc, char *const *argv)
+{
+ unsigned int errorCount = 0;
+
+ if (setup_ca_cert () == NULL)
+ {
+ fprintf (stderr, MHD_E_TEST_FILE_CREAT);
+ return -1;
+ }
+
+ if (0 != curl_global_init (CURL_GLOBAL_ALL))
+ {
+ fprintf (stderr, "Error (code: %u)\n", errorCount);
+ return -1;
+ }
+
+ char *aes256_sha = "AES256-SHA";
+ if (curl_uses_nss_ssl() == 0)
+ {
+ aes256_sha = "rsa_aes_256_sha";
+ }
+
+ errorCount +=
+ test_secure_get (NULL, aes256_sha, CURL_SSLVERSION_TLSv1);
+
+ print_test_result (errorCount, argv[0]);
+
+ curl_global_cleanup ();
+ remove (ca_cert_file_name);
+ return errorCount != 0;
+}
Copied: libmicrohttpd/src/testcurl/https/test_tls_extensions.c (from rev 26652,
libmicrohttpd/src/testcurl/https/tls_extension_test.c)
===================================================================
--- libmicrohttpd/src/testcurl/https/test_tls_extensions.c
(rev 0)
+++ libmicrohttpd/src/testcurl/https/test_tls_extensions.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -0,0 +1,270 @@
+/*
+ This file is part of libmicrohttpd
+ (C) 2007 Christian Grothoff
+
+ libmicrohttpd 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 2, or (at your
+ option) any later version.
+
+ libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file tls_extension_test.c
+ * @brief: test daemon response to TLS client hello requests containing
extensions
+ *
+ * @author Sagie Amir
+ */
+
+#include "platform.h"
+#include "microhttpd.h"
+#include "tls_test_common.h"
+#define MAX_EXT_DATA_LENGTH 256
+
+extern const char srv_key_pem[];
+extern const char srv_self_signed_cert_pem[];
+
+/**
+ * Test daemon response to TLS client hello requests containing extensions
+ *
+ * @param session
+ * @param exten_t - the type of extension being appended to client hello
request
+ * @param ext_count - the number of consecutive extension replicas inserted
into request
+ * @param ext_length - the length of each appended extension
+ * @return 0 on successful test completion, -1 otherwise
+ */
+static int
+test_hello_extension (gnutls_session_t session, extensions_t exten_t,
+ int ext_count, int ext_length)
+{
+ int i, sd, ret = 0, pos = 0;
+ int exten_data_len, ciphersuite_len, datalen;
+ struct sockaddr_in sa;
+ char url[255];
+ opaque *data = NULL;
+ uint8_t session_id_len = 0;
+ opaque rnd[TLS_RANDOM_SIZE];
+ opaque extdata[MAX_EXT_DATA_LENGTH];
+
+ /* single, null compression */
+ unsigned char comp[] = { 0x01, 0x00 };
+ struct CBC cbc;
+
+ sd = -1;
+ memset (&cbc, 0, sizeof (struct CBC));
+ if (NULL == (cbc.buf = malloc (sizeof (char) * 256)))
+ {
+ fprintf (stderr, MHD_E_MEM);
+ ret = -1;
+ goto cleanup;
+ }
+ cbc.size = 256;
+
+ sd = socket (AF_INET, SOCK_STREAM, 0);
+ if (sd == -1)
+ {
+ fprintf(stderr, "Failed to create socket: %s\n", strerror(errno));
+ free (cbc.buf);
+ return -1;
+ }
+ memset (&sa, '\0', sizeof (struct sockaddr_in));
+ sa.sin_family = AF_INET;
+ sa.sin_port = htons (DEAMON_TEST_PORT);
+ inet_pton (AF_INET, "127.0.0.1", &sa.sin_addr);
+
+ enum MHD_GNUTLS_Protocol hver;
+
+ /* init hash functions */
+ session->internals.handshake_mac_handle_md5 =
+ MHD_gtls_hash_init (MHD_GNUTLS_MAC_MD5);
+ session->internals.handshake_mac_handle_sha =
+ MHD_gtls_hash_init (MHD_GNUTLS_MAC_SHA1);
+
+ /* version = 2 , random = [4 for unix time + 28 for random bytes] */
+ datalen = 2 /* version */ + TLS_RANDOM_SIZE + (session_id_len + 1);
+
+ data = MHD_gnutls_malloc (datalen);
+ if (data == NULL)
+ {
+ free (cbc.buf);
+ return -1;
+ }
+ hver = MHD_gtls_version_max (session);
+ data[pos++] = MHD_gtls_version_get_major (hver);
+ data[pos++] = MHD_gtls_version_get_minor (hver);
+
+ /* Set the version we advertise as maximum (RSA uses it). */
+ set_adv_version (session, MHD_gtls_version_get_major (hver),
+ MHD_gtls_version_get_minor (hver));
+
+ session->security_parameters.version = hver;
+ session->security_parameters.timestamp = time (NULL);
+
+ /* generate session client random */
+ memset (session->security_parameters.client_random, 0, TLS_RANDOM_SIZE);
+ gnutls_write_uint32 (time (NULL), rnd);
+ if (GC_OK != MHD_gc_nonce ((char *) &rnd[4], TLS_RANDOM_SIZE - 4)) abort ();
+ memcpy (session->security_parameters.client_random, rnd, TLS_RANDOM_SIZE);
+ memcpy (&data[pos], rnd, TLS_RANDOM_SIZE);
+ pos += TLS_RANDOM_SIZE;
+
+ /* Copy the Session ID */
+ data[pos++] = session_id_len;
+
+ /*
+ * len = ciphersuite data + 2 bytes ciphersuite length \
+ * 1 byte compression length + 1 byte compression data + \
+ * 2 bytes extension length, extensions data
+ */
+ ciphersuite_len = MHD__gnutls_copy_ciphersuites (session, extdata,
+ sizeof (extdata));
+ exten_data_len = ext_count * (2 + 2 + ext_length);
+ datalen += ciphersuite_len + 2 + 2 + exten_data_len;
+ data = MHD_gtls_realloc_fast (data, datalen);
+ memcpy (&data[pos], extdata, sizeof (ciphersuite_len));
+ pos += ciphersuite_len;
+
+ /* set compression */
+ memcpy (&data[pos], comp, sizeof (comp));
+ pos += 2;
+
+ /* set extensions length = 2 type bytes + 2 length bytes + extension length
*/
+ gnutls_write_uint16 (exten_data_len, &data[pos]);
+ pos += 2;
+ for (i = 0; i < ext_count; ++i)
+ {
+ /* write extension type */
+ gnutls_write_uint16 (exten_t, &data[pos]);
+ pos += 2;
+ gnutls_write_uint16 (ext_length, &data[pos]);
+ pos += 2;
+ /* we might want to generate random data here */
+ memset (&data[pos], 0, ext_length);
+ pos += ext_length;
+ }
+
+ if (connect (sd, &sa, sizeof (struct sockaddr_in)) < 0)
+ {
+ fprintf (stderr, "%s\n", MHD_E_FAILED_TO_CONNECT);
+ ret = -1;
+ goto cleanup;
+ }
+
+ gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) (long) sd);
+
+ if (gen_test_file_url (url, DEAMON_TEST_PORT))
+ {
+ ret = -1;
+ goto cleanup;
+ }
+
+ /* this should crash the server */
+ ret = gnutls_send_handshake (session, data, datalen,
+ GNUTLS_HANDSHAKE_CLIENT_HELLO);
+
+ /* advance to STATE2 */
+ session->internals.handshake_state = STATE2;
+ ret = gnutls_handshake (session);
+ ret = gnutls_bye (session, GNUTLS_SHUT_WR);
+
+ gnutls_free (data);
+
+ /* make sure daemon is still functioning */
+ if (CURLE_OK != send_curl_req (url, &cbc, "AES128-SHA",
+ MHD_GNUTLS_PROTOCOL_TLS1_2))
+ {
+ ret = -1;
+ goto cleanup;
+ }
+
+cleanup:
+ if (sd != -1)
+ close (sd);
+ gnutls_free (cbc.buf);
+ return ret;
+}
+
+int
+main (int argc, char *const *argv)
+{
+ int i, errorCount = 0;
+ FILE *test_fd;
+ struct MHD_Daemon *d;
+ gnutls_session_t session;
+ gnutls_datum_t key;
+ gnutls_datum_t cert;
+ gnutls_certificate_credentials_t xcred;
+
+ int ext_arr[] = { GNUTLS_EXTENSION_SERVER_NAME,
+ -1
+ };
+
+ MHD_gtls_global_set_log_level (11);
+
+ if ((test_fd = setup_test_file ()) == NULL)
+ {
+ fprintf (stderr, MHD_E_TEST_FILE_CREAT);
+ return -1;
+ }
+
+ if (0 != curl_global_init (CURL_GLOBAL_ALL))
+ {
+ fprintf (stderr, "Error: %s\n", strerror (errno));
+ return -1;
+ }
+
+ d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
+ MHD_USE_DEBUG, DEAMON_TEST_PORT,
+ NULL, NULL, &http_ahc, NULL,
+ MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
+ MHD_OPTION_END);
+
+ if (d == NULL)
+ {
+ fprintf (stderr, "%s\n", MHD_E_SERVER_INIT);
+ return -1;
+ }
+
+ i = 0;
+ setup_session (&session, &key, &cert, &xcred);
+ errorCount += test_hello_extension (session, ext_arr[i], 1, 16);
+ teardown_session (session, &key, &cert, xcred);
+#if 1
+ i = 0;
+ while (ext_arr[i] != -1)
+ {
+ setup_session (&session, &key, &cert, &xcred);
+ errorCount += test_hello_extension (session, ext_arr[i], 1, 16);
+ teardown_session (session, &key, &cert, xcred);
+
+ setup_session (&session, &key, &cert, &xcred);
+ errorCount += test_hello_extension (session, ext_arr[i], 3, 8);
+ teardown_session (session, &key, &cert, xcred);
+
+ /* this test specifically tests the issue raised in CVE-2008-1948 */
+ setup_session (&session, &key, &cert, &xcred);
+ errorCount += test_hello_extension (session, ext_arr[i], 6, 0);
+ teardown_session (session, &key, &cert, xcred);
+ i++;
+ }
+#endif
+
+ print_test_result (errorCount, argv[0]);
+
+ MHD_stop_daemon (d);
+
+ curl_global_cleanup ();
+ fclose (test_fd);
+
+ return errorCount;
+}
Copied: libmicrohttpd/src/testcurl/https/test_tls_options.c (from rev 26652,
libmicrohttpd/src/testcurl/https/tls_daemon_options_test.c)
===================================================================
--- libmicrohttpd/src/testcurl/https/test_tls_options.c
(rev 0)
+++ libmicrohttpd/src/testcurl/https/test_tls_options.c 2013-03-29 16:16:02 UTC
(rev 26658)
@@ -0,0 +1,186 @@
+/*
+ This file is part of libmicrohttpd
+ (C) 2007, 2010 Christian Grothoff
+
+ libmicrohttpd 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 2, or (at your
+ option) any later version.
+
+ libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file tls_daemon_options_test.c
+ * @brief Testcase for libmicrohttpd HTTPS GET operations
+ * @author Sagie Amir
+ */
+
+#include "platform.h"
+#include "microhttpd.h"
+#include <sys/stat.h>
+#include <limits.h>
+#include <gcrypt.h>
+#include "tls_test_common.h"
+
+extern const char srv_key_pem[];
+extern const char srv_self_signed_cert_pem[];
+
+int curl_check_version (const char *req_version, ...);
+
+/**
+ * test server refuses to negotiate connections with unsupported protocol
versions
+ *
+ */
+static int
+test_unmatching_ssl_version (void * cls, const char *cipher_suite,
+ int curl_req_ssl_version)
+{
+ struct CBC cbc;
+ if (NULL == (cbc.buf = malloc (sizeof (char) * 256)))
+ {
+ fprintf (stderr, "Error: failed to allocate: %s\n",
+ strerror (errno));
+ return -1;
+ }
+ cbc.size = 256;
+ cbc.pos = 0;
+
+ char url[255];
+ if (gen_test_file_url (url, DEAMON_TEST_PORT))
+ {
+ free (cbc.buf);
+ fprintf (stderr, "Internal error in gen_test_file_url\n");
+ return -1;
+ }
+
+ /* assert daemon *rejected* request */
+ if (CURLE_OK ==
+ send_curl_req (url, &cbc, cipher_suite, curl_req_ssl_version))
+ {
+ free (cbc.buf);
+ fprintf (stderr, "cURL failed to reject request despite SSL version
missmatch!\n");
+ return -1;
+ }
+
+ free (cbc.buf);
+ return 0;
+}
+
+/* setup a temporary transfer test file */
+int
+main (int argc, char *const *argv)
+{
+ unsigned int errorCount = 0;
+
+ int daemon_flags =
+ MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL | MHD_USE_DEBUG;
+ gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
+ gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
+ if (curl_check_version (MHD_REQ_CURL_VERSION))
+ {
+ return 0;
+ }
+
+ if (0 != curl_global_init (CURL_GLOBAL_ALL))
+ {
+ fprintf (stderr, "Error: %s\n", strerror (errno));
+ return 0;
+ }
+
+ const char *aes128_sha = "AES128-SHA";
+ const char *aes256_sha = "AES256-SHA";
+ if (curl_uses_nss_ssl() == 0)
+ {
+ aes128_sha = "rsa_aes_128_sha";
+ aes256_sha = "rsa_aes_256_sha";
+ }
+
+
+ if (0 !=
+ test_wrap ("TLS1.0-AES-SHA1",
+ &test_https_transfer, NULL, daemon_flags,
+ aes128_sha,
+ CURL_SSLVERSION_TLSv1,
+ MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
+ MHD_OPTION_HTTPS_PRIORITIES,
"NONE:+VERS-TLS1.0:+AES-128-CBC:+SHA1:+RSA:+COMP-NULL",
+ MHD_OPTION_END))
+ {
+ fprintf (stderr, "TLS1.0-AES-SHA1 test failed\n");
+ errorCount++;
+ }
+#if 0
+ /* this used to work, but somehow no longer. gnutls issue? */
+ if (0 !=
+ test_wrap ("SSL3.0-AES256-SHA1",
+ &test_https_transfer, NULL, daemon_flags,
+ aes256_sha,
+ CURL_SSLVERSION_SSLv3,
+ MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
+ MHD_OPTION_HTTPS_PRIORITIES,
"NONE:+VERS-SSL3.0:+AES-256-CBC:+SHA1:+RSA:+COMP-NULL",
+ MHD_OPTION_END))
+ {
+ fprintf (stderr, "SSL3.0-AES256-SHA1 test failed\n");
+ errorCount++;
+ }
+ if (0 !=
+ test_wrap ("SSL3.0-AES-SHA1",
+ &test_https_transfer, NULL, daemon_flags,
+ aes128_sha,
+ CURL_SSLVERSION_SSLv3,
+ MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
+ MHD_OPTION_HTTPS_PRIORITIES,
"NONE:+VERS-SSL3.0:+AES-128-CBC:+SHA1:+RSA:+COMP-NULL",
+ MHD_OPTION_END))
+ {
+ fprintf (stderr, "SSL3.0-AES-SHA1 test failed\n");
+ errorCount++;
+ }
+#endif
+
+
+#if 0
+ /* manual inspection of the handshake suggests that CURL will
+ request TLSv1, we send back "SSL3" and CURL takes it *despite*
+ being configured to speak SSL3-only. Notably, the other way
+ round (have curl request SSL3, respond with TLSv1 only)
+ is properly refused by CURL. Either way, this does NOT seem
+ to be a bug in MHD/gnuTLS but rather in CURL; hence this
+ test is commented out here... */
+ errorCount +=
+ test_wrap ("unmatching version: SSL3 vs. TLS",
&test_unmatching_ssl_version,
+ NULL, daemon_flags, "AES256-SHA", CURL_SSLVERSION_TLSv1,
+ MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
+ MHD_OPTION_CIPHER_ALGORITHM, "SSL3", MHD_OPTION_END);
+#endif
+
+ fprintf (stderr,
+ "The following handshake should fail (and print an error
message)...\n");
+ if (0 !=
+ test_wrap ("TLS1.0 vs SSL3",
+ &test_unmatching_ssl_version, NULL, daemon_flags,
+ aes256_sha,
+ CURL_SSLVERSION_SSLv3,
+ MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
+ MHD_OPTION_HTTPS_PRIORITIES,
"NONE:+VERS-TLS1.0:+AES-256-CBC:+SHA1:+RSA:+COMP-NULL",
+ MHD_OPTION_END))
+ {
+ fprintf (stderr, "TLS1.0 vs SSL3 test failed\n");
+ errorCount++;
+ }
+ curl_global_cleanup ();
+
+ return errorCount != 0;
+}
Deleted: libmicrohttpd/src/testcurl/https/tls_authentication_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/tls_authentication_test.c 2013-03-29
15:59:58 UTC (rev 26657)
+++ libmicrohttpd/src/testcurl/https/tls_authentication_test.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -1,103 +0,0 @@
-/*
- This file is part of libmicrohttpd
- (C) 2007 Christian Grothoff
-
- libmicrohttpd 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 2, or (at your
- option) any later version.
-
- libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file tls_authentication_test.c
- * @brief Testcase for libmicrohttpd HTTPS GET operations
- * @author Sagie Amir
- */
-
-#include "platform.h"
-#include "microhttpd.h"
-#include <curl/curl.h>
-#include <limits.h>
-#include <sys/stat.h>
-
-#include "tls_test_common.h"
-
-extern int curl_check_version (const char *req_version, ...);
-extern const char test_file_data[];
-
-extern const char ca_key_pem[];
-extern const char ca_cert_pem[];
-extern const char srv_signed_cert_pem[];
-extern const char srv_signed_key_pem[];
-
-
-
-/* perform a HTTP GET request via SSL/TLS */
-static int
-test_secure_get (void * cls, char *cipher_suite, int proto_version)
-{
- int ret;
- struct MHD_Daemon *d;
-
- d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
- MHD_USE_DEBUG, DEAMON_TEST_PORT,
- NULL, NULL, &http_ahc, NULL,
- MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
- MHD_OPTION_END);
-
- if (d == NULL)
- {
- fprintf (stderr, MHD_E_SERVER_INIT);
- return -1;
- }
-
- ret = test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT,
0);
-
- MHD_stop_daemon (d);
- return ret;
-}
-
-
-int
-main (int argc, char *const *argv)
-{
- unsigned int errorCount = 0;
-
- if (setup_ca_cert () == NULL)
- {
- fprintf (stderr, MHD_E_TEST_FILE_CREAT);
- return -1;
- }
-
- if (0 != curl_global_init (CURL_GLOBAL_ALL))
- {
- fprintf (stderr, "Error (code: %u)\n", errorCount);
- return -1;
- }
-
- char *aes256_sha = "AES256-SHA";
- if (curl_uses_nss_ssl() == 0)
- {
- aes256_sha = "rsa_aes_256_sha";
- }
-
- errorCount +=
- test_secure_get (NULL, aes256_sha, CURL_SSLVERSION_TLSv1);
-
- print_test_result (errorCount, argv[0]);
-
- curl_global_cleanup ();
- remove (ca_cert_file_name);
- return errorCount != 0;
-}
Deleted: libmicrohttpd/src/testcurl/https/tls_daemon_options_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/tls_daemon_options_test.c 2013-03-29
15:59:58 UTC (rev 26657)
+++ libmicrohttpd/src/testcurl/https/tls_daemon_options_test.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -1,186 +0,0 @@
-/*
- This file is part of libmicrohttpd
- (C) 2007, 2010 Christian Grothoff
-
- libmicrohttpd 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 2, or (at your
- option) any later version.
-
- libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file tls_daemon_options_test.c
- * @brief Testcase for libmicrohttpd HTTPS GET operations
- * @author Sagie Amir
- */
-
-#include "platform.h"
-#include "microhttpd.h"
-#include <sys/stat.h>
-#include <limits.h>
-#include <gcrypt.h>
-#include "tls_test_common.h"
-
-extern const char srv_key_pem[];
-extern const char srv_self_signed_cert_pem[];
-
-int curl_check_version (const char *req_version, ...);
-
-/**
- * test server refuses to negotiate connections with unsupported protocol
versions
- *
- */
-static int
-test_unmatching_ssl_version (void * cls, const char *cipher_suite,
- int curl_req_ssl_version)
-{
- struct CBC cbc;
- if (NULL == (cbc.buf = malloc (sizeof (char) * 256)))
- {
- fprintf (stderr, "Error: failed to allocate: %s\n",
- strerror (errno));
- return -1;
- }
- cbc.size = 256;
- cbc.pos = 0;
-
- char url[255];
- if (gen_test_file_url (url, DEAMON_TEST_PORT))
- {
- free (cbc.buf);
- fprintf (stderr, "Internal error in gen_test_file_url\n");
- return -1;
- }
-
- /* assert daemon *rejected* request */
- if (CURLE_OK ==
- send_curl_req (url, &cbc, cipher_suite, curl_req_ssl_version))
- {
- free (cbc.buf);
- fprintf (stderr, "cURL failed to reject request despite SSL version
missmatch!\n");
- return -1;
- }
-
- free (cbc.buf);
- return 0;
-}
-
-/* setup a temporary transfer test file */
-int
-main (int argc, char *const *argv)
-{
- unsigned int errorCount = 0;
-
- int daemon_flags =
- MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL | MHD_USE_DEBUG;
- gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
- gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
- if (curl_check_version (MHD_REQ_CURL_VERSION))
- {
- return 0;
- }
-
- if (0 != curl_global_init (CURL_GLOBAL_ALL))
- {
- fprintf (stderr, "Error: %s\n", strerror (errno));
- return 0;
- }
-
- const char *aes128_sha = "AES128-SHA";
- const char *aes256_sha = "AES256-SHA";
- if (curl_uses_nss_ssl() == 0)
- {
- aes128_sha = "rsa_aes_128_sha";
- aes256_sha = "rsa_aes_256_sha";
- }
-
-
- if (0 !=
- test_wrap ("TLS1.0-AES-SHA1",
- &test_https_transfer, NULL, daemon_flags,
- aes128_sha,
- CURL_SSLVERSION_TLSv1,
- MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
- MHD_OPTION_HTTPS_PRIORITIES,
"NONE:+VERS-TLS1.0:+AES-128-CBC:+SHA1:+RSA:+COMP-NULL",
- MHD_OPTION_END))
- {
- fprintf (stderr, "TLS1.0-AES-SHA1 test failed\n");
- errorCount++;
- }
-#if 0
- /* this used to work, but somehow no longer. gnutls issue? */
- if (0 !=
- test_wrap ("SSL3.0-AES256-SHA1",
- &test_https_transfer, NULL, daemon_flags,
- aes256_sha,
- CURL_SSLVERSION_SSLv3,
- MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
- MHD_OPTION_HTTPS_PRIORITIES,
"NONE:+VERS-SSL3.0:+AES-256-CBC:+SHA1:+RSA:+COMP-NULL",
- MHD_OPTION_END))
- {
- fprintf (stderr, "SSL3.0-AES256-SHA1 test failed\n");
- errorCount++;
- }
- if (0 !=
- test_wrap ("SSL3.0-AES-SHA1",
- &test_https_transfer, NULL, daemon_flags,
- aes128_sha,
- CURL_SSLVERSION_SSLv3,
- MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
- MHD_OPTION_HTTPS_PRIORITIES,
"NONE:+VERS-SSL3.0:+AES-128-CBC:+SHA1:+RSA:+COMP-NULL",
- MHD_OPTION_END))
- {
- fprintf (stderr, "SSL3.0-AES-SHA1 test failed\n");
- errorCount++;
- }
-#endif
-
-
-#if 0
- /* manual inspection of the handshake suggests that CURL will
- request TLSv1, we send back "SSL3" and CURL takes it *despite*
- being configured to speak SSL3-only. Notably, the other way
- round (have curl request SSL3, respond with TLSv1 only)
- is properly refused by CURL. Either way, this does NOT seem
- to be a bug in MHD/gnuTLS but rather in CURL; hence this
- test is commented out here... */
- errorCount +=
- test_wrap ("unmatching version: SSL3 vs. TLS",
&test_unmatching_ssl_version,
- NULL, daemon_flags, "AES256-SHA", CURL_SSLVERSION_TLSv1,
- MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
- MHD_OPTION_CIPHER_ALGORITHM, "SSL3", MHD_OPTION_END);
-#endif
-
- fprintf (stderr,
- "The following handshake should fail (and print an error
message)...\n");
- if (0 !=
- test_wrap ("TLS1.0 vs SSL3",
- &test_unmatching_ssl_version, NULL, daemon_flags,
- aes256_sha,
- CURL_SSLVERSION_SSLv3,
- MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
- MHD_OPTION_HTTPS_PRIORITIES,
"NONE:+VERS-TLS1.0:+AES-256-CBC:+SHA1:+RSA:+COMP-NULL",
- MHD_OPTION_END))
- {
- fprintf (stderr, "TLS1.0 vs SSL3 test failed\n");
- errorCount++;
- }
- curl_global_cleanup ();
-
- return errorCount != 0;
-}
Deleted: libmicrohttpd/src/testcurl/https/tls_extension_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/tls_extension_test.c 2013-03-29
15:59:58 UTC (rev 26657)
+++ libmicrohttpd/src/testcurl/https/tls_extension_test.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -1,270 +0,0 @@
-/*
- This file is part of libmicrohttpd
- (C) 2007 Christian Grothoff
-
- libmicrohttpd 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 2, or (at your
- option) any later version.
-
- libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file tls_extension_test.c
- * @brief: test daemon response to TLS client hello requests containing
extensions
- *
- * @author Sagie Amir
- */
-
-#include "platform.h"
-#include "microhttpd.h"
-#include "tls_test_common.h"
-#define MAX_EXT_DATA_LENGTH 256
-
-extern const char srv_key_pem[];
-extern const char srv_self_signed_cert_pem[];
-
-/**
- * Test daemon response to TLS client hello requests containing extensions
- *
- * @param session
- * @param exten_t - the type of extension being appended to client hello
request
- * @param ext_count - the number of consecutive extension replicas inserted
into request
- * @param ext_length - the length of each appended extension
- * @return 0 on successful test completion, -1 otherwise
- */
-static int
-test_hello_extension (gnutls_session_t session, extensions_t exten_t,
- int ext_count, int ext_length)
-{
- int i, sd, ret = 0, pos = 0;
- int exten_data_len, ciphersuite_len, datalen;
- struct sockaddr_in sa;
- char url[255];
- opaque *data = NULL;
- uint8_t session_id_len = 0;
- opaque rnd[TLS_RANDOM_SIZE];
- opaque extdata[MAX_EXT_DATA_LENGTH];
-
- /* single, null compression */
- unsigned char comp[] = { 0x01, 0x00 };
- struct CBC cbc;
-
- sd = -1;
- memset (&cbc, 0, sizeof (struct CBC));
- if (NULL == (cbc.buf = malloc (sizeof (char) * 256)))
- {
- fprintf (stderr, MHD_E_MEM);
- ret = -1;
- goto cleanup;
- }
- cbc.size = 256;
-
- sd = socket (AF_INET, SOCK_STREAM, 0);
- if (sd == -1)
- {
- fprintf(stderr, "Failed to create socket: %s\n", strerror(errno));
- free (cbc.buf);
- return -1;
- }
- memset (&sa, '\0', sizeof (struct sockaddr_in));
- sa.sin_family = AF_INET;
- sa.sin_port = htons (DEAMON_TEST_PORT);
- inet_pton (AF_INET, "127.0.0.1", &sa.sin_addr);
-
- enum MHD_GNUTLS_Protocol hver;
-
- /* init hash functions */
- session->internals.handshake_mac_handle_md5 =
- MHD_gtls_hash_init (MHD_GNUTLS_MAC_MD5);
- session->internals.handshake_mac_handle_sha =
- MHD_gtls_hash_init (MHD_GNUTLS_MAC_SHA1);
-
- /* version = 2 , random = [4 for unix time + 28 for random bytes] */
- datalen = 2 /* version */ + TLS_RANDOM_SIZE + (session_id_len + 1);
-
- data = MHD_gnutls_malloc (datalen);
- if (data == NULL)
- {
- free (cbc.buf);
- return -1;
- }
- hver = MHD_gtls_version_max (session);
- data[pos++] = MHD_gtls_version_get_major (hver);
- data[pos++] = MHD_gtls_version_get_minor (hver);
-
- /* Set the version we advertise as maximum (RSA uses it). */
- set_adv_version (session, MHD_gtls_version_get_major (hver),
- MHD_gtls_version_get_minor (hver));
-
- session->security_parameters.version = hver;
- session->security_parameters.timestamp = time (NULL);
-
- /* generate session client random */
- memset (session->security_parameters.client_random, 0, TLS_RANDOM_SIZE);
- gnutls_write_uint32 (time (NULL), rnd);
- if (GC_OK != MHD_gc_nonce ((char *) &rnd[4], TLS_RANDOM_SIZE - 4)) abort ();
- memcpy (session->security_parameters.client_random, rnd, TLS_RANDOM_SIZE);
- memcpy (&data[pos], rnd, TLS_RANDOM_SIZE);
- pos += TLS_RANDOM_SIZE;
-
- /* Copy the Session ID */
- data[pos++] = session_id_len;
-
- /*
- * len = ciphersuite data + 2 bytes ciphersuite length \
- * 1 byte compression length + 1 byte compression data + \
- * 2 bytes extension length, extensions data
- */
- ciphersuite_len = MHD__gnutls_copy_ciphersuites (session, extdata,
- sizeof (extdata));
- exten_data_len = ext_count * (2 + 2 + ext_length);
- datalen += ciphersuite_len + 2 + 2 + exten_data_len;
- data = MHD_gtls_realloc_fast (data, datalen);
- memcpy (&data[pos], extdata, sizeof (ciphersuite_len));
- pos += ciphersuite_len;
-
- /* set compression */
- memcpy (&data[pos], comp, sizeof (comp));
- pos += 2;
-
- /* set extensions length = 2 type bytes + 2 length bytes + extension length
*/
- gnutls_write_uint16 (exten_data_len, &data[pos]);
- pos += 2;
- for (i = 0; i < ext_count; ++i)
- {
- /* write extension type */
- gnutls_write_uint16 (exten_t, &data[pos]);
- pos += 2;
- gnutls_write_uint16 (ext_length, &data[pos]);
- pos += 2;
- /* we might want to generate random data here */
- memset (&data[pos], 0, ext_length);
- pos += ext_length;
- }
-
- if (connect (sd, &sa, sizeof (struct sockaddr_in)) < 0)
- {
- fprintf (stderr, "%s\n", MHD_E_FAILED_TO_CONNECT);
- ret = -1;
- goto cleanup;
- }
-
- gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) (long) sd);
-
- if (gen_test_file_url (url, DEAMON_TEST_PORT))
- {
- ret = -1;
- goto cleanup;
- }
-
- /* this should crash the server */
- ret = gnutls_send_handshake (session, data, datalen,
- GNUTLS_HANDSHAKE_CLIENT_HELLO);
-
- /* advance to STATE2 */
- session->internals.handshake_state = STATE2;
- ret = gnutls_handshake (session);
- ret = gnutls_bye (session, GNUTLS_SHUT_WR);
-
- gnutls_free (data);
-
- /* make sure daemon is still functioning */
- if (CURLE_OK != send_curl_req (url, &cbc, "AES128-SHA",
- MHD_GNUTLS_PROTOCOL_TLS1_2))
- {
- ret = -1;
- goto cleanup;
- }
-
-cleanup:
- if (sd != -1)
- close (sd);
- gnutls_free (cbc.buf);
- return ret;
-}
-
-int
-main (int argc, char *const *argv)
-{
- int i, errorCount = 0;
- FILE *test_fd;
- struct MHD_Daemon *d;
- gnutls_session_t session;
- gnutls_datum_t key;
- gnutls_datum_t cert;
- gnutls_certificate_credentials_t xcred;
-
- int ext_arr[] = { GNUTLS_EXTENSION_SERVER_NAME,
- -1
- };
-
- MHD_gtls_global_set_log_level (11);
-
- if ((test_fd = setup_test_file ()) == NULL)
- {
- fprintf (stderr, MHD_E_TEST_FILE_CREAT);
- return -1;
- }
-
- if (0 != curl_global_init (CURL_GLOBAL_ALL))
- {
- fprintf (stderr, "Error: %s\n", strerror (errno));
- return -1;
- }
-
- d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
- MHD_USE_DEBUG, DEAMON_TEST_PORT,
- NULL, NULL, &http_ahc, NULL,
- MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
- MHD_OPTION_END);
-
- if (d == NULL)
- {
- fprintf (stderr, "%s\n", MHD_E_SERVER_INIT);
- return -1;
- }
-
- i = 0;
- setup_session (&session, &key, &cert, &xcred);
- errorCount += test_hello_extension (session, ext_arr[i], 1, 16);
- teardown_session (session, &key, &cert, xcred);
-#if 1
- i = 0;
- while (ext_arr[i] != -1)
- {
- setup_session (&session, &key, &cert, &xcred);
- errorCount += test_hello_extension (session, ext_arr[i], 1, 16);
- teardown_session (session, &key, &cert, xcred);
-
- setup_session (&session, &key, &cert, &xcred);
- errorCount += test_hello_extension (session, ext_arr[i], 3, 8);
- teardown_session (session, &key, &cert, xcred);
-
- /* this test specifically tests the issue raised in CVE-2008-1948 */
- setup_session (&session, &key, &cert, &xcred);
- errorCount += test_hello_extension (session, ext_arr[i], 6, 0);
- teardown_session (session, &key, &cert, xcred);
- i++;
- }
-#endif
-
- print_test_result (errorCount, argv[0]);
-
- MHD_stop_daemon (d);
-
- curl_global_cleanup ();
- fclose (test_fd);
-
- return errorCount;
-}
Deleted: libmicrohttpd/src/testcurl/https/tls_multi_thread_mode_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/tls_multi_thread_mode_test.c
2013-03-29 15:59:58 UTC (rev 26657)
+++ libmicrohttpd/src/testcurl/https/tls_multi_thread_mode_test.c
2013-03-29 16:16:02 UTC (rev 26658)
@@ -1,178 +0,0 @@
-/*
- This file is part of libmicrohttpd
- (C) 2007 Christian Grothoff
-
- libmicrohttpd 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 2, or (at your
- option) any later version.
-
- libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file tls_thread_mode_test.c
- * @brief Testcase for libmicrohttpd HTTPS GET operations
- * @author Sagie Amir
- * @author Christian Grothoff
- *
- * TODO: add test for external select!
- */
-
-#include "platform.h"
-#include "microhttpd.h"
-#include <sys/stat.h>
-#include <limits.h>
-#include <curl/curl.h>
-#include "tls_test_common.h"
-
-extern const char srv_key_pem[];
-extern const char srv_self_signed_cert_pem[];
-
-int curl_check_version (const char *req_version, ...);
-
-/**
- * used when spawning multiple threads executing curl server requests
- *
- */
-static void *
-https_transfer_thread_adapter (void *args)
-{
- static int nonnull;
- struct https_test_data *cargs = args;
- int ret;
-
- /* time spread incomming requests */
- usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX));
- ret = test_https_transfer (cargs->cls,
- cargs->cipher_suite, cargs->proto_version);
- if (ret == 0)
- return NULL;
- return &nonnull;
-}
-
-/**
- * Test non-parallel requests.
- *
- * @return: 0 upon all client requests returning '0', -1 otherwise.
- *
- * TODO : make client_count a parameter - numver of curl client threads to
spawn
- */
-static int
-test_single_client (void *cls, const char *cipher_suite,
- int curl_proto_version)
-{
- void *client_thread_ret;
- struct https_test_data client_args =
- { NULL, cipher_suite, curl_proto_version };
-
- client_thread_ret = https_transfer_thread_adapter (&client_args);
- if (client_thread_ret != NULL)
- return -1;
- return 0;
-}
-
-
-/**
- * Test parallel request handling.
- *
- * @return: 0 upon all client requests returning '0', -1 otherwise.
- *
- * TODO : make client_count a parameter - numver of curl client threads to
spawn
- */
-static int
-test_parallel_clients (void *cls, const char *cipher_suite,
- int curl_proto_version)
-{
- int i;
- int client_count = 3;
- void *client_thread_ret;
- pthread_t client_arr[client_count];
- struct https_test_data client_args =
- { NULL, cipher_suite, curl_proto_version };
-
- for (i = 0; i < client_count; ++i)
- {
- if (pthread_create (&client_arr[i], NULL,
- &https_transfer_thread_adapter, &client_args) != 0)
- {
- fprintf (stderr, "Error: failed to spawn test client threads.\n");
-
- return -1;
- }
- }
-
- /* check all client requests fulfilled correctly */
- for (i = 0; i < client_count; ++i)
- {
- if ((pthread_join (client_arr[i], &client_thread_ret) != 0) ||
- (client_thread_ret != NULL))
- return -1;
- }
-
- return 0;
-}
-
-
-int
-main (int argc, char *const *argv)
-{
- unsigned int errorCount = 0;
- const char *ssl_version;
-
- /* initialize random seed used by curl clients */
- unsigned int iseed = (unsigned int) time (NULL);
- srand (iseed);
- ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version;
- if (NULL == ssl_version)
- {
- fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n");
- return 0;
- }
- if (NULL != strcasestr (ssl_version, "openssl"))
- {
- fprintf (stderr, "Refusing to run test with OpenSSL. Please install
libcurl-gnutls\n");
- return 0;
- }
- if (0 != curl_global_init (CURL_GLOBAL_ALL))
- {
- fprintf (stderr, "Error: %s\n", strerror (errno));
- return -1;
- }
-
- char *aes256_sha = "AES256-SHA";
- if (curl_uses_nss_ssl() == 0)
- {
- aes256_sha = "rsa_aes_256_sha";
- }
-
- errorCount +=
- test_wrap ("multi threaded daemon, single client", &test_single_client,
- NULL,
- MHD_USE_SSL | MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION,
- aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
- srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
- srv_self_signed_cert_pem, MHD_OPTION_END);
-
- errorCount +=
- test_wrap ("multi threaded daemon, parallel client",
- &test_parallel_clients, NULL,
- MHD_USE_SSL | MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION,
- aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
- srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
- srv_self_signed_cert_pem, MHD_OPTION_END);
-
- if (errorCount != 0)
- fprintf (stderr, "Failed test: %s.\n", argv[0]);
-
- curl_global_cleanup ();
- return errorCount != 0;
-}
Deleted: libmicrohttpd/src/testcurl/https/tls_session_time_out_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/tls_session_time_out_test.c
2013-03-29 15:59:58 UTC (rev 26657)
+++ libmicrohttpd/src/testcurl/https/tls_session_time_out_test.c
2013-03-29 16:16:02 UTC (rev 26658)
@@ -1,130 +0,0 @@
-/*
- This file is part of libmicrohttpd
- (C) 2007 Christian Grothoff
-
- libmicrohttpd 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 2, or (at your
- option) any later version.
-
- libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file mhds_get_test.c
- * @brief: daemon TLS alert response test-case
- *
- * @author Sagie Amir
- */
-
-#include "platform.h"
-#include "microhttpd.h"
-#include "internal.h"
-#include "tls_test_common.h"
-
-extern const char srv_key_pem[];
-extern const char srv_self_signed_cert_pem[];
-
-static const int TIME_OUT = 3;
-
-char *http_get_req = "GET / HTTP/1.1\r\n\r\n";
-
-static int
-test_tls_session_time_out (gnutls_session_t session)
-{
- int sd, ret;
- struct sockaddr_in sa;
-
- sd = socket (AF_INET, SOCK_STREAM, 0);
- if (sd == -1)
- {
- fprintf (stderr, "Failed to create socket: %s\n", strerror (errno));
- return -1;
- }
-
- memset (&sa, '\0', sizeof (struct sockaddr_in));
- sa.sin_family = AF_INET;
- sa.sin_port = htons (DEAMON_TEST_PORT);
- inet_pton (AF_INET, "127.0.0.1", &sa.sin_addr);
-
- gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) (long) sd);
-
- ret = connect (sd, &sa, sizeof (struct sockaddr_in));
-
- if (ret < 0)
- {
- fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT);
- return -1;
- }
-
- ret = gnutls_handshake (session);
- if (ret < 0)
- {
- fprintf (stderr, "Handshake failed\n");
- return -1;
- }
-
- sleep (TIME_OUT + 1);
-
- /* check that server has closed the connection */
- /* TODO better RST trigger */
- if (send (sd, "", 1, 0) == 0)
- {
- fprintf (stderr, "Connection failed to time-out\n");
- return -1;
- }
-
- close (sd);
- return 0;
-}
-
-int
-main (int argc, char *const *argv)
-{
- int errorCount = 0;;
- struct MHD_Daemon *d;
- gnutls_session_t session;
- gnutls_datum_t key;
- gnutls_datum_t cert;
- gnutls_certificate_credentials_t xcred;
-
- gnutls_global_init ();
- gnutls_global_set_log_level (11);
-
- d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
- MHD_USE_DEBUG, DEAMON_TEST_PORT,
- NULL, NULL, &http_dummy_ahc, NULL,
- MHD_OPTION_CONNECTION_TIMEOUT, TIME_OUT,
- MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
- MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
- MHD_OPTION_END);
-
- if (d == NULL)
- {
- fprintf (stderr, MHD_E_SERVER_INIT);
- return -1;
- }
-
- if (0 != setup_session (&session, &key, &cert, &xcred))
- {
- fprintf (stderr, "failed to setup session\n");
- return 1;
- }
- errorCount += test_tls_session_time_out (session);
- teardown_session (session, &key, &cert, xcred);
-
- print_test_result (errorCount, argv[0]);
-
- MHD_stop_daemon (d);
- gnutls_global_deinit ();
-
- return errorCount != 0;
-}
Deleted: libmicrohttpd/src/testcurl/https/tls_thread_mode_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/tls_thread_mode_test.c 2013-03-29
15:59:58 UTC (rev 26657)
+++ libmicrohttpd/src/testcurl/https/tls_thread_mode_test.c 2013-03-29
16:16:02 UTC (rev 26658)
@@ -1,164 +0,0 @@
-/*
- This file is part of libmicrohttpd
- (C) 2007 Christian Grothoff
-
- libmicrohttpd 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 2, or (at your
- option) any later version.
-
- libmicrohttpd 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 libmicrohttpd; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file tls_thread_mode_test.c
- * @brief Testcase for libmicrohttpd HTTPS GET operations
- * @author Sagie Amir
- * @author Christian Grothoff
- *
- * TODO: add test for external select!
- */
-
-#include "platform.h"
-#include "microhttpd.h"
-#include <sys/stat.h>
-#include <limits.h>
-#include <curl/curl.h>
-#include <gcrypt.h>
-#include "tls_test_common.h"
-
-extern const char srv_key_pem[];
-extern const char srv_self_signed_cert_pem[];
-
-int curl_check_version (const char *req_version, ...);
-
-/**
- * used when spawning multiple threads executing curl server requests
- *
- */
-static void *
-https_transfer_thread_adapter (void *args)
-{
- static int nonnull;
- struct https_test_data *cargs = args;
- int ret;
-
- /* time spread incomming requests */
- usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX));
- ret = test_https_transfer (NULL,
- cargs->cipher_suite, cargs->proto_version);
- if (ret == 0)
- return NULL;
- return &nonnull;
-}
-
-/**
- * Test non-parallel requests.
- *
- * @return: 0 upon all client requests returning '0', -1 otherwise.
- *
- * TODO : make client_count a parameter - numver of curl client threads to
spawn
- */
-static int
-test_single_client (void *cls, const char *cipher_suite,
- int curl_proto_version)
-{
- void *client_thread_ret;
- struct https_test_data client_args =
- { NULL, cipher_suite, curl_proto_version };
-
- client_thread_ret = https_transfer_thread_adapter (&client_args);
- if (client_thread_ret != NULL)
- return -1;
- return 0;
-}
-
-/**
- * Test parallel request handling.
- *
- * @return: 0 upon all client requests returning '0', -1 otherwise.
- *
- * TODO : make client_count a parameter - numver of curl client threads to
spawn
- */
-static int
-test_parallel_clients (void * cls, const char *cipher_suite,
- int curl_proto_version)
-{
- int i;
- int client_count = 3;
- void *client_thread_ret;
- pthread_t client_arr[client_count];
- struct https_test_data client_args =
- { NULL, cipher_suite, curl_proto_version };
-
- for (i = 0; i < client_count; ++i)
- {
- if (pthread_create (&client_arr[i], NULL,
- &https_transfer_thread_adapter, &client_args) != 0)
- {
- fprintf (stderr, "Error: failed to spawn test client threads.\n");
- return -1;
- }
- }
-
- /* check all client requests fulfilled correctly */
- for (i = 0; i < client_count; ++i)
- {
- if ((pthread_join (client_arr[i], &client_thread_ret) != 0) ||
- (client_thread_ret != NULL))
- return -1;
- }
-
- return 0;
-}
-
-GCRY_THREAD_OPTION_PTHREAD_IMPL;
-
-int
-main (int argc, char *const *argv)
-{
- unsigned int errorCount = 0;
-
- /* initialize random seed used by curl clients */
- unsigned int iseed = (unsigned int) time (NULL);
- srand (iseed);
- gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
- if (0 != curl_global_init (CURL_GLOBAL_ALL))
- {
- fprintf (stderr, "Error: %s\n", strerror (errno));
- return -1;
- }
-
- char *aes256_sha = "AES256-SHA";
- if (curl_uses_nss_ssl() == 0)
- {
- aes256_sha = "rsa_aes_256_sha";
- }
-
- errorCount +=
- test_wrap ("single threaded daemon, single client", &test_single_client,
- NULL,
- MHD_USE_SELECT_INTERNALLY | MHD_USE_SSL | MHD_USE_DEBUG,
- aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
- srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
- srv_self_signed_cert_pem, MHD_OPTION_END);
-
- errorCount +=
- test_wrap ("single threaded daemon, parallel clients",
- &test_parallel_clients, NULL,
- MHD_USE_SELECT_INTERNALLY | MHD_USE_SSL | MHD_USE_DEBUG,
- aes256_sha, CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
- srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
- srv_self_signed_cert_pem, MHD_OPTION_END);
-
- curl_global_cleanup ();
- return errorCount != 0;
-}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r26658 - libmicrohttpd/src/testcurl/https,
gnunet <=