diff options
Diffstat (limited to 'src/testcurl/https/tls_cipher_change_test.c')
-rw-r--r-- | src/testcurl/https/tls_cipher_change_test.c | 65 |
1 files changed, 10 insertions, 55 deletions
diff --git a/src/testcurl/https/tls_cipher_change_test.c b/src/testcurl/https/tls_cipher_change_test.c index cb5b74c6..6890537c 100644 --- a/src/testcurl/https/tls_cipher_change_test.c +++ b/src/testcurl/https/tls_cipher_change_test.c | |||
@@ -31,10 +31,10 @@ | |||
31 | #include "gnutls_int.h" | 31 | #include "gnutls_int.h" |
32 | #include "gnutls_datum.h" | 32 | #include "gnutls_datum.h" |
33 | #include "gnutls_record.h" | 33 | #include "gnutls_record.h" |
34 | #include "tls_test_keys.h" | ||
35 | 34 | ||
36 | #define MHD_E_SERVER_INIT "Error: failed to start server\n" | 35 | #include "tls_test_common.h" |
37 | #define MHD_E_FAILED_TO_CONNECT "Error: server connection could not be established\n" | 36 | extern const char srv_key_pem[]; |
37 | extern const char srv_self_signed_cert_pem[]; | ||
38 | 38 | ||
39 | char *http_get_req = "GET / HTTP/1.1\r\n\r\n"; | 39 | char *http_get_req = "GET / HTTP/1.1\r\n\r\n"; |
40 | 40 | ||
@@ -58,49 +58,6 @@ rehandshake_ahc (void *cls, struct MHD_Connection *connection, | |||
58 | return 0; | 58 | return 0; |
59 | } | 59 | } |
60 | 60 | ||
61 | static int | ||
62 | setup (MHD_gtls_session_t * session, | ||
63 | MHD_gnutls_datum_t * key, | ||
64 | MHD_gnutls_datum_t * cert, MHD_gtls_cert_credentials_t * xcred) | ||
65 | { | ||
66 | int ret; | ||
67 | const char *err_pos; | ||
68 | |||
69 | MHD__gnutls_certificate_allocate_credentials (xcred); | ||
70 | |||
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, | ||
73 | strlen (srv_self_signed_cert_pem), &malloc); | ||
74 | |||
75 | MHD__gnutls_certificate_set_x509_key_mem (*xcred, cert, key, | ||
76 | GNUTLS_X509_FMT_PEM); | ||
77 | |||
78 | MHD__gnutls_init (session, GNUTLS_CLIENT); | ||
79 | ret = MHD__gnutls_priority_set_direct (*session, "NORMAL", &err_pos); | ||
80 | if (ret < 0) | ||
81 | { | ||
82 | return -1; | ||
83 | } | ||
84 | |||
85 | MHD__gnutls_credentials_set (*session, MHD_GNUTLS_CRD_CERTIFICATE, xcred); | ||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | static int | ||
90 | teardown (MHD_gtls_session_t session, | ||
91 | MHD_gnutls_datum_t * key, | ||
92 | MHD_gnutls_datum_t * cert, MHD_gtls_cert_credentials_t xcred) | ||
93 | { | ||
94 | |||
95 | MHD_gtls_free_datum_m (key, free); | ||
96 | MHD_gtls_free_datum_m (cert, free); | ||
97 | |||
98 | MHD__gnutls_deinit (session); | ||
99 | |||
100 | MHD__gnutls_certificate_free_credentials (xcred); | ||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | /* | 61 | /* |
105 | * Cipher change message should only occur while negotiating | 62 | * Cipher change message should only occur while negotiating |
106 | * the SSL/TLS handshake. | 63 | * the SSL/TLS handshake. |
@@ -118,14 +75,13 @@ test_out_of_context_cipher_change (MHD_gtls_session_t session) | |||
118 | sd = socket (AF_INET, SOCK_STREAM, 0); | 75 | sd = socket (AF_INET, SOCK_STREAM, 0); |
119 | if (sd == -1) | 76 | if (sd == -1) |
120 | { | 77 | { |
121 | fprintf(stderr, | 78 | fprintf (stderr, "Failed to create socket: %s\n", strerror (errno)); |
122 | "Failed to create socket: %s\n", | ||
123 | strerror(errno)); | ||
124 | return -1; | 79 | return -1; |
125 | } | 80 | } |
81 | |||
126 | memset (&sa, '\0', sizeof (struct sockaddr_in)); | 82 | memset (&sa, '\0', sizeof (struct sockaddr_in)); |
127 | sa.sin_family = AF_INET; | 83 | sa.sin_family = AF_INET; |
128 | sa.sin_port = htons (42433); | 84 | sa.sin_port = htons (DEAMON_TEST_PORT); |
129 | inet_pton (AF_INET, "127.0.0.1", &sa.sin_addr); | 85 | inet_pton (AF_INET, "127.0.0.1", &sa.sin_addr); |
130 | 86 | ||
131 | MHD__gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) sd); | 87 | MHD__gnutls_transport_set_ptr (session, (MHD_gnutls_transport_ptr_t) sd); |
@@ -173,7 +129,7 @@ main (int argc, char *const *argv) | |||
173 | MHD_gtls_global_set_log_level (11); | 129 | MHD_gtls_global_set_log_level (11); |
174 | 130 | ||
175 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL | | 131 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL | |
176 | MHD_USE_DEBUG, 42433, | 132 | MHD_USE_DEBUG, DEAMON_TEST_PORT, |
177 | NULL, NULL, &rehandshake_ahc, NULL, | 133 | NULL, NULL, &rehandshake_ahc, NULL, |
178 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | 134 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, |
179 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, | 135 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, |
@@ -185,12 +141,11 @@ main (int argc, char *const *argv) | |||
185 | return -1; | 141 | return -1; |
186 | } | 142 | } |
187 | 143 | ||
188 | setup (&session, &key, &cert, &xcred); | 144 | setup_session (&session, &key, &cert, &xcred); |
189 | errorCount += test_out_of_context_cipher_change (session); | 145 | errorCount += test_out_of_context_cipher_change (session); |
190 | teardown (session, &key, &cert, xcred); | 146 | teardown_session (session, &key, &cert, xcred); |
191 | 147 | ||
192 | if (errorCount != 0) | 148 | print_test_result (errorCount, argv[0]); |
193 | fprintf (stderr, "Failed test: %s.\n", argv[0]); | ||
194 | 149 | ||
195 | MHD_stop_daemon (d); | 150 | MHD_stop_daemon (d); |
196 | MHD__gnutls_global_deinit (); | 151 | MHD__gnutls_global_deinit (); |