diff options
Diffstat (limited to 'src/testcurl/https/test_https_get.c')
-rw-r--r-- | src/testcurl/https/test_https_get.c | 156 |
1 files changed, 151 insertions, 5 deletions
diff --git a/src/testcurl/https/test_https_get.c b/src/testcurl/https/test_https_get.c index 17248bf7..8f62e46c 100644 --- a/src/testcurl/https/test_https_get.c +++ b/src/testcurl/https/test_https_get.c | |||
@@ -37,6 +37,10 @@ | |||
37 | extern const char srv_signed_cert_pem[]; | 37 | extern const char srv_signed_cert_pem[]; |
38 | extern const char srv_signed_key_pem[]; | 38 | extern const char srv_signed_key_pem[]; |
39 | 39 | ||
40 | |||
41 | static int global_port; | ||
42 | |||
43 | |||
40 | /* perform a HTTP GET request via SSL/TLS */ | 44 | /* perform a HTTP GET request via SSL/TLS */ |
41 | static int | 45 | static int |
42 | test_secure_get (FILE *test_fd, | 46 | test_secure_get (FILE *test_fd, |
@@ -55,7 +59,8 @@ test_secure_get (FILE *test_fd, | |||
55 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 59 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
56 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | 60 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
57 | | MHD_USE_ERROR_LOG, port, | 61 | | MHD_USE_ERROR_LOG, port, |
58 | NULL, NULL, &http_ahc, NULL, | 62 | NULL, NULL, |
63 | &http_ahc, NULL, | ||
59 | MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, | 64 | MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, |
60 | MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, | 65 | MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, |
61 | MHD_OPTION_END); | 66 | MHD_OPTION_END); |
@@ -76,13 +81,156 @@ test_secure_get (FILE *test_fd, | |||
76 | port = (int) dinfo->port; | 81 | port = (int) dinfo->port; |
77 | } | 82 | } |
78 | 83 | ||
79 | ret = test_https_transfer (test_fd, port, cipher_suite, proto_version); | 84 | ret = test_https_transfer (test_fd, |
85 | port, | ||
86 | cipher_suite, | ||
87 | proto_version); | ||
80 | 88 | ||
81 | MHD_stop_daemon (d); | 89 | MHD_stop_daemon (d); |
82 | return ret; | 90 | return ret; |
83 | } | 91 | } |
84 | 92 | ||
85 | 93 | ||
94 | static int | ||
95 | ahc_empty (void *cls, | ||
96 | struct MHD_Connection *connection, | ||
97 | const char *url, | ||
98 | const char *method, | ||
99 | const char *version, | ||
100 | const char *upload_data, | ||
101 | size_t *upload_data_size, | ||
102 | void **unused) | ||
103 | { | ||
104 | static int ptr; | ||
105 | struct MHD_Response *response; | ||
106 | int ret; | ||
107 | (void) cls; | ||
108 | (void) url; | ||
109 | (void) url; | ||
110 | (void) version; /* Unused. Silent compiler warning. */ | ||
111 | (void) upload_data; | ||
112 | (void) upload_data_size; /* Unused. Silent compiler warning. */ | ||
113 | |||
114 | if (0 != strcasecmp ("GET", | ||
115 | method)) | ||
116 | return MHD_NO; /* unexpected method */ | ||
117 | if (&ptr != *unused) | ||
118 | { | ||
119 | *unused = &ptr; | ||
120 | return MHD_YES; | ||
121 | } | ||
122 | *unused = NULL; | ||
123 | response = MHD_create_response_from_buffer (0, | ||
124 | NULL, | ||
125 | MHD_RESPMEM_PERSISTENT); | ||
126 | ret = MHD_queue_response (connection, | ||
127 | MHD_HTTP_OK, | ||
128 | response); | ||
129 | MHD_destroy_response (response); | ||
130 | if (ret == MHD_NO) | ||
131 | { | ||
132 | fprintf (stderr, "Failed to queue response.\n"); | ||
133 | _exit (20); | ||
134 | } | ||
135 | return ret; | ||
136 | } | ||
137 | |||
138 | |||
139 | static int | ||
140 | curlExcessFound (CURL *c, | ||
141 | curl_infotype type, | ||
142 | char *data, | ||
143 | size_t size, | ||
144 | void *cls) | ||
145 | { | ||
146 | static const char *excess_found = "Excess found"; | ||
147 | const size_t str_size = strlen (excess_found); | ||
148 | (void) c; /* Unused. Silence compiler warning. */ | ||
149 | |||
150 | if ((CURLINFO_TEXT == type) | ||
151 | &&(size >= str_size) | ||
152 | &&(0 == strncmp (excess_found, data, str_size))) | ||
153 | *(int *) cls = 1; | ||
154 | return 0; | ||
155 | } | ||
156 | |||
157 | |||
158 | static int | ||
159 | testEmptyGet (int poll_flag) | ||
160 | { | ||
161 | struct MHD_Daemon *d; | ||
162 | CURL *c; | ||
163 | char buf[2048]; | ||
164 | struct CBC cbc; | ||
165 | CURLcode errornum; | ||
166 | int excess_found = 0; | ||
167 | |||
168 | |||
169 | if ( (0 == global_port) && | ||
170 | (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) ) | ||
171 | { | ||
172 | global_port = 1225; | ||
173 | |||
174 | } | ||
175 | |||
176 | cbc.buf = buf; | ||
177 | cbc.size = 2048; | ||
178 | cbc.pos = 0; | ||
179 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | ||
180 | | poll_flag | MHD_USE_TLS, | ||
181 | global_port, NULL, NULL, | ||
182 | &ahc_empty, NULL, | ||
183 | MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, | ||
184 | MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, | ||
185 | MHD_OPTION_END); | ||
186 | if (d == NULL) | ||
187 | return 4194304; | ||
188 | if (0 == global_port) | ||
189 | { | ||
190 | const union MHD_DaemonInfo *dinfo; | ||
191 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
192 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
193 | { | ||
194 | MHD_stop_daemon (d); return 32; | ||
195 | } | ||
196 | global_port = (int) dinfo->port; | ||
197 | } | ||
198 | c = curl_easy_init (); | ||
199 | curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1/"); | ||
200 | curl_easy_setopt (c, CURLOPT_PORT, (long) global_port); | ||
201 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
202 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
203 | curl_easy_setopt (c, CURLOPT_DEBUGFUNCTION, &curlExcessFound); | ||
204 | curl_easy_setopt (c, CURLOPT_DEBUGDATA, &excess_found); | ||
205 | curl_easy_setopt (c, CURLOPT_VERBOSE, 1L); | ||
206 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | ||
207 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
208 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L); | ||
209 | curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0L); | ||
210 | curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0L); | ||
211 | /* NOTE: use of CONNECTTIMEOUT without also | ||
212 | setting NOSIGNAL results in really weird | ||
213 | crashes on my system!*/ | ||
214 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | ||
215 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
216 | { | ||
217 | fprintf (stderr, | ||
218 | "curl_easy_perform failed: `%s'\n", | ||
219 | curl_easy_strerror (errornum)); | ||
220 | curl_easy_cleanup (c); | ||
221 | MHD_stop_daemon (d); | ||
222 | return 8388608; | ||
223 | } | ||
224 | curl_easy_cleanup (c); | ||
225 | MHD_stop_daemon (d); | ||
226 | if (cbc.pos != 0) | ||
227 | return 16777216; | ||
228 | if (excess_found) | ||
229 | return 33554432; | ||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | |||
86 | int | 234 | int |
87 | main (int argc, char *const *argv) | 235 | main (int argc, char *const *argv) |
88 | { | 236 | { |
@@ -109,11 +257,9 @@ main (int argc, char *const *argv) | |||
109 | { | 257 | { |
110 | aes256_sha_tlsv1 = "rsa_aes_256_sha"; | 258 | aes256_sha_tlsv1 = "rsa_aes_256_sha"; |
111 | } | 259 | } |
112 | |||
113 | errorCount += | 260 | errorCount += |
114 | test_secure_get (NULL, aes256_sha_tlsv1, CURL_SSLVERSION_TLSv1); | 261 | test_secure_get (NULL, aes256_sha_tlsv1, CURL_SSLVERSION_TLSv1); |
115 | print_test_result (errorCount, argv[0]); | 262 | errorCount += testEmptyGet (0); |
116 | |||
117 | curl_global_cleanup (); | 263 | curl_global_cleanup (); |
118 | 264 | ||
119 | return errorCount != 0 ? 1 : 0; | 265 | return errorCount != 0 ? 1 : 0; |