commit a6a989cf1200f25795e9ec1ed40b21c6024ed53e
parent 08ee1d01c9a343b41697b803150e712bd713c582
Author: lv-426 <oxcafebaby@yahoo.com>
Date: Thu, 10 Jul 2008 17:28:48 +0000
simplified write / idle handlers
SSL/TLS connection states merged into HTTP states
Diffstat:
18 files changed, 213 insertions(+), 145 deletions(-)
diff --git a/src/daemon/connection.c b/src/daemon/connection.c
@@ -31,9 +31,6 @@
#include "response.h"
#include "reason_phrase.h"
-/* get opaque type */
-#include "gnutls_int.h"
-
#ifndef LINUX
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
@@ -766,6 +763,7 @@ MHD_connection_get_fdset (struct MHD_Connection *connection,
if (connection->socket_fd != -1)
connection_close_error (connection);
return MHD_YES; /* do nothing, not even reading */
+
default:
EXTRA_CHECK (0);
}
diff --git a/src/daemon/connection_https.c b/src/daemon/connection_https.c
@@ -35,6 +35,7 @@
#include "microhttpsd.h"
/* get opaque type */
#include "gnutls_int.h"
+#include "gnutls_record.h"
/* TODO rm */
#include "gnutls_errors.h"
@@ -46,17 +47,27 @@ int MHD_connection_handle_idle (struct MHD_Connection *connection);
/* TODO rm - appears in a switch default clause */
static void
-connection_close_error (struct MHD_Connection *connection)
+MHD_tls_connection_close (struct MHD_Connection *connection)
{
+ gnutls_bye (connection->tls_session, GNUTLS_SHUT_WR);
+ connection->tls_session->internals.read_eof = 1;
+ connection->socket_fd = -1;
+
SHUTDOWN (connection->socket_fd, SHUT_RDWR);
CLOSE (connection->socket_fd);
- connection->socket_fd = -1;
connection->state = MHD_CONNECTION_CLOSED;
if (connection->daemon->notify_completed != NULL)
connection->daemon->notify_completed (connection->daemon->
notify_completed_cls, connection,
&connection->client_context,
- MHD_REQUEST_TERMINATED_WITH_ERROR);
+ MHD_REQUEST_TERMINATED_COMPLETED_OK);
+}
+
+/* TODO add error connection termination */
+static void
+MHD_tls_connection_close_err (struct MHD_Connection *connection)
+{
+ /* TODO impl */
}
/* get cipher spec for this connection */
@@ -106,32 +117,27 @@ MHDS_con_write (struct MHD_Connection *connection)
}
int
-MHDS_connection_handle_idle (struct MHD_Connection *connection)
+MHD_tls_connection_handle_idle (struct MHD_Connection *connection)
{
unsigned int timeout;
- /* TODO rm gnutls_assert (); */
while (1)
{
#if HAVE_MESSAGES
- MHD_DLOG (connection->daemon, "MHDS reached case: %d, l: %d, f: %s\n",
- connection->s_state, __LINE__, __FUNCTION__);
+ MHD_DLOG (connection->daemon, "MHDS idle: %d, l: %d, f: %s\n",
+ connection->state, __LINE__, __FUNCTION__);
#endif
- switch (connection->s_state)
+ switch (connection->state)
{
- case MHDS_HANDSHAKE_FAILED:
- connection->socket_fd = -1;
- case MHDS_CONNECTION_INIT:
- /* wait for request */
- case MHDS_HANDSHAKE_COMPLETE:
-
- case MHDS_CONNECTION_CLOSED:
- if (connection->socket_fd != -1)
- connection_close_error (connection);
- break;
-
+ case MHD_CONNECTION_CLOSED:
+ MHD_tls_connection_close (connection);
+ return MHD_NO;
+ case MHD_TLS_HANDSHAKE_FAILED:
+ MHD_tls_connection_close (connection);
+ return MHD_NO;
+ /* some http state */
default:
- break;
+ return MHD_connection_handle_idle (connection);
}
break;
}
@@ -141,24 +147,34 @@ MHDS_connection_handle_idle (struct MHD_Connection *connection)
if ((connection->socket_fd != -1) && (timeout != 0)
&& (time (NULL) - timeout > connection->last_activity))
{
- connection_close_error (connection);
+ MHD_tls_connection_close (connection);
return MHD_NO;
}
return MHD_YES;
}
+/**
+ * This function handles a particular SSL/TLS connection when
+ * it has been determined that there is data to be read off a
+ * socket. All application_data is forwarded to
+ * MHD_connection_handle_read().
+ *
+ * @return MHD_YES if we should continue to process the
+ * connection (not dead yet), MHD_NO if it died
+ */
int
-MHDS_connection_handle_read (struct MHD_Connection *connection)
+MHD_tls_connection_handle_read (struct MHD_Connection *connection)
{
int ret;
+ unsigned char msg_type;
connection->last_activity = time (NULL);
- if (connection->s_state == MHDS_CONNECTION_CLOSED)
- return MHD_NO;
-
+#if HAVE_MESSAGES
+ MHD_DLOG (connection->daemon, "MHD read: %d, l: %d, f: %s\n",
+ connection->state, __LINE__, __FUNCTION__);
+#endif
/* discover content type */
- unsigned char msg_type;
if (recv (connection->socket_fd, &msg_type, 1, MSG_PEEK) == -1)
{
#if HAVE_MESSAGES
@@ -178,16 +194,13 @@ MHDS_connection_handle_read (struct MHD_Connection *connection)
* done to decrypt alert message
*/
_gnutls_recv_int (connection->tls_session, GNUTLS_ALERT,
- GNUTLS_HANDSHAKE_FINISHED, 0);
+ GNUTLS_HANDSHAKE_FINISHED, 0, 0);
/* CLOSE_NOTIFY */
if (connection->tls_session->internals.last_alert ==
GNUTLS_A_CLOSE_NOTIFY)
{
gnutls_bye (connection->tls_session, GNUTLS_SHUT_WR);
- connection->tls_session->internals.read_eof = 1;
- connection->socket_fd = -1;
- gnutls_deinit (connection->tls_session);
return MHD_YES;
}
/* non FATAL or WARNING */
@@ -206,11 +219,7 @@ MHDS_connection_handle_read (struct MHD_Connection *connection)
else if (connection->tls_session->internals.last_alert ==
GNUTLS_AL_FATAL)
{
- connection->tls_session->internals.resumable = RESUME_FALSE;
- connection->tls_session->internals.valid_connection = VALID_FALSE;
- connection->socket_fd = -1;
- gnutls_deinit (connection->tls_session);
-
+ MHD_tls_connection_close (connection);
return MHD_NO;
}
/* this should never execut */
@@ -233,8 +242,8 @@ MHDS_connection_handle_read (struct MHD_Connection *connection)
ret = gnutls_handshake (connection->tls_session);
if (ret == 0)
{
- connection->s_state = MHDS_HANDSHAKE_COMPLETE;
connection->state = MHD_CONNECTION_INIT;
+ // connection->state = MHD_CONNECTION_INIT;
}
/* set connection as closed */
else
@@ -243,49 +252,56 @@ MHDS_connection_handle_read (struct MHD_Connection *connection)
MHD_DLOG (connection->daemon,
"Error: Handshake has failed (%d)\n", ret);
#endif
- connection->s_state = MHDS_HANDSHAKE_FAILED;
- gnutls_bye (connection->tls_session, GNUTLS_SHUT_WR);
- gnutls_deinit (connection->tls_session);
- connection_close_error(connection);
+ connection->state = MHD_TLS_HANDSHAKE_FAILED;
+ MHD_tls_connection_close (connection);
return MHD_NO;
}
break;
case GNUTLS_INNER_APPLICATION:
break;
+ default:
+#if HAVE_MESSAGES
+ MHD_DLOG (connection->daemon,
+ "Err: unrecognized tls read message. l: %d, f: %s\n",
+ connection->state, __LINE__, __FUNCTION__);
+#endif
+ return MHD_NO;
}
return MHD_YES;
}
+/**
+ * This function was created to handle writes to sockets when it has
+ * been determined that the socket can be written to.
+ *
+ * @return MHD_YES if we should continue to process the
+ * connection (not dead yet), MHD_NO if it died
+ */
int
-MHDS_connection_handle_write (struct MHD_Connection *connection)
+MHD_tls_connection_handle_write (struct MHD_Connection *connection)
{
connection->last_activity = time (NULL);
- /* TODO rm */
- gnutls_assert ();
+
while (1)
{
#if HAVE_MESSAGES
- MHD_DLOG (connection->daemon, "MHDS reached case: %d, l: %d, f: %s\n",
- connection->s_state, __LINE__, __FUNCTION__);
+ MHD_DLOG (connection->daemon, "MHD write: %d, l: %d, f: %s\n",
+ connection->state, __LINE__, __FUNCTION__);
#endif
- switch (connection->s_state)
+ switch (connection->state)
{
-
- /* these cases shouldn't occur */
- case MHDS_HANDSHAKE_COMPLETE:
- case MHDS_CONNECTION_INIT:
- /* TODO do we have to write back a responce ? */
- case MHDS_HANDSHAKE_FAILED:
- /* we should first exit MHDS_REPLY_SENDING */
-
- case MHDS_CONNECTION_CLOSED:
- if (connection->socket_fd != -1)
- connection_close_error (connection);
+ case MHD_CONNECTION_CLOSED:
+ MHD_tls_connection_close (connection);
return MHD_NO;
+ case MHD_TLS_HANDSHAKE_FAILED:
+ MHD_tls_connection_close (connection);
+ return MHD_NO;
+ /* some HTTP state */
+ default:
+ return MHD_connection_handle_write (connection);
}
}
- return MHD_YES;
}
void
@@ -293,7 +309,7 @@ MHD_set_https_calbacks (struct MHD_Connection *connection)
{
connection->recv_cls = &MHDS_con_read;
connection->send_cls = &MHDS_con_write;
- connection->read_handler = &MHDS_connection_handle_read;
- connection->write_handler = &MHD_connection_handle_write;
- connection->idle_handler = &MHD_connection_handle_idle;
+ connection->read_handler = &MHD_tls_connection_handle_read;
+ connection->write_handler = &MHD_tls_connection_handle_write;
+ connection->idle_handler = &MHD_tls_connection_handle_idle;
}
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
@@ -29,6 +29,7 @@
#include "connection.h"
#include "memorypool.h"
+#include "gnutls.h"
#include "gnutls_int.h"
#include "gnutls_datum.h"
#include "gnutls_global.h"
@@ -102,17 +103,15 @@ MHDS_init (struct MHD_Daemon *daemon){
}
else if (daemon->https_mem_cert && daemon->https_mem_key)
{
- gnutls_datum_t *key =
- (gnutls_datum_t *) malloc (sizeof (gnutls_datum_t));
- gnutls_datum_t *cert =
- (gnutls_datum_t *) malloc (sizeof (gnutls_datum_t));
+ gnutls_datum_t key ;
+ gnutls_datum_t cert ;
- _gnutls_set_datum_m (key, daemon->https_mem_key,
+ _gnutls_set_datum_m (&key, daemon->https_mem_key,
strlen (daemon->https_mem_key), &malloc);
- _gnutls_set_datum_m (cert, daemon->https_mem_cert,
+ _gnutls_set_datum_m (&cert, daemon->https_mem_cert,
strlen (daemon->https_mem_cert), &malloc);
- gnutls_certificate_set_x509_key_mem (daemon->x509_cret, cert, key,
+ gnutls_certificate_set_x509_key_mem (daemon->x509_cret, &cert, &key,
GNUTLS_X509_FMT_PEM);
}
else
@@ -309,21 +308,18 @@ gnutls_push_param_adapter (void *connection,
static void *
MHDS_handle_connection (void *data)
{
- gnutls_session_t tls_session;
struct MHD_Connection *con = data;
if (con == NULL)
abort ();
- gnutls_init (&tls_session, GNUTLS_SERVER);
-
- con->tls_session = tls_session;
+ gnutls_init (&con->tls_session, GNUTLS_SERVER);
/* sets cipher priorities */
- gnutls_priority_set (tls_session, con->daemon->priority_cache);
+ gnutls_priority_set (con->tls_session, con->daemon->priority_cache);
/* set needed credentials for certificate authentication. */
- gnutls_credentials_set (tls_session, GNUTLS_CRD_CERTIFICATE,
+ gnutls_credentials_set (con->tls_session, GNUTLS_CRD_CERTIFICATE,
con->daemon->x509_cret);
/* TODO avoid gnutls blocking recv / write calls
@@ -331,7 +327,7 @@ MHDS_handle_connection (void *data)
gnutls_transport_set_push_function(tls_session, &send);
*/
- gnutls_transport_set_ptr (tls_session, con->socket_fd);
+ gnutls_transport_set_ptr (con->tls_session, con->socket_fd);
return MHD_handle_connection (data);
}
@@ -554,7 +550,11 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
free (pos->addr);
free (pos);
daemon->max_connections++;
- /* TODO add tls con cleanup */
+#if HTTPS_SUPPORT
+ if(pos->tls_session != 0){
+ gnutls_deinit (pos->tls_session);
+ }
+#endif
if (prev == NULL)
pos = daemon->connections;
else
@@ -915,10 +915,10 @@ MHD_start_daemon (unsigned int options,
case MHD_OPTION_HTTPS_MEM_CERT:
retVal->https_mem_cert = va_arg (ap, const char *);
break;
- case MHDS_KX_PRIORITY:
+ case MHD_OPTION_KX_PRIORITY:
_set_priority (&retVal->priority_cache->cipher, va_arg (ap, const int *));
break;
- case MHDS_CIPHER_ALGORITHM:
+ case MHD_OPTION_CIPHER_ALGORITHM:
_set_priority (&retVal->priority_cache->cipher, va_arg (ap, const int *));
break;
#endif
diff --git a/src/daemon/https/https_common.c b/src/daemon/https/https_common.c
@@ -8,12 +8,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* GNUTLS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -192,7 +192,7 @@ print_x509_info (gnutls_session_t session, const char *hostname)
printf (" # fingerprint: %s\n", print);
}
- /* Print the version of the X.509
+ /* Print the version of the X.509
* certificate.
*/
if (verbose)
diff --git a/src/daemon/https/openpgp/gnutls_extra.c b/src/daemon/https/openpgp/gnutls_extra.c
@@ -9,12 +9,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* GNUTLS-EXTRA 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -38,7 +38,7 @@ extern int _gnutls_comp_algorithms_size;
static int _gnutls_init_extra = 0;
/**
- * gnutls_global_init_extra - This function initializes the global state of gnutls-extra
+ * gnutls_global_init_extra - This function initializes the global state of gnutls-extra
*
* This function initializes the global state of gnutls-extra library
* to defaults. Returns zero on success.
@@ -51,8 +51,6 @@ static int _gnutls_init_extra = 0;
int
gnutls_global_init_extra (void)
{
- int ret;
-
/* If the version of libgnutls != version of
* libextra, then do not initialize the library.
* This is because it may break things.
diff --git a/src/daemon/https/tls/ext_oprfi.c b/src/daemon/https/tls/ext_oprfi.c
@@ -38,7 +38,6 @@ oprfi_recv_server (gnutls_session_t session,
{
ssize_t data_size = _data_size;
uint16_t len;
- int ret;
if (!session->security_parameters.extensions.oprfi_cb)
{
@@ -75,7 +74,6 @@ oprfi_recv_client (gnutls_session_t session,
{
ssize_t data_size = _data_size;
uint16_t len;
- int ret;
if (session->security_parameters.extensions.oprfi_client == NULL)
{
@@ -149,7 +147,6 @@ oprfi_send_server (gnutls_session_t session, opaque * data, size_t _data_size)
opaque *p = data;
int ret;
ssize_t data_size = _data_size;
- size_t len;
if (!session->security_parameters.extensions.oprfi_client ||
!session->security_parameters.extensions.oprfi_cb)
diff --git a/src/daemon/https/tls/gnutls_asn1_tab.c b/src/daemon/https/tls/gnutls_asn1_tab.c
@@ -4,7 +4,7 @@
#include <libtasn1.h>
-extern const ASN1_ARRAY_TYPE gnutls_asn1_tab[] = {
+const ASN1_ARRAY_TYPE gnutls_asn1_tab[] = {
{"GNUTLS", 536872976, 0},
{0, 1073741836, 0},
{"RSAPublicKey", 1610612741, 0},
diff --git a/src/daemon/https/tls/gnutls_compress_int.c b/src/daemon/https/tls/gnutls_compress_int.c
@@ -34,7 +34,6 @@ comp_hd_t
_gnutls_comp_init (gnutls_compression_method_t method, int d)
{
comp_hd_t ret;
- int err;
ret = gnutls_malloc (sizeof (struct comp_hd_t_STRUCT));
if (ret == NULL)
@@ -105,8 +104,6 @@ cleanup_ret:
void
_gnutls_comp_deinit (comp_hd_t handle, int d)
{
- int err;
-
if (handle != NULL)
{
switch (handle->algo)
@@ -128,7 +125,7 @@ _gnutls_comp_deinit (comp_hd_t handle, int d)
}
}
-/* These functions are memory consuming
+/* These functions are memory consuming
*/
int
@@ -137,7 +134,6 @@ _gnutls_compress (comp_hd_t handle, const opaque * plain,
size_t max_comp_size)
{
int compressed_size = GNUTLS_E_COMPRESSION_FAILED;
- int err;
/* NULL compression is not handled here
*/
@@ -212,8 +208,7 @@ _gnutls_decompress (comp_hd_t handle, opaque * compressed,
size_t compressed_size, opaque ** plain,
size_t max_record_size)
{
- int plain_size = GNUTLS_E_DECOMPRESSION_FAILED, err;
- int cur_pos;
+ int plain_size = GNUTLS_E_DECOMPRESSION_FAILED;
if (compressed_size > max_record_size + EXTRA_COMP_SIZE)
{
diff --git a/src/daemon/https/tls/gnutls_global.c b/src/daemon/https/tls/gnutls_global.c
@@ -160,7 +160,7 @@ static void
_gnutls_gcry_log_handler (void *dummy, int level,
const char *fmt, va_list list)
{
- _gnutls_log (fmt, list);
+ _gnutls_log (level, fmt, list);
}
#endif
diff --git a/src/daemon/https/tls/gnutls_mpi.h b/src/daemon/https/tls/gnutls_mpi.h
@@ -23,7 +23,7 @@
*/
#ifndef GNUTLS_MPI_H
-# define GNUTLS_MPI_H
+#define GNUTLS_MPI_H
# include <gnutls_int.h>
# include <gcrypt.h>
diff --git a/src/daemon/https/tls/gnutls_pk.h b/src/daemon/https/tls/gnutls_pk.h
@@ -23,7 +23,7 @@
*/
#ifndef GNUTLS_PK_H
-# define GNUTLS_PK_H
+#define GNUTLS_PK_H
int _gnutls_pkcs1_rsa_encrypt (gnutls_datum_t * ciphertext,
const gnutls_datum_t * plaintext,
diff --git a/src/daemon/https/x509/mpi.c b/src/daemon/https/x509/mpi.c
@@ -82,7 +82,7 @@ _gnutls_x509_read_rsa_params (opaque * der, int dersize, mpi_t * params)
}
-/* reads p,q and g
+/* reads p,q and g
* from the certificate (subjectPublicKey BIT STRING).
* params[0-2]
*/
@@ -193,7 +193,7 @@ _gnutls_x509_read_der_int (opaque * der, int dersize, mpi_t * out)
}
/* reads DSA's Y
- * from the certificate
+ * from the certificate
* only sets params[3]
*/
int
@@ -339,7 +339,6 @@ _gnutls_x509_write_sig_params (ASN1_TYPE dst,
gnutls_digest_algorithm_t dig,
mpi_t * params, int params_size)
{
- gnutls_datum_t der;
int result;
char name[128];
const char *pk;
diff --git a/src/daemon/internal.h b/src/daemon/internal.h
@@ -284,24 +284,20 @@ enum MHD_CONNECTION_STATE
*/
MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1,
-};
-
-
-/**
- * States in a state machine for a secure SSL/TLS connection.
- *
- */
-enum MHDS_CONNECTION_STATE
-{
- /* initial HTTPS state */
- MHDS_CONNECTION_INIT = 0,
+#if HTTPS_SUPPORT
+ /*
+ * SSL/TLS connection states
+ */
+ MHD_TLS_HANDSHAKE_FAILED = MHD_CONNECTION_CLOSED +1,
- MHDS_HANDSHAKE_FAILED,
+ MHD_TLS_HANDSHAKE_COMPLETE,
+#endif
+};
- MHDS_HANDSHAKE_COMPLETE,
- MHDS_CONNECTION_CLOSED
-};
+#if DEBUG_STATES
+ /* TODO add state dictionary */
+#endif
struct MHD_Connection
{
@@ -486,7 +482,7 @@ struct MHD_Connection
*/
enum MHD_CONNECTION_STATE state;
- enum MHDS_CONNECTION_STATE s_state;
+ //enum MHDS_CONNECTION_STATE s_state;
/**
* HTTP response code. Only valid if response object
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
@@ -386,14 +386,29 @@ enum MHD_OPTION
* cipher priority order to which the HTTPS daemon should adhere.
* "const int *" argument.
*/
- MHDS_CIPHER_ALGORITHM,
+ MHD_OPTION_CIPHER_ALGORITHM,
/*
* Memory pointer to a zero terminated int array representing the
* key exchange algorithm priority order to which the HTTPS daemon should adhere.
* "const int *" argument.
*/
- MHDS_KX_PRIORITY,
+ MHD_OPTION_KX_PRIORITY,
+
+ /*
+ * used to indicate which type of certificate this server will use,
+ */
+ MHD_OPTION_CRET_TYPE,
+
+ /*
+ * mac algorithm used by server
+ */
+ MHD_OPTION_MAC_ALGO,
+
+ /*
+ * compression algorithm used by server
+ */
+ MHD_OPTION_TLS_COMP_ALGO,
MHD_HTTPS_OPTION_END,
};
diff --git a/src/include/microhttpsd.h b/src/include/microhttpsd.h
@@ -125,7 +125,6 @@
/* get cipher spec for this connection */
gnutls_cipher_algorithm_t MHDS_get_session_cipher (struct MHD_Connection * session );
-
gnutls_kx_algorithm_t MHDS_get_session_kx (struct MHD_Connection * session );
gnutls_mac_algorithm_t MHDS_get_session_mac (struct MHD_Connection * session );
gnutls_compression_method_t MHDS_get_session_compression (struct MHD_Connection * session );
diff --git a/src/testcurl/https/mhds_get_test.c b/src/testcurl/https/mhds_get_test.c
@@ -40,6 +40,7 @@
#define PAGE_NOT_FOUND "<html><head><title>File not found</title></head><body>File not found</body></html>"
+#define MHD_E_MEM "Error: memory error\n"
#define MHD_E_SERVER_INIT "Error: failed to start server\n"
#define MHD_E_TEST_FILE_CREAT "Error: failed to setup test file\n"
#define MHD_E_CERT_FILE_CREAT "Error: failed to setup test certificate\n"
@@ -192,7 +193,12 @@ test_daemon_get (FILE * test_fd, char *cipher_suite, int proto_version)
/* setup test file path, url */
doc_path = get_current_dir_name ();
- mem_test_file_local = malloc (len);
+ if (NULL == (mem_test_file_local = malloc (len)))
+ {
+ fclose (test_fd);
+ fprintf (stderr, MHD_E_MEM);
+ return -1;
+ }
fseek (test_fd, 0, SEEK_SET);
if (fread (mem_test_file_local, sizeof (char), len, test_fd) != len)
@@ -206,8 +212,7 @@ test_daemon_get (FILE * test_fd, char *cipher_suite, int proto_version)
if (NULL == (cbc.buf = malloc (sizeof (char) * len)))
{
fclose (test_fd);
- fprintf (stderr, "Error: failed to read test file. %s\n",
- strerror (errno));
+ fprintf (stderr, MHD_E_MEM);
return -1;
}
cbc.size = len;
@@ -219,7 +224,7 @@ test_daemon_get (FILE * test_fd, char *cipher_suite, int proto_version)
c = curl_easy_init ();
#ifdef DEBUG
- curl_easy_setopt (c, CURLOPT_VERBOSE, 1);
+ //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_0);
@@ -255,9 +260,14 @@ test_daemon_get (FILE * test_fd, char *cipher_suite, int proto_version)
if (memcmp (cbc.buf, mem_test_file_local, len) != 0)
{
fprintf (stderr, "Error: local file & received file differ.\n");
+ free (cbc.buf);
+ free (mem_test_file_local);
return -1;
}
+ free (mem_test_file_local);
+ free (cbc.buf);
+ free (doc_path);
return 0;
}
@@ -265,7 +275,6 @@ test_daemon_get (FILE * test_fd, char *cipher_suite, int proto_version)
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 |
@@ -346,7 +355,7 @@ test_cipher_option (FILE * test_fd, char *cipher_suite, int proto_version)
NULL, NULL, &http_ahc, NULL,
MHD_OPTION_HTTPS_MEM_KEY, key_pem,
MHD_OPTION_HTTPS_MEM_CERT, cert_pem,
- MHDS_CIPHER_ALGORITHM, ciper, MHD_OPTION_END);
+ MHD_OPTION_CIPHER_ALGORITHM, ciper, MHD_OPTION_END);
if (d == NULL)
{
@@ -373,7 +382,34 @@ test_kx_option (FILE * test_fd, char *cipher_suite, int proto_version)
NULL, NULL, &http_ahc, NULL,
MHD_OPTION_HTTPS_MEM_KEY, key_pem,
MHD_OPTION_HTTPS_MEM_CERT, cert_pem,
- MHDS_KX_PRIORITY, kx, MHD_OPTION_END);
+ MHD_OPTION_KX_PRIORITY, kx, MHD_OPTION_END);
+
+ if (d == NULL)
+ {
+ fprintf (stderr, MHD_E_SERVER_INIT);
+ return -1;
+ }
+
+ ret = test_daemon_get (test_fd, cipher_suite, proto_version);
+
+ MHD_stop_daemon (d);
+ return ret;
+}
+
+int
+test_mac_option (FILE * test_fd, char *cipher_suite, int proto_version)
+{
+
+ int ret;
+ int mac[] = { GNUTLS_MAC_SHA1, 0 };
+ struct MHD_Daemon *d;
+
+ d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
+ MHD_USE_DEBUG, 42433,
+ NULL, NULL, &http_ahc, NULL,
+ MHD_OPTION_HTTPS_MEM_KEY, key_pem,
+ MHD_OPTION_HTTPS_MEM_CERT, cert_pem,
+ MHD_OPTION_MAC_ALGO, mac, MHD_OPTION_END);
if (d == NULL)
{
@@ -434,18 +470,29 @@ main (int argc, char *const *argv)
return -1;
}
+ //gnutls_global_set_log_level(11);
+// errorCount +=
+// test_secure_get (test_fd, "AES256-SHA", CURL_SSLVERSION_TLSv1);
+//
+// errorCount +=
+// test_secure_get (test_fd, "AES256-SHA", CURL_SSLVERSION_TLSv1);
+//
+// sleep(1);
+
errorCount +=
test_secure_get (test_fd, "AES256-SHA", CURL_SSLVERSION_TLSv1);
- errorCount +=
- test_secure_get (test_fd, "AES256-SHA", CURL_SSLVERSION_SSLv3);
- errorCount +=
- test_file_certificates (test_fd, "AES256-SHA", CURL_SSLVERSION_TLSv1);
- /* TODO resolve cipher setting issue when compiling against GNU TLS */
- errorCount +=
- test_cipher_option (test_fd, "DES-CBC3-SHA", CURL_SSLVERSION_SSLv3);
- errorCount +=
- test_kx_option (test_fd, "EDH-RSA-DES-CBC3-SHA", CURL_SSLVERSION_SSLv3);
+// errorCount +=
+// test_secure_get (test_fd, "AES256-SHA", CURL_SSLVERSION_SSLv3);
+// errorCount +=
+// test_file_certificates (test_fd, "AES256-SHA", CURL_SSLVERSION_TLSv1);
+//
+// /* TODO resolve cipher setting issue when compiling against GNU TLS */
+// errorCount +=
+// test_cipher_option (test_fd, "DES-CBC3-SHA", CURL_SSLVERSION_SSLv3);
+// errorCount +=
+// test_kx_option (test_fd, "EDH-RSA-DES-CBC3-SHA", CURL_SSLVERSION_SSLv3);
+
if (errorCount != 0)
fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/https/mhds_multi_daemon_test.c b/src/testcurl/https/mhds_multi_daemon_test.c
@@ -254,9 +254,15 @@ test_daemon_get (FILE * test_fd, char *cipher_suite, int proto_version,
if (memcmp (cbc.buf, mem_test_file_local, len) != 0)
{
fprintf (stderr, "Error: local file & received file differ.\n");
+ free (mem_test_file_local);
+ free (cbc.buf);
+ free (doc_path);
return -1;
}
+ free (mem_test_file_local);
+ free (cbc.buf);
+ free (doc_path);
return 0;
}
diff --git a/src/testcurl/https/mhds_session_info_test.c b/src/testcurl/https/mhds_session_info_test.c
@@ -209,14 +209,16 @@ test_query_session ()
{
fprintf (stderr, "curl_easy_perform failed: `%s'\n",
curl_easy_strerror (errornum));
- curl_easy_cleanup (c);
+
MHD_stop_daemon (d);
- return 4;
+ curl_easy_cleanup (c);
+ free (cbc.buf);
+ return -1;
}
- curl_easy_cleanup (c);
MHD_stop_daemon (d);
-
+ curl_easy_cleanup (c);
+ free (cbc.buf);
return 0;
}