David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2014, Google Inc. |
| 2 | * |
| 3 | * Permission to use, copy, modify, and/or distribute this software for any |
| 4 | * purpose with or without fee is hereby granted, provided that the above |
| 5 | * copyright notice and this permission notice appear in all copies. |
| 6 | * |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 14 | |
Adam Langley | ded9358 | 2014-07-31 15:23:51 -0700 | [diff] [blame] | 15 | #include <openssl/base.h> |
| 16 | |
| 17 | #if !defined(OPENSSL_WINDOWS) |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 18 | #include <arpa/inet.h> |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 19 | #include <netinet/in.h> |
| 20 | #include <signal.h> |
| 21 | #include <sys/socket.h> |
David Benjamin | 8f2c20e | 2014-07-09 09:30:38 -0400 | [diff] [blame] | 22 | #include <unistd.h> |
Adam Langley | ded9358 | 2014-07-31 15:23:51 -0700 | [diff] [blame] | 23 | #endif |
| 24 | |
| 25 | #include <sys/types.h> |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 26 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 27 | #include <openssl/bio.h> |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 28 | #include <openssl/buf.h> |
David Benjamin | 8f2c20e | 2014-07-09 09:30:38 -0400 | [diff] [blame] | 29 | #include <openssl/bytestring.h> |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 30 | #include <openssl/ssl.h> |
| 31 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 32 | #include "async_bio.h" |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 33 | #include "packeted_bio.h" |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 34 | #include "test_config.h" |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 35 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 36 | static int usage(const char *program) { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 37 | fprintf(stderr, "Usage: %s [flags...]\n", |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 38 | program); |
| 39 | return 1; |
| 40 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 41 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 42 | static int g_ex_data_index = 0; |
| 43 | |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame^] | 44 | static bool SetConfigPtr(SSL *ssl, const TestConfig *config) { |
| 45 | return SSL_set_ex_data(ssl, g_ex_data_index, (void *)config) == 1; |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static const TestConfig *GetConfigPtr(SSL *ssl) { |
| 49 | return (const TestConfig *)SSL_get_ex_data(ssl, g_ex_data_index); |
| 50 | } |
| 51 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 52 | static EVP_PKEY *LoadPrivateKey(const std::string &file) { |
| 53 | BIO *bio = BIO_new(BIO_s_file()); |
| 54 | if (bio == NULL) { |
| 55 | return NULL; |
| 56 | } |
| 57 | if (!BIO_read_filename(bio, file.c_str())) { |
| 58 | BIO_free(bio); |
| 59 | return NULL; |
| 60 | } |
| 61 | EVP_PKEY *pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL); |
| 62 | BIO_free(bio); |
| 63 | return pkey; |
| 64 | } |
| 65 | |
David Benjamin | 1f5f62b | 2014-07-12 16:18:02 -0400 | [diff] [blame] | 66 | static int early_callback_called = 0; |
David Benjamin | 8f2c20e | 2014-07-09 09:30:38 -0400 | [diff] [blame] | 67 | |
David Benjamin | 1f5f62b | 2014-07-12 16:18:02 -0400 | [diff] [blame] | 68 | static int select_certificate_callback(const struct ssl_early_callback_ctx *ctx) { |
David Benjamin | 8f2c20e | 2014-07-09 09:30:38 -0400 | [diff] [blame] | 69 | early_callback_called = 1; |
| 70 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 71 | const TestConfig *config = GetConfigPtr(ctx->ssl); |
| 72 | |
| 73 | if (config->expected_server_name.empty()) { |
David Benjamin | 7b03051 | 2014-07-08 17:30:11 -0400 | [diff] [blame] | 74 | return 1; |
| 75 | } |
David Benjamin | 8f2c20e | 2014-07-09 09:30:38 -0400 | [diff] [blame] | 76 | |
David Benjamin | 7b03051 | 2014-07-08 17:30:11 -0400 | [diff] [blame] | 77 | const uint8_t *extension_data; |
| 78 | size_t extension_len; |
| 79 | CBS extension, server_name_list, host_name; |
| 80 | uint8_t name_type; |
David Benjamin | 8f2c20e | 2014-07-09 09:30:38 -0400 | [diff] [blame] | 81 | |
David Benjamin | 7b03051 | 2014-07-08 17:30:11 -0400 | [diff] [blame] | 82 | if (!SSL_early_callback_ctx_extension_get(ctx, TLSEXT_TYPE_server_name, |
| 83 | &extension_data, |
| 84 | &extension_len)) { |
| 85 | fprintf(stderr, "Could not find server_name extension.\n"); |
| 86 | return -1; |
| 87 | } |
David Benjamin | 8f2c20e | 2014-07-09 09:30:38 -0400 | [diff] [blame] | 88 | |
David Benjamin | 7b03051 | 2014-07-08 17:30:11 -0400 | [diff] [blame] | 89 | CBS_init(&extension, extension_data, extension_len); |
| 90 | if (!CBS_get_u16_length_prefixed(&extension, &server_name_list) || |
| 91 | CBS_len(&extension) != 0 || |
| 92 | !CBS_get_u8(&server_name_list, &name_type) || |
| 93 | name_type != TLSEXT_NAMETYPE_host_name || |
| 94 | !CBS_get_u16_length_prefixed(&server_name_list, &host_name) || |
| 95 | CBS_len(&server_name_list) != 0) { |
| 96 | fprintf(stderr, "Could not decode server_name extension.\n"); |
| 97 | return -1; |
| 98 | } |
| 99 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 100 | if (!CBS_mem_equal(&host_name, |
| 101 | (const uint8_t*)config->expected_server_name.data(), |
| 102 | config->expected_server_name.size())) { |
David Benjamin | 7b03051 | 2014-07-08 17:30:11 -0400 | [diff] [blame] | 103 | fprintf(stderr, "Server name mismatch.\n"); |
David Benjamin | 8f2c20e | 2014-07-09 09:30:38 -0400 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | return 1; |
| 107 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 108 | |
David Benjamin | 1f5f62b | 2014-07-12 16:18:02 -0400 | [diff] [blame] | 109 | static int skip_verify(int preverify_ok, X509_STORE_CTX *store_ctx) { |
David Benjamin | 67666e7 | 2014-07-12 15:47:52 -0400 | [diff] [blame] | 110 | return 1; |
| 111 | } |
| 112 | |
David Benjamin | 1f5f62b | 2014-07-12 16:18:02 -0400 | [diff] [blame] | 113 | static int next_protos_advertised_callback(SSL *ssl, |
David Benjamin | 7e3305e | 2014-07-28 14:52:32 -0400 | [diff] [blame] | 114 | const uint8_t **out, |
| 115 | unsigned int *out_len, |
| 116 | void *arg) { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 117 | const TestConfig *config = GetConfigPtr(ssl); |
| 118 | if (config->advertise_npn.empty()) |
David Benjamin | 1f5f62b | 2014-07-12 16:18:02 -0400 | [diff] [blame] | 119 | return SSL_TLSEXT_ERR_NOACK; |
| 120 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 121 | *out = (const uint8_t*)config->advertise_npn.data(); |
| 122 | *out_len = config->advertise_npn.size(); |
David Benjamin | 1f5f62b | 2014-07-12 16:18:02 -0400 | [diff] [blame] | 123 | return SSL_TLSEXT_ERR_OK; |
| 124 | } |
| 125 | |
David Benjamin | 7e3305e | 2014-07-28 14:52:32 -0400 | [diff] [blame] | 126 | static int next_proto_select_callback(SSL* ssl, |
| 127 | uint8_t** out, |
| 128 | uint8_t* outlen, |
| 129 | const uint8_t* in, |
| 130 | unsigned inlen, |
| 131 | void* arg) { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 132 | const TestConfig *config = GetConfigPtr(ssl); |
| 133 | if (config->select_next_proto.empty()) |
David Benjamin | 7e3305e | 2014-07-28 14:52:32 -0400 | [diff] [blame] | 134 | return SSL_TLSEXT_ERR_NOACK; |
| 135 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 136 | *out = (uint8_t*)config->select_next_proto.data(); |
| 137 | *outlen = config->select_next_proto.size(); |
David Benjamin | 7e3305e | 2014-07-28 14:52:32 -0400 | [diff] [blame] | 138 | return SSL_TLSEXT_ERR_OK; |
| 139 | } |
| 140 | |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 141 | static int alpn_select_callback(SSL* ssl, |
| 142 | const uint8_t** out, |
| 143 | uint8_t* outlen, |
| 144 | const uint8_t* in, |
| 145 | unsigned inlen, |
| 146 | void* arg) { |
| 147 | const TestConfig *config = GetConfigPtr(ssl); |
| 148 | if (config->select_alpn.empty()) |
| 149 | return SSL_TLSEXT_ERR_NOACK; |
| 150 | |
| 151 | if (!config->expected_advertised_alpn.empty() && |
| 152 | (config->expected_advertised_alpn.size() != inlen || |
| 153 | memcmp(config->expected_advertised_alpn.data(), |
| 154 | in, inlen) != 0)) { |
| 155 | fprintf(stderr, "bad ALPN select callback inputs\n"); |
| 156 | exit(1); |
| 157 | } |
| 158 | |
| 159 | *out = (const uint8_t*)config->select_alpn.data(); |
| 160 | *outlen = config->select_alpn.size(); |
| 161 | return SSL_TLSEXT_ERR_OK; |
| 162 | } |
| 163 | |
David Benjamin | fb4ea28 | 2014-08-15 13:38:15 -0400 | [diff] [blame] | 164 | static int cookie_generate_callback(SSL *ssl, uint8_t *cookie, size_t *cookie_len) { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 165 | *cookie_len = 32; |
| 166 | memset(cookie, 42, *cookie_len); |
| 167 | return 1; |
| 168 | } |
| 169 | |
David Benjamin | fb4ea28 | 2014-08-15 13:38:15 -0400 | [diff] [blame] | 170 | static int cookie_verify_callback(SSL *ssl, const uint8_t *cookie, size_t cookie_len) { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 171 | if (cookie_len != 32) { |
| 172 | fprintf(stderr, "Cookie length mismatch.\n"); |
| 173 | return 0; |
| 174 | } |
| 175 | for (size_t i = 0; i < cookie_len; i++) { |
| 176 | if (cookie[i] != 42) { |
| 177 | fprintf(stderr, "Cookie mismatch.\n"); |
| 178 | return 0; |
| 179 | } |
| 180 | } |
| 181 | return 1; |
| 182 | } |
| 183 | |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 184 | static unsigned psk_client_callback(SSL *ssl, const char *hint, |
| 185 | char *out_identity, |
| 186 | unsigned max_identity_len, |
| 187 | uint8_t *out_psk, unsigned max_psk_len) { |
| 188 | const TestConfig *config = GetConfigPtr(ssl); |
| 189 | |
| 190 | if (strcmp(hint ? hint : "", config->psk_identity.c_str()) != 0) { |
| 191 | fprintf(stderr, "Server PSK hint did not match.\n"); |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | // Account for the trailing '\0' for the identity. |
| 196 | if (config->psk_identity.size() >= max_identity_len || |
| 197 | config->psk.size() > max_psk_len) { |
| 198 | fprintf(stderr, "PSK buffers too small\n"); |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | BUF_strlcpy(out_identity, config->psk_identity.c_str(), |
| 203 | max_identity_len); |
| 204 | memcpy(out_psk, config->psk.data(), config->psk.size()); |
| 205 | return config->psk.size(); |
| 206 | } |
| 207 | |
| 208 | static unsigned psk_server_callback(SSL *ssl, const char *identity, |
| 209 | uint8_t *out_psk, unsigned max_psk_len) { |
| 210 | const TestConfig *config = GetConfigPtr(ssl); |
| 211 | |
| 212 | if (strcmp(identity, config->psk_identity.c_str()) != 0) { |
| 213 | fprintf(stderr, "Client PSK identity did not match.\n"); |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | if (config->psk.size() > max_psk_len) { |
| 218 | fprintf(stderr, "PSK buffers too small\n"); |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | memcpy(out_psk, config->psk.data(), config->psk.size()); |
| 223 | return config->psk.size(); |
| 224 | } |
| 225 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 226 | static SSL_CTX *setup_ctx(const TestConfig *config) { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 227 | SSL_CTX *ssl_ctx = NULL; |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 228 | DH *dh = NULL; |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 229 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 230 | const SSL_METHOD *method; |
| 231 | if (config->is_dtls) { |
| 232 | // TODO(davidben): Get DTLS 1.2 working and test the version negotiation |
| 233 | // codepath. This doesn't currently work because |
| 234 | // - Session resumption is broken: https://crbug.com/403378 |
| 235 | // - DTLS hasn't been updated for EVP_AEAD. |
| 236 | if (config->is_server) { |
| 237 | method = DTLSv1_server_method(); |
| 238 | } else { |
| 239 | method = DTLSv1_client_method(); |
| 240 | } |
| 241 | } else { |
| 242 | if (config->is_server) { |
| 243 | method = SSLv23_server_method(); |
| 244 | } else { |
| 245 | method = SSLv23_client_method(); |
| 246 | } |
| 247 | } |
| 248 | ssl_ctx = SSL_CTX_new(method); |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 249 | if (ssl_ctx == NULL) { |
| 250 | goto err; |
| 251 | } |
| 252 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 253 | if (config->is_dtls) { |
| 254 | // DTLS needs read-ahead to function on a datagram BIO. |
| 255 | // |
| 256 | // TODO(davidben): this should not be necessary. DTLS code should only |
| 257 | // expect a datagram BIO. |
| 258 | SSL_CTX_set_read_ahead(ssl_ctx, 1); |
| 259 | } |
| 260 | |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 261 | if (!SSL_CTX_set_ecdh_auto(ssl_ctx, 1)) { |
| 262 | goto err; |
| 263 | } |
| 264 | |
| 265 | if (!SSL_CTX_set_cipher_list(ssl_ctx, "ALL")) { |
| 266 | goto err; |
| 267 | } |
| 268 | |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 269 | dh = DH_get_2048_256(NULL); |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame^] | 270 | if (dh == NULL || |
| 271 | !SSL_CTX_set_tmp_dh(ssl_ctx, dh)) { |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 272 | goto err; |
| 273 | } |
| 274 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 275 | SSL_CTX_set_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_BOTH); |
| 276 | |
David Benjamin | 8f2c20e | 2014-07-09 09:30:38 -0400 | [diff] [blame] | 277 | ssl_ctx->select_certificate_cb = select_certificate_callback; |
| 278 | |
David Benjamin | 1f5f62b | 2014-07-12 16:18:02 -0400 | [diff] [blame] | 279 | SSL_CTX_set_next_protos_advertised_cb( |
| 280 | ssl_ctx, next_protos_advertised_callback, NULL); |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 281 | if (!config->select_next_proto.empty()) { |
| 282 | SSL_CTX_set_next_proto_select_cb(ssl_ctx, next_proto_select_callback, NULL); |
| 283 | } |
| 284 | |
| 285 | if (!config->select_alpn.empty()) { |
| 286 | SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_callback, NULL); |
| 287 | } |
David Benjamin | 1f5f62b | 2014-07-12 16:18:02 -0400 | [diff] [blame] | 288 | |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 289 | SSL_CTX_set_cookie_generate_cb(ssl_ctx, cookie_generate_callback); |
| 290 | SSL_CTX_set_cookie_verify_cb(ssl_ctx, cookie_verify_callback); |
| 291 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 292 | ssl_ctx->tlsext_channel_id_enabled_new = 1; |
| 293 | |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 294 | DH_free(dh); |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 295 | return ssl_ctx; |
| 296 | |
| 297 | err: |
David Benjamin | f4e5c4e | 2014-08-02 17:35:45 -0400 | [diff] [blame] | 298 | if (dh != NULL) { |
| 299 | DH_free(dh); |
| 300 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 301 | if (ssl_ctx != NULL) { |
| 302 | SSL_CTX_free(ssl_ctx); |
| 303 | } |
| 304 | return NULL; |
| 305 | } |
| 306 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 307 | static int retry_async(SSL *ssl, int ret, BIO *bio) { |
| 308 | // No error; don't retry. |
| 309 | if (ret >= 0) { |
| 310 | return 0; |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 311 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 312 | // See if we needed to read or write more. If so, allow one byte through on |
| 313 | // the appropriate end to maximally stress the state machine. |
| 314 | int err = SSL_get_error(ssl, ret); |
| 315 | if (err == SSL_ERROR_WANT_READ) { |
| 316 | async_bio_allow_read(bio, 1); |
| 317 | return 1; |
| 318 | } else if (err == SSL_ERROR_WANT_WRITE) { |
| 319 | async_bio_allow_write(bio, 1); |
| 320 | return 1; |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 321 | } |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 322 | return 0; |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 323 | } |
| 324 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 325 | static int do_exchange(SSL_SESSION **out_session, |
| 326 | SSL_CTX *ssl_ctx, |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 327 | const TestConfig *config, |
| 328 | bool is_resume, |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 329 | int fd, |
| 330 | SSL_SESSION *session) { |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 331 | early_callback_called = 0; |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 332 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 333 | SSL *ssl = SSL_new(ssl_ctx); |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 334 | if (ssl == NULL) { |
| 335 | BIO_print_errors_fp(stdout); |
| 336 | return 1; |
| 337 | } |
| 338 | |
Adam Langley | 69a0160 | 2014-11-17 17:26:55 -0800 | [diff] [blame^] | 339 | if (!SetConfigPtr(ssl, config)) { |
| 340 | BIO_print_errors_fp(stdout); |
| 341 | return 1; |
| 342 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 343 | |
| 344 | if (config->fallback_scsv) { |
| 345 | if (!SSL_enable_fallback_scsv(ssl)) { |
| 346 | BIO_print_errors_fp(stdout); |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 347 | return 1; |
| 348 | } |
| 349 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 350 | if (!config->key_file.empty()) { |
| 351 | if (!SSL_use_PrivateKey_file(ssl, config->key_file.c_str(), |
| 352 | SSL_FILETYPE_PEM)) { |
| 353 | BIO_print_errors_fp(stdout); |
| 354 | return 1; |
| 355 | } |
| 356 | } |
| 357 | if (!config->cert_file.empty()) { |
| 358 | if (!SSL_use_certificate_file(ssl, config->cert_file.c_str(), |
| 359 | SSL_FILETYPE_PEM)) { |
| 360 | BIO_print_errors_fp(stdout); |
| 361 | return 1; |
| 362 | } |
| 363 | } |
| 364 | if (config->require_any_client_certificate) { |
| 365 | SSL_set_verify(ssl, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, |
| 366 | skip_verify); |
| 367 | } |
| 368 | if (config->false_start) { |
| 369 | SSL_set_mode(ssl, SSL_MODE_HANDSHAKE_CUTTHROUGH); |
| 370 | } |
| 371 | if (config->cbc_record_splitting) { |
| 372 | SSL_set_mode(ssl, SSL_MODE_CBC_RECORD_SPLITTING); |
| 373 | } |
| 374 | if (config->partial_write) { |
| 375 | SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE); |
| 376 | } |
| 377 | if (config->no_tls12) { |
| 378 | SSL_set_options(ssl, SSL_OP_NO_TLSv1_2); |
| 379 | } |
| 380 | if (config->no_tls11) { |
| 381 | SSL_set_options(ssl, SSL_OP_NO_TLSv1_1); |
| 382 | } |
| 383 | if (config->no_tls1) { |
| 384 | SSL_set_options(ssl, SSL_OP_NO_TLSv1); |
| 385 | } |
| 386 | if (config->no_ssl3) { |
| 387 | SSL_set_options(ssl, SSL_OP_NO_SSLv3); |
| 388 | } |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 389 | if (config->cookie_exchange) { |
| 390 | SSL_set_options(ssl, SSL_OP_COOKIE_EXCHANGE); |
| 391 | } |
David Benjamin | 5c24a1d | 2014-08-31 00:59:27 -0400 | [diff] [blame] | 392 | if (config->tls_d5_bug) { |
| 393 | SSL_set_options(ssl, SSL_OP_TLS_D5_BUG); |
| 394 | } |
David Benjamin | ca6554b | 2014-11-08 12:31:52 -0500 | [diff] [blame] | 395 | if (config->allow_unsafe_legacy_renegotiation) { |
| 396 | SSL_set_options(ssl, SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION); |
| 397 | } |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 398 | if (!config->expected_channel_id.empty()) { |
| 399 | SSL_enable_tls_channel_id(ssl); |
| 400 | } |
| 401 | if (!config->send_channel_id.empty()) { |
| 402 | EVP_PKEY *pkey = LoadPrivateKey(config->send_channel_id); |
| 403 | if (pkey == NULL) { |
| 404 | BIO_print_errors_fp(stdout); |
| 405 | return 1; |
| 406 | } |
| 407 | SSL_enable_tls_channel_id(ssl); |
| 408 | if (!SSL_set1_tls_channel_id(ssl, pkey)) { |
| 409 | EVP_PKEY_free(pkey); |
| 410 | BIO_print_errors_fp(stdout); |
| 411 | return 1; |
| 412 | } |
| 413 | EVP_PKEY_free(pkey); |
| 414 | } |
David Benjamin | e78bfde | 2014-09-06 12:45:15 -0400 | [diff] [blame] | 415 | if (!config->host_name.empty()) { |
| 416 | SSL_set_tlsext_host_name(ssl, config->host_name.c_str()); |
| 417 | } |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 418 | if (!config->advertise_alpn.empty()) { |
| 419 | SSL_set_alpn_protos(ssl, (const uint8_t *)config->advertise_alpn.data(), |
| 420 | config->advertise_alpn.size()); |
| 421 | } |
David Benjamin | 48cae08 | 2014-10-27 01:06:24 -0400 | [diff] [blame] | 422 | if (!config->psk.empty()) { |
| 423 | SSL_set_psk_client_callback(ssl, psk_client_callback); |
| 424 | SSL_set_psk_server_callback(ssl, psk_server_callback); |
| 425 | } |
| 426 | if (!config->psk_identity.empty()) { |
| 427 | if (!SSL_use_psk_identity_hint(ssl, config->psk_identity.c_str())) { |
| 428 | BIO_print_errors_fp(stdout); |
| 429 | return 1; |
| 430 | } |
| 431 | } |
David Benjamin | ca6c826 | 2014-11-15 19:06:08 -0500 | [diff] [blame] | 432 | if (!config->srtp_profiles.empty()) { |
| 433 | if (!SSL_set_srtp_profiles(ssl, config->srtp_profiles.c_str())) { |
| 434 | BIO_print_errors_fp(stdout); |
| 435 | return 1; |
| 436 | } |
| 437 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 438 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 439 | BIO *bio = BIO_new_fd(fd, 1 /* take ownership */); |
| 440 | if (bio == NULL) { |
| 441 | BIO_print_errors_fp(stdout); |
| 442 | return 1; |
| 443 | } |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 444 | if (config->is_dtls) { |
| 445 | BIO *packeted = packeted_bio_create(); |
| 446 | BIO_push(packeted, bio); |
| 447 | bio = packeted; |
| 448 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 449 | if (config->async) { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 450 | BIO *async = |
| 451 | config->is_dtls ? async_bio_create_datagram() : async_bio_create(); |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 452 | BIO_push(async, bio); |
| 453 | bio = async; |
| 454 | } |
| 455 | SSL_set_bio(ssl, bio, bio); |
| 456 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 457 | if (session != NULL) { |
| 458 | if (SSL_set_session(ssl, session) != 1) { |
| 459 | fprintf(stderr, "failed to set session\n"); |
| 460 | return 2; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | int ret; |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 465 | do { |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 466 | if (config->is_server) { |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 467 | ret = SSL_accept(ssl); |
| 468 | } else { |
| 469 | ret = SSL_connect(ssl); |
| 470 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 471 | } while (config->async && retry_async(ssl, ret, bio)); |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 472 | if (ret != 1) { |
| 473 | SSL_free(ssl); |
| 474 | BIO_print_errors_fp(stdout); |
| 475 | return 2; |
| 476 | } |
| 477 | |
David Benjamin | 01fe820 | 2014-09-24 15:21:44 -0400 | [diff] [blame] | 478 | if (is_resume && (SSL_session_reused(ssl) == config->expect_session_miss)) { |
| 479 | fprintf(stderr, "session was%s reused\n", |
| 480 | SSL_session_reused(ssl) ? "" : " not"); |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 481 | return 2; |
| 482 | } |
| 483 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 484 | if (!config->expected_server_name.empty()) { |
David Benjamin | 197b3ab | 2014-07-02 18:37:33 -0400 | [diff] [blame] | 485 | const char *server_name = |
| 486 | SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 487 | if (server_name != config->expected_server_name) { |
David Benjamin | 197b3ab | 2014-07-02 18:37:33 -0400 | [diff] [blame] | 488 | fprintf(stderr, "servername mismatch (got %s; want %s)\n", |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 489 | server_name, config->expected_server_name.c_str()); |
David Benjamin | 197b3ab | 2014-07-02 18:37:33 -0400 | [diff] [blame] | 490 | return 2; |
| 491 | } |
David Benjamin | 8f2c20e | 2014-07-09 09:30:38 -0400 | [diff] [blame] | 492 | |
| 493 | if (!early_callback_called) { |
| 494 | fprintf(stderr, "early callback not called\n"); |
| 495 | return 2; |
| 496 | } |
David Benjamin | 197b3ab | 2014-07-02 18:37:33 -0400 | [diff] [blame] | 497 | } |
| 498 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 499 | if (!config->expected_certificate_types.empty()) { |
David Benjamin | 7b03051 | 2014-07-08 17:30:11 -0400 | [diff] [blame] | 500 | uint8_t *certificate_types; |
| 501 | int num_certificate_types = |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 502 | SSL_get0_certificate_types(ssl, &certificate_types); |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 503 | if (num_certificate_types != |
| 504 | (int)config->expected_certificate_types.size() || |
David Benjamin | 7b03051 | 2014-07-08 17:30:11 -0400 | [diff] [blame] | 505 | memcmp(certificate_types, |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 506 | config->expected_certificate_types.data(), |
David Benjamin | 7b03051 | 2014-07-08 17:30:11 -0400 | [diff] [blame] | 507 | num_certificate_types) != 0) { |
| 508 | fprintf(stderr, "certificate types mismatch\n"); |
| 509 | return 2; |
| 510 | } |
| 511 | } |
| 512 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 513 | if (!config->expected_next_proto.empty()) { |
David Benjamin | 1f5f62b | 2014-07-12 16:18:02 -0400 | [diff] [blame] | 514 | const uint8_t *next_proto; |
| 515 | unsigned next_proto_len; |
| 516 | SSL_get0_next_proto_negotiated(ssl, &next_proto, &next_proto_len); |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 517 | if (next_proto_len != config->expected_next_proto.size() || |
| 518 | memcmp(next_proto, config->expected_next_proto.data(), |
| 519 | next_proto_len) != 0) { |
David Benjamin | 1f5f62b | 2014-07-12 16:18:02 -0400 | [diff] [blame] | 520 | fprintf(stderr, "negotiated next proto mismatch\n"); |
| 521 | return 2; |
| 522 | } |
| 523 | } |
| 524 | |
David Benjamin | ae2888f | 2014-09-06 12:58:58 -0400 | [diff] [blame] | 525 | if (!config->expected_alpn.empty()) { |
| 526 | const uint8_t *alpn_proto; |
| 527 | unsigned alpn_proto_len; |
| 528 | SSL_get0_alpn_selected(ssl, &alpn_proto, &alpn_proto_len); |
| 529 | if (alpn_proto_len != config->expected_alpn.size() || |
| 530 | memcmp(alpn_proto, config->expected_alpn.data(), |
| 531 | alpn_proto_len) != 0) { |
| 532 | fprintf(stderr, "negotiated alpn proto mismatch\n"); |
| 533 | return 2; |
| 534 | } |
| 535 | } |
| 536 | |
David Benjamin | a08e49d | 2014-08-24 01:46:07 -0400 | [diff] [blame] | 537 | if (!config->expected_channel_id.empty()) { |
| 538 | uint8_t channel_id[64]; |
| 539 | if (!SSL_get_tls_channel_id(ssl, channel_id, sizeof(channel_id))) { |
| 540 | fprintf(stderr, "no channel id negotiated\n"); |
| 541 | return 2; |
| 542 | } |
| 543 | if (config->expected_channel_id.size() != 64 || |
| 544 | memcmp(config->expected_channel_id.data(), |
| 545 | channel_id, 64) != 0) { |
| 546 | fprintf(stderr, "channel id mismatch\n"); |
| 547 | return 2; |
| 548 | } |
| 549 | } |
| 550 | |
Adam Langley | 7571292 | 2014-10-10 16:23:43 -0700 | [diff] [blame] | 551 | if (config->expect_extended_master_secret) { |
| 552 | if (!ssl->session->extended_master_secret) { |
| 553 | fprintf(stderr, "No EMS for session when expected"); |
| 554 | return 2; |
| 555 | } |
| 556 | } |
| 557 | |
Adam Langley | 2ae77d2 | 2014-10-28 17:29:33 -0700 | [diff] [blame] | 558 | if (config->renegotiate) { |
| 559 | if (config->async) { |
| 560 | fprintf(stderr, "--renegotiate is not supported with --async.\n"); |
| 561 | return 2; |
| 562 | } |
| 563 | |
| 564 | SSL_renegotiate(ssl); |
| 565 | |
| 566 | ret = SSL_do_handshake(ssl); |
| 567 | if (ret != 1) { |
| 568 | SSL_free(ssl); |
| 569 | BIO_print_errors_fp(stdout); |
| 570 | return 2; |
| 571 | } |
| 572 | |
| 573 | SSL_set_state(ssl, SSL_ST_ACCEPT); |
| 574 | ret = SSL_do_handshake(ssl); |
| 575 | if (ret != 1) { |
| 576 | SSL_free(ssl); |
| 577 | BIO_print_errors_fp(stdout); |
| 578 | return 2; |
| 579 | } |
| 580 | } |
| 581 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 582 | if (config->write_different_record_sizes) { |
David Benjamin | 6fd297b | 2014-08-11 18:43:38 -0400 | [diff] [blame] | 583 | if (config->is_dtls) { |
| 584 | fprintf(stderr, "write_different_record_sizes not supported for DTLS\n"); |
| 585 | return 6; |
| 586 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 587 | // This mode writes a number of different record sizes in an attempt to |
| 588 | // trip up the CBC record splitting code. |
| 589 | uint8_t buf[32769]; |
| 590 | memset(buf, 0x42, sizeof(buf)); |
| 591 | static const size_t kRecordSizes[] = { |
| 592 | 0, 1, 255, 256, 257, 16383, 16384, 16385, 32767, 32768, 32769}; |
| 593 | for (size_t i = 0; i < sizeof(kRecordSizes) / sizeof(kRecordSizes[0]); |
| 594 | i++) { |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 595 | int w; |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 596 | const size_t len = kRecordSizes[i]; |
| 597 | size_t off = 0; |
| 598 | |
| 599 | if (len > sizeof(buf)) { |
| 600 | fprintf(stderr, "Bad kRecordSizes value.\n"); |
| 601 | return 5; |
| 602 | } |
| 603 | |
David Benjamin | 43ec06f | 2014-08-05 02:28:57 -0400 | [diff] [blame] | 604 | do { |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 605 | w = SSL_write(ssl, buf + off, len - off); |
| 606 | if (w > 0) { |
| 607 | off += (size_t) w; |
| 608 | } |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 609 | } while ((config->async && retry_async(ssl, w, bio)) || |
| 610 | (w > 0 && off < len)); |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 611 | |
| 612 | if (w < 0 || off != len) { |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 613 | SSL_free(ssl); |
| 614 | BIO_print_errors_fp(stdout); |
| 615 | return 4; |
| 616 | } |
| 617 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 618 | } else { |
David Benjamin | e58c4f5 | 2014-08-24 03:47:07 -0400 | [diff] [blame] | 619 | if (config->shim_writes_first) { |
| 620 | int w; |
| 621 | do { |
| 622 | w = SSL_write(ssl, "hello", 5); |
| 623 | } while (config->async && retry_async(ssl, w, bio)); |
| 624 | } |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 625 | for (;;) { |
| 626 | uint8_t buf[512]; |
| 627 | int n; |
| 628 | do { |
| 629 | n = SSL_read(ssl, buf, sizeof(buf)); |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 630 | } while (config->async && retry_async(ssl, n, bio)); |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 631 | if (n < 0) { |
| 632 | SSL_free(ssl); |
| 633 | BIO_print_errors_fp(stdout); |
| 634 | return 3; |
| 635 | } else if (n == 0) { |
| 636 | break; |
| 637 | } else { |
| 638 | for (int i = 0; i < n; i++) { |
| 639 | buf[i] ^= 0xff; |
| 640 | } |
| 641 | int w; |
| 642 | do { |
| 643 | w = SSL_write(ssl, buf, n); |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 644 | } while (config->async && retry_async(ssl, w, bio)); |
Kenny Root | 7fdeaf1 | 2014-08-05 15:23:37 -0700 | [diff] [blame] | 645 | if (w != n) { |
| 646 | SSL_free(ssl); |
| 647 | BIO_print_errors_fp(stdout); |
| 648 | return 4; |
| 649 | } |
| 650 | } |
| 651 | } |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 652 | } |
| 653 | |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 654 | if (out_session) { |
| 655 | *out_session = SSL_get1_session(ssl); |
| 656 | } |
| 657 | |
| 658 | SSL_shutdown(ssl); |
David Benjamin | 025b3d3 | 2014-07-01 19:53:04 -0400 | [diff] [blame] | 659 | SSL_free(ssl); |
| 660 | return 0; |
| 661 | } |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 662 | |
| 663 | int main(int argc, char **argv) { |
Adam Langley | ded9358 | 2014-07-31 15:23:51 -0700 | [diff] [blame] | 664 | #if !defined(OPENSSL_WINDOWS) |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 665 | signal(SIGPIPE, SIG_IGN); |
Adam Langley | ded9358 | 2014-07-31 15:23:51 -0700 | [diff] [blame] | 666 | #endif |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 667 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 668 | if (!SSL_library_init()) { |
| 669 | return 1; |
| 670 | } |
| 671 | g_ex_data_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL); |
| 672 | |
| 673 | TestConfig config; |
| 674 | if (!ParseConfig(argc - 1, argv + 1, &config)) { |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 675 | return usage(argv[0]); |
| 676 | } |
| 677 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 678 | SSL_CTX *ssl_ctx = setup_ctx(&config); |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 679 | if (ssl_ctx == NULL) { |
| 680 | BIO_print_errors_fp(stdout); |
| 681 | return 1; |
| 682 | } |
| 683 | |
Adam Langley | e7bf281 | 2014-08-19 11:36:45 -0700 | [diff] [blame] | 684 | SSL_SESSION *session = NULL; |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 685 | int ret = do_exchange(&session, |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 686 | ssl_ctx, &config, |
| 687 | false /* is_resume */, |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 688 | 3 /* fd */, NULL /* session */); |
| 689 | if (ret != 0) { |
Adam Langley | e7bf281 | 2014-08-19 11:36:45 -0700 | [diff] [blame] | 690 | goto out; |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 691 | } |
| 692 | |
David Benjamin | 5a593af | 2014-08-11 19:51:50 -0400 | [diff] [blame] | 693 | if (config.resume) { |
Adam Langley | e7bf281 | 2014-08-19 11:36:45 -0700 | [diff] [blame] | 694 | ret = do_exchange(NULL, |
| 695 | ssl_ctx, &config, |
| 696 | true /* is_resume */, |
| 697 | 4 /* fd */, |
| 698 | config.is_server ? NULL : session); |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 699 | if (ret != 0) { |
Adam Langley | e7bf281 | 2014-08-19 11:36:45 -0700 | [diff] [blame] | 700 | goto out; |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 701 | } |
| 702 | } |
| 703 | |
Adam Langley | e7bf281 | 2014-08-19 11:36:45 -0700 | [diff] [blame] | 704 | ret = 0; |
| 705 | |
| 706 | out: |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 707 | SSL_SESSION_free(session); |
| 708 | SSL_CTX_free(ssl_ctx); |
Adam Langley | e7bf281 | 2014-08-19 11:36:45 -0700 | [diff] [blame] | 709 | return ret; |
David Benjamin | 1d5c83e | 2014-07-22 19:20:02 -0400 | [diff] [blame] | 710 | } |