mirror of
https://git.gnunet.org/libmicrohttpd.git
synced 2026-10-01 04:03:18 +03:00
fixed some memory leaks
removed includes dir
This commit is contained in:
1 parent
1cd7c17479
commit
04c37e5bd7
23 files changed
+412
-933
No files matched your search
@@ -2,18 +2,27 @@ SUBDIRS = .
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_srcdir)/src/include \
|
||||
-I$(top_srcdir)/src/daemon/https/includes \
|
||||
-I$(top_srcdir)/src/daemon/https \
|
||||
-I$(top_srcdir)/src/daemon/https/tls \
|
||||
-I$(top_srcdir)/src/daemon/https/lgl \
|
||||
-I$(top_srcdir)/src/daemon/https/x509 \
|
||||
-I$(top_srcdir)/src/daemon
|
||||
|
||||
|
||||
check_PROGRAMS = \
|
||||
tls_authentication_test \
|
||||
mhds_get_test \
|
||||
mhds_session_info_test \
|
||||
mhds_multi_daemon_test
|
||||
|
||||
tls_authentication_test \
|
||||
mhds_multi_daemon_test \
|
||||
mhds_session_info_test
|
||||
|
||||
TESTS = $(check_PROGRAMS)
|
||||
|
||||
tls_alert_test_SOURCES = \
|
||||
tls_alert_test.c
|
||||
tls_alert_test_LDADD = \
|
||||
$(top_builddir)/src/daemon/libmicrohttpd.la \
|
||||
@LIBCURL@
|
||||
|
||||
tls_authentication_test_SOURCES = \
|
||||
tls_authentication_test.c
|
||||
tls_authentication_test_LDADD = \
|
||||
|
||||
@@ -235,7 +235,8 @@ test_secure_get (FILE * test_fd, char *cipher_suite, int proto_version)
|
||||
MHD_USE_DEBUG, 42433,
|
||||
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);
|
||||
MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
|
||||
MHD_OPTION_END);
|
||||
|
||||
if (d == NULL)
|
||||
{
|
||||
@@ -255,10 +256,13 @@ test_file_certificates (FILE * test_fd, char *cipher_suite, int proto_version)
|
||||
int ret;
|
||||
struct MHD_Daemon *d;
|
||||
FILE *cert_fd, *key_fd;
|
||||
char cert_path[255], key_path[255];
|
||||
char cert_path[255], key_path[255], *cur_dir;
|
||||
|
||||
cur_dir = get_current_dir_name ();
|
||||
|
||||
sprintf (cert_path, "%s/%s", cur_dir, "cert.pem");
|
||||
sprintf (key_path, "%s/%s", cur_dir, "key.pem");
|
||||
|
||||
sprintf (cert_path, "%s/%s", get_current_dir_name (), "cert.pem");
|
||||
sprintf (key_path, "%s/%s", get_current_dir_name (), "key.pem");
|
||||
|
||||
if (NULL == (key_fd = fopen (key_path, "w+")))
|
||||
{
|
||||
@@ -272,7 +276,8 @@ test_file_certificates (FILE * test_fd, char *cipher_suite, int proto_version)
|
||||
}
|
||||
|
||||
fwrite (srv_key_pem, strlen (srv_key_pem), sizeof (char), key_fd);
|
||||
fwrite (srv_self_signed_cert_pem, strlen (srv_self_signed_cert_pem), sizeof (char), cert_fd);
|
||||
fwrite (srv_self_signed_cert_pem, strlen (srv_self_signed_cert_pem),
|
||||
sizeof (char), cert_fd);
|
||||
fclose (key_fd);
|
||||
fclose (cert_fd);
|
||||
|
||||
@@ -292,6 +297,7 @@ test_file_certificates (FILE * test_fd, char *cipher_suite, int proto_version)
|
||||
ret = test_daemon_get (test_fd, cipher_suite, proto_version);
|
||||
MHD_stop_daemon (d);
|
||||
|
||||
free (cur_dir);
|
||||
remove (cert_path);
|
||||
remove (key_path);
|
||||
return ret;
|
||||
@@ -412,6 +418,8 @@ main (int argc, char *const *argv)
|
||||
FILE *test_fd;
|
||||
unsigned int errorCount = 0;
|
||||
|
||||
// gnutls_global_set_log_level(11);
|
||||
|
||||
if ((test_fd = setupTestFile ()) == NULL)
|
||||
{
|
||||
fprintf (stderr, MHD_E_TEST_FILE_CREAT);
|
||||
@@ -420,18 +428,16 @@ main (int argc, char *const *argv)
|
||||
|
||||
if (0 != curl_global_init (CURL_GLOBAL_ALL))
|
||||
{
|
||||
fprintf (stderr, "Error (code: %u)\n", errorCount);
|
||||
fprintf (stderr, "Error: %s\n", strerror (errno));
|
||||
return -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);
|
||||
@@ -439,9 +445,6 @@ main (int argc, char *const *argv)
|
||||
test_kx_option (test_fd, "EDH-RSA-DES-CBC3-SHA", CURL_SSLVERSION_SSLv3);
|
||||
|
||||
|
||||
if (errorCount != 0)
|
||||
fprintf (stderr, "Error (code: %u)\n", errorCount);
|
||||
|
||||
curl_global_cleanup ();
|
||||
fclose (test_fd);
|
||||
|
||||
|
||||
@@ -236,7 +236,8 @@ test_concurent_daemon_pair (FILE * test_fd, char *cipher_suite,
|
||||
MHD_USE_DEBUG, 42433,
|
||||
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);
|
||||
MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
|
||||
MHD_OPTION_END);
|
||||
|
||||
if (d1 == NULL)
|
||||
{
|
||||
@@ -248,7 +249,8 @@ test_concurent_daemon_pair (FILE * test_fd, char *cipher_suite,
|
||||
MHD_USE_DEBUG, 42434,
|
||||
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);
|
||||
MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
|
||||
MHD_OPTION_END);
|
||||
|
||||
if (d2 == NULL)
|
||||
{
|
||||
|
||||
@@ -75,54 +75,61 @@ query_session_ahc (void *cls, struct MHD_Connection *connection,
|
||||
int ret;
|
||||
|
||||
/* assert actual connection cipher is the one negotiated */
|
||||
if (MHD_get_session_info (connection,MHS_INFO_CIPHER_ALGO).cipher_algorithm != GNUTLS_CIPHER_AES_256_CBC)
|
||||
if (MHD_get_tls_session_info (connection, MHS_INFO_CIPHER_ALGO).
|
||||
cipher_algorithm != GNUTLS_CIPHER_AES_256_CBC)
|
||||
{
|
||||
fprintf (stderr, "Error: requested cipher mismatch. %s\n",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (MHD_get_session_info (connection,MHD_INFO_KX_ALGO).kx_algorithm != GNUTLS_KX_RSA)
|
||||
{
|
||||
fprintf (stderr, "Error: requested key exchange mismatch. %s\n",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
if (MHD_get_tls_session_info (connection, MHD_INFO_KX_ALGO).kx_algorithm !=
|
||||
GNUTLS_KX_RSA)
|
||||
{
|
||||
fprintf (stderr, "Error: requested key exchange mismatch. %s\n",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (MHD_get_session_info (connection,MHD_INFO_MAC_ALGO).mac_algorithm != GNUTLS_MAC_SHA1)
|
||||
if (MHD_get_tls_session_info (connection, MHD_INFO_MAC_ALGO).
|
||||
mac_algorithm != GNUTLS_MAC_SHA1)
|
||||
{
|
||||
fprintf (stderr, "Error: requested mac algorithm mismatch. %s\n",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (MHD_get_session_info (connection,MHD_INFO_COMPRESSION_METHOD).compression_method != GNUTLS_COMP_NULL)
|
||||
if (MHD_get_tls_session_info (connection, MHD_INFO_COMPRESSION_METHOD).
|
||||
compression_method != GNUTLS_COMP_NULL)
|
||||
{
|
||||
fprintf (stderr, "Error: requested compression mismatch. %s\n",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (MHD_get_session_info (connection,MHD_INFO_PROTOCOL).protocol != GNUTLS_SSL3)
|
||||
{
|
||||
fprintf (stderr, "Error: requested compression mismatch. %s\n",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
if (MHD_get_tls_session_info (connection, MHD_INFO_PROTOCOL).protocol !=
|
||||
GNUTLS_SSL3)
|
||||
{
|
||||
fprintf (stderr, "Error: requested compression mismatch. %s\n",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (MHD_get_session_info (connection,MHD_INFO_CERT_TYPE).certificate_type != GNUTLS_CRT_X509)
|
||||
if (MHD_get_tls_session_info (connection, MHD_INFO_CERT_TYPE).
|
||||
certificate_type != GNUTLS_CRT_X509)
|
||||
{
|
||||
fprintf (stderr, "Error: requested certificate mismatch. %s\n",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (MHD_get_session_info (connection,MHD_INFO_CREDENTIALS_TYPE).credentials_type != GNUTLS_CRD_CERTIFICATE)
|
||||
{
|
||||
fprintf (stderr, "Error: requested certificate mismatch. %s\n",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
if (MHD_get_tls_session_info (connection, MHD_INFO_CREDENTIALS_TYPE).
|
||||
credentials_type != GNUTLS_CRD_CERTIFICATE)
|
||||
{
|
||||
fprintf (stderr, "Error: requested certificate mismatch. %s\n",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
response = MHD_create_response_from_data (strlen (EMPTY_PAGE),
|
||||
(void *) EMPTY_PAGE,
|
||||
@@ -154,7 +161,8 @@ test_query_session ()
|
||||
MHD_USE_DEBUG, 42433,
|
||||
NULL, NULL, &query_session_ahc, NULL,
|
||||
MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
|
||||
MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, MHD_OPTION_END);
|
||||
MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
|
||||
MHD_OPTION_END);
|
||||
|
||||
if (d == NULL)
|
||||
return 2;
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
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 "config.h"
|
||||
#include "plibc.h"
|
||||
#include "microhttpsd.h"
|
||||
#include <errno.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#define MHD_E_MEM "Error: memory error\n"
|
||||
#define MHD_E_SERVER_INIT "Error: failed to start server\n"
|
||||
|
||||
#include "gnutls_int.h"
|
||||
#include "gnutls_datum.h"
|
||||
#include "tls_test_keys.h"
|
||||
|
||||
const char *ca_cert_file_name = "ca_cert_pem";
|
||||
const char *test_file_name = "https_test_file";
|
||||
const char test_file_data[] = "Hello World\n";
|
||||
|
||||
struct CBC
|
||||
{
|
||||
char *buf;
|
||||
size_t pos;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
static int
|
||||
file_reader (void *cls, size_t pos, char *buf, int max)
|
||||
{
|
||||
FILE *file = cls;
|
||||
fseek (file, pos, SEEK_SET);
|
||||
return fread (buf, 1, max, file);
|
||||
}
|
||||
|
||||
/* HTTP access handler call back */
|
||||
static int
|
||||
http_ahc (void *cls, struct MHD_Connection *connection,
|
||||
const char *url, const char *method, const char *upload_data,
|
||||
const char *version, unsigned int *upload_data_size, void **ptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
test_alert_response ()
|
||||
{
|
||||
|
||||
|
||||
int sd, ret;
|
||||
char *err_pos;
|
||||
struct sockaddr_in sa;
|
||||
gnutls_priority_t priority_cache;
|
||||
gnutls_session_t session;
|
||||
gnutls_certificate_credentials_t xcred;
|
||||
|
||||
|
||||
gnutls_global_init ();
|
||||
|
||||
gnutls_datum_t key;
|
||||
gnutls_datum_t cert;
|
||||
|
||||
|
||||
gnutls_certificate_allocate_credentials (&xcred);
|
||||
|
||||
_gnutls_set_datum_m (&key, srv_key_pem, strlen (srv_key_pem), &malloc);
|
||||
_gnutls_set_datum_m (&cert, srv_self_signed_cert_pem,
|
||||
strlen (srv_self_signed_cert_pem), &malloc);
|
||||
|
||||
gnutls_certificate_set_x509_key_mem (xcred, &cert, &key,
|
||||
GNUTLS_X509_FMT_PEM);
|
||||
|
||||
ret = gnutls_priority_init (&priority_cache,
|
||||
"NONE:+VERS-TLS1.0:+AES-256-CBC:+RSA:+SHA1:+COMP-NULL",
|
||||
&err_pos);
|
||||
if (ret < 0)
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
|
||||
|
||||
sd = socket (AF_INET, SOCK_STREAM, 0);
|
||||
memset (&sa, '\0', sizeof (struct sockaddr_in));
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_port = htons (42433);
|
||||
inet_pton (AF_INET, "127.0.0.1", &sa.sin_addr);
|
||||
|
||||
ret = connect (sd, &sa, sizeof (struct sockaddr_in));
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
ret = gnutls_handshake (session);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
gnutls_alert_send (session, GNUTLS_AL_FATAL, GNUTLS_A_CLOSE_NOTIFY);
|
||||
|
||||
/* check server responds with a 'close-notify' */
|
||||
_gnutls_recv_int (session, GNUTLS_ALERT, GNUTLS_HANDSHAKE_FINISHED, 0, 0);
|
||||
|
||||
/* CLOSE_NOTIFY */
|
||||
if (session->internals.last_alert != GNUTLS_A_CLOSE_NOTIFY)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
close (sd);
|
||||
|
||||
gnutls_deinit (session);
|
||||
|
||||
gnutls_certificate_free_credentials (xcred);
|
||||
|
||||
gnutls_global_deinit ();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *const *argv)
|
||||
{
|
||||
int ret, errorCount = 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, 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;
|
||||
}
|
||||
|
||||
errorCount += test_alert_response ();
|
||||
|
||||
if (errorCount != 0)
|
||||
fprintf (stderr, "Error (code: %u)\n", errorCount);
|
||||
|
||||
MHD_stop_daemon (d);
|
||||
return errorCount != 0;
|
||||
}
|
||||
Reference in new issue
Block a user