aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/https/test_https_time_out.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/https/test_https_time_out.c')
-rw-r--r--src/testcurl/https/test_https_time_out.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/src/testcurl/https/test_https_time_out.c b/src/testcurl/https/test_https_time_out.c
index c86aaccd..a6d1b3bb 100644
--- a/src/testcurl/https/test_https_time_out.c
+++ b/src/testcurl/https/test_https_time_out.c
@@ -1,6 +1,7 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 Copyright (C) 2007 Christian Grothoff 3 Copyright (C) 2007 Christian Grothoff
4 Copyright (C) 2014-2021 Karlson2k (Evgeny Grin)
4 5
5 libmicrohttpd is free software; you can redistribute it and/or modify 6 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 7 it under the terms of the GNU General Public License as published
@@ -23,6 +24,7 @@
23 * @brief: daemon TLS alert response test-case 24 * @brief: daemon TLS alert response test-case
24 * 25 *
25 * @author Sagie Amir 26 * @author Sagie Amir
27 * @author Karlson2k (Evgeny Grin)
26 */ 28 */
27 29
28#include "platform.h" 30#include "platform.h"
@@ -31,6 +33,9 @@
31#ifdef MHD_HTTPS_REQUIRE_GRYPT 33#ifdef MHD_HTTPS_REQUIRE_GRYPT
32#include <gcrypt.h> 34#include <gcrypt.h>
33#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 35#endif /* MHD_HTTPS_REQUIRE_GRYPT */
36#ifdef HAVE_SIGNAL_H
37#include <signal.h>
38#endif /* HAVE_SIGNAL_H */
34#include "mhd_sockets.h" /* only macros used */ 39#include "mhd_sockets.h" /* only macros used */
35 40
36 41
@@ -83,7 +88,7 @@ test_tls_session_time_out (gnutls_session_t session, int port)
83 if (sd == MHD_INVALID_SOCKET) 88 if (sd == MHD_INVALID_SOCKET)
84 { 89 {
85 fprintf (stderr, "Failed to create socket: %s\n", strerror (errno)); 90 fprintf (stderr, "Failed to create socket: %s\n", strerror (errno));
86 return -1; 91 return 2;
87 } 92 }
88 93
89 memset (&sa, '\0', sizeof (struct sockaddr_in)); 94 memset (&sa, '\0', sizeof (struct sockaddr_in));
@@ -91,33 +96,37 @@ test_tls_session_time_out (gnutls_session_t session, int port)
91 sa.sin_port = htons (port); 96 sa.sin_port = htons (port);
92 sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 97 sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
93 98
94 gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) (intptr_t) sd);
95
96 ret = connect (sd, (struct sockaddr *) &sa, sizeof (struct sockaddr_in)); 99 ret = connect (sd, (struct sockaddr *) &sa, sizeof (struct sockaddr_in));
97 100
98 if (ret < 0) 101 if (ret < 0)
99 { 102 {
100 fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT); 103 fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT);
101 MHD_socket_close_chk_ (sd); 104 MHD_socket_close_chk_ (sd);
102 return -1; 105 return 2;
103 } 106 }
104 107
108#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030109) && ! defined(_WIN64)
109 gnutls_transport_set_int (session, (int) (sd));
110#else /* GnuTLS before 3.1.9 or Win64 */
111 gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) (intptr_t) (sd));
112#endif /* GnuTLS before 3.1.9 or Win64 */
113
105 ret = gnutls_handshake (session); 114 ret = gnutls_handshake (session);
106 if (ret < 0) 115 if (ret < 0)
107 { 116 {
108 fprintf (stderr, "Handshake failed\n"); 117 fprintf (stderr, "Handshake failed\n");
109 MHD_socket_close_chk_ (sd); 118 MHD_socket_close_chk_ (sd);
110 return -1; 119 return 2;
111 } 120 }
112 121
113 (void) sleep (TIME_OUT + 1); 122 (void) sleep (TIME_OUT + 2);
114 123
115 /* check that server has closed the connection */ 124 /* check that server has closed the connection */
116 if (1 == num_disconnects) 125 if (1 == num_disconnects)
117 { 126 {
118 fprintf (stderr, "Connection failed to time-out\n"); 127 fprintf (stderr, "Connection failed to time-out\n");
119 MHD_socket_close_chk_ (sd); 128 MHD_socket_close_chk_ (sd);
120 return -1; 129 return 1;
121 } 130 }
122 else if (0 != num_disconnects) 131 else if (0 != num_disconnects)
123 abort (); 132 abort ();
@@ -133,8 +142,6 @@ main (int argc, char *const *argv)
133 int errorCount = 0; 142 int errorCount = 0;
134 struct MHD_Daemon *d; 143 struct MHD_Daemon *d;
135 gnutls_session_t session; 144 gnutls_session_t session;
136 gnutls_datum_t key;
137 gnutls_datum_t cert;
138 gnutls_certificate_credentials_t xcred; 145 gnutls_certificate_credentials_t xcred;
139 int port; 146 int port;
140 (void) argc; /* Unused. Silent compiler warning. */ 147 (void) argc; /* Unused. Silent compiler warning. */
@@ -144,13 +151,30 @@ main (int argc, char *const *argv)
144 else 151 else
145 port = 3070; 152 port = 3070;
146 153
154#ifdef MHD_SEND_SPIPE_SUPPRESS_NEEDED
155#if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)
156 if (SIG_ERR == signal (SIGPIPE, SIG_IGN))
157 {
158 fprintf (stderr, "Error suppressing SIGPIPE signal.\n");
159 exit (99);
160 }
161#else /* ! HAVE_SIGNAL_H || ! SIGPIPE */
162 fprintf (stderr, "Cannot suppress SIGPIPE signal.\n");
163 /* exit (77); */
164#endif
165#endif /* MHD_SEND_SPIPE_SUPPRESS_NEEDED */
166
147#ifdef MHD_HTTPS_REQUIRE_GRYPT 167#ifdef MHD_HTTPS_REQUIRE_GRYPT
148 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); 168 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
149#ifdef GCRYCTL_INITIALIZATION_FINISHED 169#ifdef GCRYCTL_INITIALIZATION_FINISHED
150 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); 170 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
151#endif 171#endif
152#endif /* MHD_HTTPS_REQUIRE_GRYPT */ 172#endif /* MHD_HTTPS_REQUIRE_GRYPT */
153 gnutls_global_init (); 173 if (GNUTLS_E_SUCCESS != gnutls_global_init ())
174 {
175 fprintf (stderr, "Cannot initialize GnuTLS.\n");
176 exit (99);
177 }
154 gnutls_global_set_log_level (11); 178 gnutls_global_set_log_level (11);
155 179
156 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION 180 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
@@ -178,13 +202,13 @@ main (int argc, char *const *argv)
178 port = (int) dinfo->port; 202 port = (int) dinfo->port;
179 } 203 }
180 204
181 if (0 != setup_session (&session, &key, &cert, &xcred)) 205 if (0 != setup_session (&session, &xcred))
182 { 206 {
183 fprintf (stderr, "failed to setup session\n"); 207 fprintf (stderr, "failed to setup session\n");
184 return 1; 208 return 1;
185 } 209 }
186 errorCount += test_tls_session_time_out (session, port); 210 errorCount += test_tls_session_time_out (session, port);
187 teardown_session (session, &key, &cert, xcred); 211 teardown_session (session, xcred);
188 212
189 print_test_result (errorCount, argv[0]); 213 print_test_result (errorCount, argv[0]);
190 214