testcurl/https: stopped CA file creation/removal

Use CA cert file which is already in the filesystem
This commit is contained in:
Evgeny Grin (Karlson2k)
2022-10-05 18:42:19 +03:00
parent 28e28436c6
commit 0be4e8c2a7
6 changed files with 7 additions and 68 deletions
+1 -5
View File
@@ -9,6 +9,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/src/include \
-I$(top_srcdir)/src/microhttpd \
-DMHD_CPU_COUNT=$(CPU_COUNT) \
-DSRCDIR=\"$(srcdir)\" \
$(CPPFLAGS_ac) $(LIBCURL_CPPFLAGS) $(MHD_TLS_LIB_CPPFLAGS)
AM_CFLAGS = $(CFLAGS_ac) @LIBGCRYPT_CFLAGS@
@@ -136,16 +137,11 @@ test_https_get_iovec_SOURCES = \
tls_test_common.h \
tls_test_common.c
if HAVE_GNUTLS_SNI
test_https_sni_SOURCES = \
test_https_sni.c \
tls_test_keys.h \
tls_test_common.h \
tls_test_common.c
test_https_sni_CPPFLAGS = \
$(AM_CPPFLAGS) \
-DABS_SRCDIR=\"$(abs_srcdir)\"
endif
test_https_get_select_SOURCES = \
test_https_get_select.c \
@@ -131,7 +131,6 @@ int
main (int argc, char *const *argv)
{
unsigned int errorCount = 0;
FILE *cert;
const char *aes256_sha = "AES256-SHA";
(void) argc; (void) argv; /* Unused. Silent compiler warning. */
@@ -149,12 +148,6 @@ main (int argc, char *const *argv)
curl_global_cleanup ();
return 77;
}
if ((cert = setup_ca_cert ()) == NULL)
{
fprintf (stderr, MHD_E_TEST_FILE_CREAT);
curl_global_cleanup ();
return 99;
}
if (curl_tls_is_nss ())
{
@@ -167,10 +160,5 @@ main (int argc, char *const *argv)
print_test_result (errorCount, "concurent_daemon_pair");
curl_global_cleanup ();
fclose (cert);
if (0 != remove (ca_cert_file_name))
fprintf (stderr,
"Failed to remove `%s'\n",
ca_cert_file_name);
return errorCount != 0 ? 1 : 0;
}
+5 -5
View File
@@ -209,7 +209,7 @@ do_get (const char *url, uint16_t port)
curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 10L);
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
curl_easy_setopt (c, CURLOPT_FILE, &cbc);
curl_easy_setopt (c, CURLOPT_CAINFO, ABS_SRCDIR "/test-ca.crt");
curl_easy_setopt (c, CURLOPT_CAINFO, SRCDIR "/test-ca.crt");
/* perform peer authentication */
/* TODO merge into send_curl_req */
@@ -288,10 +288,10 @@ main (int argc, char *const *argv)
return 77;
}
load_keys ("mhdhost1", ABS_SRCDIR "/mhdhost1.crt",
ABS_SRCDIR "/mhdhost1.key");
load_keys ("mhdhost2", ABS_SRCDIR "/mhdhost2.crt",
ABS_SRCDIR "/mhdhost2.key");
load_keys ("mhdhost1", SRCDIR "/mhdhost1.crt",
SRCDIR "/mhdhost1.key");
load_keys ("mhdhost2", SRCDIR "/mhdhost2.crt",
SRCDIR "/mhdhost2.key");
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
| MHD_USE_ERROR_LOG,
@@ -87,7 +87,6 @@ main (int argc, char *const *argv)
{
unsigned int errorCount = 0;
const char *aes256_sha = "AES256-SHA";
FILE *crt;
(void) argc;
(void) argv; /* Unused. Silent compiler warning. */
@@ -106,13 +105,6 @@ main (int argc, char *const *argv)
return 77;
}
if (NULL == (crt = setup_ca_cert ()))
{
fprintf (stderr, MHD_E_TEST_FILE_CREAT);
curl_global_cleanup ();
return 99;
}
fclose (crt);
if (curl_tls_is_nss ())
{
aes256_sha = "rsa_aes_256_sha";
@@ -124,9 +116,5 @@ main (int argc, char *const *argv)
print_test_result (errorCount, argv[0]);
curl_global_cleanup ();
if (0 != remove (ca_cert_file_name))
fprintf (stderr,
"Failed to remove `%s'\n",
ca_cert_file_name);
return errorCount != 0 ? 1 : 0;
}
-30
View File
@@ -27,36 +27,6 @@
#include "tls_test_keys.h"
FILE *
setup_ca_cert (void)
{
FILE *cert_fd;
if (NULL == (cert_fd = fopen (ca_cert_file_name, "wb+")))
{
fprintf (stderr, "Error: failed to open `%s': %s\n",
ca_cert_file_name, strerror (errno));
return NULL;
}
if (fwrite (ca_cert_pem, sizeof (char), strlen (ca_cert_pem) + 1, cert_fd)
!= strlen (ca_cert_pem) + 1)
{
fprintf (stderr, "Error: failed to write `%s. %s'\n",
ca_cert_file_name, strerror (errno));
fclose (cert_fd);
return NULL;
}
if (fflush (cert_fd))
{
fprintf (stderr, "Error: failed to flush ca cert file stream. %s\n",
strerror (errno));
fclose (cert_fd);
return NULL;
}
return cert_fd;
}
/*
* test HTTPS transfer
*/
+1 -4
View File
@@ -33,7 +33,7 @@
#define CURL_VERBOS_LEVEL 0
#define test_data "Hello World\n"
#define ca_cert_file_name "tmp_ca_cert.pem"
#define ca_cert_file_name SRCDIR "/test-ca.crt"
#define EMPTY_PAGE \
"<html><head><title>Empty page</title></head><body>Empty page</body></html>"
@@ -89,9 +89,6 @@ curl_tls_is_schannel (void);
int
curl_tls_is_sectransport (void);
FILE *
setup_ca_cert (void);
/**
* perform cURL request for file
*/