Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 2 | * All rights reserved. |
| 3 | * |
| 4 | * This package is an SSL implementation written |
| 5 | * by Eric Young (eay@cryptsoft.com). |
| 6 | * The implementation was written so as to conform with Netscapes SSL. |
| 7 | * |
| 8 | * This library is free for commercial and non-commercial use as long as |
| 9 | * the following conditions are aheared to. The following conditions |
| 10 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 11 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 12 | * included with this distribution is covered by the same copyright terms |
| 13 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 14 | * |
| 15 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 16 | * the code are not to be removed. |
| 17 | * If this package is used in a product, Eric Young should be given attribution |
| 18 | * as the author of the parts of the library used. |
| 19 | * This can be in the form of a textual message at program startup or |
| 20 | * in documentation (online or textual) provided with the package. |
| 21 | * |
| 22 | * Redistribution and use in source and binary forms, with or without |
| 23 | * modification, are permitted provided that the following conditions |
| 24 | * are met: |
| 25 | * 1. Redistributions of source code must retain the copyright |
| 26 | * notice, this list of conditions and the following disclaimer. |
| 27 | * 2. Redistributions in binary form must reproduce the above copyright |
| 28 | * notice, this list of conditions and the following disclaimer in the |
| 29 | * documentation and/or other materials provided with the distribution. |
| 30 | * 3. All advertising materials mentioning features or use of this software |
| 31 | * must display the following acknowledgement: |
| 32 | * "This product includes cryptographic software written by |
| 33 | * Eric Young (eay@cryptsoft.com)" |
| 34 | * The word 'cryptographic' can be left out if the rouines from the library |
| 35 | * being used are not cryptographic related :-). |
| 36 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 37 | * the apps directory (application code) you must include an acknowledgement: |
| 38 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 39 | * |
| 40 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 43 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 44 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 45 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 46 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 50 | * SUCH DAMAGE. |
| 51 | * |
| 52 | * The licence and distribution terms for any publically available version or |
| 53 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 54 | * copied and put under another distribution licence |
| 55 | * [including the GNU Public Licence.] |
| 56 | */ |
| 57 | /* ==================================================================== |
| 58 | * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved. |
| 59 | * |
| 60 | * Redistribution and use in source and binary forms, with or without |
| 61 | * modification, are permitted provided that the following conditions |
| 62 | * are met: |
| 63 | * |
| 64 | * 1. Redistributions of source code must retain the above copyright |
| 65 | * notice, this list of conditions and the following disclaimer. |
| 66 | * |
| 67 | * 2. Redistributions in binary form must reproduce the above copyright |
| 68 | * notice, this list of conditions and the following disclaimer in |
| 69 | * the documentation and/or other materials provided with the |
| 70 | * distribution. |
| 71 | * |
| 72 | * 3. All advertising materials mentioning features or use of this |
| 73 | * software must display the following acknowledgment: |
| 74 | * "This product includes software developed by the OpenSSL Project |
| 75 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" |
| 76 | * |
| 77 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
| 78 | * endorse or promote products derived from this software without |
| 79 | * prior written permission. For written permission, please contact |
| 80 | * openssl-core@openssl.org. |
| 81 | * |
| 82 | * 5. Products derived from this software may not be called "OpenSSL" |
| 83 | * nor may "OpenSSL" appear in their names without prior written |
| 84 | * permission of the OpenSSL Project. |
| 85 | * |
| 86 | * 6. Redistributions of any form whatsoever must retain the following |
| 87 | * acknowledgment: |
| 88 | * "This product includes software developed by the OpenSSL Project |
| 89 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" |
| 90 | * |
| 91 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
| 92 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 93 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 94 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
| 95 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 96 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 97 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 98 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 99 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 100 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 101 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 102 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 103 | * ==================================================================== |
| 104 | * |
| 105 | * This product includes cryptographic software written by Eric Young |
| 106 | * (eay@cryptsoft.com). This product includes software written by Tim |
| 107 | * Hudson (tjh@cryptsoft.com). |
| 108 | * |
| 109 | */ |
| 110 | /* ==================================================================== |
| 111 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
| 112 | * ECC cipher suite support in OpenSSL originally developed by |
| 113 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. |
| 114 | */ |
| 115 | /* ==================================================================== |
| 116 | * Copyright 2005 Nokia. All rights reserved. |
| 117 | * |
| 118 | * The portions of the attached software ("Contribution") is developed by |
| 119 | * Nokia Corporation and is licensed pursuant to the OpenSSL open source |
| 120 | * license. |
| 121 | * |
| 122 | * The Contribution, originally written by Mika Kousa and Pasi Eronen of |
| 123 | * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites |
| 124 | * support (see RFC 4279) to OpenSSL. |
| 125 | * |
| 126 | * No patent licenses or other rights except those expressly stated in |
| 127 | * the OpenSSL open source license shall be deemed granted or received |
| 128 | * expressly, by implication, estoppel, or otherwise. |
| 129 | * |
| 130 | * No assurances are provided by Nokia that the Contribution does not |
| 131 | * infringe the patent or other intellectual property rights of any third |
| 132 | * party or that the license provides you with all the necessary rights |
| 133 | * to make use of the Contribution. |
| 134 | * |
| 135 | * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN |
| 136 | * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA |
| 137 | * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY |
| 138 | * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR |
| 139 | * OTHERWISE. */ |
| 140 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 141 | #include <assert.h> |
David Benjamin | f0ae170 | 2015-04-07 23:05:04 -0400 | [diff] [blame] | 142 | #include <stdio.h> |
| 143 | #include <string.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 144 | |
David Benjamin | 39482a1 | 2014-07-20 13:30:15 -0400 | [diff] [blame] | 145 | #include <openssl/bytestring.h> |
David Benjamin | 7c6d09b | 2015-09-05 11:00:19 -0400 | [diff] [blame^] | 146 | #include <openssl/crypto.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 147 | #include <openssl/dh.h> |
David Benjamin | f0ae170 | 2015-04-07 23:05:04 -0400 | [diff] [blame] | 148 | #include <openssl/err.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 149 | #include <openssl/lhash.h> |
| 150 | #include <openssl/mem.h> |
| 151 | #include <openssl/obj.h> |
| 152 | #include <openssl/rand.h> |
| 153 | #include <openssl/x509v3.h> |
| 154 | |
David Benjamin | 2ee94aa | 2015-04-07 22:38:30 -0400 | [diff] [blame] | 155 | #include "internal.h" |
David Benjamin | 546f1a5 | 2015-04-15 16:46:09 -0400 | [diff] [blame] | 156 | #include "../crypto/internal.h" |
| 157 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 158 | |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 159 | /* |SSL_R_UNKNOWN_PROTOCOL| is no longer emitted, but continue to define it |
David Benjamin | 97760d5 | 2015-07-24 23:02:49 -0400 | [diff] [blame] | 160 | * to avoid downstream churn. */ |
David Benjamin | 76c2efc | 2015-08-31 14:24:29 -0400 | [diff] [blame] | 161 | OPENSSL_DECLARE_ERROR_REASON(SSL, UNKNOWN_PROTOCOL) |
David Benjamin | 97760d5 | 2015-07-24 23:02:49 -0400 | [diff] [blame] | 162 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 163 | /* Some error codes are special. Ensure the make_errors.go script never |
| 164 | * regresses this. */ |
| 165 | OPENSSL_COMPILE_ASSERT(SSL_R_TLSV1_ALERT_NO_RENEGOTIATION == |
| 166 | SSL_AD_NO_RENEGOTIATION + SSL_AD_REASON_OFFSET, |
| 167 | ssl_alert_reason_code_mismatch); |
David Benjamin | e113608 | 2014-09-20 12:28:58 -0400 | [diff] [blame] | 168 | |
David Benjamin | 1d0a194 | 2015-04-26 15:35:35 -0400 | [diff] [blame] | 169 | /* kMaxHandshakeSize is the maximum size, in bytes, of a handshake message. */ |
| 170 | static const size_t kMaxHandshakeSize = (1u << 24) - 1; |
| 171 | |
David Benjamin | aa58513 | 2015-06-29 23:36:17 -0400 | [diff] [blame] | 172 | static CRYPTO_EX_DATA_CLASS g_ex_data_class_ssl = |
| 173 | CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA; |
| 174 | static CRYPTO_EX_DATA_CLASS g_ex_data_class_ssl_ctx = |
| 175 | CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA; |
David Benjamin | 9f33fc6 | 2015-04-15 17:29:53 -0400 | [diff] [blame] | 176 | |
David Benjamin | 7c6d09b | 2015-09-05 11:00:19 -0400 | [diff] [blame^] | 177 | int SSL_library_init(void) { |
| 178 | CRYPTO_library_init(); |
| 179 | return 1; |
| 180 | } |
| 181 | |
| 182 | void SSL_load_error_strings(void) {} |
| 183 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 184 | int SSL_clear(SSL *ssl) { |
| 185 | if (ssl->method == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 186 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_METHOD_SPECIFIED); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 187 | return 0; |
| 188 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 189 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 190 | if (ssl_clear_bad_session(ssl)) { |
| 191 | SSL_SESSION_free(ssl->session); |
| 192 | ssl->session = NULL; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 193 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 194 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 195 | ssl->hit = 0; |
| 196 | ssl->shutdown = 0; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 197 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 198 | /* SSL_clear may be called before or after the |ssl| is initialized in either |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 199 | * accept or connect state. In the latter case, SSL_clear should preserve the |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 200 | * half and reset |ssl->state| accordingly. */ |
| 201 | if (ssl->handshake_func != NULL) { |
| 202 | if (ssl->server) { |
| 203 | SSL_set_accept_state(ssl); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 204 | } else { |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 205 | SSL_set_connect_state(ssl); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 206 | } |
| 207 | } else { |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 208 | assert(ssl->state == 0); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 209 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 210 | |
David Benjamin | 5f387e3 | 2015-05-15 22:05:42 -0400 | [diff] [blame] | 211 | /* TODO(davidben): Some state on |ssl| is reset both in |SSL_new| and |
David Benjamin | 62fd162 | 2015-01-11 13:30:01 -0500 | [diff] [blame] | 212 | * |SSL_clear| because it is per-connection state rather than configuration |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 213 | * state. Per-connection state should be on |ssl->s3| and |ssl->d1| so it is |
David Benjamin | 62fd162 | 2015-01-11 13:30:01 -0500 | [diff] [blame] | 214 | * naturally reset at the right points between |SSL_new|, |SSL_clear|, and |
| 215 | * |ssl3_new|. */ |
| 216 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 217 | ssl->rwstate = SSL_NOTHING; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 218 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 219 | BUF_MEM_free(ssl->init_buf); |
| 220 | ssl->init_buf = NULL; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 221 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 222 | ssl_clear_cipher_ctx(ssl); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 223 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 224 | OPENSSL_free(ssl->next_proto_negotiated); |
| 225 | ssl->next_proto_negotiated = NULL; |
| 226 | ssl->next_proto_negotiated_len = 0; |
David Benjamin | 62fd162 | 2015-01-11 13:30:01 -0500 | [diff] [blame] | 227 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 228 | /* The ssl->d1->mtu is simultaneously configuration (preserved across |
David Benjamin | 62fd162 | 2015-01-11 13:30:01 -0500 | [diff] [blame] | 229 | * clear) and connection-specific state (gets reset). |
| 230 | * |
| 231 | * TODO(davidben): Avoid this. */ |
| 232 | unsigned mtu = 0; |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 233 | if (ssl->d1 != NULL) { |
| 234 | mtu = ssl->d1->mtu; |
David Benjamin | 62fd162 | 2015-01-11 13:30:01 -0500 | [diff] [blame] | 235 | } |
| 236 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 237 | ssl->method->ssl_free(ssl); |
| 238 | if (!ssl->method->ssl_new(ssl)) { |
David Benjamin | 62fd162 | 2015-01-11 13:30:01 -0500 | [diff] [blame] | 239 | return 0; |
| 240 | } |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 241 | ssl->enc_method = ssl3_get_enc_method(ssl->version); |
| 242 | assert(ssl->enc_method != NULL); |
David Benjamin | 62fd162 | 2015-01-11 13:30:01 -0500 | [diff] [blame] | 243 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 244 | if (SSL_IS_DTLS(ssl) && (SSL_get_options(ssl) & SSL_OP_NO_QUERY_MTU)) { |
| 245 | ssl->d1->mtu = mtu; |
David Benjamin | 62fd162 | 2015-01-11 13:30:01 -0500 | [diff] [blame] | 246 | } |
| 247 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 248 | ssl->client_version = ssl->version; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 249 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 250 | return 1; |
| 251 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 252 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 253 | SSL *SSL_new(SSL_CTX *ctx) { |
| 254 | SSL *s; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 255 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 256 | if (ctx == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 257 | OPENSSL_PUT_ERROR(SSL, SSL_R_NULL_SSL_CTX); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 258 | return NULL; |
| 259 | } |
| 260 | if (ctx->method == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 261 | OPENSSL_PUT_ERROR(SSL, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 262 | return NULL; |
| 263 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 264 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 265 | s = (SSL *)OPENSSL_malloc(sizeof(SSL)); |
| 266 | if (s == NULL) { |
| 267 | goto err; |
| 268 | } |
| 269 | memset(s, 0, sizeof(SSL)); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 270 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 271 | s->min_version = ctx->min_version; |
| 272 | s->max_version = ctx->max_version; |
David Benjamin | 1eb367c | 2014-12-12 18:17:51 -0500 | [diff] [blame] | 273 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 274 | s->options = ctx->options; |
| 275 | s->mode = ctx->mode; |
| 276 | s->max_cert_list = ctx->max_cert_list; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 277 | |
David Benjamin | a5a3eeb | 2015-03-18 20:26:30 -0400 | [diff] [blame] | 278 | s->cert = ssl_cert_dup(ctx->cert); |
| 279 | if (s->cert == NULL) { |
| 280 | goto err; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 281 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 282 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 283 | s->msg_callback = ctx->msg_callback; |
| 284 | s->msg_callback_arg = ctx->msg_callback_arg; |
| 285 | s->verify_mode = ctx->verify_mode; |
| 286 | s->sid_ctx_length = ctx->sid_ctx_length; |
| 287 | assert(s->sid_ctx_length <= sizeof s->sid_ctx); |
| 288 | memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx)); |
| 289 | s->verify_callback = ctx->default_verify_callback; |
| 290 | s->generate_session_id = ctx->generate_session_id; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 291 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 292 | s->param = X509_VERIFY_PARAM_new(); |
| 293 | if (!s->param) { |
| 294 | goto err; |
| 295 | } |
| 296 | X509_VERIFY_PARAM_inherit(s->param, ctx->param); |
| 297 | s->quiet_shutdown = ctx->quiet_shutdown; |
| 298 | s->max_send_fragment = ctx->max_send_fragment; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 299 | |
Adam Langley | 0b5e390 | 2015-05-15 13:08:38 -0700 | [diff] [blame] | 300 | CRYPTO_refcount_inc(&ctx->references); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 301 | s->ctx = ctx; |
Adam Langley | 0b5e390 | 2015-05-15 13:08:38 -0700 | [diff] [blame] | 302 | CRYPTO_refcount_inc(&ctx->references); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 303 | s->initial_ctx = ctx; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 304 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 305 | if (ctx->tlsext_ellipticcurvelist) { |
| 306 | s->tlsext_ellipticcurvelist = |
| 307 | BUF_memdup(ctx->tlsext_ellipticcurvelist, |
| 308 | ctx->tlsext_ellipticcurvelist_length * 2); |
| 309 | if (!s->tlsext_ellipticcurvelist) { |
| 310 | goto err; |
| 311 | } |
| 312 | s->tlsext_ellipticcurvelist_length = ctx->tlsext_ellipticcurvelist_length; |
| 313 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 314 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 315 | if (s->ctx->alpn_client_proto_list) { |
| 316 | s->alpn_client_proto_list = BUF_memdup(s->ctx->alpn_client_proto_list, |
| 317 | s->ctx->alpn_client_proto_list_len); |
| 318 | if (s->alpn_client_proto_list == NULL) { |
| 319 | goto err; |
| 320 | } |
| 321 | s->alpn_client_proto_list_len = s->ctx->alpn_client_proto_list_len; |
| 322 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 323 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 324 | s->verify_result = X509_V_OK; |
| 325 | s->method = ctx->method; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 326 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 327 | if (!s->method->ssl_new(s)) { |
| 328 | goto err; |
| 329 | } |
| 330 | s->enc_method = ssl3_get_enc_method(s->version); |
| 331 | assert(s->enc_method != NULL); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 332 | |
David Benjamin | 62fd162 | 2015-01-11 13:30:01 -0500 | [diff] [blame] | 333 | s->rwstate = SSL_NOTHING; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 334 | |
David Benjamin | 9f33fc6 | 2015-04-15 17:29:53 -0400 | [diff] [blame] | 335 | CRYPTO_new_ex_data(&g_ex_data_class_ssl, s, &s->ex_data); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 336 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 337 | s->psk_identity_hint = NULL; |
| 338 | if (ctx->psk_identity_hint) { |
| 339 | s->psk_identity_hint = BUF_strdup(ctx->psk_identity_hint); |
| 340 | if (s->psk_identity_hint == NULL) { |
| 341 | goto err; |
| 342 | } |
| 343 | } |
| 344 | s->psk_client_callback = ctx->psk_client_callback; |
| 345 | s->psk_server_callback = ctx->psk_server_callback; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 346 | |
David Benjamin | 02ddbfd | 2015-01-11 13:09:11 -0500 | [diff] [blame] | 347 | s->tlsext_channel_id_enabled = ctx->tlsext_channel_id_enabled; |
| 348 | if (ctx->tlsext_channel_id_private) { |
David Benjamin | 9a10f8f | 2015-05-05 22:22:40 -0400 | [diff] [blame] | 349 | s->tlsext_channel_id_private = |
| 350 | EVP_PKEY_up_ref(ctx->tlsext_channel_id_private); |
David Benjamin | 02ddbfd | 2015-01-11 13:09:11 -0500 | [diff] [blame] | 351 | } |
| 352 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 353 | s->signed_cert_timestamps_enabled = s->ctx->signed_cert_timestamps_enabled; |
| 354 | s->ocsp_stapling_enabled = s->ctx->ocsp_stapling_enabled; |
HÃ¥vard Molland | 9169c96 | 2014-08-14 14:42:37 +0200 | [diff] [blame] | 355 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 356 | return s; |
| 357 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 358 | err: |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 359 | SSL_free(s); |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 360 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 361 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 362 | return NULL; |
| 363 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 364 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 365 | int SSL_CTX_set_session_id_context(SSL_CTX *ctx, const uint8_t *sid_ctx, |
| 366 | unsigned int sid_ctx_len) { |
| 367 | if (sid_ctx_len > sizeof ctx->sid_ctx) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 368 | OPENSSL_PUT_ERROR(SSL, SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 369 | return 0; |
| 370 | } |
| 371 | ctx->sid_ctx_length = sid_ctx_len; |
| 372 | memcpy(ctx->sid_ctx, sid_ctx, sid_ctx_len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 373 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 374 | return 1; |
| 375 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 376 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 377 | int SSL_set_session_id_context(SSL *ssl, const uint8_t *sid_ctx, |
| 378 | unsigned int sid_ctx_len) { |
| 379 | if (sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 380 | OPENSSL_PUT_ERROR(SSL, SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 381 | return 0; |
| 382 | } |
| 383 | ssl->sid_ctx_length = sid_ctx_len; |
| 384 | memcpy(ssl->sid_ctx, sid_ctx, sid_ctx_len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 385 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 386 | return 1; |
| 387 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 388 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 389 | int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 390 | ctx->generate_session_id = cb; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 391 | return 1; |
| 392 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 393 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 394 | int SSL_set_generate_session_id(SSL *ssl, GEN_SESSION_CB cb) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 395 | ssl->generate_session_id = cb; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 396 | return 1; |
| 397 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 398 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 399 | int SSL_has_matching_session_id(const SSL *ssl, const uint8_t *id, |
| 400 | unsigned int id_len) { |
| 401 | /* A quick examination of SSL_SESSION_hash and SSL_SESSION_cmp shows how we |
| 402 | * can "construct" a session to give us the desired check - ie. to find if |
| 403 | * there's a session in the hash table that would conflict with any new |
| 404 | * session built out of this id/id_len and the ssl_version in use by this |
| 405 | * SSL. */ |
| 406 | SSL_SESSION r, *p; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 407 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 408 | if (id_len > sizeof r.session_id) { |
| 409 | return 0; |
| 410 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 411 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 412 | r.ssl_version = ssl->version; |
| 413 | r.session_id_length = id_len; |
| 414 | memcpy(r.session_id, id, id_len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 415 | |
Adam Langley | 4bdb6e4 | 2015-05-15 15:29:21 -0700 | [diff] [blame] | 416 | CRYPTO_MUTEX_lock_read(&ssl->ctx->lock); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 417 | p = lh_SSL_SESSION_retrieve(ssl->ctx->sessions, &r); |
Adam Langley | 4bdb6e4 | 2015-05-15 15:29:21 -0700 | [diff] [blame] | 418 | CRYPTO_MUTEX_unlock(&ssl->ctx->lock); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 419 | return p != NULL; |
| 420 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 421 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 422 | int SSL_CTX_set_purpose(SSL_CTX *s, int purpose) { |
| 423 | return X509_VERIFY_PARAM_set_purpose(s->param, purpose); |
| 424 | } |
| 425 | |
| 426 | int SSL_set_purpose(SSL *s, int purpose) { |
| 427 | return X509_VERIFY_PARAM_set_purpose(s->param, purpose); |
| 428 | } |
| 429 | |
| 430 | int SSL_CTX_set_trust(SSL_CTX *s, int trust) { |
| 431 | return X509_VERIFY_PARAM_set_trust(s->param, trust); |
| 432 | } |
| 433 | |
| 434 | int SSL_set_trust(SSL *s, int trust) { |
| 435 | return X509_VERIFY_PARAM_set_trust(s->param, trust); |
| 436 | } |
| 437 | |
| 438 | int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm) { |
| 439 | return X509_VERIFY_PARAM_set1(ctx->param, vpm); |
| 440 | } |
| 441 | |
| 442 | int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm) { |
| 443 | return X509_VERIFY_PARAM_set1(ssl->param, vpm); |
| 444 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 445 | |
Adam Langley | 858a88d | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 446 | void ssl_cipher_preference_list_free( |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 447 | struct ssl_cipher_preference_list_st *cipher_list) { |
David Benjamin | 5d1ec73 | 2015-04-22 13:38:00 -0400 | [diff] [blame] | 448 | if (cipher_list == NULL) { |
| 449 | return; |
| 450 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 451 | sk_SSL_CIPHER_free(cipher_list->ciphers); |
| 452 | OPENSSL_free(cipher_list->in_group_flags); |
| 453 | OPENSSL_free(cipher_list); |
| 454 | } |
Adam Langley | 858a88d | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 455 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 456 | struct ssl_cipher_preference_list_st *ssl_cipher_preference_list_dup( |
| 457 | struct ssl_cipher_preference_list_st *cipher_list) { |
| 458 | struct ssl_cipher_preference_list_st *ret = NULL; |
| 459 | size_t n = sk_SSL_CIPHER_num(cipher_list->ciphers); |
Adam Langley | 858a88d | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 460 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 461 | ret = OPENSSL_malloc(sizeof(struct ssl_cipher_preference_list_st)); |
| 462 | if (!ret) { |
| 463 | goto err; |
| 464 | } |
| 465 | |
| 466 | ret->ciphers = NULL; |
| 467 | ret->in_group_flags = NULL; |
| 468 | ret->ciphers = sk_SSL_CIPHER_dup(cipher_list->ciphers); |
| 469 | if (!ret->ciphers) { |
| 470 | goto err; |
| 471 | } |
| 472 | ret->in_group_flags = BUF_memdup(cipher_list->in_group_flags, n); |
| 473 | if (!ret->in_group_flags) { |
| 474 | goto err; |
| 475 | } |
| 476 | |
| 477 | return ret; |
Adam Langley | 858a88d | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 478 | |
| 479 | err: |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 480 | ssl_cipher_preference_list_free(ret); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 481 | return NULL; |
| 482 | } |
Adam Langley | 858a88d | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 483 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 484 | struct ssl_cipher_preference_list_st *ssl_cipher_preference_list_from_ciphers( |
David Benjamin | 60da0cd | 2015-05-03 15:21:28 -0400 | [diff] [blame] | 485 | STACK_OF(SSL_CIPHER) *ciphers) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 486 | struct ssl_cipher_preference_list_st *ret = NULL; |
| 487 | size_t n = sk_SSL_CIPHER_num(ciphers); |
Adam Langley | 858a88d | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 488 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 489 | ret = OPENSSL_malloc(sizeof(struct ssl_cipher_preference_list_st)); |
| 490 | if (!ret) { |
| 491 | goto err; |
| 492 | } |
| 493 | ret->ciphers = NULL; |
| 494 | ret->in_group_flags = NULL; |
| 495 | ret->ciphers = sk_SSL_CIPHER_dup(ciphers); |
| 496 | if (!ret->ciphers) { |
| 497 | goto err; |
| 498 | } |
| 499 | ret->in_group_flags = OPENSSL_malloc(n); |
| 500 | if (!ret->in_group_flags) { |
| 501 | goto err; |
| 502 | } |
| 503 | memset(ret->in_group_flags, 0, n); |
| 504 | return ret; |
Adam Langley | 858a88d | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 505 | |
| 506 | err: |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 507 | ssl_cipher_preference_list_free(ret); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 508 | return NULL; |
| 509 | } |
Adam Langley | 858a88d | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 510 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 511 | X509_VERIFY_PARAM *SSL_CTX_get0_param(SSL_CTX *ctx) { return ctx->param; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 512 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 513 | X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl) { return ssl->param; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 514 | |
David Benjamin | 7481d39 | 2015-07-05 19:38:46 -0400 | [diff] [blame] | 515 | void SSL_certs_clear(SSL *ssl) { ssl_cert_clear_certs(ssl->cert); } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 516 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 517 | void SSL_free(SSL *ssl) { |
| 518 | if (ssl == NULL) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 519 | return; |
| 520 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 521 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 522 | X509_VERIFY_PARAM_free(ssl->param); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 523 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 524 | CRYPTO_free_ex_data(&g_ex_data_class_ssl, ssl, &ssl->ex_data); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 525 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 526 | if (ssl->bbio != NULL) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 527 | /* If the buffering BIO is in place, pop it off */ |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 528 | if (ssl->bbio == ssl->wbio) { |
| 529 | ssl->wbio = BIO_pop(ssl->wbio); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 530 | } |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 531 | BIO_free(ssl->bbio); |
| 532 | ssl->bbio = NULL; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 533 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 534 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 535 | int free_wbio = ssl->wbio != ssl->rbio; |
| 536 | BIO_free_all(ssl->rbio); |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 537 | if (free_wbio) { |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 538 | BIO_free_all(ssl->wbio); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 539 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 540 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 541 | BUF_MEM_free(ssl->init_buf); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 542 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 543 | /* add extra stuff */ |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 544 | ssl_cipher_preference_list_free(ssl->cipher_list); |
| 545 | sk_SSL_CIPHER_free(ssl->cipher_list_by_id); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 546 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 547 | ssl_clear_bad_session(ssl); |
| 548 | SSL_SESSION_free(ssl->session); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 549 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 550 | ssl_clear_cipher_ctx(ssl); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 551 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 552 | ssl_cert_free(ssl->cert); |
Adam Langley | 0289c73 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 553 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 554 | OPENSSL_free(ssl->tlsext_hostname); |
| 555 | SSL_CTX_free(ssl->initial_ctx); |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 556 | OPENSSL_free(ssl->tlsext_ellipticcurvelist); |
| 557 | OPENSSL_free(ssl->alpn_client_proto_list); |
| 558 | EVP_PKEY_free(ssl->tlsext_channel_id_private); |
| 559 | OPENSSL_free(ssl->psk_identity_hint); |
| 560 | sk_X509_NAME_pop_free(ssl->client_CA, X509_NAME_free); |
| 561 | OPENSSL_free(ssl->next_proto_negotiated); |
| 562 | sk_SRTP_PROTECTION_PROFILE_free(ssl->srtp_profiles); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 563 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 564 | if (ssl->method != NULL) { |
| 565 | ssl->method->ssl_free(ssl); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 566 | } |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 567 | SSL_CTX_free(ssl->ctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 568 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 569 | OPENSSL_free(ssl); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 570 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 571 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 572 | void SSL_set_bio(SSL *s, BIO *rbio, BIO *wbio) { |
| 573 | /* If the output buffering BIO is still in place, remove it. */ |
| 574 | if (s->bbio != NULL) { |
| 575 | if (s->wbio == s->bbio) { |
| 576 | s->wbio = s->wbio->next_bio; |
| 577 | s->bbio->next_bio = NULL; |
| 578 | } |
| 579 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 580 | |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 581 | if (s->rbio != rbio) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 582 | BIO_free_all(s->rbio); |
| 583 | } |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 584 | if (s->wbio != wbio && s->rbio != s->wbio) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 585 | BIO_free_all(s->wbio); |
| 586 | } |
| 587 | s->rbio = rbio; |
| 588 | s->wbio = wbio; |
| 589 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 590 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 591 | BIO *SSL_get_rbio(const SSL *s) { return s->rbio; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 592 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 593 | BIO *SSL_get_wbio(const SSL *s) { return s->wbio; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 594 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 595 | int SSL_get_fd(const SSL *s) { return SSL_get_rfd(s); } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 596 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 597 | int SSL_get_rfd(const SSL *s) { |
| 598 | int ret = -1; |
| 599 | BIO *b, *r; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 600 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 601 | b = SSL_get_rbio(s); |
| 602 | r = BIO_find_type(b, BIO_TYPE_DESCRIPTOR); |
| 603 | if (r != NULL) { |
| 604 | BIO_get_fd(r, &ret); |
| 605 | } |
| 606 | return ret; |
| 607 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 608 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 609 | int SSL_get_wfd(const SSL *s) { |
| 610 | int ret = -1; |
| 611 | BIO *b, *r; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 612 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 613 | b = SSL_get_wbio(s); |
| 614 | r = BIO_find_type(b, BIO_TYPE_DESCRIPTOR); |
| 615 | if (r != NULL) { |
| 616 | BIO_get_fd(r, &ret); |
| 617 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 618 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 619 | return ret; |
| 620 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 621 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 622 | int SSL_set_fd(SSL *s, int fd) { |
| 623 | int ret = 0; |
| 624 | BIO *bio = NULL; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 625 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 626 | bio = BIO_new(BIO_s_fd()); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 627 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 628 | if (bio == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 629 | OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 630 | goto err; |
| 631 | } |
| 632 | BIO_set_fd(bio, fd, BIO_NOCLOSE); |
| 633 | SSL_set_bio(s, bio, bio); |
| 634 | ret = 1; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 635 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 636 | err: |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 637 | return ret; |
| 638 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 639 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 640 | int SSL_set_wfd(SSL *s, int fd) { |
| 641 | int ret = 0; |
| 642 | BIO *bio = NULL; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 643 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 644 | if (s->rbio == NULL || BIO_method_type(s->rbio) != BIO_TYPE_FD || |
| 645 | (int)BIO_get_fd(s->rbio, NULL) != fd) { |
| 646 | bio = BIO_new(BIO_s_fd()); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 647 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 648 | if (bio == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 649 | OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 650 | goto err; |
| 651 | } |
| 652 | BIO_set_fd(bio, fd, BIO_NOCLOSE); |
| 653 | SSL_set_bio(s, SSL_get_rbio(s), bio); |
| 654 | } else { |
| 655 | SSL_set_bio(s, SSL_get_rbio(s), SSL_get_rbio(s)); |
| 656 | } |
| 657 | |
| 658 | ret = 1; |
| 659 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 660 | err: |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 661 | return ret; |
| 662 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 663 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 664 | int SSL_set_rfd(SSL *s, int fd) { |
| 665 | int ret = 0; |
| 666 | BIO *bio = NULL; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 667 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 668 | if (s->wbio == NULL || BIO_method_type(s->wbio) != BIO_TYPE_FD || |
| 669 | (int)BIO_get_fd(s->wbio, NULL) != fd) { |
| 670 | bio = BIO_new(BIO_s_fd()); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 671 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 672 | if (bio == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 673 | OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 674 | goto err; |
| 675 | } |
| 676 | BIO_set_fd(bio, fd, BIO_NOCLOSE); |
| 677 | SSL_set_bio(s, bio, SSL_get_wbio(s)); |
| 678 | } else { |
| 679 | SSL_set_bio(s, SSL_get_wbio(s), SSL_get_wbio(s)); |
| 680 | } |
| 681 | ret = 1; |
| 682 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 683 | err: |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 684 | return ret; |
| 685 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 686 | |
| 687 | /* return length of latest Finished message we sent, copy to 'buf' */ |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 688 | size_t SSL_get_finished(const SSL *s, void *buf, size_t count) { |
| 689 | size_t ret = 0; |
| 690 | |
| 691 | if (s->s3 != NULL) { |
| 692 | ret = s->s3->tmp.finish_md_len; |
| 693 | if (count > ret) { |
| 694 | count = ret; |
| 695 | } |
| 696 | memcpy(buf, s->s3->tmp.finish_md, count); |
| 697 | } |
| 698 | |
| 699 | return ret; |
| 700 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 701 | |
| 702 | /* return length of latest Finished message we expected, copy to 'buf' */ |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 703 | size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count) { |
| 704 | size_t ret = 0; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 705 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 706 | if (s->s3 != NULL) { |
| 707 | ret = s->s3->tmp.peer_finish_md_len; |
| 708 | if (count > ret) { |
| 709 | count = ret; |
| 710 | } |
| 711 | memcpy(buf, s->s3->tmp.peer_finish_md, count); |
| 712 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 713 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 714 | return ret; |
| 715 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 716 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 717 | int SSL_get_verify_mode(const SSL *s) { return s->verify_mode; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 718 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 719 | int SSL_get_verify_depth(const SSL *s) { |
| 720 | return X509_VERIFY_PARAM_get_depth(s->param); |
| 721 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 722 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 723 | int (*SSL_get_verify_callback(const SSL *s))(int, X509_STORE_CTX *) { |
| 724 | return s->verify_callback; |
| 725 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 726 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 727 | int SSL_CTX_get_verify_mode(const SSL_CTX *ctx) { return ctx->verify_mode; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 728 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 729 | int SSL_CTX_get_verify_depth(const SSL_CTX *ctx) { |
| 730 | return X509_VERIFY_PARAM_get_depth(ctx->param); |
| 731 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 732 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 733 | int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int, X509_STORE_CTX *) { |
| 734 | return ctx->default_verify_callback; |
| 735 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 736 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 737 | void SSL_set_verify(SSL *s, int mode, |
| 738 | int (*callback)(int ok, X509_STORE_CTX *ctx)) { |
| 739 | s->verify_mode = mode; |
| 740 | if (callback != NULL) { |
| 741 | s->verify_callback = callback; |
| 742 | } |
| 743 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 744 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 745 | void SSL_set_verify_depth(SSL *s, int depth) { |
| 746 | X509_VERIFY_PARAM_set_depth(s->param, depth); |
| 747 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 748 | |
David Benjamin | 9a41d1b | 2015-05-16 01:30:09 -0400 | [diff] [blame] | 749 | int SSL_CTX_get_read_ahead(const SSL_CTX *ctx) { return 0; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 750 | |
David Benjamin | 9a41d1b | 2015-05-16 01:30:09 -0400 | [diff] [blame] | 751 | int SSL_get_read_ahead(const SSL *s) { return 0; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 752 | |
David Benjamin | 9a41d1b | 2015-05-16 01:30:09 -0400 | [diff] [blame] | 753 | void SSL_CTX_set_read_ahead(SSL_CTX *ctx, int yes) { } |
David Benjamin | 61ecccf | 2015-05-05 09:44:51 -0400 | [diff] [blame] | 754 | |
David Benjamin | 9a41d1b | 2015-05-16 01:30:09 -0400 | [diff] [blame] | 755 | void SSL_set_read_ahead(SSL *s, int yes) { } |
David Benjamin | 61ecccf | 2015-05-05 09:44:51 -0400 | [diff] [blame] | 756 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 757 | int SSL_pending(const SSL *s) { |
David Benjamin | 904dc72 | 2015-05-30 16:39:07 -0400 | [diff] [blame] | 758 | return (s->s3->rrec.type == SSL3_RT_APPLICATION_DATA) ? s->s3->rrec.length |
| 759 | : 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 760 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 761 | |
David Benjamin | 26416e9 | 2015-08-22 16:04:17 -0400 | [diff] [blame] | 762 | X509 *SSL_get_peer_certificate(const SSL *ssl) { |
| 763 | if (ssl == NULL || ssl->session == NULL || ssl->session->peer == NULL) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 764 | return NULL; |
| 765 | } |
David Benjamin | 26416e9 | 2015-08-22 16:04:17 -0400 | [diff] [blame] | 766 | return X509_up_ref(ssl->session->peer); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 767 | } |
| 768 | |
David Benjamin | 26416e9 | 2015-08-22 16:04:17 -0400 | [diff] [blame] | 769 | STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *ssl) { |
| 770 | if (ssl == NULL || ssl->session == NULL) { |
| 771 | return NULL; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 772 | } |
David Benjamin | 26416e9 | 2015-08-22 16:04:17 -0400 | [diff] [blame] | 773 | return ssl->session->cert_chain; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 774 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 775 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 776 | /* Fix this so it checks all the valid key/cert options */ |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 777 | int SSL_CTX_check_private_key(const SSL_CTX *ctx) { |
David Benjamin | 651b3d9 | 2015-08-09 12:07:25 -0400 | [diff] [blame] | 778 | if (ctx->cert->x509 == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 779 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATE_ASSIGNED); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 780 | return 0; |
| 781 | } |
| 782 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 783 | if (ctx->cert->privatekey == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 784 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_PRIVATE_KEY_ASSIGNED); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 785 | return 0; |
| 786 | } |
| 787 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 788 | return X509_check_private_key(ctx->cert->x509, ctx->cert->privatekey); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 789 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 790 | |
| 791 | /* Fix this function so that it takes an optional type parameter */ |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 792 | int SSL_check_private_key(const SSL *ssl) { |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 793 | if (ssl->cert->x509 == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 794 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATE_ASSIGNED); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 795 | return 0; |
| 796 | } |
David Benjamin | 0b145c2 | 2014-11-26 20:10:09 -0500 | [diff] [blame] | 797 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 798 | if (ssl->cert->privatekey == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 799 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_PRIVATE_KEY_ASSIGNED); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 800 | return 0; |
| 801 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 802 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 803 | return X509_check_private_key(ssl->cert->x509, ssl->cert->privatekey); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 804 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 805 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 806 | int SSL_accept(SSL *s) { |
| 807 | if (s->handshake_func == 0) { |
| 808 | /* Not properly initialized yet */ |
| 809 | SSL_set_accept_state(s); |
| 810 | } |
David Benjamin | 0b145c2 | 2014-11-26 20:10:09 -0500 | [diff] [blame] | 811 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 812 | if (s->handshake_func != s->method->ssl_accept) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 813 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 814 | return -1; |
| 815 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 816 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 817 | return s->handshake_func(s); |
| 818 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 819 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 820 | int SSL_connect(SSL *s) { |
| 821 | if (s->handshake_func == 0) { |
| 822 | /* Not properly initialized yet */ |
| 823 | SSL_set_connect_state(s); |
| 824 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 825 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 826 | if (s->handshake_func != s->method->ssl_connect) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 827 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 828 | return -1; |
| 829 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 830 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 831 | return s->handshake_func(s); |
| 832 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 833 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 834 | long SSL_get_default_timeout(const SSL *s) { |
| 835 | return SSL_DEFAULT_SESSION_TIMEOUT; |
| 836 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 837 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 838 | int SSL_read(SSL *s, void *buf, int num) { |
| 839 | if (s->handshake_func == 0) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 840 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 841 | return -1; |
| 842 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 843 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 844 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) { |
| 845 | s->rwstate = SSL_NOTHING; |
| 846 | return 0; |
| 847 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 848 | |
David Benjamin | 904dc72 | 2015-05-30 16:39:07 -0400 | [diff] [blame] | 849 | ERR_clear_system_error(); |
| 850 | return s->method->ssl_read_app_data(s, buf, num, 0); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 851 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 852 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 853 | int SSL_peek(SSL *s, void *buf, int num) { |
| 854 | if (s->handshake_func == 0) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 855 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 856 | return -1; |
| 857 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 858 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 859 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) { |
| 860 | return 0; |
| 861 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 862 | |
David Benjamin | 904dc72 | 2015-05-30 16:39:07 -0400 | [diff] [blame] | 863 | ERR_clear_system_error(); |
| 864 | return s->method->ssl_read_app_data(s, buf, num, 1); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 865 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 866 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 867 | int SSL_write(SSL *s, const void *buf, int num) { |
| 868 | if (s->handshake_func == 0) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 869 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 870 | return -1; |
| 871 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 872 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 873 | if (s->shutdown & SSL_SENT_SHUTDOWN) { |
| 874 | s->rwstate = SSL_NOTHING; |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 875 | OPENSSL_PUT_ERROR(SSL, SSL_R_PROTOCOL_IS_SHUTDOWN); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 876 | return -1; |
| 877 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 878 | |
David Benjamin | 904dc72 | 2015-05-30 16:39:07 -0400 | [diff] [blame] | 879 | ERR_clear_system_error(); |
| 880 | return s->method->ssl_write_app_data(s, buf, num); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 881 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 882 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 883 | int SSL_shutdown(SSL *s) { |
| 884 | /* Note that this function behaves differently from what one might expect. |
| 885 | * Return values are 0 for no success (yet), 1 for success; but calling it |
| 886 | * once is usually not enough, even if blocking I/O is used (see |
| 887 | * ssl3_shutdown). */ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 888 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 889 | if (s->handshake_func == 0) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 890 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 891 | return -1; |
| 892 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 893 | |
David Benjamin | 904dc72 | 2015-05-30 16:39:07 -0400 | [diff] [blame] | 894 | if (SSL_in_init(s)) { |
| 895 | return 1; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 896 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 897 | |
David Benjamin | 904dc72 | 2015-05-30 16:39:07 -0400 | [diff] [blame] | 898 | /* Do nothing if configured not to send a close_notify. */ |
| 899 | if (s->quiet_shutdown) { |
| 900 | s->shutdown = SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN; |
| 901 | return 1; |
| 902 | } |
| 903 | |
| 904 | if (!(s->shutdown & SSL_SENT_SHUTDOWN)) { |
| 905 | s->shutdown |= SSL_SENT_SHUTDOWN; |
| 906 | ssl3_send_alert(s, SSL3_AL_WARNING, SSL_AD_CLOSE_NOTIFY); |
| 907 | |
| 908 | /* our shutdown alert has been sent now, and if it still needs to be |
| 909 | * written, s->s3->alert_dispatch will be true */ |
| 910 | if (s->s3->alert_dispatch) { |
| 911 | return -1; /* return WANT_WRITE */ |
| 912 | } |
| 913 | } else if (s->s3->alert_dispatch) { |
| 914 | /* resend it if not sent */ |
| 915 | int ret = s->method->ssl_dispatch_alert(s); |
| 916 | if (ret == -1) { |
| 917 | /* we only get to return -1 here the 2nd/Nth invocation, we must have |
| 918 | * already signalled return 0 upon a previous invoation, return |
| 919 | * WANT_WRITE */ |
| 920 | return ret; |
| 921 | } |
| 922 | } else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN)) { |
| 923 | /* If we are waiting for a close from our peer, we are closed */ |
| 924 | s->method->ssl_read_close_notify(s); |
| 925 | if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN)) { |
| 926 | return -1; /* return WANT_READ */ |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | if (s->shutdown == (SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN) && |
| 931 | !s->s3->alert_dispatch) { |
| 932 | return 1; |
| 933 | } else { |
| 934 | return 0; |
| 935 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 936 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 937 | |
David Benjamin | 44d3eed | 2015-05-21 01:29:55 -0400 | [diff] [blame] | 938 | int SSL_renegotiate(SSL *ssl) { |
| 939 | /* Caller-initiated renegotiation is not supported. */ |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 940 | OPENSSL_PUT_ERROR(SSL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
David Benjamin | 44d3eed | 2015-05-21 01:29:55 -0400 | [diff] [blame] | 941 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 942 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 943 | |
David Benjamin | 44d3eed | 2015-05-21 01:29:55 -0400 | [diff] [blame] | 944 | int SSL_renegotiate_pending(SSL *ssl) { |
| 945 | return SSL_in_init(ssl) && ssl->s3->initial_handshake_complete; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 946 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 947 | |
David Benjamin | 61ecccf | 2015-05-05 09:44:51 -0400 | [diff] [blame] | 948 | uint32_t SSL_CTX_set_options(SSL_CTX *ctx, uint32_t options) { |
| 949 | ctx->options |= options; |
| 950 | return ctx->options; |
| 951 | } |
| 952 | |
| 953 | uint32_t SSL_set_options(SSL *ssl, uint32_t options) { |
| 954 | ssl->options |= options; |
| 955 | return ssl->options; |
| 956 | } |
| 957 | |
| 958 | uint32_t SSL_CTX_clear_options(SSL_CTX *ctx, uint32_t options) { |
| 959 | ctx->options &= ~options; |
| 960 | return ctx->options; |
| 961 | } |
| 962 | |
| 963 | uint32_t SSL_clear_options(SSL *ssl, uint32_t options) { |
| 964 | ssl->options &= ~options; |
| 965 | return ssl->options; |
| 966 | } |
| 967 | |
| 968 | uint32_t SSL_CTX_get_options(const SSL_CTX *ctx) { return ctx->options; } |
| 969 | |
| 970 | uint32_t SSL_get_options(const SSL *ssl) { return ssl->options; } |
| 971 | |
| 972 | uint32_t SSL_CTX_set_mode(SSL_CTX *ctx, uint32_t mode) { |
| 973 | ctx->mode |= mode; |
| 974 | return ctx->mode; |
| 975 | } |
| 976 | |
| 977 | uint32_t SSL_set_mode(SSL *ssl, uint32_t mode) { |
| 978 | ssl->mode |= mode; |
| 979 | return ssl->mode; |
| 980 | } |
| 981 | |
| 982 | uint32_t SSL_CTX_clear_mode(SSL_CTX *ctx, uint32_t mode) { |
| 983 | ctx->mode &= ~mode; |
| 984 | return ctx->mode; |
| 985 | } |
| 986 | |
| 987 | uint32_t SSL_clear_mode(SSL *ssl, uint32_t mode) { |
| 988 | ssl->mode &= ~mode; |
| 989 | return ssl->mode; |
| 990 | } |
| 991 | |
| 992 | uint32_t SSL_CTX_get_mode(const SSL_CTX *ctx) { return ctx->mode; } |
| 993 | |
| 994 | uint32_t SSL_get_mode(const SSL *ssl) { return ssl->mode; } |
| 995 | |
David Benjamin | 1d0a194 | 2015-04-26 15:35:35 -0400 | [diff] [blame] | 996 | size_t SSL_CTX_get_max_cert_list(const SSL_CTX *ctx) { |
| 997 | return ctx->max_cert_list; |
| 998 | } |
| 999 | |
| 1000 | void SSL_CTX_set_max_cert_list(SSL_CTX *ctx, size_t max_cert_list) { |
| 1001 | if (max_cert_list > kMaxHandshakeSize) { |
| 1002 | max_cert_list = kMaxHandshakeSize; |
| 1003 | } |
| 1004 | ctx->max_cert_list = (uint32_t)max_cert_list; |
| 1005 | } |
| 1006 | |
| 1007 | size_t SSL_get_max_cert_list(const SSL *ssl) { |
| 1008 | return ssl->max_cert_list; |
| 1009 | } |
| 1010 | |
| 1011 | void SSL_set_max_cert_list(SSL *ssl, size_t max_cert_list) { |
| 1012 | if (max_cert_list > kMaxHandshakeSize) { |
| 1013 | max_cert_list = kMaxHandshakeSize; |
| 1014 | } |
| 1015 | ssl->max_cert_list = (uint32_t)max_cert_list; |
| 1016 | } |
| 1017 | |
| 1018 | void SSL_CTX_set_max_send_fragment(SSL_CTX *ctx, size_t max_send_fragment) { |
| 1019 | if (max_send_fragment < 512) { |
| 1020 | max_send_fragment = 512; |
| 1021 | } |
| 1022 | if (max_send_fragment > SSL3_RT_MAX_PLAIN_LENGTH) { |
| 1023 | max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH; |
| 1024 | } |
| 1025 | ctx->max_send_fragment = (uint16_t)max_send_fragment; |
| 1026 | } |
| 1027 | |
| 1028 | void SSL_set_max_send_fragment(SSL *ssl, size_t max_send_fragment) { |
| 1029 | if (max_send_fragment < 512) { |
| 1030 | max_send_fragment = 512; |
| 1031 | } |
| 1032 | if (max_send_fragment > SSL3_RT_MAX_PLAIN_LENGTH) { |
| 1033 | max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH; |
| 1034 | } |
| 1035 | ssl->max_send_fragment = (uint16_t)max_send_fragment; |
| 1036 | } |
| 1037 | |
David Benjamin | cb9cf79 | 2015-05-05 09:46:14 -0400 | [diff] [blame] | 1038 | int SSL_set_mtu(SSL *ssl, unsigned mtu) { |
| 1039 | if (!SSL_IS_DTLS(ssl) || mtu < dtls1_min_mtu()) { |
| 1040 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1041 | } |
David Benjamin | cb9cf79 | 2015-05-05 09:46:14 -0400 | [diff] [blame] | 1042 | ssl->d1->mtu = mtu; |
| 1043 | return 1; |
| 1044 | } |
| 1045 | |
| 1046 | int SSL_get_secure_renegotiation_support(const SSL *ssl) { |
| 1047 | return ssl->s3->send_connection_binding; |
| 1048 | } |
| 1049 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1050 | LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx) { return ctx->sessions; } |
| 1051 | |
David Benjamin | 71f7d3d | 2015-05-05 09:46:38 -0400 | [diff] [blame] | 1052 | size_t SSL_CTX_sess_number(const SSL_CTX *ctx) { |
| 1053 | return lh_SSL_SESSION_num_items(ctx->sessions); |
| 1054 | } |
| 1055 | |
| 1056 | unsigned long SSL_CTX_sess_set_cache_size(SSL_CTX *ctx, unsigned long size) { |
| 1057 | unsigned long ret = ctx->session_cache_size; |
| 1058 | ctx->session_cache_size = size; |
| 1059 | return ret; |
| 1060 | } |
| 1061 | |
| 1062 | unsigned long SSL_CTX_sess_get_cache_size(const SSL_CTX *ctx) { |
| 1063 | return ctx->session_cache_size; |
| 1064 | } |
| 1065 | |
| 1066 | int SSL_CTX_set_session_cache_mode(SSL_CTX *ctx, int mode) { |
| 1067 | int ret = ctx->session_cache_mode; |
| 1068 | ctx->session_cache_mode = mode; |
| 1069 | return ret; |
| 1070 | } |
| 1071 | |
| 1072 | int SSL_CTX_get_session_cache_mode(const SSL_CTX *ctx) { |
| 1073 | return ctx->session_cache_mode; |
| 1074 | } |
| 1075 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1076 | /* return a STACK of the ciphers available for the SSL and in order of |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1077 | * preference */ |
David Benjamin | 60da0cd | 2015-05-03 15:21:28 -0400 | [diff] [blame] | 1078 | STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1079 | if (s == NULL) { |
| 1080 | return NULL; |
| 1081 | } |
Adam Langley | 0b5c1ac | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1082 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1083 | if (s->cipher_list != NULL) { |
| 1084 | return s->cipher_list->ciphers; |
| 1085 | } |
Adam Langley | 0b5c1ac | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1086 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1087 | if (s->version >= TLS1_1_VERSION && s->ctx != NULL && |
| 1088 | s->ctx->cipher_list_tls11 != NULL) { |
| 1089 | return s->ctx->cipher_list_tls11->ciphers; |
| 1090 | } |
Adam Langley | 0b5c1ac | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1091 | |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 1092 | if (s->version >= TLS1_VERSION && s->ctx != NULL && |
| 1093 | s->ctx->cipher_list_tls10 != NULL) { |
| 1094 | return s->ctx->cipher_list_tls10->ciphers; |
| 1095 | } |
| 1096 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1097 | if (s->ctx != NULL && s->ctx->cipher_list != NULL) { |
| 1098 | return s->ctx->cipher_list->ciphers; |
| 1099 | } |
Adam Langley | 0b5c1ac | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1100 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1101 | return NULL; |
| 1102 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1103 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1104 | /* return a STACK of the ciphers available for the SSL and in order of |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1105 | * algorithm id */ |
David Benjamin | 60da0cd | 2015-05-03 15:21:28 -0400 | [diff] [blame] | 1106 | STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1107 | if (s == NULL) { |
| 1108 | return NULL; |
| 1109 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1110 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1111 | if (s->cipher_list_by_id != NULL) { |
| 1112 | return s->cipher_list_by_id; |
| 1113 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1114 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1115 | if (s->ctx != NULL && s->ctx->cipher_list_by_id != NULL) { |
| 1116 | return s->ctx->cipher_list_by_id; |
| 1117 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1118 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1119 | return NULL; |
| 1120 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1121 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1122 | /* The old interface to get the same thing as SSL_get_ciphers() */ |
| 1123 | const char *SSL_get_cipher_list(const SSL *s, int n) { |
| 1124 | const SSL_CIPHER *c; |
David Benjamin | 60da0cd | 2015-05-03 15:21:28 -0400 | [diff] [blame] | 1125 | STACK_OF(SSL_CIPHER) *sk; |
Adam Langley | 0b5c1ac | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1126 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1127 | if (s == NULL) { |
| 1128 | return NULL; |
| 1129 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1130 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1131 | sk = SSL_get_ciphers(s); |
| 1132 | if (sk == NULL || n < 0 || (size_t)n >= sk_SSL_CIPHER_num(sk)) { |
| 1133 | return NULL; |
| 1134 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1135 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1136 | c = sk_SSL_CIPHER_value(sk, n); |
| 1137 | if (c == NULL) { |
| 1138 | return NULL; |
| 1139 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1140 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1141 | return c->name; |
| 1142 | } |
David Benjamin | 5491e3f | 2014-09-29 19:33:09 -0400 | [diff] [blame] | 1143 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1144 | /* specify the ciphers to be used by default by the SSL_CTX */ |
| 1145 | int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str) { |
| 1146 | STACK_OF(SSL_CIPHER) *sk; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1147 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1148 | sk = ssl_create_cipher_list(ctx->method, &ctx->cipher_list, |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1149 | &ctx->cipher_list_by_id, str); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1150 | /* ssl_create_cipher_list may return an empty stack if it was unable to find |
| 1151 | * a cipher matching the given rule string (for example if the rule string |
| 1152 | * specifies a cipher which has been disabled). This is not an error as far |
| 1153 | * as ssl_create_cipher_list is concerned, and hence ctx->cipher_list and |
| 1154 | * ctx->cipher_list_by_id has been updated. */ |
| 1155 | if (sk == NULL) { |
| 1156 | return 0; |
| 1157 | } else if (sk_SSL_CIPHER_num(sk) == 0) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1158 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1159 | return 0; |
| 1160 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1161 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1162 | return 1; |
| 1163 | } |
David Benjamin | 39482a1 | 2014-07-20 13:30:15 -0400 | [diff] [blame] | 1164 | |
Adam Langley | cef7583 | 2015-09-03 14:51:12 -0700 | [diff] [blame] | 1165 | int SSL_CTX_set_cipher_list_tls10(SSL_CTX *ctx, const char *str) { |
| 1166 | STACK_OF(SSL_CIPHER) *sk; |
| 1167 | |
| 1168 | sk = ssl_create_cipher_list(ctx->method, &ctx->cipher_list_tls10, NULL, str); |
| 1169 | if (sk == NULL) { |
| 1170 | return 0; |
| 1171 | } else if (sk_SSL_CIPHER_num(sk) == 0) { |
| 1172 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH); |
| 1173 | return 0; |
| 1174 | } |
| 1175 | |
| 1176 | return 1; |
| 1177 | } |
| 1178 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1179 | int SSL_CTX_set_cipher_list_tls11(SSL_CTX *ctx, const char *str) { |
| 1180 | STACK_OF(SSL_CIPHER) *sk; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1181 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1182 | sk = ssl_create_cipher_list(ctx->method, &ctx->cipher_list_tls11, NULL, str); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1183 | if (sk == NULL) { |
| 1184 | return 0; |
| 1185 | } else if (sk_SSL_CIPHER_num(sk) == 0) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1186 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1187 | return 0; |
| 1188 | } |
David Benjamin | 9f2c0d7 | 2014-10-21 22:00:19 -0400 | [diff] [blame] | 1189 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1190 | return 1; |
| 1191 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1192 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1193 | /* specify the ciphers to be used by the SSL */ |
| 1194 | int SSL_set_cipher_list(SSL *s, const char *str) { |
| 1195 | STACK_OF(SSL_CIPHER) *sk; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1196 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1197 | sk = ssl_create_cipher_list(s->ctx->method, &s->cipher_list, |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1198 | &s->cipher_list_by_id, str); |
David Benjamin | 39482a1 | 2014-07-20 13:30:15 -0400 | [diff] [blame] | 1199 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1200 | /* see comment in SSL_CTX_set_cipher_list */ |
| 1201 | if (sk == NULL) { |
| 1202 | return 0; |
| 1203 | } else if (sk_SSL_CIPHER_num(sk) == 0) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1204 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1205 | return 0; |
| 1206 | } |
David Benjamin | 39482a1 | 2014-07-20 13:30:15 -0400 | [diff] [blame] | 1207 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1208 | return 1; |
| 1209 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1210 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1211 | int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk, uint8_t *p) { |
| 1212 | size_t i; |
| 1213 | const SSL_CIPHER *c; |
| 1214 | CERT *ct = s->cert; |
| 1215 | uint8_t *q; |
| 1216 | /* Set disabled masks for this session */ |
| 1217 | ssl_set_client_disabled(s); |
Adam Langley | 2970779 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1218 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1219 | if (sk == NULL) { |
| 1220 | return 0; |
| 1221 | } |
| 1222 | q = p; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1223 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1224 | for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) { |
| 1225 | c = sk_SSL_CIPHER_value(sk, i); |
| 1226 | /* Skip disabled ciphers */ |
| 1227 | if (c->algorithm_ssl & ct->mask_ssl || |
| 1228 | c->algorithm_mkey & ct->mask_k || |
| 1229 | c->algorithm_auth & ct->mask_a) { |
| 1230 | continue; |
| 1231 | } |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 1232 | s2n(ssl_cipher_get_value(c), p); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | /* If all ciphers were disabled, return the error to the caller. */ |
| 1236 | if (p == q) { |
| 1237 | return 0; |
| 1238 | } |
| 1239 | |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 1240 | /* For SSLv3, the SCSV is added. Otherwise the renegotiation extension is |
| 1241 | * added. */ |
| 1242 | if (s->client_version == SSL3_VERSION && |
| 1243 | !s->s3->initial_handshake_complete) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1244 | s2n(SSL3_CK_SCSV & 0xffff, p); |
Adam Langley | 5021b22 | 2015-06-12 18:27:58 -0700 | [diff] [blame] | 1245 | /* The renegotiation extension is required to be at index zero. */ |
| 1246 | s->s3->tmp.extensions.sent |= (1u << 0); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1247 | } |
| 1248 | |
Adam Langley | 5f0efe0 | 2015-02-20 13:03:16 -0800 | [diff] [blame] | 1249 | if (s->mode & SSL_MODE_SEND_FALLBACK_SCSV) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1250 | s2n(SSL3_CK_FALLBACK_SCSV & 0xffff, p); |
| 1251 | } |
| 1252 | |
| 1253 | return p - q; |
| 1254 | } |
| 1255 | |
| 1256 | STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, const CBS *cbs) { |
| 1257 | CBS cipher_suites = *cbs; |
| 1258 | const SSL_CIPHER *c; |
David Benjamin | 60da0cd | 2015-05-03 15:21:28 -0400 | [diff] [blame] | 1259 | STACK_OF(SSL_CIPHER) *sk; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1260 | |
| 1261 | if (s->s3) { |
| 1262 | s->s3->send_connection_binding = 0; |
| 1263 | } |
| 1264 | |
| 1265 | if (CBS_len(&cipher_suites) % 2 != 0) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1266 | OPENSSL_PUT_ERROR(SSL, SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1267 | return NULL; |
| 1268 | } |
| 1269 | |
| 1270 | sk = sk_SSL_CIPHER_new_null(); |
| 1271 | if (sk == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1272 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1273 | goto err; |
| 1274 | } |
| 1275 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1276 | while (CBS_len(&cipher_suites) > 0) { |
| 1277 | uint16_t cipher_suite; |
| 1278 | |
| 1279 | if (!CBS_get_u16(&cipher_suites, &cipher_suite)) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1280 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1281 | goto err; |
| 1282 | } |
| 1283 | |
| 1284 | /* Check for SCSV. */ |
| 1285 | if (s->s3 && cipher_suite == (SSL3_CK_SCSV & 0xffff)) { |
| 1286 | /* SCSV is fatal if renegotiating. */ |
David Benjamin | 20f6e97 | 2015-05-15 21:51:49 -0400 | [diff] [blame] | 1287 | if (s->s3->initial_handshake_complete) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1288 | OPENSSL_PUT_ERROR(SSL, SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1289 | ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); |
| 1290 | goto err; |
| 1291 | } |
| 1292 | s->s3->send_connection_binding = 1; |
| 1293 | continue; |
| 1294 | } |
| 1295 | |
| 1296 | /* Check for FALLBACK_SCSV. */ |
| 1297 | if (s->s3 && cipher_suite == (SSL3_CK_FALLBACK_SCSV & 0xffff)) { |
| 1298 | uint16_t max_version = ssl3_get_max_server_version(s); |
| 1299 | if (SSL_IS_DTLS(s) ? (uint16_t)s->version > max_version |
| 1300 | : (uint16_t)s->version < max_version) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1301 | OPENSSL_PUT_ERROR(SSL, SSL_R_INAPPROPRIATE_FALLBACK); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1302 | ssl3_send_alert(s, SSL3_AL_FATAL, SSL3_AD_INAPPROPRIATE_FALLBACK); |
| 1303 | goto err; |
| 1304 | } |
| 1305 | continue; |
| 1306 | } |
| 1307 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 1308 | c = SSL_get_cipher_by_value(cipher_suite); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1309 | if (c != NULL && !sk_SSL_CIPHER_push(sk, c)) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1310 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1311 | goto err; |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | return sk; |
David Benjamin | 9f2c0d7 | 2014-10-21 22:00:19 -0400 | [diff] [blame] | 1316 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1317 | err: |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1318 | sk_SSL_CIPHER_free(sk); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1319 | return NULL; |
| 1320 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1321 | |
| 1322 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1323 | /* return a servername extension value if provided in Client Hello, or NULL. So |
| 1324 | * far, only host_name types are defined (RFC 3546). */ |
| 1325 | const char *SSL_get_servername(const SSL *s, const int type) { |
| 1326 | if (type != TLSEXT_NAMETYPE_host_name) { |
| 1327 | return NULL; |
| 1328 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1329 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1330 | return s->session && !s->tlsext_hostname ? s->session->tlsext_hostname |
| 1331 | : s->tlsext_hostname; |
| 1332 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1333 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1334 | int SSL_get_servername_type(const SSL *s) { |
| 1335 | if (s->session && |
| 1336 | (!s->tlsext_hostname ? s->session->tlsext_hostname : s->tlsext_hostname)) { |
| 1337 | return TLSEXT_NAMETYPE_host_name; |
| 1338 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1339 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1340 | return -1; |
| 1341 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1342 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1343 | void SSL_CTX_enable_signed_cert_timestamps(SSL_CTX *ctx) { |
| 1344 | ctx->signed_cert_timestamps_enabled = 1; |
| 1345 | } |
HÃ¥vard Molland | 9169c96 | 2014-08-14 14:42:37 +0200 | [diff] [blame] | 1346 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1347 | int SSL_enable_signed_cert_timestamps(SSL *ssl) { |
| 1348 | ssl->signed_cert_timestamps_enabled = 1; |
| 1349 | return 1; |
| 1350 | } |
HÃ¥vard Molland | 9169c96 | 2014-08-14 14:42:37 +0200 | [diff] [blame] | 1351 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1352 | void SSL_CTX_enable_ocsp_stapling(SSL_CTX *ctx) { |
| 1353 | ctx->ocsp_stapling_enabled = 1; |
| 1354 | } |
David Benjamin | 6c7aed0 | 2014-08-27 16:42:38 -0400 | [diff] [blame] | 1355 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1356 | int SSL_enable_ocsp_stapling(SSL *ssl) { |
| 1357 | ssl->ocsp_stapling_enabled = 1; |
| 1358 | return 1; |
| 1359 | } |
David Benjamin | 6c7aed0 | 2014-08-27 16:42:38 -0400 | [diff] [blame] | 1360 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1361 | void SSL_get0_signed_cert_timestamp_list(const SSL *ssl, const uint8_t **out, |
| 1362 | size_t *out_len) { |
| 1363 | SSL_SESSION *session = ssl->session; |
Adam Langley | 3cb50e0 | 2014-08-26 14:00:31 -0700 | [diff] [blame] | 1364 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1365 | *out_len = 0; |
| 1366 | *out = NULL; |
| 1367 | if (ssl->server || !session || !session->tlsext_signed_cert_timestamp_list) { |
| 1368 | return; |
| 1369 | } |
HÃ¥vard Molland | 9169c96 | 2014-08-14 14:42:37 +0200 | [diff] [blame] | 1370 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1371 | *out = session->tlsext_signed_cert_timestamp_list; |
| 1372 | *out_len = session->tlsext_signed_cert_timestamp_list_length; |
| 1373 | } |
David Benjamin | 6c7aed0 | 2014-08-27 16:42:38 -0400 | [diff] [blame] | 1374 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1375 | void SSL_get0_ocsp_response(const SSL *ssl, const uint8_t **out, |
| 1376 | size_t *out_len) { |
| 1377 | SSL_SESSION *session = ssl->session; |
| 1378 | |
| 1379 | *out_len = 0; |
| 1380 | *out = NULL; |
| 1381 | if (ssl->server || !session || !session->ocsp_response) { |
| 1382 | return; |
| 1383 | } |
| 1384 | *out = session->ocsp_response; |
| 1385 | *out_len = session->ocsp_response_length; |
| 1386 | } |
David Benjamin | 6c7aed0 | 2014-08-27 16:42:38 -0400 | [diff] [blame] | 1387 | |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 1388 | int SSL_CTX_set_ocsp_response(SSL_CTX *ctx, const uint8_t *response, |
| 1389 | size_t response_len) { |
| 1390 | OPENSSL_free(ctx->ocsp_response); |
| 1391 | ctx->ocsp_response_length = 0; |
| 1392 | |
| 1393 | ctx->ocsp_response = BUF_memdup(response, response_len); |
| 1394 | if (ctx->ocsp_response == NULL) { |
| 1395 | return 0; |
| 1396 | } |
| 1397 | ctx->ocsp_response_length = response_len; |
| 1398 | |
| 1399 | return 1; |
| 1400 | } |
| 1401 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1402 | /* SSL_select_next_proto implements the standard protocol selection. It is |
| 1403 | * expected that this function is called from the callback set by |
| 1404 | * SSL_CTX_set_next_proto_select_cb. |
| 1405 | * |
| 1406 | * The protocol data is assumed to be a vector of 8-bit, length prefixed byte |
| 1407 | * strings. The length byte itself is not included in the length. A byte |
| 1408 | * string of length 0 is invalid. No byte string may be truncated. |
| 1409 | * |
| 1410 | * The current, but experimental algorithm for selecting the protocol is: |
| 1411 | * |
| 1412 | * 1) If the server doesn't support NPN then this is indicated to the |
| 1413 | * callback. In this case, the client application has to abort the connection |
| 1414 | * or have a default application level protocol. |
| 1415 | * |
| 1416 | * 2) If the server supports NPN, but advertises an empty list then the |
| 1417 | * client selects the first protcol in its list, but indicates via the |
| 1418 | * API that this fallback case was enacted. |
| 1419 | * |
| 1420 | * 3) Otherwise, the client finds the first protocol in the server's list |
| 1421 | * that it supports and selects this protocol. This is because it's |
| 1422 | * assumed that the server has better information about which protocol |
| 1423 | * a client should use. |
| 1424 | * |
| 1425 | * 4) If the client doesn't support any of the server's advertised |
| 1426 | * protocols, then this is treated the same as case 2. |
| 1427 | * |
| 1428 | * It returns either |
| 1429 | * OPENSSL_NPN_NEGOTIATED if a common protocol was found, or |
| 1430 | * OPENSSL_NPN_NO_OVERLAP if the fallback case was reached. |
| 1431 | */ |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1432 | int SSL_select_next_proto(uint8_t **out, uint8_t *outlen, const uint8_t *server, |
| 1433 | unsigned int server_len, const uint8_t *client, |
| 1434 | unsigned int client_len) { |
| 1435 | unsigned int i, j; |
| 1436 | const uint8_t *result; |
| 1437 | int status = OPENSSL_NPN_UNSUPPORTED; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1438 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1439 | /* For each protocol in server preference order, see if we support it. */ |
| 1440 | for (i = 0; i < server_len;) { |
| 1441 | for (j = 0; j < client_len;) { |
| 1442 | if (server[i] == client[j] && |
| 1443 | memcmp(&server[i + 1], &client[j + 1], server[i]) == 0) { |
| 1444 | /* We found a match */ |
| 1445 | result = &server[i]; |
| 1446 | status = OPENSSL_NPN_NEGOTIATED; |
| 1447 | goto found; |
| 1448 | } |
| 1449 | j += client[j]; |
| 1450 | j++; |
| 1451 | } |
| 1452 | i += server[i]; |
| 1453 | i++; |
| 1454 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1455 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1456 | /* There's no overlap between our protocols and the server's list. */ |
| 1457 | result = client; |
| 1458 | status = OPENSSL_NPN_NO_OVERLAP; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1459 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1460 | found: |
| 1461 | *out = (uint8_t *)result + 1; |
| 1462 | *outlen = result[0]; |
| 1463 | return status; |
| 1464 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1465 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1466 | /* SSL_get0_next_proto_negotiated sets *data and *len to point to the client's |
| 1467 | * requested protocol for this connection and returns 0. If the client didn't |
| 1468 | * request any protocol, then *data is set to NULL. |
| 1469 | * |
| 1470 | * Note that the client can request any protocol it chooses. The value returned |
| 1471 | * from this function need not be a member of the list of supported protocols |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1472 | * provided by the callback. */ |
| 1473 | void SSL_get0_next_proto_negotiated(const SSL *s, const uint8_t **data, |
| 1474 | unsigned *len) { |
| 1475 | *data = s->next_proto_negotiated; |
| 1476 | if (!*data) { |
| 1477 | *len = 0; |
| 1478 | } else { |
| 1479 | *len = s->next_proto_negotiated_len; |
| 1480 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | /* SSL_CTX_set_next_protos_advertised_cb sets a callback that is called when a |
| 1484 | * TLS server needs a list of supported protocols for Next Protocol |
| 1485 | * Negotiation. The returned list must be in wire format. The list is returned |
| 1486 | * by setting |out| to point to it and |outlen| to its length. This memory will |
| 1487 | * not be modified, but one should assume that the SSL* keeps a reference to |
| 1488 | * it. |
| 1489 | * |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1490 | * The callback should return SSL_TLSEXT_ERR_OK if it wishes to advertise. |
| 1491 | * Otherwise, no such extension will be included in the ServerHello. */ |
| 1492 | void SSL_CTX_set_next_protos_advertised_cb( |
| 1493 | SSL_CTX *ctx, |
| 1494 | int (*cb)(SSL *ssl, const uint8_t **out, unsigned int *outlen, void *arg), |
| 1495 | void *arg) { |
| 1496 | ctx->next_protos_advertised_cb = cb; |
| 1497 | ctx->next_protos_advertised_cb_arg = arg; |
| 1498 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1499 | |
| 1500 | /* SSL_CTX_set_next_proto_select_cb sets a callback that is called when a |
| 1501 | * client needs to select a protocol from the server's provided list. |out| |
| 1502 | * must be set to point to the selected protocol (which may be within |in|). |
| 1503 | * The length of the protocol name must be written into |outlen|. The server's |
| 1504 | * advertised protocols are provided in |in| and |inlen|. The callback can |
| 1505 | * assume that |in| is syntactically valid. |
| 1506 | * |
| 1507 | * The client must select a protocol. It is fatal to the connection if this |
| 1508 | * callback returns a value other than SSL_TLSEXT_ERR_OK. |
| 1509 | */ |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1510 | void SSL_CTX_set_next_proto_select_cb( |
| 1511 | SSL_CTX *ctx, int (*cb)(SSL *s, uint8_t **out, uint8_t *outlen, |
| 1512 | const uint8_t *in, unsigned int inlen, void *arg), |
| 1513 | void *arg) { |
| 1514 | ctx->next_proto_select_cb = cb; |
| 1515 | ctx->next_proto_select_cb_arg = arg; |
| 1516 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1517 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1518 | int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const uint8_t *protos, |
| 1519 | unsigned protos_len) { |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1520 | OPENSSL_free(ctx->alpn_client_proto_list); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1521 | ctx->alpn_client_proto_list = BUF_memdup(protos, protos_len); |
| 1522 | if (!ctx->alpn_client_proto_list) { |
| 1523 | return 1; |
| 1524 | } |
| 1525 | ctx->alpn_client_proto_list_len = protos_len; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1526 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1527 | return 0; |
| 1528 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1529 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1530 | int SSL_set_alpn_protos(SSL *ssl, const uint8_t *protos, unsigned protos_len) { |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1531 | OPENSSL_free(ssl->alpn_client_proto_list); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1532 | ssl->alpn_client_proto_list = BUF_memdup(protos, protos_len); |
| 1533 | if (!ssl->alpn_client_proto_list) { |
| 1534 | return 1; |
| 1535 | } |
| 1536 | ssl->alpn_client_proto_list_len = protos_len; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1537 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1538 | return 0; |
| 1539 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1540 | |
| 1541 | /* SSL_CTX_set_alpn_select_cb sets a callback function on |ctx| that is called |
| 1542 | * during ClientHello processing in order to select an ALPN protocol from the |
| 1543 | * client's list of offered protocols. */ |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1544 | void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx, |
| 1545 | int (*cb)(SSL *ssl, const uint8_t **out, |
| 1546 | uint8_t *outlen, const uint8_t *in, |
| 1547 | unsigned int inlen, void *arg), |
| 1548 | void *arg) { |
| 1549 | ctx->alpn_select_cb = cb; |
| 1550 | ctx->alpn_select_cb_arg = arg; |
| 1551 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1552 | |
| 1553 | /* SSL_get0_alpn_selected gets the selected ALPN protocol (if any) from |ssl|. |
| 1554 | * On return it sets |*data| to point to |*len| bytes of protocol name (not |
| 1555 | * including the leading length-prefix byte). If the server didn't respond with |
| 1556 | * a negotiated protocol then |*len| will be zero. */ |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1557 | void SSL_get0_alpn_selected(const SSL *ssl, const uint8_t **data, |
| 1558 | unsigned *len) { |
| 1559 | *data = NULL; |
| 1560 | if (ssl->s3) { |
| 1561 | *data = ssl->s3->alpn_selected; |
| 1562 | } |
| 1563 | if (*data == NULL) { |
| 1564 | *len = 0; |
| 1565 | } else { |
| 1566 | *len = ssl->s3->alpn_selected_len; |
| 1567 | } |
| 1568 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1569 | |
David Benjamin | cfd248b | 2015-04-03 11:02:24 -0400 | [diff] [blame] | 1570 | int SSL_export_keying_material(SSL *s, uint8_t *out, size_t out_len, |
| 1571 | const char *label, size_t label_len, |
| 1572 | const uint8_t *context, size_t context_len, |
| 1573 | int use_context) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1574 | if (s->version < TLS1_VERSION) { |
David Benjamin | c565ebb | 2015-04-03 04:06:36 -0400 | [diff] [blame] | 1575 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1576 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1577 | |
David Benjamin | cfd248b | 2015-04-03 11:02:24 -0400 | [diff] [blame] | 1578 | return s->enc_method->export_keying_material( |
| 1579 | s, out, out_len, label, label_len, context, context_len, use_context); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1580 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1581 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1582 | static uint32_t ssl_session_hash(const SSL_SESSION *a) { |
| 1583 | uint32_t hash = |
| 1584 | ((uint32_t)a->session_id[0]) || |
| 1585 | ((uint32_t)a->session_id[1] << 8) || |
| 1586 | ((uint32_t)a->session_id[2] << 16) || |
| 1587 | ((uint32_t)a->session_id[3] << 24); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1588 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1589 | return hash; |
| 1590 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1591 | |
| 1592 | /* NB: If this function (or indeed the hash function which uses a sort of |
| 1593 | * coarser function than this one) is changed, ensure |
| 1594 | * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being |
| 1595 | * able to construct an SSL_SESSION that will collide with any existing session |
| 1596 | * with a matching session ID. */ |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1597 | static int ssl_session_cmp(const SSL_SESSION *a, const SSL_SESSION *b) { |
| 1598 | if (a->ssl_version != b->ssl_version) { |
| 1599 | return 1; |
| 1600 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1601 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1602 | if (a->session_id_length != b->session_id_length) { |
| 1603 | return 1; |
| 1604 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1605 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1606 | return memcmp(a->session_id, b->session_id, a->session_id_length); |
| 1607 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1608 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 1609 | SSL_CTX *SSL_CTX_new(const SSL_METHOD *method) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1610 | SSL_CTX *ret = NULL; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1611 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 1612 | if (method == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1613 | OPENSSL_PUT_ERROR(SSL, SSL_R_NULL_SSL_METHOD_PASSED); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1614 | return NULL; |
| 1615 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1616 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1617 | if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1618 | OPENSSL_PUT_ERROR(SSL, SSL_R_X509_VERIFICATION_SETUP_PROBLEMS); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1619 | goto err; |
| 1620 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1621 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1622 | ret = (SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX)); |
| 1623 | if (ret == NULL) { |
| 1624 | goto err; |
| 1625 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1626 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1627 | memset(ret, 0, sizeof(SSL_CTX)); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1628 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 1629 | ret->method = method->method; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1630 | |
Adam Langley | 4bdb6e4 | 2015-05-15 15:29:21 -0700 | [diff] [blame] | 1631 | CRYPTO_MUTEX_init(&ret->lock); |
| 1632 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1633 | ret->session_cache_mode = SSL_SESS_CACHE_SERVER; |
| 1634 | ret->session_cache_size = SSL_SESSION_CACHE_MAX_SIZE_DEFAULT; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1635 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1636 | /* We take the system default */ |
| 1637 | ret->session_timeout = SSL_DEFAULT_SESSION_TIMEOUT; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1638 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1639 | ret->references = 1; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1640 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1641 | ret->max_cert_list = SSL_MAX_CERT_LIST_DEFAULT; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1642 | ret->verify_mode = SSL_VERIFY_NONE; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1643 | ret->cert = ssl_cert_new(); |
| 1644 | if (ret->cert == NULL) { |
| 1645 | goto err; |
| 1646 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1647 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1648 | ret->sessions = lh_SSL_SESSION_new(ssl_session_hash, ssl_session_cmp); |
| 1649 | if (ret->sessions == NULL) { |
| 1650 | goto err; |
| 1651 | } |
| 1652 | ret->cert_store = X509_STORE_new(); |
| 1653 | if (ret->cert_store == NULL) { |
| 1654 | goto err; |
| 1655 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1656 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1657 | ssl_create_cipher_list(ret->method, &ret->cipher_list, |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1658 | &ret->cipher_list_by_id, SSL_DEFAULT_CIPHER_LIST); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1659 | if (ret->cipher_list == NULL || |
| 1660 | sk_SSL_CIPHER_num(ret->cipher_list->ciphers) <= 0) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1661 | OPENSSL_PUT_ERROR(SSL, SSL_R_LIBRARY_HAS_NO_CIPHERS); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1662 | goto err2; |
| 1663 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1664 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1665 | ret->param = X509_VERIFY_PARAM_new(); |
| 1666 | if (!ret->param) { |
| 1667 | goto err; |
| 1668 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1669 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1670 | ret->client_CA = sk_X509_NAME_new_null(); |
| 1671 | if (ret->client_CA == NULL) { |
| 1672 | goto err; |
| 1673 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1674 | |
David Benjamin | 9f33fc6 | 2015-04-15 17:29:53 -0400 | [diff] [blame] | 1675 | CRYPTO_new_ex_data(&g_ex_data_class_ssl_ctx, ret, &ret->ex_data); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1676 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1677 | ret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH; |
David Benjamin | 422d3a4 | 2014-08-20 11:09:03 -0400 | [diff] [blame] | 1678 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1679 | /* Setup RFC4507 ticket keys */ |
| 1680 | if (!RAND_bytes(ret->tlsext_tick_key_name, 16) || |
| 1681 | !RAND_bytes(ret->tlsext_tick_hmac_key, 16) || |
| 1682 | !RAND_bytes(ret->tlsext_tick_aes_key, 16)) { |
| 1683 | ret->options |= SSL_OP_NO_TICKET; |
| 1684 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1685 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1686 | /* Default is to connect to non-RI servers. When RI is more widely deployed |
| 1687 | * might change this. */ |
| 1688 | ret->options |= SSL_OP_LEGACY_SERVER_CONNECT; |
| 1689 | |
| 1690 | /* Lock the SSL_CTX to the specified version, for compatibility with legacy |
| 1691 | * uses of SSL_METHOD. */ |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 1692 | if (method->version != 0) { |
| 1693 | SSL_CTX_set_max_version(ret, method->version); |
| 1694 | SSL_CTX_set_min_version(ret, method->version); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | return ret; |
| 1698 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1699 | err: |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1700 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1701 | err2: |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1702 | SSL_CTX_free(ret); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1703 | return NULL; |
| 1704 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1705 | |
David Benjamin | 4fcc2e2 | 2015-04-22 12:58:16 -0400 | [diff] [blame] | 1706 | void SSL_CTX_free(SSL_CTX *ctx) { |
| 1707 | if (ctx == NULL || |
Adam Langley | 0b5e390 | 2015-05-15 13:08:38 -0700 | [diff] [blame] | 1708 | !CRYPTO_refcount_dec_and_test_zero(&ctx->references)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1709 | return; |
| 1710 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1711 | |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1712 | X509_VERIFY_PARAM_free(ctx->param); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1713 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1714 | /* Free internal session cache. However: the remove_cb() may reference the |
| 1715 | * ex_data of SSL_CTX, thus the ex_data store can only be removed after the |
| 1716 | * sessions were flushed. As the ex_data handling routines might also touch |
| 1717 | * the session cache, the most secure solution seems to be: empty (flush) the |
| 1718 | * cache, then free ex_data, then finally free the cache. (See ticket |
| 1719 | * [openssl.org #212].) */ |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1720 | SSL_CTX_flush_sessions(ctx, 0); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1721 | |
David Benjamin | 4fcc2e2 | 2015-04-22 12:58:16 -0400 | [diff] [blame] | 1722 | CRYPTO_free_ex_data(&g_ex_data_class_ssl_ctx, ctx, &ctx->ex_data); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1723 | |
Adam Langley | 4bdb6e4 | 2015-05-15 15:29:21 -0700 | [diff] [blame] | 1724 | CRYPTO_MUTEX_cleanup(&ctx->lock); |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1725 | lh_SSL_SESSION_free(ctx->sessions); |
| 1726 | X509_STORE_free(ctx->cert_store); |
| 1727 | ssl_cipher_preference_list_free(ctx->cipher_list); |
| 1728 | sk_SSL_CIPHER_free(ctx->cipher_list_by_id); |
Adam Langley | 8748920 | 2015-09-03 15:52:29 -0700 | [diff] [blame] | 1729 | ssl_cipher_preference_list_free(ctx->cipher_list_tls10); |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1730 | ssl_cipher_preference_list_free(ctx->cipher_list_tls11); |
| 1731 | ssl_cert_free(ctx->cert); |
Adam Langley | 0950563 | 2015-07-30 18:10:13 -0700 | [diff] [blame] | 1732 | sk_SSL_CUSTOM_EXTENSION_pop_free(ctx->client_custom_extensions, |
| 1733 | SSL_CUSTOM_EXTENSION_free); |
| 1734 | sk_SSL_CUSTOM_EXTENSION_pop_free(ctx->server_custom_extensions, |
| 1735 | SSL_CUSTOM_EXTENSION_free); |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1736 | sk_X509_NAME_pop_free(ctx->client_CA, X509_NAME_free); |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1737 | sk_SRTP_PROTECTION_PROFILE_free(ctx->srtp_profiles); |
| 1738 | OPENSSL_free(ctx->psk_identity_hint); |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1739 | OPENSSL_free(ctx->tlsext_ellipticcurvelist); |
| 1740 | OPENSSL_free(ctx->alpn_client_proto_list); |
Paul Lietar | aeeff2c | 2015-08-12 11:47:11 +0100 | [diff] [blame] | 1741 | OPENSSL_free(ctx->ocsp_response); |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1742 | EVP_PKEY_free(ctx->tlsext_channel_id_private); |
| 1743 | BIO_free(ctx->keylog_bio); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1744 | |
David Benjamin | 4fcc2e2 | 2015-04-22 12:58:16 -0400 | [diff] [blame] | 1745 | OPENSSL_free(ctx); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1746 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1747 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1748 | void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb) { |
| 1749 | ctx->default_passwd_callback = cb; |
| 1750 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1751 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1752 | void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u) { |
| 1753 | ctx->default_passwd_callback_userdata = u; |
| 1754 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1755 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1756 | void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, |
| 1757 | int (*cb)(X509_STORE_CTX *, void *), |
| 1758 | void *arg) { |
| 1759 | ctx->app_verify_callback = cb; |
| 1760 | ctx->app_verify_arg = arg; |
| 1761 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1762 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1763 | void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, |
| 1764 | int (*cb)(int, X509_STORE_CTX *)) { |
| 1765 | ctx->verify_mode = mode; |
| 1766 | ctx->default_verify_callback = cb; |
| 1767 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1768 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1769 | void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth) { |
| 1770 | X509_VERIFY_PARAM_set_depth(ctx->param, depth); |
| 1771 | } |
Adam Langley | 1258b6a | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1772 | |
David Benjamin | 7481d39 | 2015-07-05 19:38:46 -0400 | [diff] [blame] | 1773 | void SSL_CTX_set_cert_cb(SSL_CTX *ctx, int (*cb)(SSL *ssl, void *arg), |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1774 | void *arg) { |
David Benjamin | 7481d39 | 2015-07-05 19:38:46 -0400 | [diff] [blame] | 1775 | ssl_cert_set_cert_cb(ctx->cert, cb, arg); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1776 | } |
David Benjamin | 859ec3c | 2014-09-02 16:29:36 -0400 | [diff] [blame] | 1777 | |
David Benjamin | 7481d39 | 2015-07-05 19:38:46 -0400 | [diff] [blame] | 1778 | void SSL_set_cert_cb(SSL *ssl, int (*cb)(SSL *ssl, void *arg), void *arg) { |
| 1779 | ssl_cert_set_cert_cb(ssl->cert, cb, arg); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1780 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1781 | |
David Benjamin | 107db58 | 2015-04-08 00:41:59 -0400 | [diff] [blame] | 1782 | void ssl_get_compatible_server_ciphers(SSL *s, uint32_t *out_mask_k, |
| 1783 | uint32_t *out_mask_a) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1784 | CERT *c = s->cert; |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 1785 | int have_rsa_cert = 0, dh_tmp; |
David Benjamin | 107db58 | 2015-04-08 00:41:59 -0400 | [diff] [blame] | 1786 | uint32_t mask_k, mask_a; |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 1787 | int have_ecc_cert = 0, ecdsa_ok; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1788 | X509 *x; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1789 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1790 | dh_tmp = (c->dh_tmp != NULL || c->dh_tmp_cb != NULL); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1791 | |
nagendra modadugu | 601448a | 2015-07-24 09:31:31 -0700 | [diff] [blame] | 1792 | if (s->cert->x509 != NULL && ssl_has_private_key(s)) { |
| 1793 | if (ssl_private_key_type(s) == EVP_PKEY_RSA) { |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 1794 | have_rsa_cert = 1; |
nagendra modadugu | 601448a | 2015-07-24 09:31:31 -0700 | [diff] [blame] | 1795 | } else if (ssl_private_key_type(s) == EVP_PKEY_EC) { |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 1796 | have_ecc_cert = 1; |
| 1797 | } |
| 1798 | } |
nagendra modadugu | 601448a | 2015-07-24 09:31:31 -0700 | [diff] [blame] | 1799 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1800 | mask_k = 0; |
| 1801 | mask_a = 0; |
David Benjamin | f31e681 | 2014-11-13 18:05:55 -0500 | [diff] [blame] | 1802 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1803 | if (dh_tmp) { |
David Benjamin | 7061e28 | 2015-03-19 11:10:48 -0400 | [diff] [blame] | 1804 | mask_k |= SSL_kDHE; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1805 | } |
David Benjamin | bb20f52 | 2015-07-04 17:18:14 -0400 | [diff] [blame] | 1806 | if (have_rsa_cert) { |
| 1807 | mask_k |= SSL_kRSA; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1808 | mask_a |= SSL_aRSA; |
| 1809 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1810 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1811 | /* An ECC certificate may be usable for ECDSA cipher suites depending on the |
| 1812 | * key usage extension and on the client's curve preferences. */ |
| 1813 | if (have_ecc_cert) { |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 1814 | x = c->x509; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1815 | /* This call populates extension flags (ex_flags). */ |
| 1816 | X509_check_purpose(x, -1, 0); |
| 1817 | ecdsa_ok = (x->ex_flags & EXFLAG_KUSAGE) |
| 1818 | ? (x->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE) |
| 1819 | : 1; |
| 1820 | if (!tls1_check_ec_cert(s, x)) { |
| 1821 | ecdsa_ok = 0; |
| 1822 | } |
| 1823 | if (ecdsa_ok) { |
| 1824 | mask_a |= SSL_aECDSA; |
| 1825 | } |
| 1826 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1827 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1828 | /* If we are considering an ECC cipher suite that uses an ephemeral EC |
| 1829 | * key, check it. */ |
David Benjamin | dd97878 | 2015-04-24 15:20:13 -0400 | [diff] [blame] | 1830 | if (tls1_check_ec_tmp_key(s)) { |
David Benjamin | 7061e28 | 2015-03-19 11:10:48 -0400 | [diff] [blame] | 1831 | mask_k |= SSL_kECDHE; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1832 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1833 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1834 | /* PSK requires a server callback. */ |
| 1835 | if (s->psk_server_callback != NULL) { |
| 1836 | mask_k |= SSL_kPSK; |
| 1837 | mask_a |= SSL_aPSK; |
| 1838 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1839 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1840 | *out_mask_k = mask_k; |
| 1841 | *out_mask_a = mask_a; |
| 1842 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1843 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1844 | void ssl_update_cache(SSL *s, int mode) { |
David Benjamin | b6d0c6d | 2015-03-19 19:07:26 -0400 | [diff] [blame] | 1845 | /* Never cache sessions with empty session IDs. */ |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1846 | if (s->session->session_id_length == 0) { |
| 1847 | return; |
| 1848 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1849 | |
David Benjamin | 95d3182 | 2015-06-15 19:53:32 -0400 | [diff] [blame] | 1850 | int has_new_session = !s->hit; |
| 1851 | if (!s->server && s->tlsext_ticket_expected) { |
| 1852 | /* A client may see new sessions on abbreviated handshakes if the server |
| 1853 | * decides to renew the ticket. Once the handshake is completed, it should |
| 1854 | * be inserted into the cache. */ |
| 1855 | has_new_session = 1; |
| 1856 | } |
| 1857 | |
David Benjamin | b6d0c6d | 2015-03-19 19:07:26 -0400 | [diff] [blame] | 1858 | SSL_CTX *ctx = s->initial_ctx; |
David Benjamin | 95d3182 | 2015-06-15 19:53:32 -0400 | [diff] [blame] | 1859 | if ((ctx->session_cache_mode & mode) == mode && has_new_session && |
David Benjamin | b6d0c6d | 2015-03-19 19:07:26 -0400 | [diff] [blame] | 1860 | ((ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE) || |
| 1861 | SSL_CTX_add_session(ctx, s->session)) && |
| 1862 | ctx->new_session_cb != NULL) { |
| 1863 | /* Note: |new_session_cb| is called whether the internal session cache is |
| 1864 | * used or not. */ |
| 1865 | if (!ctx->new_session_cb(s, SSL_SESSION_up_ref(s->session))) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1866 | SSL_SESSION_free(s->session); |
| 1867 | } |
| 1868 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1869 | |
David Benjamin | b6d0c6d | 2015-03-19 19:07:26 -0400 | [diff] [blame] | 1870 | if (!(ctx->session_cache_mode & SSL_SESS_CACHE_NO_AUTO_CLEAR) && |
| 1871 | !(ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE) && |
| 1872 | (ctx->session_cache_mode & mode) == mode) { |
| 1873 | /* Automatically flush the internal session cache every 255 connections. */ |
| 1874 | int flush_cache = 0; |
Adam Langley | 4bdb6e4 | 2015-05-15 15:29:21 -0700 | [diff] [blame] | 1875 | CRYPTO_MUTEX_lock_write(&ctx->lock); |
David Benjamin | b6d0c6d | 2015-03-19 19:07:26 -0400 | [diff] [blame] | 1876 | ctx->handshakes_since_cache_flush++; |
| 1877 | if (ctx->handshakes_since_cache_flush >= 255) { |
| 1878 | flush_cache = 1; |
| 1879 | ctx->handshakes_since_cache_flush = 0; |
| 1880 | } |
Adam Langley | 4bdb6e4 | 2015-05-15 15:29:21 -0700 | [diff] [blame] | 1881 | CRYPTO_MUTEX_unlock(&ctx->lock); |
David Benjamin | b6d0c6d | 2015-03-19 19:07:26 -0400 | [diff] [blame] | 1882 | |
| 1883 | if (flush_cache) { |
| 1884 | SSL_CTX_flush_sessions(ctx, (unsigned long)time(NULL)); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1885 | } |
| 1886 | } |
| 1887 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1888 | |
David Benjamin | 1a5c50f | 2015-03-11 16:22:37 -0400 | [diff] [blame] | 1889 | int SSL_get_error(const SSL *s, int ret_code) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1890 | int reason; |
David Benjamin | 1a5c50f | 2015-03-11 16:22:37 -0400 | [diff] [blame] | 1891 | uint32_t err; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1892 | BIO *bio; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1893 | |
David Benjamin | 1a5c50f | 2015-03-11 16:22:37 -0400 | [diff] [blame] | 1894 | if (ret_code > 0) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1895 | return SSL_ERROR_NONE; |
| 1896 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1897 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1898 | /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake etc, |
| 1899 | * where we do encode the error */ |
David Benjamin | 1a5c50f | 2015-03-11 16:22:37 -0400 | [diff] [blame] | 1900 | err = ERR_peek_error(); |
| 1901 | if (err != 0) { |
| 1902 | if (ERR_GET_LIB(err) == ERR_LIB_SYS) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1903 | return SSL_ERROR_SYSCALL; |
| 1904 | } |
| 1905 | return SSL_ERROR_SSL; |
| 1906 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1907 | |
David Benjamin | 1a5c50f | 2015-03-11 16:22:37 -0400 | [diff] [blame] | 1908 | if (ret_code == 0) { |
David Benjamin | 9a38e92 | 2015-01-22 16:06:11 -0500 | [diff] [blame] | 1909 | if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) && |
| 1910 | (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY)) { |
| 1911 | /* The socket was cleanly shut down with a close_notify. */ |
| 1912 | return SSL_ERROR_ZERO_RETURN; |
| 1913 | } |
| 1914 | /* An EOF was observed which violates the protocol, and the underlying |
| 1915 | * transport does not participate in the error queue. Bubble up to the |
| 1916 | * caller. */ |
| 1917 | return SSL_ERROR_SYSCALL; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1918 | } |
Adam Langley | b2ce058 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1919 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1920 | if (SSL_want_session(s)) { |
| 1921 | return SSL_ERROR_PENDING_SESSION; |
| 1922 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1923 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1924 | if (SSL_want_certificate(s)) { |
| 1925 | return SSL_ERROR_PENDING_CERTIFICATE; |
| 1926 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1927 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1928 | if (SSL_want_read(s)) { |
| 1929 | bio = SSL_get_rbio(s); |
| 1930 | if (BIO_should_read(bio)) { |
| 1931 | return SSL_ERROR_WANT_READ; |
| 1932 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1933 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1934 | if (BIO_should_write(bio)) { |
| 1935 | /* This one doesn't make too much sense ... We never try to write to the |
| 1936 | * rbio, and an application program where rbio and wbio are separate |
| 1937 | * couldn't even know what it should wait for. However if we ever set |
| 1938 | * s->rwstate incorrectly (so that we have SSL_want_read(s) instead of |
| 1939 | * SSL_want_write(s)) and rbio and wbio *are* the same, this test works |
| 1940 | * around that bug; so it might be safer to keep it. */ |
| 1941 | return SSL_ERROR_WANT_WRITE; |
| 1942 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1943 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1944 | if (BIO_should_io_special(bio)) { |
| 1945 | reason = BIO_get_retry_reason(bio); |
| 1946 | if (reason == BIO_RR_CONNECT) { |
| 1947 | return SSL_ERROR_WANT_CONNECT; |
| 1948 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1949 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1950 | if (reason == BIO_RR_ACCEPT) { |
| 1951 | return SSL_ERROR_WANT_ACCEPT; |
| 1952 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1953 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1954 | return SSL_ERROR_SYSCALL; /* unknown */ |
| 1955 | } |
| 1956 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1957 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1958 | if (SSL_want_write(s)) { |
| 1959 | bio = SSL_get_wbio(s); |
| 1960 | if (BIO_should_write(bio)) { |
| 1961 | return SSL_ERROR_WANT_WRITE; |
| 1962 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1963 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1964 | if (BIO_should_read(bio)) { |
| 1965 | /* See above (SSL_want_read(s) with BIO_should_write(bio)) */ |
| 1966 | return SSL_ERROR_WANT_READ; |
| 1967 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1968 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1969 | if (BIO_should_io_special(bio)) { |
| 1970 | reason = BIO_get_retry_reason(bio); |
| 1971 | if (reason == BIO_RR_CONNECT) { |
| 1972 | return SSL_ERROR_WANT_CONNECT; |
| 1973 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1974 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1975 | if (reason == BIO_RR_ACCEPT) { |
| 1976 | return SSL_ERROR_WANT_ACCEPT; |
| 1977 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1978 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1979 | return SSL_ERROR_SYSCALL; |
| 1980 | } |
| 1981 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1982 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1983 | if (SSL_want_x509_lookup(s)) { |
| 1984 | return SSL_ERROR_WANT_X509_LOOKUP; |
| 1985 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1986 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1987 | if (SSL_want_channel_id_lookup(s)) { |
| 1988 | return SSL_ERROR_WANT_CHANNEL_ID_LOOKUP; |
| 1989 | } |
Adam Langley | 0f4746e | 2014-08-13 12:26:32 -0700 | [diff] [blame] | 1990 | |
David Benjamin | b4d65fd | 2015-05-29 17:11:21 -0400 | [diff] [blame] | 1991 | if (SSL_want_private_key_operation(s)) { |
| 1992 | return SSL_ERROR_WANT_PRIVATE_KEY_OPERATION; |
| 1993 | } |
| 1994 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1995 | return SSL_ERROR_SYSCALL; |
| 1996 | } |
Adam Langley | 0f4746e | 2014-08-13 12:26:32 -0700 | [diff] [blame] | 1997 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1998 | int SSL_do_handshake(SSL *s) { |
| 1999 | int ret = 1; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2000 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2001 | if (s->handshake_func == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 2002 | OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_TYPE_NOT_SET); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2003 | return -1; |
| 2004 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2005 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2006 | if (SSL_in_init(s)) { |
| 2007 | ret = s->handshake_func(s); |
| 2008 | } |
| 2009 | return ret; |
| 2010 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2011 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 2012 | void SSL_set_accept_state(SSL *ssl) { |
| 2013 | ssl->server = 1; |
| 2014 | ssl->shutdown = 0; |
David Benjamin | 8ec8810 | 2015-05-15 23:40:13 -0400 | [diff] [blame] | 2015 | ssl->state = SSL_ST_ACCEPT; |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 2016 | ssl->handshake_func = ssl->method->ssl_accept; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2017 | /* clear the current cipher */ |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 2018 | ssl_clear_cipher_ctx(ssl); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2019 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2020 | |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 2021 | void SSL_set_connect_state(SSL *ssl) { |
| 2022 | ssl->server = 0; |
| 2023 | ssl->shutdown = 0; |
David Benjamin | 8ec8810 | 2015-05-15 23:40:13 -0400 | [diff] [blame] | 2024 | ssl->state = SSL_ST_CONNECT; |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 2025 | ssl->handshake_func = ssl->method->ssl_connect; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2026 | /* clear the current cipher */ |
David Benjamin | 4831c33 | 2015-05-16 11:43:13 -0400 | [diff] [blame] | 2027 | ssl_clear_cipher_ctx(ssl); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2028 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2029 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2030 | static const char *ssl_get_version(int version) { |
| 2031 | switch (version) { |
| 2032 | case TLS1_2_VERSION: |
| 2033 | return "TLSv1.2"; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2034 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2035 | case TLS1_1_VERSION: |
| 2036 | return "TLSv1.1"; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2037 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2038 | case TLS1_VERSION: |
| 2039 | return "TLSv1"; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2040 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2041 | case SSL3_VERSION: |
| 2042 | return "SSLv3"; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2043 | |
David Benjamin | 1c722b7 | 2015-04-20 13:53:10 -0400 | [diff] [blame] | 2044 | case DTLS1_VERSION: |
| 2045 | return "DTLSv1"; |
| 2046 | |
| 2047 | case DTLS1_2_VERSION: |
| 2048 | return "DTLSv1.2"; |
| 2049 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2050 | default: |
| 2051 | return "unknown"; |
| 2052 | } |
| 2053 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2054 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2055 | const char *SSL_get_version(const SSL *s) { |
| 2056 | return ssl_get_version(s->version); |
| 2057 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2058 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2059 | const char *SSL_SESSION_get_version(const SSL_SESSION *sess) { |
| 2060 | return ssl_get_version(sess->ssl_version); |
| 2061 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2062 | |
Sigbjorn Vik | 2b23d24 | 2015-06-29 15:07:26 +0200 | [diff] [blame] | 2063 | const char* SSL_get_curve_name(uint16_t curve_id) { |
| 2064 | return tls1_ec_curve_id2name(curve_id); |
| 2065 | } |
| 2066 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2067 | void ssl_clear_cipher_ctx(SSL *s) { |
David Benjamin | 31a0779 | 2015-03-03 14:20:26 -0500 | [diff] [blame] | 2068 | SSL_AEAD_CTX_free(s->aead_read_ctx); |
| 2069 | s->aead_read_ctx = NULL; |
| 2070 | SSL_AEAD_CTX_free(s->aead_write_ctx); |
| 2071 | s->aead_write_ctx = NULL; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2072 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2073 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2074 | X509 *SSL_get_certificate(const SSL *s) { |
| 2075 | if (s->cert != NULL) { |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 2076 | return s->cert->x509; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | return NULL; |
| 2080 | } |
| 2081 | |
| 2082 | EVP_PKEY *SSL_get_privatekey(const SSL *s) { |
| 2083 | if (s->cert != NULL) { |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 2084 | return s->cert->privatekey; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | return NULL; |
| 2088 | } |
| 2089 | |
| 2090 | X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx) { |
| 2091 | if (ctx->cert != NULL) { |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 2092 | return ctx->cert->x509; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | return NULL; |
| 2096 | } |
| 2097 | |
| 2098 | EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx) { |
| 2099 | if (ctx->cert != NULL) { |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 2100 | return ctx->cert->privatekey; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | return NULL; |
| 2104 | } |
| 2105 | |
| 2106 | const SSL_CIPHER *SSL_get_current_cipher(const SSL *s) { |
David Benjamin | a07c0fc | 2015-05-13 13:19:42 -0400 | [diff] [blame] | 2107 | if (s->aead_write_ctx == NULL) { |
| 2108 | return NULL; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2109 | } |
David Benjamin | a07c0fc | 2015-05-13 13:19:42 -0400 | [diff] [blame] | 2110 | return s->aead_write_ctx->cipher; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2111 | } |
| 2112 | |
Matt Braithwaite | 6a1275b | 2015-06-26 12:09:10 -0700 | [diff] [blame] | 2113 | const COMP_METHOD *SSL_get_current_compression(SSL *s) { return NULL; } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2114 | |
Matt Braithwaite | 6a1275b | 2015-06-26 12:09:10 -0700 | [diff] [blame] | 2115 | const COMP_METHOD *SSL_get_current_expansion(SSL *s) { return NULL; } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2116 | |
| 2117 | int ssl_init_wbio_buffer(SSL *s, int push) { |
| 2118 | BIO *bbio; |
| 2119 | |
| 2120 | if (s->bbio == NULL) { |
| 2121 | bbio = BIO_new(BIO_f_buffer()); |
| 2122 | if (bbio == NULL) { |
| 2123 | return 0; |
| 2124 | } |
| 2125 | s->bbio = bbio; |
| 2126 | } else { |
| 2127 | bbio = s->bbio; |
| 2128 | if (s->bbio == s->wbio) { |
| 2129 | s->wbio = BIO_pop(s->wbio); |
| 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | BIO_reset(bbio); |
| 2134 | if (!BIO_set_read_buffer_size(bbio, 1)) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 2135 | OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2136 | return 0; |
| 2137 | } |
| 2138 | |
| 2139 | if (push) { |
| 2140 | if (s->wbio != bbio) { |
| 2141 | s->wbio = BIO_push(bbio, s->wbio); |
| 2142 | } |
| 2143 | } else { |
| 2144 | if (s->wbio == bbio) { |
| 2145 | s->wbio = BIO_pop(bbio); |
| 2146 | } |
| 2147 | } |
| 2148 | |
| 2149 | return 1; |
| 2150 | } |
| 2151 | |
| 2152 | void ssl_free_wbio_buffer(SSL *s) { |
| 2153 | if (s->bbio == NULL) { |
| 2154 | return; |
| 2155 | } |
| 2156 | |
| 2157 | if (s->bbio == s->wbio) { |
| 2158 | /* remove buffering */ |
| 2159 | s->wbio = BIO_pop(s->wbio); |
| 2160 | } |
| 2161 | |
| 2162 | BIO_free(s->bbio); |
| 2163 | s->bbio = NULL; |
| 2164 | } |
| 2165 | |
| 2166 | void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode) { |
| 2167 | ctx->quiet_shutdown = mode; |
| 2168 | } |
| 2169 | |
| 2170 | int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx) { |
| 2171 | return ctx->quiet_shutdown; |
| 2172 | } |
| 2173 | |
| 2174 | void SSL_set_quiet_shutdown(SSL *s, int mode) { s->quiet_shutdown = mode; } |
| 2175 | |
| 2176 | int SSL_get_quiet_shutdown(const SSL *s) { return s->quiet_shutdown; } |
| 2177 | |
| 2178 | void SSL_set_shutdown(SSL *s, int mode) { s->shutdown = mode; } |
| 2179 | |
| 2180 | int SSL_get_shutdown(const SSL *s) { return s->shutdown; } |
| 2181 | |
| 2182 | int SSL_version(const SSL *s) { return s->version; } |
| 2183 | |
| 2184 | SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl) { return ssl->ctx; } |
| 2185 | |
| 2186 | SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx) { |
| 2187 | if (ssl->ctx == ctx) { |
| 2188 | return ssl->ctx; |
| 2189 | } |
| 2190 | |
| 2191 | if (ctx == NULL) { |
| 2192 | ctx = ssl->initial_ctx; |
| 2193 | } |
| 2194 | |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 2195 | ssl_cert_free(ssl->cert); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2196 | ssl->cert = ssl_cert_dup(ctx->cert); |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 2197 | |
Adam Langley | 0b5e390 | 2015-05-15 13:08:38 -0700 | [diff] [blame] | 2198 | CRYPTO_refcount_inc(&ctx->references); |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 2199 | SSL_CTX_free(ssl->ctx); /* decrement reference count */ |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2200 | ssl->ctx = ctx; |
| 2201 | |
| 2202 | ssl->sid_ctx_length = ctx->sid_ctx_length; |
| 2203 | assert(ssl->sid_ctx_length <= sizeof(ssl->sid_ctx)); |
| 2204 | memcpy(ssl->sid_ctx, ctx->sid_ctx, sizeof(ssl->sid_ctx)); |
| 2205 | |
| 2206 | return ssl->ctx; |
| 2207 | } |
| 2208 | |
| 2209 | int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx) { |
| 2210 | return X509_STORE_set_default_paths(ctx->cert_store); |
| 2211 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2212 | |
| 2213 | int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2214 | const char *CApath) { |
| 2215 | return X509_STORE_load_locations(ctx->cert_store, CAfile, CApath); |
| 2216 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2217 | |
| 2218 | void SSL_set_info_callback(SSL *ssl, |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2219 | void (*cb)(const SSL *ssl, int type, int val)) { |
| 2220 | ssl->info_callback = cb; |
| 2221 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2222 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2223 | void (*SSL_get_info_callback(const SSL *ssl))(const SSL * /*ssl*/, int /*type*/, |
| 2224 | int /*val*/) { |
| 2225 | return ssl->info_callback; |
| 2226 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2227 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2228 | int SSL_state(const SSL *ssl) { return ssl->state; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2229 | |
David Benjamin | ece089c | 2015-05-15 23:52:42 -0400 | [diff] [blame] | 2230 | void SSL_set_state(SSL *ssl, int state) { } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2231 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2232 | void SSL_set_verify_result(SSL *ssl, long arg) { ssl->verify_result = arg; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2233 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2234 | long SSL_get_verify_result(const SSL *ssl) { return ssl->verify_result; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2235 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2236 | int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
| 2237 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) { |
David Benjamin | 9f33fc6 | 2015-04-15 17:29:53 -0400 | [diff] [blame] | 2238 | int index; |
| 2239 | if (!CRYPTO_get_ex_new_index(&g_ex_data_class_ssl, &index, argl, argp, |
| 2240 | new_func, dup_func, free_func)) { |
| 2241 | return -1; |
| 2242 | } |
| 2243 | return index; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2244 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2245 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2246 | int SSL_set_ex_data(SSL *s, int idx, void *arg) { |
| 2247 | return CRYPTO_set_ex_data(&s->ex_data, idx, arg); |
| 2248 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2249 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2250 | void *SSL_get_ex_data(const SSL *s, int idx) { |
| 2251 | return CRYPTO_get_ex_data(&s->ex_data, idx); |
| 2252 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2253 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2254 | int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
| 2255 | CRYPTO_EX_dup *dup_func, |
| 2256 | CRYPTO_EX_free *free_func) { |
David Benjamin | 9f33fc6 | 2015-04-15 17:29:53 -0400 | [diff] [blame] | 2257 | int index; |
| 2258 | if (!CRYPTO_get_ex_new_index(&g_ex_data_class_ssl_ctx, &index, argl, argp, |
| 2259 | new_func, dup_func, free_func)) { |
| 2260 | return -1; |
| 2261 | } |
| 2262 | return index; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2263 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2264 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2265 | int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg) { |
| 2266 | return CRYPTO_set_ex_data(&s->ex_data, idx, arg); |
| 2267 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2268 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2269 | void *SSL_CTX_get_ex_data(const SSL_CTX *s, int idx) { |
| 2270 | return CRYPTO_get_ex_data(&s->ex_data, idx); |
| 2271 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2272 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2273 | X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx) { |
| 2274 | return ctx->cert_store; |
| 2275 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2276 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2277 | void SSL_CTX_set_cert_store(SSL_CTX *ctx, X509_STORE *store) { |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 2278 | X509_STORE_free(ctx->cert_store); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2279 | ctx->cert_store = store; |
| 2280 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2281 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2282 | int SSL_want(const SSL *s) { return s->rwstate; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2283 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2284 | void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx, |
| 2285 | RSA *(*cb)(SSL *ssl, int is_export, |
| 2286 | int keylength)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2287 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2288 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2289 | void SSL_set_tmp_rsa_callback(SSL *ssl, RSA *(*cb)(SSL *ssl, int is_export, |
| 2290 | int keylength)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx, |
David Benjamin | 59015c3 | 2015-04-26 13:13:55 -0400 | [diff] [blame] | 2294 | DH *(*callback)(SSL *ssl, int is_export, |
| 2295 | int keylength)) { |
| 2296 | ctx->cert->dh_tmp_cb = callback; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2297 | } |
| 2298 | |
David Benjamin | 59015c3 | 2015-04-26 13:13:55 -0400 | [diff] [blame] | 2299 | void SSL_set_tmp_dh_callback(SSL *ssl, DH *(*callback)(SSL *ssl, int is_export, |
| 2300 | int keylength)) { |
| 2301 | ssl->cert->dh_tmp_cb = callback; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx, |
David Benjamin | dd97878 | 2015-04-24 15:20:13 -0400 | [diff] [blame] | 2305 | EC_KEY *(*callback)(SSL *ssl, int is_export, |
| 2306 | int keylength)) { |
David Benjamin | 59015c3 | 2015-04-26 13:13:55 -0400 | [diff] [blame] | 2307 | ctx->cert->ecdh_tmp_cb = callback; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | void SSL_set_tmp_ecdh_callback(SSL *ssl, |
David Benjamin | dd97878 | 2015-04-24 15:20:13 -0400 | [diff] [blame] | 2311 | EC_KEY *(*callback)(SSL *ssl, int is_export, |
| 2312 | int keylength)) { |
David Benjamin | 59015c3 | 2015-04-26 13:13:55 -0400 | [diff] [blame] | 2313 | ssl->cert->ecdh_tmp_cb = callback; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint) { |
| 2317 | if (identity_hint != NULL && strlen(identity_hint) > PSK_MAX_IDENTITY_LEN) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 2318 | OPENSSL_PUT_ERROR(SSL, SSL_R_DATA_LENGTH_TOO_LONG); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2319 | return 0; |
| 2320 | } |
| 2321 | |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 2322 | OPENSSL_free(ctx->psk_identity_hint); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2323 | |
| 2324 | if (identity_hint != NULL) { |
| 2325 | ctx->psk_identity_hint = BUF_strdup(identity_hint); |
| 2326 | if (ctx->psk_identity_hint == NULL) { |
| 2327 | return 0; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2328 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2329 | } else { |
| 2330 | ctx->psk_identity_hint = NULL; |
| 2331 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2332 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2333 | return 1; |
| 2334 | } |
| 2335 | |
| 2336 | int SSL_use_psk_identity_hint(SSL *s, const char *identity_hint) { |
| 2337 | if (s == NULL) { |
| 2338 | return 0; |
| 2339 | } |
| 2340 | |
| 2341 | if (identity_hint != NULL && strlen(identity_hint) > PSK_MAX_IDENTITY_LEN) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 2342 | OPENSSL_PUT_ERROR(SSL, SSL_R_DATA_LENGTH_TOO_LONG); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2343 | return 0; |
| 2344 | } |
| 2345 | |
| 2346 | /* Clear currently configured hint, if any. */ |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 2347 | OPENSSL_free(s->psk_identity_hint); |
| 2348 | s->psk_identity_hint = NULL; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2349 | |
| 2350 | if (identity_hint != NULL) { |
| 2351 | s->psk_identity_hint = BUF_strdup(identity_hint); |
| 2352 | if (s->psk_identity_hint == NULL) { |
| 2353 | return 0; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2354 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2355 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2356 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2357 | return 1; |
| 2358 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2359 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2360 | const char *SSL_get_psk_identity_hint(const SSL *s) { |
| 2361 | if (s == NULL) { |
| 2362 | return NULL; |
| 2363 | } |
| 2364 | return s->psk_identity_hint; |
| 2365 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2366 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2367 | const char *SSL_get_psk_identity(const SSL *s) { |
| 2368 | if (s == NULL || s->session == NULL) { |
| 2369 | return NULL; |
| 2370 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2371 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2372 | return s->session->psk_identity; |
| 2373 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2374 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2375 | void SSL_set_psk_client_callback( |
| 2376 | SSL *s, unsigned int (*cb)(SSL *ssl, const char *hint, char *identity, |
| 2377 | unsigned int max_identity_len, uint8_t *psk, |
| 2378 | unsigned int max_psk_len)) { |
| 2379 | s->psk_client_callback = cb; |
| 2380 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2381 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2382 | void SSL_CTX_set_psk_client_callback( |
| 2383 | SSL_CTX *ctx, unsigned int (*cb)(SSL *ssl, const char *hint, char *identity, |
| 2384 | unsigned int max_identity_len, |
| 2385 | uint8_t *psk, unsigned int max_psk_len)) { |
| 2386 | ctx->psk_client_callback = cb; |
| 2387 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2388 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2389 | void SSL_set_psk_server_callback( |
| 2390 | SSL *s, unsigned int (*cb)(SSL *ssl, const char *identity, uint8_t *psk, |
| 2391 | unsigned int max_psk_len)) { |
| 2392 | s->psk_server_callback = cb; |
| 2393 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2394 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2395 | void SSL_CTX_set_psk_server_callback( |
| 2396 | SSL_CTX *ctx, unsigned int (*cb)(SSL *ssl, const char *identity, |
| 2397 | uint8_t *psk, unsigned int max_psk_len)) { |
| 2398 | ctx->psk_server_callback = cb; |
| 2399 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2400 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2401 | void SSL_CTX_set_min_version(SSL_CTX *ctx, uint16_t version) { |
| 2402 | ctx->min_version = version; |
| 2403 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2404 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2405 | void SSL_CTX_set_max_version(SSL_CTX *ctx, uint16_t version) { |
| 2406 | ctx->max_version = version; |
| 2407 | } |
Adam Langley | 0289c73 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2408 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2409 | void SSL_set_min_version(SSL *ssl, uint16_t version) { |
| 2410 | ssl->min_version = version; |
| 2411 | } |
Adam Langley | 0289c73 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2412 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2413 | void SSL_set_max_version(SSL *ssl, uint16_t version) { |
| 2414 | ssl->max_version = version; |
| 2415 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2416 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2417 | void SSL_CTX_set_msg_callback(SSL_CTX *ctx, |
| 2418 | void (*cb)(int write_p, int version, |
| 2419 | int content_type, const void *buf, |
| 2420 | size_t len, SSL *ssl, void *arg)) { |
David Benjamin | 59015c3 | 2015-04-26 13:13:55 -0400 | [diff] [blame] | 2421 | ctx->msg_callback = cb; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2422 | } |
David Benjamin | 61ecccf | 2015-05-05 09:44:51 -0400 | [diff] [blame] | 2423 | |
| 2424 | void SSL_CTX_set_msg_callback_arg(SSL_CTX *ctx, void *arg) { |
| 2425 | ctx->msg_callback_arg = arg; |
| 2426 | } |
| 2427 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2428 | void SSL_set_msg_callback(SSL *ssl, |
| 2429 | void (*cb)(int write_p, int version, int content_type, |
| 2430 | const void *buf, size_t len, SSL *ssl, |
| 2431 | void *arg)) { |
David Benjamin | 59015c3 | 2015-04-26 13:13:55 -0400 | [diff] [blame] | 2432 | ssl->msg_callback = cb; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2433 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2434 | |
David Benjamin | 61ecccf | 2015-05-05 09:44:51 -0400 | [diff] [blame] | 2435 | void SSL_set_msg_callback_arg(SSL *ssl, void *arg) { |
| 2436 | ssl->msg_callback_arg = arg; |
| 2437 | } |
| 2438 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2439 | void SSL_CTX_set_keylog_bio(SSL_CTX *ctx, BIO *keylog_bio) { |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 2440 | BIO_free(ctx->keylog_bio); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2441 | ctx->keylog_bio = keylog_bio; |
| 2442 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2443 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2444 | static int cbb_add_hex(CBB *cbb, const uint8_t *in, size_t in_len) { |
| 2445 | static const char hextable[] = "0123456789abcdef"; |
| 2446 | uint8_t *out; |
| 2447 | size_t i; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2448 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2449 | if (!CBB_add_space(cbb, &out, in_len * 2)) { |
| 2450 | return 0; |
| 2451 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2452 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2453 | for (i = 0; i < in_len; i++) { |
| 2454 | *(out++) = (uint8_t)hextable[in[i] >> 4]; |
| 2455 | *(out++) = (uint8_t)hextable[in[i] & 0xf]; |
| 2456 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2457 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2458 | return 1; |
| 2459 | } |
David Benjamin | 859ec3c | 2014-09-02 16:29:36 -0400 | [diff] [blame] | 2460 | |
| 2461 | int ssl_ctx_log_rsa_client_key_exchange(SSL_CTX *ctx, |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2462 | const uint8_t *encrypted_premaster, |
| 2463 | size_t encrypted_premaster_len, |
| 2464 | const uint8_t *premaster, |
| 2465 | size_t premaster_len) { |
| 2466 | BIO *bio = ctx->keylog_bio; |
| 2467 | CBB cbb; |
| 2468 | uint8_t *out; |
| 2469 | size_t out_len; |
| 2470 | int ret; |
David Benjamin | 859ec3c | 2014-09-02 16:29:36 -0400 | [diff] [blame] | 2471 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2472 | if (bio == NULL) { |
| 2473 | return 1; |
| 2474 | } |
David Benjamin | 859ec3c | 2014-09-02 16:29:36 -0400 | [diff] [blame] | 2475 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2476 | if (encrypted_premaster_len < 8) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 2477 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2478 | return 0; |
| 2479 | } |
David Benjamin | 859ec3c | 2014-09-02 16:29:36 -0400 | [diff] [blame] | 2480 | |
David Benjamin | a865320 | 2015-06-28 01:26:10 -0400 | [diff] [blame] | 2481 | CBB_zero(&cbb); |
| 2482 | if (!CBB_init(&cbb, 4 + 16 + 1 + premaster_len * 2 + 1) || |
| 2483 | !CBB_add_bytes(&cbb, (const uint8_t *)"RSA ", 4) || |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2484 | /* Only the first 8 bytes of the encrypted premaster secret are |
| 2485 | * logged. */ |
| 2486 | !cbb_add_hex(&cbb, encrypted_premaster, 8) || |
| 2487 | !CBB_add_bytes(&cbb, (const uint8_t *)" ", 1) || |
| 2488 | !cbb_add_hex(&cbb, premaster, premaster_len) || |
| 2489 | !CBB_add_bytes(&cbb, (const uint8_t *)"\n", 1) || |
| 2490 | !CBB_finish(&cbb, &out, &out_len)) { |
| 2491 | CBB_cleanup(&cbb); |
| 2492 | return 0; |
| 2493 | } |
David Benjamin | 859ec3c | 2014-09-02 16:29:36 -0400 | [diff] [blame] | 2494 | |
Adam Langley | 4bdb6e4 | 2015-05-15 15:29:21 -0700 | [diff] [blame] | 2495 | CRYPTO_MUTEX_lock_write(&ctx->lock); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2496 | ret = BIO_write(bio, out, out_len) >= 0 && BIO_flush(bio); |
Adam Langley | 4bdb6e4 | 2015-05-15 15:29:21 -0700 | [diff] [blame] | 2497 | CRYPTO_MUTEX_unlock(&ctx->lock); |
David Benjamin | 859ec3c | 2014-09-02 16:29:36 -0400 | [diff] [blame] | 2498 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2499 | OPENSSL_free(out); |
| 2500 | return ret; |
Adam Langley | 95f2288 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2503 | int ssl_ctx_log_master_secret(SSL_CTX *ctx, const uint8_t *client_random, |
| 2504 | size_t client_random_len, const uint8_t *master, |
| 2505 | size_t master_len) { |
| 2506 | BIO *bio = ctx->keylog_bio; |
| 2507 | CBB cbb; |
| 2508 | uint8_t *out; |
| 2509 | size_t out_len; |
| 2510 | int ret; |
Adam Langley | adb739e | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2511 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2512 | if (bio == NULL) { |
| 2513 | return 1; |
| 2514 | } |
Adam Langley | adb739e | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2515 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2516 | if (client_random_len != 32) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 2517 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2518 | return 0; |
| 2519 | } |
Adam Langley | adb739e | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2520 | |
David Benjamin | a865320 | 2015-06-28 01:26:10 -0400 | [diff] [blame] | 2521 | CBB_zero(&cbb); |
| 2522 | if (!CBB_init(&cbb, 14 + 64 + 1 + master_len * 2 + 1) || |
| 2523 | !CBB_add_bytes(&cbb, (const uint8_t *)"CLIENT_RANDOM ", 14) || |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2524 | !cbb_add_hex(&cbb, client_random, 32) || |
| 2525 | !CBB_add_bytes(&cbb, (const uint8_t *)" ", 1) || |
| 2526 | !cbb_add_hex(&cbb, master, master_len) || |
| 2527 | !CBB_add_bytes(&cbb, (const uint8_t *)"\n", 1) || |
| 2528 | !CBB_finish(&cbb, &out, &out_len)) { |
| 2529 | CBB_cleanup(&cbb); |
| 2530 | return 0; |
| 2531 | } |
Adam Langley | adb739e | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2532 | |
Adam Langley | 4bdb6e4 | 2015-05-15 15:29:21 -0700 | [diff] [blame] | 2533 | CRYPTO_MUTEX_lock_write(&ctx->lock); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2534 | ret = BIO_write(bio, out, out_len) >= 0 && BIO_flush(bio); |
Adam Langley | 4bdb6e4 | 2015-05-15 15:29:21 -0700 | [diff] [blame] | 2535 | CRYPTO_MUTEX_unlock(&ctx->lock); |
David Benjamin | e99e912 | 2014-12-11 01:46:01 -0500 | [diff] [blame] | 2536 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2537 | OPENSSL_free(out); |
| 2538 | return ret; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2539 | } |
| 2540 | |
David Benjamin | ed7c475 | 2015-02-16 19:16:46 -0500 | [diff] [blame] | 2541 | int SSL_in_false_start(const SSL *s) { |
| 2542 | return s->s3->tmp.in_false_start; |
| 2543 | } |
| 2544 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2545 | int SSL_cutthrough_complete(const SSL *s) { |
David Benjamin | ed7c475 | 2015-02-16 19:16:46 -0500 | [diff] [blame] | 2546 | return SSL_in_false_start(s); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2547 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2548 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2549 | void SSL_get_structure_sizes(size_t *ssl_size, size_t *ssl_ctx_size, |
| 2550 | size_t *ssl_session_size) { |
| 2551 | *ssl_size = sizeof(SSL); |
| 2552 | *ssl_ctx_size = sizeof(SSL_CTX); |
| 2553 | *ssl_session_size = sizeof(SSL_SESSION); |
| 2554 | } |
Feng Lu | 41aa325 | 2014-11-21 22:47:56 -0800 | [diff] [blame] | 2555 | |
David Benjamin | ed7c475 | 2015-02-16 19:16:46 -0500 | [diff] [blame] | 2556 | int ssl3_can_false_start(const SSL *s) { |
David Benjamin | 195dc78 | 2015-02-19 13:27:05 -0500 | [diff] [blame] | 2557 | const SSL_CIPHER *const cipher = SSL_get_current_cipher(s); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2558 | |
Adam Langley | e631d96 | 2015-04-01 13:11:01 -0700 | [diff] [blame] | 2559 | /* False Start only for TLS 1.2 with an ECDHE+AEAD cipher and ALPN or NPN. */ |
David Benjamin | 195dc78 | 2015-02-19 13:27:05 -0500 | [diff] [blame] | 2560 | return !SSL_IS_DTLS(s) && |
| 2561 | SSL_version(s) >= TLS1_2_VERSION && |
| 2562 | (s->s3->alpn_selected || s->s3->next_proto_neg_seen) && |
| 2563 | cipher != NULL && |
Adam Langley | e631d96 | 2015-04-01 13:11:01 -0700 | [diff] [blame] | 2564 | cipher->algorithm_mkey == SSL_kECDHE && |
David Benjamin | 195dc78 | 2015-02-19 13:27:05 -0500 | [diff] [blame] | 2565 | (cipher->algorithm_enc == SSL_AES128GCM || |
| 2566 | cipher->algorithm_enc == SSL_AES256GCM || |
| 2567 | cipher->algorithm_enc == SSL_CHACHA20POLY1305); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | const SSL3_ENC_METHOD *ssl3_get_enc_method(uint16_t version) { |
| 2571 | switch (version) { |
| 2572 | case SSL3_VERSION: |
| 2573 | return &SSLv3_enc_data; |
| 2574 | |
| 2575 | case TLS1_VERSION: |
| 2576 | return &TLSv1_enc_data; |
| 2577 | |
David Benjamin | 9e13e1a | 2015-03-05 01:56:32 -0500 | [diff] [blame] | 2578 | case DTLS1_VERSION: |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2579 | case TLS1_1_VERSION: |
| 2580 | return &TLSv1_1_enc_data; |
| 2581 | |
David Benjamin | 9e13e1a | 2015-03-05 01:56:32 -0500 | [diff] [blame] | 2582 | case DTLS1_2_VERSION: |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2583 | case TLS1_2_VERSION: |
| 2584 | return &TLSv1_2_enc_data; |
| 2585 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2586 | default: |
| 2587 | return NULL; |
| 2588 | } |
| 2589 | } |
| 2590 | |
| 2591 | uint16_t ssl3_get_max_server_version(const SSL *s) { |
| 2592 | uint16_t max_version; |
| 2593 | |
| 2594 | if (SSL_IS_DTLS(s)) { |
| 2595 | max_version = (s->max_version != 0) ? s->max_version : DTLS1_2_VERSION; |
| 2596 | if (!(s->options & SSL_OP_NO_DTLSv1_2) && DTLS1_2_VERSION >= max_version) { |
| 2597 | return DTLS1_2_VERSION; |
| 2598 | } |
| 2599 | if (!(s->options & SSL_OP_NO_DTLSv1) && DTLS1_VERSION >= max_version) { |
| 2600 | return DTLS1_VERSION; |
| 2601 | } |
| 2602 | return 0; |
| 2603 | } |
| 2604 | |
| 2605 | max_version = (s->max_version != 0) ? s->max_version : TLS1_2_VERSION; |
| 2606 | if (!(s->options & SSL_OP_NO_TLSv1_2) && TLS1_2_VERSION <= max_version) { |
| 2607 | return TLS1_2_VERSION; |
| 2608 | } |
| 2609 | if (!(s->options & SSL_OP_NO_TLSv1_1) && TLS1_1_VERSION <= max_version) { |
| 2610 | return TLS1_1_VERSION; |
| 2611 | } |
| 2612 | if (!(s->options & SSL_OP_NO_TLSv1) && TLS1_VERSION <= max_version) { |
| 2613 | return TLS1_VERSION; |
| 2614 | } |
| 2615 | if (!(s->options & SSL_OP_NO_SSLv3) && SSL3_VERSION <= max_version) { |
| 2616 | return SSL3_VERSION; |
| 2617 | } |
| 2618 | return 0; |
| 2619 | } |
| 2620 | |
| 2621 | uint16_t ssl3_get_mutual_version(SSL *s, uint16_t client_version) { |
| 2622 | uint16_t version = 0; |
| 2623 | |
| 2624 | if (SSL_IS_DTLS(s)) { |
| 2625 | /* Clamp client_version to max_version. */ |
| 2626 | if (s->max_version != 0 && client_version < s->max_version) { |
| 2627 | client_version = s->max_version; |
| 2628 | } |
| 2629 | |
| 2630 | if (client_version <= DTLS1_2_VERSION && !(s->options & SSL_OP_NO_DTLSv1_2)) { |
| 2631 | version = DTLS1_2_VERSION; |
| 2632 | } else if (client_version <= DTLS1_VERSION && |
David Benjamin | b18f024 | 2015-03-10 18:30:08 -0400 | [diff] [blame] | 2633 | !(s->options & SSL_OP_NO_DTLSv1)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2634 | version = DTLS1_VERSION; |
| 2635 | } |
| 2636 | |
| 2637 | /* Check against min_version. */ |
| 2638 | if (version != 0 && s->min_version != 0 && version > s->min_version) { |
| 2639 | return 0; |
| 2640 | } |
| 2641 | return version; |
| 2642 | } else { |
| 2643 | /* Clamp client_version to max_version. */ |
| 2644 | if (s->max_version != 0 && client_version > s->max_version) { |
| 2645 | client_version = s->max_version; |
| 2646 | } |
| 2647 | |
| 2648 | if (client_version >= TLS1_2_VERSION && !(s->options & SSL_OP_NO_TLSv1_2)) { |
| 2649 | version = TLS1_2_VERSION; |
| 2650 | } else if (client_version >= TLS1_1_VERSION && |
| 2651 | !(s->options & SSL_OP_NO_TLSv1_1)) { |
| 2652 | version = TLS1_1_VERSION; |
| 2653 | } else if (client_version >= TLS1_VERSION && !(s->options & SSL_OP_NO_TLSv1)) { |
| 2654 | version = TLS1_VERSION; |
| 2655 | } else if (client_version >= SSL3_VERSION && !(s->options & SSL_OP_NO_SSLv3)) { |
| 2656 | version = SSL3_VERSION; |
| 2657 | } |
| 2658 | |
| 2659 | /* Check against min_version. */ |
| 2660 | if (version != 0 && s->min_version != 0 && version < s->min_version) { |
| 2661 | return 0; |
| 2662 | } |
| 2663 | return version; |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | uint16_t ssl3_get_max_client_version(SSL *s) { |
David Benjamin | 123a8fd | 2015-04-26 14:16:41 -0400 | [diff] [blame] | 2668 | uint32_t options = s->options; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2669 | uint16_t version = 0; |
| 2670 | |
| 2671 | /* OpenSSL's API for controlling versions entails blacklisting individual |
| 2672 | * protocols. This has two problems. First, on the client, the protocol can |
| 2673 | * only express a contiguous range of versions. Second, a library consumer |
| 2674 | * trying to set a maximum version cannot disable protocol versions that get |
| 2675 | * added in a future version of the library. |
| 2676 | * |
| 2677 | * To account for both of these, OpenSSL interprets the client-side bitmask |
| 2678 | * as a min/max range by picking the lowest contiguous non-empty range of |
| 2679 | * enabled protocols. Note that this means it is impossible to set a maximum |
| 2680 | * version of TLS 1.2 in a future-proof way. |
| 2681 | * |
| 2682 | * By this scheme, the maximum version is the lowest version V such that V is |
| 2683 | * enabled and V+1 is disabled or unimplemented. */ |
| 2684 | if (SSL_IS_DTLS(s)) { |
| 2685 | if (!(options & SSL_OP_NO_DTLSv1_2)) { |
| 2686 | version = DTLS1_2_VERSION; |
| 2687 | } |
| 2688 | if (!(options & SSL_OP_NO_DTLSv1) && (options & SSL_OP_NO_DTLSv1_2)) { |
| 2689 | version = DTLS1_VERSION; |
| 2690 | } |
| 2691 | if (s->max_version != 0 && version < s->max_version) { |
| 2692 | version = s->max_version; |
| 2693 | } |
| 2694 | } else { |
| 2695 | if (!(options & SSL_OP_NO_TLSv1_2)) { |
| 2696 | version = TLS1_2_VERSION; |
| 2697 | } |
| 2698 | if (!(options & SSL_OP_NO_TLSv1_1) && (options & SSL_OP_NO_TLSv1_2)) { |
| 2699 | version = TLS1_1_VERSION; |
| 2700 | } |
| 2701 | if (!(options & SSL_OP_NO_TLSv1) && (options & SSL_OP_NO_TLSv1_1)) { |
| 2702 | version = TLS1_VERSION; |
| 2703 | } |
| 2704 | if (!(options & SSL_OP_NO_SSLv3) && (options & SSL_OP_NO_TLSv1)) { |
| 2705 | version = SSL3_VERSION; |
| 2706 | } |
| 2707 | if (s->max_version != 0 && version > s->max_version) { |
| 2708 | version = s->max_version; |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | return version; |
| 2713 | } |
| 2714 | |
| 2715 | int ssl3_is_version_enabled(SSL *s, uint16_t version) { |
| 2716 | if (SSL_IS_DTLS(s)) { |
| 2717 | if (s->max_version != 0 && version < s->max_version) { |
| 2718 | return 0; |
| 2719 | } |
| 2720 | if (s->min_version != 0 && version > s->min_version) { |
| 2721 | return 0; |
| 2722 | } |
| 2723 | |
| 2724 | switch (version) { |
| 2725 | case DTLS1_VERSION: |
| 2726 | return !(s->options & SSL_OP_NO_DTLSv1); |
| 2727 | |
| 2728 | case DTLS1_2_VERSION: |
| 2729 | return !(s->options & SSL_OP_NO_DTLSv1_2); |
| 2730 | |
| 2731 | default: |
| 2732 | return 0; |
| 2733 | } |
| 2734 | } else { |
| 2735 | if (s->max_version != 0 && version > s->max_version) { |
| 2736 | return 0; |
| 2737 | } |
| 2738 | if (s->min_version != 0 && version < s->min_version) { |
| 2739 | return 0; |
| 2740 | } |
| 2741 | |
| 2742 | switch (version) { |
| 2743 | case SSL3_VERSION: |
| 2744 | return !(s->options & SSL_OP_NO_SSLv3); |
| 2745 | |
| 2746 | case TLS1_VERSION: |
| 2747 | return !(s->options & SSL_OP_NO_TLSv1); |
| 2748 | |
| 2749 | case TLS1_1_VERSION: |
| 2750 | return !(s->options & SSL_OP_NO_TLSv1_1); |
| 2751 | |
| 2752 | case TLS1_2_VERSION: |
| 2753 | return !(s->options & SSL_OP_NO_TLSv1_2); |
| 2754 | |
| 2755 | default: |
| 2756 | return 0; |
| 2757 | } |
| 2758 | } |
| 2759 | } |
| 2760 | |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 2761 | uint16_t ssl3_version_from_wire(SSL *s, uint16_t wire_version) { |
| 2762 | if (!SSL_IS_DTLS(s)) { |
| 2763 | return wire_version; |
| 2764 | } |
| 2765 | |
| 2766 | uint16_t tls_version = ~wire_version; |
| 2767 | uint16_t version = tls_version + 0x0201; |
| 2768 | /* If either component overflowed, clamp it so comparisons still work. */ |
| 2769 | if ((version >> 8) < (tls_version >> 8)) { |
| 2770 | version = 0xff00 | (version & 0xff); |
| 2771 | } |
| 2772 | if ((version & 0xff) < (tls_version & 0xff)) { |
| 2773 | version = (version & 0xff00) | 0xff; |
| 2774 | } |
| 2775 | /* DTLS 1.0 maps to TLS 1.1, not TLS 1.0. */ |
| 2776 | if (version == TLS1_VERSION) { |
| 2777 | version = TLS1_1_VERSION; |
| 2778 | } |
| 2779 | return version; |
| 2780 | } |
| 2781 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 2782 | int SSL_cache_hit(SSL *s) { return s->hit; } |
| 2783 | |
| 2784 | int SSL_is_server(SSL *s) { return s->server; } |
| 2785 | |
Adam Langley | 524e717 | 2015-02-20 16:04:00 -0800 | [diff] [blame] | 2786 | void SSL_CTX_set_dos_protection_cb( |
| 2787 | SSL_CTX *ctx, int (*cb)(const struct ssl_early_callback_ctx *)) { |
| 2788 | ctx->dos_protection_cb = cb; |
| 2789 | } |
| 2790 | |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 2791 | void SSL_set_reject_peer_renegotiations(SSL *s, int reject) { |
David Benjamin | 897e5e0 | 2015-05-12 17:03:54 -0400 | [diff] [blame] | 2792 | s->accept_peer_renegotiations = !reject; |
David Benjamin | b16346b | 2015-04-08 19:16:58 -0400 | [diff] [blame] | 2793 | } |
| 2794 | |
Adam Langley | 3f92d21 | 2015-02-20 15:32:52 -0800 | [diff] [blame] | 2795 | int SSL_get_rc4_state(const SSL *ssl, const RC4_KEY **read_key, |
| 2796 | const RC4_KEY **write_key) { |
| 2797 | if (ssl->aead_read_ctx == NULL || ssl->aead_write_ctx == NULL) { |
| 2798 | return 0; |
| 2799 | } |
| 2800 | |
| 2801 | return EVP_AEAD_CTX_get_rc4_state(&ssl->aead_read_ctx->ctx, read_key) && |
| 2802 | EVP_AEAD_CTX_get_rc4_state(&ssl->aead_write_ctx->ctx, write_key); |
| 2803 | } |
David Benjamin | da881e9 | 2015-04-26 14:45:04 -0400 | [diff] [blame] | 2804 | |
Adam Langley | af0e32c | 2015-06-03 09:57:23 -0700 | [diff] [blame] | 2805 | int SSL_get_tls_unique(const SSL *ssl, uint8_t *out, size_t *out_len, |
| 2806 | size_t max_out) { |
| 2807 | /* The tls-unique value is the first Finished message in the handshake, which |
| 2808 | * is the client's in a full handshake and the server's for a resumption. See |
| 2809 | * https://tools.ietf.org/html/rfc5929#section-3.1. */ |
| 2810 | const uint8_t *finished = ssl->s3->previous_client_finished; |
| 2811 | size_t finished_len = ssl->s3->previous_client_finished_len; |
| 2812 | if (ssl->hit) { |
| 2813 | /* tls-unique is broken for resumed sessions unless EMS is used. */ |
| 2814 | if (!ssl->session->extended_master_secret) { |
| 2815 | goto err; |
| 2816 | } |
| 2817 | finished = ssl->s3->previous_server_finished; |
| 2818 | finished_len = ssl->s3->previous_server_finished_len; |
| 2819 | } |
| 2820 | |
| 2821 | if (!ssl->s3->initial_handshake_complete || |
| 2822 | ssl->version < TLS1_VERSION) { |
| 2823 | goto err; |
| 2824 | } |
| 2825 | |
| 2826 | *out_len = finished_len; |
| 2827 | if (finished_len > max_out) { |
| 2828 | *out_len = max_out; |
| 2829 | } |
| 2830 | |
| 2831 | memcpy(out, finished, *out_len); |
| 2832 | return 1; |
| 2833 | |
| 2834 | err: |
| 2835 | *out_len = 0; |
| 2836 | memset(out, 0, max_out); |
| 2837 | return 0; |
| 2838 | } |
| 2839 | |
David Benjamin | da881e9 | 2015-04-26 14:45:04 -0400 | [diff] [blame] | 2840 | int SSL_CTX_sess_connect(const SSL_CTX *ctx) { return 0; } |
| 2841 | int SSL_CTX_sess_connect_good(const SSL_CTX *ctx) { return 0; } |
| 2842 | int SSL_CTX_sess_connect_renegotiate(const SSL_CTX *ctx) { return 0; } |
| 2843 | int SSL_CTX_sess_accept(const SSL_CTX *ctx) { return 0; } |
| 2844 | int SSL_CTX_sess_accept_renegotiate(const SSL_CTX *ctx) { return 0; } |
| 2845 | int SSL_CTX_sess_accept_good(const SSL_CTX *ctx) { return 0; } |
| 2846 | int SSL_CTX_sess_hits(const SSL_CTX *ctx) { return 0; } |
| 2847 | int SSL_CTX_sess_cb_hits(const SSL_CTX *ctx) { return 0; } |
| 2848 | int SSL_CTX_sess_misses(const SSL_CTX *ctx) { return 0; } |
| 2849 | int SSL_CTX_sess_timeouts(const SSL_CTX *ctx) { return 0; } |
| 2850 | int SSL_CTX_sess_cache_full(const SSL_CTX *ctx) { return 0; } |
Matt Braithwaite | 4838d8a | 2015-08-20 13:20:03 -0700 | [diff] [blame] | 2851 | void ERR_load_SSL_strings(void) {} |