aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/https/tls_cipher_change_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcurl/https/tls_cipher_change_test.c')
-rw-r--r--src/testcurl/https/tls_cipher_change_test.c72
1 files changed, 37 insertions, 35 deletions
diff --git a/src/testcurl/https/tls_cipher_change_test.c b/src/testcurl/https/tls_cipher_change_test.c
index cbd832e4..78881a62 100644
--- a/src/testcurl/https/tls_cipher_change_test.c
+++ b/src/testcurl/https/tls_cipher_change_test.c
@@ -47,7 +47,7 @@ rehandshake_ahc (void *cls, struct MHD_Connection *connection,
47{ 47{
48 int ret; 48 int ret;
49 /* server side re-handshake request */ 49 /* server side re-handshake request */
50 ret = MHD_gnutls_rehandshake (connection->tls_session); 50 ret = MHD__gnutls_rehandshake (connection->tls_session);
51 51
52 if (ret < 0) 52 if (ret < 0)
53 { 53 {
@@ -59,45 +59,46 @@ rehandshake_ahc (void *cls, struct MHD_Connection *connection,
59} 59}
60 60
61static int 61static int
62setup (mhd_gtls_session_t * session, 62setup (MHD_gtls_session_t * session,
63 gnutls_datum_t * key, 63 MHD_gnutls_datum_t * key,
64 gnutls_datum_t * cert, mhd_gtls_cert_credentials_t * xcred) 64 MHD_gnutls_datum_t * cert, MHD_gtls_cert_credentials_t * xcred)
65{ 65{
66 int ret; 66 int ret;
67 const char **err_pos; 67 const char **err_pos;
68 68
69 MHD_gnutls_certificate_allocate_credentials (xcred); 69 MHD__gnutls_certificate_allocate_credentials (xcred);
70 70
71 mhd_gtls_set_datum_m (key, srv_key_pem, strlen (srv_key_pem), &malloc); 71 MHD_gtls_set_datum_m (key, srv_key_pem, strlen (srv_key_pem), &malloc);
72 mhd_gtls_set_datum_m (cert, srv_self_signed_cert_pem, 72 MHD_gtls_set_datum_m (cert, srv_self_signed_cert_pem,
73 strlen (srv_self_signed_cert_pem), &malloc); 73 strlen (srv_self_signed_cert_pem), &malloc);
74 74
75 MHD_gnutls_certificate_set_x509_key_mem (*xcred, cert, key, 75 MHD__gnutls_certificate_set_x509_key_mem (*xcred, cert, key,
76 GNUTLS_X509_FMT_PEM); 76 GNUTLS_X509_FMT_PEM);
77 77
78 MHD_gnutls_init (session, GNUTLS_CLIENT); 78 MHD__gnutls_init (session, GNUTLS_CLIENT);
79 ret = MHD_gnutls_priority_set_direct (*session, "NORMAL", err_pos); 79 ret = MHD__gnutls_priority_set_direct (*session, "NORMAL", err_pos);
80 if (ret < 0) 80 if (ret < 0)
81 { 81 {
82 return -1; 82 return -1;
83 } 83 }
84 84
85 MHD_gnutls_credentials_set (*session, MHD_GNUTLS_CRD_CERTIFICATE, xcred); 85 MHD__gnutls_credentials_set (*session, MHD_GNUTLS_CRD_CERTIFICATE, xcred);
86 return 0; 86 return 0;
87} 87}
88 88
89static int 89static int
90teardown (mhd_gtls_session_t session, 90teardown (MHD_gtls_session_t session,
91 gnutls_datum_t * key, 91 MHD_gnutls_datum_t * key,
92 gnutls_datum_t * cert, mhd_gtls_cert_credentials_t xcred) 92 MHD_gnutls_datum_t * cert,
93 MHD_gtls_cert_credentials_t xcred)
93{ 94{
94 95
95 mhd_gtls_free_datum_m (key, free); 96 MHD_gtls_free_datum_m (key, free);
96 mhd_gtls_free_datum_m (cert, free); 97 MHD_gtls_free_datum_m (cert, free);
97 98
98 MHD_gnutls_deinit (session); 99 MHD__gnutls_deinit (session);
99 100
100 MHD_gnutls_certificate_free_credentials (xcred); 101 MHD__gnutls_certificate_free_credentials (xcred);
101 return 0; 102 return 0;
102} 103}
103 104
@@ -110,7 +111,7 @@ teardown (mhd_gtls_session_t session,
110 * @param session: initiallized TLS session 111 * @param session: initiallized TLS session
111 */ 112 */
112static int 113static int
113test_out_of_context_cipher_change (mhd_gtls_session_t session) 114test_out_of_context_cipher_change (MHD_gtls_session_t session)
114{ 115{
115 int sd, ret; 116 int sd, ret;
116 struct sockaddr_in sa; 117 struct sockaddr_in sa;
@@ -121,7 +122,7 @@ test_out_of_context_cipher_change (mhd_gtls_session_t session)
121 sa.sin_port = htons (42433); 122 sa.sin_port = htons (42433);
122 inet_pton (AF_INET, "127.0.0.1", &sa.sin_addr); 123 inet_pton (AF_INET, "127.0.0.1", &sa.sin_addr);
123 124
124 MHD_gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); 125 MHD__gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) sd);
125 126
126 ret = connect (sd, &sa, sizeof (struct sockaddr_in)); 127 ret = connect (sd, &sa, sizeof (struct sockaddr_in));
127 128
@@ -131,14 +132,14 @@ test_out_of_context_cipher_change (mhd_gtls_session_t session)
131 return -1; 132 return -1;
132 } 133 }
133 134
134 ret = MHD_gnutls_handshake (session); 135 ret = MHD__gnutls_handshake (session);
135 if (ret < 0) 136 if (ret < 0)
136 { 137 {
137 return -1; 138 return -1;
138 } 139 }
139 140
140 /* send an out of context cipher change spec */ 141 /* send an out of context cipher change spec */
141 mhd_gtls_send_change_cipher_spec (session, 0); 142 MHD_gtls_send_change_cipher_spec (session, 0);
142 143
143 144
144 /* assert server has closed connection */ 145 /* assert server has closed connection */
@@ -155,7 +156,7 @@ test_out_of_context_cipher_change (mhd_gtls_session_t session)
155 156
156/* */ 157/* */
157static int 158static int
158test_rehandshake (mhd_gtls_session_t session) 159test_rehandshake (MHD_gtls_session_t session)
159{ 160{
160 int sd, ret; 161 int sd, ret;
161 struct sockaddr_in sa; 162 struct sockaddr_in sa;
@@ -166,7 +167,7 @@ test_rehandshake (mhd_gtls_session_t session)
166 sa.sin_port = htons (42433); 167 sa.sin_port = htons (42433);
167 inet_pton (AF_INET, "127.0.0.1", &sa.sin_addr); 168 inet_pton (AF_INET, "127.0.0.1", &sa.sin_addr);
168 169
169 MHD_gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); 170 MHD__gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) sd);
170 171
171 ret = connect (sd, &sa, sizeof (struct sockaddr_in)); 172 ret = connect (sd, &sa, sizeof (struct sockaddr_in));
172 173
@@ -176,22 +177,22 @@ test_rehandshake (mhd_gtls_session_t session)
176 return -1; 177 return -1;
177 } 178 }
178 179
179 ret = MHD_gnutls_handshake (session); 180 ret = MHD__gnutls_handshake (session);
180 if (ret < 0) 181 if (ret < 0)
181 { 182 {
182 return -1; 183 return 1;
183 } 184 }
184 185
185 ret = MHD_gnutls_record_send (session, http_get_req, strlen (http_get_req)); 186 ret = MHD__gnutls_record_send (session, http_get_req, strlen (http_get_req));
186 187
187 /* check server responds with a 'close-notify' */ 188 /* check server responds with a 'close-notify' */
188 mhd_gtls_recv_int (session, GNUTLS_ALERT, GNUTLS_HANDSHAKE_FINISHED, 0, 0); 189 MHD_gtls_recv_int (session, GNUTLS_ALERT, GNUTLS_HANDSHAKE_FINISHED, 0, 0);
189 190
190 191
191 /* CLOSE_NOTIFY */ 192 /* CLOSE_NOTIFY */
192 if (session->internals.last_alert != GNUTLS_A_CLOSE_NOTIFY) 193 if (session->internals.last_alert != GNUTLS_A_CLOSE_NOTIFY)
193 { 194 {
194 return -1; 195 return 1;
195 } 196 }
196 197
197 close (sd); 198 close (sd);
@@ -203,12 +204,12 @@ main (int argc, char *const *argv)
203{ 204{
204 int errorCount = 0;; 205 int errorCount = 0;;
205 struct MHD_Daemon *d; 206 struct MHD_Daemon *d;
206 mhd_gtls_session_t session; 207 MHD_gtls_session_t session;
207 gnutls_datum_t key; 208 MHD_gnutls_datum_t key;
208 gnutls_datum_t cert; 209 MHD_gnutls_datum_t cert;
209 mhd_gtls_cert_credentials_t xcred; 210 MHD_gtls_cert_credentials_t xcred;
210 211
211 MHD_gnutls_global_init (); 212 MHD__gnutls_global_init ();
212 MHD_gtls_global_set_log_level (11); 213 MHD_gtls_global_set_log_level (11);
213 214
214 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL | 215 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
@@ -226,13 +227,14 @@ main (int argc, char *const *argv)
226 227
227 setup (&session, &key, &cert, &xcred); 228 setup (&session, &key, &cert, &xcred);
228 errorCount += test_out_of_context_cipher_change (session); 229 errorCount += test_out_of_context_cipher_change (session);
230 errorCount += test_rehandshake (session);
229 teardown (session, &key, &cert, xcred); 231 teardown (session, &key, &cert, xcred);
230 232
231 if (errorCount != 0) 233 if (errorCount != 0)
232 fprintf (stderr, "Failed test: %s.\n", argv[0]); 234 fprintf (stderr, "Failed test: %s.\n", argv[0]);
233 235
234 MHD_stop_daemon (d); 236 MHD_stop_daemon (d);
235 MHD_gnutls_global_deinit (); 237 MHD__gnutls_global_deinit ();
236 238
237 return errorCount != 0; 239 return errorCount != 0;
238} 240}