aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-10-10 16:25:38 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-10-10 16:25:38 +0300
commit4ccbeb54f9df34c7b844b5c1e562181786c9a916 (patch)
tree85226d7b535e858e1b033e77ec9d62093eac278c
parentc930fe1ae351b63502580491c4b02e8a2fdef0f8 (diff)
downloadlibmicrohttpd-4ccbeb54f9df34c7b844b5c1e562181786c9a916.tar.gz
libmicrohttpd-4ccbeb54f9df34c7b844b5c1e562181786c9a916.zip
testcurl/https: handle libcurl with missing custom CA support
-rw-r--r--src/testcurl/https/test_https_multi_daemon.c42
-rw-r--r--src/testcurl/https/test_tls_authentication.c35
-rw-r--r--src/testcurl/https/tls_test_common.c24
-rw-r--r--src/testcurl/https/tls_test_common.h17
4 files changed, 99 insertions, 19 deletions
diff --git a/src/testcurl/https/test_https_multi_daemon.c b/src/testcurl/https/test_https_multi_daemon.c
index 8ffef656..b7b9b065 100644
--- a/src/testcurl/https/test_https_multi_daemon.c
+++ b/src/testcurl/https/test_https_multi_daemon.c
@@ -47,12 +47,12 @@ test_concurent_daemon_pair (void *cls,
47 int proto_version) 47 int proto_version)
48{ 48{
49 unsigned int ret; 49 unsigned int ret;
50 enum test_get_result res;
50 struct MHD_Daemon *d1; 51 struct MHD_Daemon *d1;
51 struct MHD_Daemon *d2; 52 struct MHD_Daemon *d2;
52 uint16_t port1, port2; 53 uint16_t port1, port2;
53 (void) cls; /* Unused. Silent compiler warning. */ 54 (void) cls; /* Unused. Silent compiler warning. */
54 55
55
56 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) 56 if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
57 port1 = port2 = 0; 57 port1 = port2 = 0;
58 else 58 else
@@ -115,15 +115,42 @@ test_concurent_daemon_pair (void *cls,
115 port2 = (int) dinfo->port; 115 port2 = (int) dinfo->port;
116 } 116 }
117 117
118 ret = 118 res =
119 test_daemon_get (NULL, cipher_suite, proto_version, port1, 0); 119 test_daemon_get (NULL, cipher_suite, proto_version, port1, 0);
120 ret += 120 ret = (unsigned int) res;
121 if ((TEST_GET_HARD_ERROR == res) ||
122 (TEST_GET_CURL_GEN_ERROR == res))
123 {
124 fprintf (stderr, "libcurl error.\nTest aborted.\n");
125 MHD_stop_daemon (d2);
126 MHD_stop_daemon (d1);
127 return 99;
128 }
129
130 res =
121 test_daemon_get (NULL, cipher_suite, proto_version, 131 test_daemon_get (NULL, cipher_suite, proto_version,
122 port2, 0); 132 port2, 0);
133 ret += (unsigned int) res;
134 if ((TEST_GET_HARD_ERROR == res) ||
135 (TEST_GET_CURL_GEN_ERROR == res))
136 {
137 fprintf (stderr, "libcurl error.\nTest aborted.\n");
138 MHD_stop_daemon (d2);
139 MHD_stop_daemon (d1);
140 return 99;
141 }
123 142
124 MHD_stop_daemon (d2); 143 MHD_stop_daemon (d2);
125 ret += 144 res =
126 test_daemon_get (NULL, cipher_suite, proto_version, port1, 0); 145 test_daemon_get (NULL, cipher_suite, proto_version, port1, 0);
146 ret += (unsigned int) res;
147 if ((TEST_GET_HARD_ERROR == res) ||
148 (TEST_GET_CURL_GEN_ERROR == res))
149 {
150 fprintf (stderr, "libcurl error.\nTest aborted.\n");
151 MHD_stop_daemon (d1);
152 return 99;
153 }
127 MHD_stop_daemon (d1); 154 MHD_stop_daemon (d1);
128 return ret; 155 return ret;
129} 156}
@@ -132,7 +159,7 @@ test_concurent_daemon_pair (void *cls,
132int 159int
133main (int argc, char *const *argv) 160main (int argc, char *const *argv)
134{ 161{
135 unsigned int errorCount = 0; 162 unsigned int errorCount;
136 (void) argc; (void) argv; /* Unused. Silent compiler warning. */ 163 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
137 164
138#ifdef MHD_HTTPS_REQUIRE_GCRYPT 165#ifdef MHD_HTTPS_REQUIRE_GCRYPT
@@ -150,11 +177,14 @@ main (int argc, char *const *argv)
150 return 77; 177 return 77;
151 } 178 }
152 179
153 errorCount += 180 errorCount =
154 test_concurent_daemon_pair (NULL, NULL, CURL_SSLVERSION_DEFAULT); 181 test_concurent_daemon_pair (NULL, NULL, CURL_SSLVERSION_DEFAULT);
155 182
156 print_test_result (errorCount, "concurent_daemon_pair"); 183 print_test_result (errorCount, "concurent_daemon_pair");
157 184
158 curl_global_cleanup (); 185 curl_global_cleanup ();
186 if (99 == errorCount)
187 return 99;
188
159 return errorCount != 0 ? 1 : 0; 189 return errorCount != 0 ? 1 : 0;
160} 190}
diff --git a/src/testcurl/https/test_tls_authentication.c b/src/testcurl/https/test_tls_authentication.c
index 51c87c0e..5637eaaf 100644
--- a/src/testcurl/https/test_tls_authentication.c
+++ b/src/testcurl/https/test_tls_authentication.c
@@ -42,7 +42,7 @@
42static unsigned int 42static unsigned int
43test_secure_get (void *cls, const char *cipher_suite, int proto_version) 43test_secure_get (void *cls, const char *cipher_suite, int proto_version)
44{ 44{
45 unsigned int ret; 45 enum test_get_result ret;
46 struct MHD_Daemon *d; 46 struct MHD_Daemon *d;
47 uint16_t port; 47 uint16_t port;
48 (void) cls; /* Unused. Silent compiler warning. */ 48 (void) cls; /* Unused. Silent compiler warning. */
@@ -80,14 +80,28 @@ test_secure_get (void *cls, const char *cipher_suite, int proto_version)
80 ret = test_daemon_get (NULL, cipher_suite, proto_version, port, 1); 80 ret = test_daemon_get (NULL, cipher_suite, proto_version, port, 1);
81 81
82 MHD_stop_daemon (d); 82 MHD_stop_daemon (d);
83 return ret; 83 if (TEST_GET_HARD_ERROR == ret)
84 return 99;
85 if (TEST_GET_CURL_GEN_ERROR == ret)
86 {
87 fprintf (stderr, "libcurl error.\nTest aborted.\n");
88 return 99;
89 }
90 if ((TEST_GET_CURL_CA_ERROR == ret) ||
91 (TEST_GET_CURL_NOT_IMPLT == ret))
92 {
93 fprintf (stderr, "libcurl TLS backend does not support custom CA.\n"
94 "Test skipped.\n");
95 return 77;
96 }
97 return TEST_GET_OK == ret ? 0 : 1;
84} 98}
85 99
86 100
87int 101int
88main (int argc, char *const *argv) 102main (int argc, char *const *argv)
89{ 103{
90 unsigned int errorCount = 0; 104 unsigned int errorCount;
91 (void) argc; 105 (void) argc;
92 (void) argv; /* Unused. Silent compiler warning. */ 106 (void) argv; /* Unused. Silent compiler warning. */
93 107
@@ -105,12 +119,25 @@ main (int argc, char *const *argv)
105 curl_global_cleanup (); 119 curl_global_cleanup ();
106 return 77; 120 return 77;
107 } 121 }
122#if ! CURL_AT_LEAST_VERSION (7,60,0)
123 if (curl_tls_is_schannel ())
124 {
125 fprintf (stderr, "libcurl before version 7.60.0 does not support "
126 "custom CA with Schannel backend.\nTest skipped.\n");
127 curl_global_cleanup ();
128 return 77;
129 }
130#endif /* ! CURL_AT_LEAST_VERSION(7,60,0) */
108 131
109 errorCount += 132 errorCount =
110 test_secure_get (NULL, NULL, CURL_SSLVERSION_DEFAULT); 133 test_secure_get (NULL, NULL, CURL_SSLVERSION_DEFAULT);
111 134
112 print_test_result (errorCount, argv[0]); 135 print_test_result (errorCount, argv[0]);
113 136
114 curl_global_cleanup (); 137 curl_global_cleanup ();
138 if (77 == errorCount)
139 return 77;
140 if (99 == errorCount)
141 return 77;
115 return errorCount != 0 ? 1 : 0; 142 return errorCount != 0 ? 1 : 0;
116} 143}
diff --git a/src/testcurl/https/tls_test_common.c b/src/testcurl/https/tls_test_common.c
index 98d62482..044394b9 100644
--- a/src/testcurl/https/tls_test_common.c
+++ b/src/testcurl/https/tls_test_common.c
@@ -98,7 +98,7 @@ const long libcurl_tls_max_vers_map[KNOW_TLS_IDS_COUNT] = {
98/* 98/*
99 * test HTTPS transfer 99 * test HTTPS transfer
100 */ 100 */
101unsigned int 101enum test_get_result
102test_daemon_get (void *cls, 102test_daemon_get (void *cls,
103 const char *cipher_suite, 103 const char *cipher_suite,
104 int proto_version, 104 int proto_version,
@@ -117,7 +117,7 @@ test_daemon_get (void *cls,
117 if (NULL == (cbc.buf = malloc (sizeof (char) * len))) 117 if (NULL == (cbc.buf = malloc (sizeof (char) * len)))
118 { 118 {
119 fprintf (stderr, MHD_E_MEM); 119 fprintf (stderr, MHD_E_MEM);
120 return 1; 120 return TEST_GET_HARD_ERROR;
121 } 121 }
122 cbc.size = len; 122 cbc.size = len;
123 cbc.pos = 0; 123 cbc.pos = 0;
@@ -146,7 +146,7 @@ test_daemon_get (void *cls,
146 curl_easy_strerror (e)); 146 curl_easy_strerror (e));
147 curl_easy_cleanup (c); 147 curl_easy_cleanup (c);
148 free (cbc.buf); 148 free (cbc.buf);
149 return 1; 149 return TEST_GET_CURL_GEN_ERROR;
150 } 150 }
151 151
152 /* TLS options */ 152 /* TLS options */
@@ -166,7 +166,7 @@ test_daemon_get (void *cls,
166 curl_easy_strerror (e)); 166 curl_easy_strerror (e));
167 curl_easy_cleanup (c); 167 curl_easy_cleanup (c);
168 free (cbc.buf); 168 free (cbc.buf);
169 return 1; 169 return TEST_GET_CURL_GEN_ERROR;
170 } 170 }
171 if (ver_peer && 171 if (ver_peer &&
172 (CURLE_OK != 172 (CURLE_OK !=
@@ -176,7 +176,7 @@ test_daemon_get (void *cls,
176 curl_easy_strerror (e)); 176 curl_easy_strerror (e));
177 curl_easy_cleanup (c); 177 curl_easy_cleanup (c);
178 free (cbc.buf); 178 free (cbc.buf);
179 return 1; 179 return TEST_GET_CURL_CA_ERROR;
180 } 180 }
181 if (CURLE_OK != (errornum = curl_easy_perform (c))) 181 if (CURLE_OK != (errornum = curl_easy_perform (c)))
182 { 182 {
@@ -184,7 +184,15 @@ test_daemon_get (void *cls,
184 curl_easy_strerror (errornum)); 184 curl_easy_strerror (errornum));
185 curl_easy_cleanup (c); 185 curl_easy_cleanup (c);
186 free (cbc.buf); 186 free (cbc.buf);
187 return 1; 187 if ((CURLE_SSL_CACERT_BADFILE == errornum)
188#if CURL_AT_LEAST_VERSION (7,21,5)
189 || (CURLE_NOT_BUILT_IN == errornum)
190#endif /* CURL_AT_LEAST_VERSION (7,21,5) */
191 )
192 return TEST_GET_CURL_CA_ERROR;
193 if (CURLE_OUT_OF_MEMORY == errornum)
194 return TEST_GET_HARD_ERROR;
195 return TEST_GET_ERROR;
188 } 196 }
189 197
190 curl_easy_cleanup (c); 198 curl_easy_cleanup (c);
@@ -193,11 +201,11 @@ test_daemon_get (void *cls,
193 { 201 {
194 fprintf (stderr, "Error: local data & received data differ.\n"); 202 fprintf (stderr, "Error: local data & received data differ.\n");
195 free (cbc.buf); 203 free (cbc.buf);
196 return 1; 204 return TEST_GET_TRANSFER_ERROR;
197 } 205 }
198 206
199 free (cbc.buf); 207 free (cbc.buf);
200 return 0; 208 return TEST_GET_OK;
201} 209}
202 210
203 211
diff --git a/src/testcurl/https/tls_test_common.h b/src/testcurl/https/tls_test_common.h
index dc4be451..863bab66 100644
--- a/src/testcurl/https/tls_test_common.h
+++ b/src/testcurl/https/tls_test_common.h
@@ -133,10 +133,25 @@ curl_tls_is_schannel (void);
133int 133int
134curl_tls_is_sectransport (void); 134curl_tls_is_sectransport (void);
135 135
136
137enum test_get_result
138{
139 TEST_GET_OK = 0,
140 TEST_GET_ERROR = 1,
141
142 TEST_GET_MHD_ERROR = 16,
143 TEST_GET_TRANSFER_ERROR = 17,
144
145 TEST_GET_CURL_GEN_ERROR = 32,
146 TEST_GET_CURL_CA_ERROR = 33,
147 TEST_GET_CURL_NOT_IMPLT = 34,
148
149 TEST_GET_HARD_ERROR = 999
150};
136/** 151/**
137 * perform cURL request for file 152 * perform cURL request for file
138 */ 153 */
139unsigned int 154enum test_get_result
140test_daemon_get (void *cls, 155test_daemon_get (void *cls,
141 const char *cipher_suite, int proto_version, 156 const char *cipher_suite, int proto_version,
142 uint16_t port, int ver_peer); 157 uint16_t port, int ver_peer);