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 | |
David Benjamin | 443a1f6 | 2015-09-04 15:05:05 -0400 | [diff] [blame] | 115 | #include <openssl/ssl.h> |
| 116 | |
Steven Valdez | bf5aa84 | 2016-07-15 07:07:40 -0400 | [diff] [blame] | 117 | #include <assert.h> |
Steven Valdez | a833c35 | 2016-11-01 13:39:36 -0400 | [diff] [blame] | 118 | #include <limits.h> |
David Benjamin | f0ae170 | 2015-04-07 23:05:04 -0400 | [diff] [blame] | 119 | #include <string.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 120 | |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 121 | #include <utility> |
| 122 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 123 | #include <openssl/bn.h> |
David Benjamin | 676d1e7 | 2014-07-08 14:34:10 -0400 | [diff] [blame] | 124 | #include <openssl/buf.h> |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 125 | #include <openssl/bytestring.h> |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 126 | #include <openssl/ec_key.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 127 | #include <openssl/err.h> |
| 128 | #include <openssl/mem.h> |
David Benjamin | 5c900c8 | 2016-07-13 23:03:26 -0400 | [diff] [blame] | 129 | #include <openssl/sha.h> |
David Benjamin | 680ca96 | 2015-06-18 12:37:23 -0400 | [diff] [blame] | 130 | #include <openssl/x509.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 131 | |
Adam Langley | 0da323a | 2015-05-15 12:49:30 -0700 | [diff] [blame] | 132 | #include "../crypto/internal.h" |
David Benjamin | 2ee94aa | 2015-04-07 22:38:30 -0400 | [diff] [blame] | 133 | #include "internal.h" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 134 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 135 | |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 136 | namespace bssl { |
| 137 | |
Adam Langley | 3509dac | 2017-02-01 11:59:18 -0800 | [diff] [blame] | 138 | CERT *ssl_cert_new(const SSL_X509_METHOD *x509_method) { |
David Benjamin | e64d2c7 | 2017-07-12 16:31:08 -0400 | [diff] [blame] | 139 | CERT *ret = (CERT *)OPENSSL_malloc(sizeof(CERT)); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 140 | if (ret == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 141 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 142 | return NULL; |
| 143 | } |
David Benjamin | 17cf2cb | 2016-12-13 01:07:13 -0500 | [diff] [blame] | 144 | OPENSSL_memset(ret, 0, sizeof(CERT)); |
Adam Langley | 3509dac | 2017-02-01 11:59:18 -0800 | [diff] [blame] | 145 | ret->x509_method = x509_method; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 146 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 147 | return ret; |
| 148 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 149 | |
Adam Langley | 3a2b47a | 2017-01-24 13:59:42 -0800 | [diff] [blame] | 150 | static CRYPTO_BUFFER *buffer_up_ref(CRYPTO_BUFFER *buffer) { |
| 151 | CRYPTO_BUFFER_up_ref(buffer); |
| 152 | return buffer; |
| 153 | } |
| 154 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 155 | CERT *ssl_cert_dup(CERT *cert) { |
David Benjamin | e64d2c7 | 2017-07-12 16:31:08 -0400 | [diff] [blame] | 156 | CERT *ret = (CERT *)OPENSSL_malloc(sizeof(CERT)); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 157 | if (ret == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 158 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 159 | return NULL; |
| 160 | } |
David Benjamin | 17cf2cb | 2016-12-13 01:07:13 -0500 | [diff] [blame] | 161 | OPENSSL_memset(ret, 0, sizeof(CERT)); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 162 | |
Adam Langley | 3a2b47a | 2017-01-24 13:59:42 -0800 | [diff] [blame] | 163 | ret->chain = sk_CRYPTO_BUFFER_deep_copy(cert->chain, buffer_up_ref, |
| 164 | CRYPTO_BUFFER_free); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 165 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 166 | if (cert->privatekey != NULL) { |
Adam Langley | 310d3f6 | 2016-07-12 10:39:20 -0700 | [diff] [blame] | 167 | EVP_PKEY_up_ref(cert->privatekey); |
| 168 | ret->privatekey = cert->privatekey; |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 169 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 170 | |
Tom Thorogood | 66b2fe8 | 2016-03-06 20:08:38 +1030 | [diff] [blame] | 171 | ret->key_method = cert->key_method; |
Adam Langley | 3509dac | 2017-02-01 11:59:18 -0800 | [diff] [blame] | 172 | ret->x509_method = cert->x509_method; |
Tom Thorogood | 66b2fe8 | 2016-03-06 20:08:38 +1030 | [diff] [blame] | 173 | |
David Benjamin | 0fc37ef | 2016-08-17 15:29:46 -0400 | [diff] [blame] | 174 | if (cert->sigalgs != NULL) { |
David Benjamin | e64d2c7 | 2017-07-12 16:31:08 -0400 | [diff] [blame] | 175 | ret->sigalgs = (uint16_t *)BUF_memdup( |
| 176 | cert->sigalgs, cert->num_sigalgs * sizeof(cert->sigalgs[0])); |
David Benjamin | 0fc37ef | 2016-08-17 15:29:46 -0400 | [diff] [blame] | 177 | if (ret->sigalgs == NULL) { |
| 178 | goto err; |
| 179 | } |
| 180 | } |
| 181 | ret->num_sigalgs = cert->num_sigalgs; |
| 182 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 183 | ret->cert_cb = cert->cert_cb; |
| 184 | ret->cert_cb_arg = cert->cert_cb_arg; |
| 185 | |
Adam Langley | 2a3b343 | 2017-02-10 13:56:48 -0800 | [diff] [blame] | 186 | ret->x509_method->cert_dup(ret, cert); |
Adam Langley | d323f4b | 2016-03-01 15:58:14 -0800 | [diff] [blame] | 187 | |
David Benjamin | 83a3212 | 2017-02-14 18:34:54 -0500 | [diff] [blame] | 188 | if (cert->signed_cert_timestamp_list != NULL) { |
| 189 | CRYPTO_BUFFER_up_ref(cert->signed_cert_timestamp_list); |
| 190 | ret->signed_cert_timestamp_list = cert->signed_cert_timestamp_list; |
| 191 | } |
| 192 | |
| 193 | if (cert->ocsp_response != NULL) { |
| 194 | CRYPTO_BUFFER_up_ref(cert->ocsp_response); |
| 195 | ret->ocsp_response = cert->ocsp_response; |
| 196 | } |
| 197 | |
David Benjamin | 5960a90 | 2017-02-14 20:07:11 -0500 | [diff] [blame] | 198 | ret->sid_ctx_length = cert->sid_ctx_length; |
| 199 | OPENSSL_memcpy(ret->sid_ctx, cert->sid_ctx, sizeof(ret->sid_ctx)); |
| 200 | |
Alessandro Ghedini | 67bb45f | 2017-03-30 16:33:24 -0500 | [diff] [blame] | 201 | ret->enable_early_data = cert->enable_early_data; |
| 202 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 203 | return ret; |
| 204 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 205 | err: |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 206 | ssl_cert_free(ret); |
| 207 | return NULL; |
| 208 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 209 | |
| 210 | /* Free up and clear all certificates and chains */ |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 211 | void ssl_cert_clear_certs(CERT *cert) { |
| 212 | if (cert == NULL) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 213 | return; |
| 214 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 215 | |
Adam Langley | 3509dac | 2017-02-01 11:59:18 -0800 | [diff] [blame] | 216 | cert->x509_method->cert_clear(cert); |
Adam Langley | e1e7813 | 2017-01-31 15:24:31 -0800 | [diff] [blame] | 217 | |
Adam Langley | 3a2b47a | 2017-01-24 13:59:42 -0800 | [diff] [blame] | 218 | sk_CRYPTO_BUFFER_pop_free(cert->chain, CRYPTO_BUFFER_free); |
| 219 | cert->chain = NULL; |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 220 | EVP_PKEY_free(cert->privatekey); |
| 221 | cert->privatekey = NULL; |
David Benjamin | 71d2e54 | 2015-07-06 00:30:25 -0400 | [diff] [blame] | 222 | cert->key_method = NULL; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 223 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 224 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 225 | void ssl_cert_free(CERT *c) { |
| 226 | if (c == NULL) { |
| 227 | return; |
| 228 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 229 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 230 | ssl_cert_clear_certs(c); |
Adam Langley | 2a3b343 | 2017-02-10 13:56:48 -0800 | [diff] [blame] | 231 | c->x509_method->cert_free(c); |
David Benjamin | d246b81 | 2016-07-08 15:07:02 -0700 | [diff] [blame] | 232 | OPENSSL_free(c->sigalgs); |
David Benjamin | 83a3212 | 2017-02-14 18:34:54 -0500 | [diff] [blame] | 233 | CRYPTO_BUFFER_free(c->signed_cert_timestamp_list); |
| 234 | CRYPTO_BUFFER_free(c->ocsp_response); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 235 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 236 | OPENSSL_free(c); |
| 237 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 238 | |
David Benjamin | a2bda9f | 2016-12-03 23:29:05 -0500 | [diff] [blame] | 239 | static void ssl_cert_set_cert_cb(CERT *c, int (*cb)(SSL *ssl, void *arg), |
| 240 | void *arg) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 241 | c->cert_cb = cb; |
| 242 | c->cert_cb_arg = arg; |
| 243 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 244 | |
Adam Langley | d04ca95 | 2017-02-28 11:26:51 -0800 | [diff] [blame] | 245 | enum leaf_cert_and_privkey_result_t { |
| 246 | leaf_cert_and_privkey_error, |
| 247 | leaf_cert_and_privkey_ok, |
| 248 | leaf_cert_and_privkey_mismatch, |
| 249 | }; |
| 250 | |
| 251 | /* check_leaf_cert_and_privkey checks whether the certificate in |leaf_buffer| |
| 252 | * and the private key in |privkey| are suitable and coherent. It returns |
| 253 | * |leaf_cert_and_privkey_error| and pushes to the error queue if a problem is |
| 254 | * found. If the certificate and private key are valid, but incoherent, it |
| 255 | * returns |leaf_cert_and_privkey_mismatch|. Otherwise it returns |
| 256 | * |leaf_cert_and_privkey_ok|. */ |
| 257 | static enum leaf_cert_and_privkey_result_t check_leaf_cert_and_privkey( |
| 258 | CRYPTO_BUFFER *leaf_buffer, EVP_PKEY *privkey) { |
Adam Langley | 52940c4 | 2017-02-01 12:40:31 -0800 | [diff] [blame] | 259 | CBS cert_cbs; |
Adam Langley | d04ca95 | 2017-02-28 11:26:51 -0800 | [diff] [blame] | 260 | CRYPTO_BUFFER_init_CBS(leaf_buffer, &cert_cbs); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 261 | UniquePtr<EVP_PKEY> pubkey = ssl_cert_parse_pubkey(&cert_cbs); |
| 262 | if (!pubkey) { |
Adam Langley | d04ca95 | 2017-02-28 11:26:51 -0800 | [diff] [blame] | 263 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 264 | return leaf_cert_and_privkey_error; |
Adam Langley | 52940c4 | 2017-02-01 12:40:31 -0800 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | if (!ssl_is_key_type_supported(pubkey->type)) { |
| 268 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNKNOWN_CERTIFICATE_TYPE); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 269 | return leaf_cert_and_privkey_error; |
Adam Langley | 52940c4 | 2017-02-01 12:40:31 -0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /* An ECC certificate may be usable for ECDH or ECDSA. We only support ECDSA |
| 273 | * certificates, so sanity-check the key usage extension. */ |
| 274 | if (pubkey->type == EVP_PKEY_EC && |
| 275 | !ssl_cert_check_digital_signature_key_usage(&cert_cbs)) { |
| 276 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNKNOWN_CERTIFICATE_TYPE); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 277 | return leaf_cert_and_privkey_error; |
Adam Langley | d04ca95 | 2017-02-28 11:26:51 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | if (privkey != NULL && |
| 281 | /* Sanity-check that the private key and the certificate match. */ |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 282 | !ssl_compare_public_and_private_key(pubkey.get(), privkey)) { |
Adam Langley | d04ca95 | 2017-02-28 11:26:51 -0800 | [diff] [blame] | 283 | ERR_clear_error(); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 284 | return leaf_cert_and_privkey_mismatch; |
Adam Langley | d04ca95 | 2017-02-28 11:26:51 -0800 | [diff] [blame] | 285 | } |
| 286 | |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 287 | return leaf_cert_and_privkey_ok; |
Adam Langley | d04ca95 | 2017-02-28 11:26:51 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | static int cert_set_chain_and_key( |
| 291 | CERT *cert, CRYPTO_BUFFER *const *certs, size_t num_certs, |
| 292 | EVP_PKEY *privkey, const SSL_PRIVATE_KEY_METHOD *privkey_method) { |
| 293 | if (num_certs == 0 || |
| 294 | (privkey == NULL && privkey_method == NULL)) { |
| 295 | OPENSSL_PUT_ERROR(SSL, ERR_R_PASSED_NULL_PARAMETER); |
Adam Langley | 52940c4 | 2017-02-01 12:40:31 -0800 | [diff] [blame] | 296 | return 0; |
| 297 | } |
| 298 | |
Adam Langley | d04ca95 | 2017-02-28 11:26:51 -0800 | [diff] [blame] | 299 | if (privkey != NULL && privkey_method != NULL) { |
| 300 | OPENSSL_PUT_ERROR(SSL, SSL_R_CANNOT_HAVE_BOTH_PRIVKEY_AND_METHOD); |
| 301 | return 0; |
Adam Langley | 52940c4 | 2017-02-01 12:40:31 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Adam Langley | d04ca95 | 2017-02-28 11:26:51 -0800 | [diff] [blame] | 304 | switch (check_leaf_cert_and_privkey(certs[0], privkey)) { |
| 305 | case leaf_cert_and_privkey_error: |
| 306 | return 0; |
| 307 | case leaf_cert_and_privkey_mismatch: |
| 308 | OPENSSL_PUT_ERROR(SSL, SSL_R_CERTIFICATE_AND_PRIVATE_KEY_MISMATCH); |
| 309 | return 0; |
| 310 | case leaf_cert_and_privkey_ok: |
| 311 | break; |
| 312 | } |
| 313 | |
| 314 | STACK_OF(CRYPTO_BUFFER) *certs_sk = sk_CRYPTO_BUFFER_new_null(); |
| 315 | if (certs_sk == NULL) { |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | for (size_t i = 0; i < num_certs; i++) { |
| 320 | if (!sk_CRYPTO_BUFFER_push(certs_sk, certs[i])) { |
| 321 | sk_CRYPTO_BUFFER_pop_free(certs_sk, CRYPTO_BUFFER_free); |
| 322 | return 0; |
| 323 | } |
| 324 | CRYPTO_BUFFER_up_ref(certs[i]); |
| 325 | } |
| 326 | |
| 327 | EVP_PKEY_free(cert->privatekey); |
| 328 | cert->privatekey = privkey; |
| 329 | if (privkey != NULL) { |
| 330 | EVP_PKEY_up_ref(privkey); |
| 331 | } |
| 332 | cert->key_method = privkey_method; |
| 333 | |
| 334 | sk_CRYPTO_BUFFER_pop_free(cert->chain, CRYPTO_BUFFER_free); |
| 335 | cert->chain = certs_sk; |
| 336 | |
| 337 | return 1; |
| 338 | } |
| 339 | |
Adam Langley | d04ca95 | 2017-02-28 11:26:51 -0800 | [diff] [blame] | 340 | int ssl_set_cert(CERT *cert, CRYPTO_BUFFER *buffer) { |
| 341 | switch (check_leaf_cert_and_privkey(buffer, cert->privatekey)) { |
| 342 | case leaf_cert_and_privkey_error: |
| 343 | return 0; |
| 344 | case leaf_cert_and_privkey_mismatch: |
| 345 | /* don't fail for a cert/key mismatch, just free current private key |
| 346 | * (when switching to a different cert & key, first this function should |
| 347 | * be used, then |ssl_set_pkey|. */ |
| 348 | EVP_PKEY_free(cert->privatekey); |
| 349 | cert->privatekey = NULL; |
| 350 | break; |
| 351 | case leaf_cert_and_privkey_ok: |
| 352 | break; |
| 353 | } |
Adam Langley | 52940c4 | 2017-02-01 12:40:31 -0800 | [diff] [blame] | 354 | |
| 355 | cert->x509_method->cert_flush_cached_leaf(cert); |
| 356 | |
| 357 | if (cert->chain != NULL) { |
| 358 | CRYPTO_BUFFER_free(sk_CRYPTO_BUFFER_value(cert->chain, 0)); |
| 359 | sk_CRYPTO_BUFFER_set(cert->chain, 0, buffer); |
| 360 | CRYPTO_BUFFER_up_ref(buffer); |
| 361 | return 1; |
| 362 | } |
| 363 | |
| 364 | cert->chain = sk_CRYPTO_BUFFER_new_null(); |
| 365 | if (cert->chain == NULL) { |
| 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | if (!sk_CRYPTO_BUFFER_push(cert->chain, buffer)) { |
| 370 | sk_CRYPTO_BUFFER_free(cert->chain); |
| 371 | cert->chain = NULL; |
| 372 | return 0; |
| 373 | } |
| 374 | CRYPTO_BUFFER_up_ref(buffer); |
| 375 | |
| 376 | return 1; |
| 377 | } |
| 378 | |
David Benjamin | 32a66d5 | 2016-07-13 22:03:11 -0400 | [diff] [blame] | 379 | int ssl_has_certificate(const SSL *ssl) { |
Adam Langley | 3a2b47a | 2017-01-24 13:59:42 -0800 | [diff] [blame] | 380 | return ssl->cert->chain != NULL && |
| 381 | sk_CRYPTO_BUFFER_value(ssl->cert->chain, 0) != NULL && |
| 382 | ssl_has_private_key(ssl); |
David Benjamin | 32a66d5 | 2016-07-13 22:03:11 -0400 | [diff] [blame] | 383 | } |
| 384 | |
David Benjamin | e664a53 | 2017-07-20 20:19:36 -0400 | [diff] [blame] | 385 | bool ssl_parse_cert_chain(uint8_t *out_alert, |
| 386 | UniquePtr<STACK_OF(CRYPTO_BUFFER)> *out_chain, |
| 387 | UniquePtr<EVP_PKEY> *out_pubkey, |
| 388 | uint8_t *out_leaf_sha256, CBS *cbs, |
| 389 | CRYPTO_BUFFER_POOL *pool) { |
| 390 | out_chain->reset(); |
| 391 | out_pubkey->reset(); |
David Benjamin | 5c900c8 | 2016-07-13 23:03:26 -0400 | [diff] [blame] | 392 | |
David Benjamin | 5c900c8 | 2016-07-13 23:03:26 -0400 | [diff] [blame] | 393 | CBS certificate_list; |
| 394 | if (!CBS_get_u24_length_prefixed(cbs, &certificate_list)) { |
| 395 | *out_alert = SSL_AD_DECODE_ERROR; |
| 396 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
David Benjamin | e664a53 | 2017-07-20 20:19:36 -0400 | [diff] [blame] | 397 | return false; |
David Benjamin | 5c900c8 | 2016-07-13 23:03:26 -0400 | [diff] [blame] | 398 | } |
| 399 | |
David Benjamin | e664a53 | 2017-07-20 20:19:36 -0400 | [diff] [blame] | 400 | if (CBS_len(&certificate_list) == 0) { |
| 401 | return true; |
| 402 | } |
| 403 | |
| 404 | UniquePtr<STACK_OF(CRYPTO_BUFFER)> chain(sk_CRYPTO_BUFFER_new_null()); |
| 405 | if (!chain) { |
| 406 | *out_alert = SSL_AD_INTERNAL_ERROR; |
| 407 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
| 408 | return false; |
| 409 | } |
| 410 | |
| 411 | UniquePtr<EVP_PKEY> pubkey; |
David Benjamin | 5c900c8 | 2016-07-13 23:03:26 -0400 | [diff] [blame] | 412 | while (CBS_len(&certificate_list) > 0) { |
| 413 | CBS certificate; |
Adam Langley | 68e7124 | 2016-12-12 11:06:16 -0800 | [diff] [blame] | 414 | if (!CBS_get_u24_length_prefixed(&certificate_list, &certificate) || |
| 415 | CBS_len(&certificate) == 0) { |
David Benjamin | 5c900c8 | 2016-07-13 23:03:26 -0400 | [diff] [blame] | 416 | *out_alert = SSL_AD_DECODE_ERROR; |
| 417 | OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_LENGTH_MISMATCH); |
David Benjamin | e664a53 | 2017-07-20 20:19:36 -0400 | [diff] [blame] | 418 | return false; |
David Benjamin | 5c900c8 | 2016-07-13 23:03:26 -0400 | [diff] [blame] | 419 | } |
| 420 | |
David Benjamin | e664a53 | 2017-07-20 20:19:36 -0400 | [diff] [blame] | 421 | if (sk_CRYPTO_BUFFER_num(chain.get()) == 0) { |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 422 | pubkey = ssl_cert_parse_pubkey(&certificate); |
| 423 | if (!pubkey) { |
Adam Langley | 7dccc71 | 2017-02-08 08:51:25 -0800 | [diff] [blame] | 424 | *out_alert = SSL_AD_DECODE_ERROR; |
David Benjamin | e664a53 | 2017-07-20 20:19:36 -0400 | [diff] [blame] | 425 | return false; |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /* Retain the hash of the leaf certificate if requested. */ |
| 429 | if (out_leaf_sha256 != NULL) { |
| 430 | SHA256(CBS_data(&certificate), CBS_len(&certificate), out_leaf_sha256); |
| 431 | } |
David Benjamin | 5c900c8 | 2016-07-13 23:03:26 -0400 | [diff] [blame] | 432 | } |
| 433 | |
Adam Langley | d519bf6 | 2016-12-12 11:16:44 -0800 | [diff] [blame] | 434 | CRYPTO_BUFFER *buf = |
| 435 | CRYPTO_BUFFER_new_from_CBS(&certificate, pool); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 436 | if (buf == NULL || |
David Benjamin | e664a53 | 2017-07-20 20:19:36 -0400 | [diff] [blame] | 437 | !sk_CRYPTO_BUFFER_push(chain.get(), buf)) { |
David Benjamin | 5c900c8 | 2016-07-13 23:03:26 -0400 | [diff] [blame] | 438 | *out_alert = SSL_AD_INTERNAL_ERROR; |
Adam Langley | 68e7124 | 2016-12-12 11:06:16 -0800 | [diff] [blame] | 439 | CRYPTO_BUFFER_free(buf); |
David Benjamin | 5c900c8 | 2016-07-13 23:03:26 -0400 | [diff] [blame] | 440 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
David Benjamin | e664a53 | 2017-07-20 20:19:36 -0400 | [diff] [blame] | 441 | return false; |
David Benjamin | 5c900c8 | 2016-07-13 23:03:26 -0400 | [diff] [blame] | 442 | } |
David Benjamin | 5c900c8 | 2016-07-13 23:03:26 -0400 | [diff] [blame] | 443 | } |
| 444 | |
David Benjamin | e664a53 | 2017-07-20 20:19:36 -0400 | [diff] [blame] | 445 | *out_chain = std::move(chain); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 446 | *out_pubkey = std::move(pubkey); |
David Benjamin | e664a53 | 2017-07-20 20:19:36 -0400 | [diff] [blame] | 447 | return true; |
David Benjamin | 5c900c8 | 2016-07-13 23:03:26 -0400 | [diff] [blame] | 448 | } |
| 449 | |
David Benjamin | 7583643 | 2016-06-17 18:48:29 -0400 | [diff] [blame] | 450 | int ssl_add_cert_chain(SSL *ssl, CBB *cbb) { |
David Benjamin | 32a66d5 | 2016-07-13 22:03:11 -0400 | [diff] [blame] | 451 | if (!ssl_has_certificate(ssl)) { |
| 452 | return CBB_add_u24(cbb, 0); |
| 453 | } |
| 454 | |
Adam Langley | 3a2b47a | 2017-01-24 13:59:42 -0800 | [diff] [blame] | 455 | CBB certs; |
| 456 | if (!CBB_add_u24_length_prefixed(cbb, &certs)) { |
David Benjamin | e64d2c7 | 2017-07-12 16:31:08 -0400 | [diff] [blame] | 457 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 458 | return 0; |
David Benjamin | 7583643 | 2016-06-17 18:48:29 -0400 | [diff] [blame] | 459 | } |
| 460 | |
Adam Langley | 3a2b47a | 2017-01-24 13:59:42 -0800 | [diff] [blame] | 461 | STACK_OF(CRYPTO_BUFFER) *chain = ssl->cert->chain; |
| 462 | for (size_t i = 0; i < sk_CRYPTO_BUFFER_num(chain); i++) { |
| 463 | CRYPTO_BUFFER *buffer = sk_CRYPTO_BUFFER_value(chain, i); |
| 464 | CBB child; |
| 465 | if (!CBB_add_u24_length_prefixed(&certs, &child) || |
| 466 | !CBB_add_bytes(&child, CRYPTO_BUFFER_data(buffer), |
| 467 | CRYPTO_BUFFER_len(buffer)) || |
| 468 | !CBB_flush(&certs)) { |
David Benjamin | e64d2c7 | 2017-07-12 16:31:08 -0400 | [diff] [blame] | 469 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 470 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 471 | } |
| 472 | } |
| 473 | |
David Benjamin | 7583643 | 2016-06-17 18:48:29 -0400 | [diff] [blame] | 474 | return CBB_flush(cbb); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 475 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 476 | |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 477 | /* ssl_cert_skip_to_spki parses a DER-encoded, X.509 certificate from |in| and |
| 478 | * positions |*out_tbs_cert| to cover the TBSCertificate, starting at the |
| 479 | * subjectPublicKeyInfo. */ |
| 480 | static int ssl_cert_skip_to_spki(const CBS *in, CBS *out_tbs_cert) { |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 481 | /* From RFC 5280, section 4.1 |
| 482 | * Certificate ::= SEQUENCE { |
| 483 | * tbsCertificate TBSCertificate, |
| 484 | * signatureAlgorithm AlgorithmIdentifier, |
| 485 | * signatureValue BIT STRING } |
| 486 | |
| 487 | * TBSCertificate ::= SEQUENCE { |
| 488 | * version [0] EXPLICIT Version DEFAULT v1, |
| 489 | * serialNumber CertificateSerialNumber, |
| 490 | * signature AlgorithmIdentifier, |
| 491 | * issuer Name, |
| 492 | * validity Validity, |
| 493 | * subject Name, |
| 494 | * subjectPublicKeyInfo SubjectPublicKeyInfo, |
| 495 | * ... } */ |
| 496 | CBS buf = *in; |
| 497 | |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 498 | CBS toplevel; |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 499 | if (!CBS_get_asn1(&buf, &toplevel, CBS_ASN1_SEQUENCE) || |
| 500 | CBS_len(&buf) != 0 || |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 501 | !CBS_get_asn1(&toplevel, out_tbs_cert, CBS_ASN1_SEQUENCE) || |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 502 | /* version */ |
| 503 | !CBS_get_optional_asn1( |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 504 | out_tbs_cert, NULL, NULL, |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 505 | CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 0) || |
| 506 | /* serialNumber */ |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 507 | !CBS_get_asn1(out_tbs_cert, NULL, CBS_ASN1_INTEGER) || |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 508 | /* signature algorithm */ |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 509 | !CBS_get_asn1(out_tbs_cert, NULL, CBS_ASN1_SEQUENCE) || |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 510 | /* issuer */ |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 511 | !CBS_get_asn1(out_tbs_cert, NULL, CBS_ASN1_SEQUENCE) || |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 512 | /* validity */ |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 513 | !CBS_get_asn1(out_tbs_cert, NULL, CBS_ASN1_SEQUENCE) || |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 514 | /* subject */ |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 515 | !CBS_get_asn1(out_tbs_cert, NULL, CBS_ASN1_SEQUENCE)) { |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | return 1; |
| 520 | } |
| 521 | |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 522 | UniquePtr<EVP_PKEY> ssl_cert_parse_pubkey(const CBS *in) { |
David Benjamin | 5b410b6 | 2017-01-03 08:08:57 -0500 | [diff] [blame] | 523 | CBS buf = *in, tbs_cert; |
| 524 | if (!ssl_cert_skip_to_spki(&buf, &tbs_cert)) { |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 525 | OPENSSL_PUT_ERROR(SSL, SSL_R_CANNOT_PARSE_LEAF_CERT); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 526 | return nullptr; |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 527 | } |
| 528 | |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 529 | return UniquePtr<EVP_PKEY>(EVP_parse_public_key(&tbs_cert)); |
Adam Langley | d515722 | 2016-12-12 11:37:43 -0800 | [diff] [blame] | 530 | } |
| 531 | |
Adam Langley | c26692c | 2017-01-25 09:34:42 -0800 | [diff] [blame] | 532 | int ssl_compare_public_and_private_key(const EVP_PKEY *pubkey, |
| 533 | const EVP_PKEY *privkey) { |
Adam Langley | d04ca95 | 2017-02-28 11:26:51 -0800 | [diff] [blame] | 534 | if (EVP_PKEY_is_opaque(privkey)) { |
| 535 | /* We cannot check an opaque private key and have to trust that it |
| 536 | * matches. */ |
| 537 | return 1; |
| 538 | } |
| 539 | |
Adam Langley | 3a2b47a | 2017-01-24 13:59:42 -0800 | [diff] [blame] | 540 | int ret = 0; |
| 541 | |
| 542 | switch (EVP_PKEY_cmp(pubkey, privkey)) { |
| 543 | case 1: |
| 544 | ret = 1; |
| 545 | break; |
| 546 | case 0: |
| 547 | OPENSSL_PUT_ERROR(X509, X509_R_KEY_VALUES_MISMATCH); |
| 548 | break; |
| 549 | case -1: |
| 550 | OPENSSL_PUT_ERROR(X509, X509_R_KEY_TYPE_MISMATCH); |
| 551 | break; |
| 552 | case -2: |
| 553 | OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_KEY_TYPE); |
Adam Langley | 11d11d6 | 2017-07-17 11:10:46 -0700 | [diff] [blame] | 554 | break; |
Adam Langley | 3a2b47a | 2017-01-24 13:59:42 -0800 | [diff] [blame] | 555 | default: |
| 556 | assert(0); |
| 557 | break; |
| 558 | } |
| 559 | |
Adam Langley | 3a2b47a | 2017-01-24 13:59:42 -0800 | [diff] [blame] | 560 | return ret; |
| 561 | } |
| 562 | |
| 563 | int ssl_cert_check_private_key(const CERT *cert, const EVP_PKEY *privkey) { |
| 564 | if (privkey == NULL) { |
| 565 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_PRIVATE_KEY_ASSIGNED); |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | if (cert->chain == NULL || |
| 570 | sk_CRYPTO_BUFFER_value(cert->chain, 0) == NULL) { |
| 571 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATE_ASSIGNED); |
| 572 | return 0; |
| 573 | } |
| 574 | |
Adam Langley | c26692c | 2017-01-25 09:34:42 -0800 | [diff] [blame] | 575 | CBS cert_cbs; |
| 576 | CRYPTO_BUFFER_init_CBS(sk_CRYPTO_BUFFER_value(cert->chain, 0), &cert_cbs); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 577 | UniquePtr<EVP_PKEY> pubkey = ssl_cert_parse_pubkey(&cert_cbs); |
Adam Langley | c26692c | 2017-01-25 09:34:42 -0800 | [diff] [blame] | 578 | if (!pubkey) { |
| 579 | OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_KEY_TYPE); |
| 580 | return 0; |
| 581 | } |
| 582 | |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 583 | return ssl_compare_public_and_private_key(pubkey.get(), privkey); |
Adam Langley | 3a2b47a | 2017-01-24 13:59:42 -0800 | [diff] [blame] | 584 | } |
| 585 | |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 586 | int ssl_cert_check_digital_signature_key_usage(const CBS *in) { |
| 587 | CBS buf = *in; |
| 588 | |
| 589 | CBS tbs_cert, outer_extensions; |
| 590 | int has_extensions; |
| 591 | if (!ssl_cert_skip_to_spki(&buf, &tbs_cert) || |
| 592 | /* subjectPublicKeyInfo */ |
| 593 | !CBS_get_asn1(&tbs_cert, NULL, CBS_ASN1_SEQUENCE) || |
| 594 | /* issuerUniqueID */ |
| 595 | !CBS_get_optional_asn1( |
| 596 | &tbs_cert, NULL, NULL, |
| 597 | CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 1) || |
| 598 | /* subjectUniqueID */ |
| 599 | !CBS_get_optional_asn1( |
| 600 | &tbs_cert, NULL, NULL, |
| 601 | CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 2) || |
| 602 | !CBS_get_optional_asn1( |
| 603 | &tbs_cert, &outer_extensions, &has_extensions, |
| 604 | CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 3)) { |
| 605 | goto parse_err; |
| 606 | } |
| 607 | |
| 608 | if (!has_extensions) { |
| 609 | return 1; |
| 610 | } |
| 611 | |
| 612 | CBS extensions; |
| 613 | if (!CBS_get_asn1(&outer_extensions, &extensions, CBS_ASN1_SEQUENCE)) { |
| 614 | goto parse_err; |
| 615 | } |
| 616 | |
| 617 | while (CBS_len(&extensions) > 0) { |
| 618 | CBS extension, oid, contents; |
| 619 | if (!CBS_get_asn1(&extensions, &extension, CBS_ASN1_SEQUENCE) || |
| 620 | !CBS_get_asn1(&extension, &oid, CBS_ASN1_OBJECT) || |
| 621 | (CBS_peek_asn1_tag(&extension, CBS_ASN1_BOOLEAN) && |
| 622 | !CBS_get_asn1(&extension, NULL, CBS_ASN1_BOOLEAN)) || |
| 623 | !CBS_get_asn1(&extension, &contents, CBS_ASN1_OCTETSTRING) || |
| 624 | CBS_len(&extension) != 0) { |
| 625 | goto parse_err; |
| 626 | } |
| 627 | |
| 628 | static const uint8_t kKeyUsageOID[3] = {0x55, 0x1d, 0x0f}; |
| 629 | if (CBS_len(&oid) != sizeof(kKeyUsageOID) || |
David Benjamin | 17cf2cb | 2016-12-13 01:07:13 -0500 | [diff] [blame] | 630 | OPENSSL_memcmp(CBS_data(&oid), kKeyUsageOID, sizeof(kKeyUsageOID)) != |
| 631 | 0) { |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 632 | continue; |
| 633 | } |
| 634 | |
| 635 | CBS bit_string; |
| 636 | if (!CBS_get_asn1(&contents, &bit_string, CBS_ASN1_BITSTRING) || |
| 637 | CBS_len(&contents) != 0) { |
| 638 | goto parse_err; |
| 639 | } |
| 640 | |
| 641 | /* This is the KeyUsage extension. See |
| 642 | * https://tools.ietf.org/html/rfc5280#section-4.2.1.3 */ |
| 643 | if (!CBS_is_valid_asn1_bitstring(&bit_string)) { |
| 644 | goto parse_err; |
| 645 | } |
| 646 | |
| 647 | if (!CBS_asn1_bitstring_has_bit(&bit_string, 0)) { |
| 648 | OPENSSL_PUT_ERROR(SSL, SSL_R_ECC_CERT_NOT_FOR_SIGNING); |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | return 1; |
| 653 | } |
| 654 | |
| 655 | /* No KeyUsage extension found. */ |
| 656 | return 1; |
| 657 | |
| 658 | parse_err: |
| 659 | OPENSSL_PUT_ERROR(SSL, SSL_R_CANNOT_PARSE_LEAF_CERT); |
| 660 | return 0; |
| 661 | } |
| 662 | |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 663 | UniquePtr<STACK_OF(CRYPTO_BUFFER)> ssl_parse_client_CA_list(SSL *ssl, |
| 664 | uint8_t *out_alert, |
| 665 | CBS *cbs) { |
Adam Langley | 34b4c82 | 2017-02-02 10:57:17 -0800 | [diff] [blame] | 666 | CRYPTO_BUFFER_POOL *const pool = ssl->ctx->pool; |
| 667 | |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 668 | UniquePtr<STACK_OF(CRYPTO_BUFFER)> ret(sk_CRYPTO_BUFFER_new_null()); |
| 669 | if (!ret) { |
David Benjamin | e0332e8 | 2016-07-13 22:40:36 -0400 | [diff] [blame] | 670 | *out_alert = SSL_AD_INTERNAL_ERROR; |
| 671 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 672 | return nullptr; |
David Benjamin | e0332e8 | 2016-07-13 22:40:36 -0400 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | CBS child; |
| 676 | if (!CBS_get_u16_length_prefixed(cbs, &child)) { |
| 677 | *out_alert = SSL_AD_DECODE_ERROR; |
| 678 | OPENSSL_PUT_ERROR(SSL, SSL_R_LENGTH_MISMATCH); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 679 | return nullptr; |
David Benjamin | e0332e8 | 2016-07-13 22:40:36 -0400 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | while (CBS_len(&child) > 0) { |
| 683 | CBS distinguished_name; |
| 684 | if (!CBS_get_u16_length_prefixed(&child, &distinguished_name)) { |
| 685 | *out_alert = SSL_AD_DECODE_ERROR; |
| 686 | OPENSSL_PUT_ERROR(SSL, SSL_R_CA_DN_TOO_LONG); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 687 | return nullptr; |
David Benjamin | e0332e8 | 2016-07-13 22:40:36 -0400 | [diff] [blame] | 688 | } |
| 689 | |
Adam Langley | 34b4c82 | 2017-02-02 10:57:17 -0800 | [diff] [blame] | 690 | CRYPTO_BUFFER *buffer = |
| 691 | CRYPTO_BUFFER_new_from_CBS(&distinguished_name, pool); |
| 692 | if (buffer == NULL || |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 693 | !sk_CRYPTO_BUFFER_push(ret.get(), buffer)) { |
Adam Langley | 34b4c82 | 2017-02-02 10:57:17 -0800 | [diff] [blame] | 694 | CRYPTO_BUFFER_free(buffer); |
David Benjamin | e0332e8 | 2016-07-13 22:40:36 -0400 | [diff] [blame] | 695 | *out_alert = SSL_AD_INTERNAL_ERROR; |
| 696 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 697 | return nullptr; |
David Benjamin | e0332e8 | 2016-07-13 22:40:36 -0400 | [diff] [blame] | 698 | } |
David Benjamin | e0332e8 | 2016-07-13 22:40:36 -0400 | [diff] [blame] | 699 | } |
| 700 | |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 701 | if (!ssl->ctx->x509_method->check_client_CA_list(ret.get())) { |
Adam Langley | 0bdef09 | 2017-02-23 15:02:58 -0800 | [diff] [blame] | 702 | *out_alert = SSL_AD_INTERNAL_ERROR; |
| 703 | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 704 | return nullptr; |
Adam Langley | 0bdef09 | 2017-02-23 15:02:58 -0800 | [diff] [blame] | 705 | } |
| 706 | |
David Benjamin | e0332e8 | 2016-07-13 22:40:36 -0400 | [diff] [blame] | 707 | return ret; |
David Benjamin | e0332e8 | 2016-07-13 22:40:36 -0400 | [diff] [blame] | 708 | } |
| 709 | |
David Benjamin | 32a66d5 | 2016-07-13 22:03:11 -0400 | [diff] [blame] | 710 | int ssl_add_client_CA_list(SSL *ssl, CBB *cbb) { |
| 711 | CBB child, name_cbb; |
| 712 | if (!CBB_add_u16_length_prefixed(cbb, &child)) { |
| 713 | return 0; |
| 714 | } |
| 715 | |
Adam Langley | 34b4c82 | 2017-02-02 10:57:17 -0800 | [diff] [blame] | 716 | STACK_OF(CRYPTO_BUFFER) *names = ssl->client_CA; |
| 717 | if (names == NULL) { |
| 718 | names = ssl->ctx->client_CA; |
| 719 | } |
| 720 | if (names == NULL) { |
David Benjamin | 32a66d5 | 2016-07-13 22:03:11 -0400 | [diff] [blame] | 721 | return CBB_flush(cbb); |
| 722 | } |
| 723 | |
David Benjamin | ec78383 | 2017-07-25 23:23:03 -0400 | [diff] [blame^] | 724 | for (const CRYPTO_BUFFER *name : names) { |
David Benjamin | 32a66d5 | 2016-07-13 22:03:11 -0400 | [diff] [blame] | 725 | if (!CBB_add_u16_length_prefixed(&child, &name_cbb) || |
Adam Langley | 34b4c82 | 2017-02-02 10:57:17 -0800 | [diff] [blame] | 726 | !CBB_add_bytes(&name_cbb, CRYPTO_BUFFER_data(name), |
| 727 | CRYPTO_BUFFER_len(name))) { |
David Benjamin | 32a66d5 | 2016-07-13 22:03:11 -0400 | [diff] [blame] | 728 | return 0; |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | return CBB_flush(cbb); |
| 733 | } |
| 734 | |
David Benjamin | 45738dd | 2017-02-09 20:01:26 -0500 | [diff] [blame] | 735 | int ssl_check_leaf_certificate(SSL_HANDSHAKE *hs, EVP_PKEY *pkey, |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 736 | const CRYPTO_BUFFER *leaf) { |
David Benjamin | 45738dd | 2017-02-09 20:01:26 -0500 | [diff] [blame] | 737 | SSL *const ssl = hs->ssl; |
David Benjamin | 938fa7c | 2016-10-07 00:27:05 -0400 | [diff] [blame] | 738 | assert(ssl3_protocol_version(ssl) < TLS1_3_VERSION); |
| 739 | |
Steven Valdez | bf5aa84 | 2016-07-15 07:07:40 -0400 | [diff] [blame] | 740 | /* Check the certificate's type matches the cipher. */ |
David Benjamin | 6952211 | 2017-03-28 15:38:29 -0500 | [diff] [blame] | 741 | if (!(hs->new_cipher->algorithm_auth & ssl_cipher_auth_mask_for_key(pkey))) { |
Steven Valdez | bf5aa84 | 2016-07-15 07:07:40 -0400 | [diff] [blame] | 742 | OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CERTIFICATE_TYPE); |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 743 | return 0; |
Steven Valdez | bf5aa84 | 2016-07-15 07:07:40 -0400 | [diff] [blame] | 744 | } |
| 745 | |
David Benjamin | 6952211 | 2017-03-28 15:38:29 -0500 | [diff] [blame] | 746 | /* Check key usages for all key types but RSA. This is needed to distinguish |
| 747 | * ECDH certificates, which we do not support, from ECDSA certificates. In |
| 748 | * principle, we should check RSA key usages based on cipher, but this breaks |
| 749 | * buggy antivirus deployments. Other key types are always used for signing. |
| 750 | * |
| 751 | * TODO(davidben): Get more recent data on RSA key usages. */ |
| 752 | if (EVP_PKEY_id(pkey) != EVP_PKEY_RSA) { |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 753 | CBS leaf_cbs; |
| 754 | CBS_init(&leaf_cbs, CRYPTO_BUFFER_data(leaf), CRYPTO_BUFFER_len(leaf)); |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 755 | if (!ssl_cert_check_digital_signature_key_usage(&leaf_cbs)) { |
| 756 | return 0; |
Steven Valdez | bf5aa84 | 2016-07-15 07:07:40 -0400 | [diff] [blame] | 757 | } |
David Benjamin | 6952211 | 2017-03-28 15:38:29 -0500 | [diff] [blame] | 758 | } |
Steven Valdez | bf5aa84 | 2016-07-15 07:07:40 -0400 | [diff] [blame] | 759 | |
David Benjamin | 6952211 | 2017-03-28 15:38:29 -0500 | [diff] [blame] | 760 | if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) { |
David Benjamin | 938fa7c | 2016-10-07 00:27:05 -0400 | [diff] [blame] | 761 | /* Check the key's group and point format are acceptable. */ |
David Benjamin | 6952211 | 2017-03-28 15:38:29 -0500 | [diff] [blame] | 762 | EC_KEY *ec_key = EVP_PKEY_get0_EC_KEY(pkey); |
David Benjamin | 938fa7c | 2016-10-07 00:27:05 -0400 | [diff] [blame] | 763 | uint16_t group_id; |
| 764 | if (!ssl_nid_to_group_id( |
| 765 | &group_id, EC_GROUP_get_curve_name(EC_KEY_get0_group(ec_key))) || |
| 766 | !tls1_check_group_id(ssl, group_id) || |
| 767 | EC_KEY_get_conv_form(ec_key) != POINT_CONVERSION_UNCOMPRESSED) { |
Steven Valdez | bf5aa84 | 2016-07-15 07:07:40 -0400 | [diff] [blame] | 768 | OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_ECC_CERT); |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 769 | return 0; |
Steven Valdez | bf5aa84 | 2016-07-15 07:07:40 -0400 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | |
Adam Langley | 0567220 | 2016-12-13 12:05:49 -0800 | [diff] [blame] | 773 | return 1; |
Steven Valdez | bf5aa84 | 2016-07-15 07:07:40 -0400 | [diff] [blame] | 774 | } |
David Benjamin | 5edfc8c | 2016-12-10 15:46:58 -0500 | [diff] [blame] | 775 | |
David Benjamin | a232a71 | 2017-03-30 15:51:53 -0500 | [diff] [blame] | 776 | int ssl_on_certificate_selected(SSL_HANDSHAKE *hs) { |
| 777 | SSL *const ssl = hs->ssl; |
| 778 | if (!ssl_has_certificate(ssl)) { |
| 779 | /* Nothing to do. */ |
| 780 | return 1; |
| 781 | } |
| 782 | |
| 783 | if (!ssl->ctx->x509_method->ssl_auto_chain_if_needed(ssl)) { |
| 784 | return 0; |
| 785 | } |
| 786 | |
| 787 | CBS leaf; |
| 788 | CRYPTO_BUFFER_init_CBS(sk_CRYPTO_BUFFER_value(ssl->cert->chain, 0), &leaf); |
| 789 | |
David Benjamin | a232a71 | 2017-03-30 15:51:53 -0500 | [diff] [blame] | 790 | hs->local_pubkey = ssl_cert_parse_pubkey(&leaf); |
| 791 | return hs->local_pubkey != NULL; |
| 792 | } |
| 793 | |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 794 | } // namespace bssl |
| 795 | |
| 796 | using namespace bssl; |
| 797 | |
| 798 | int SSL_set_chain_and_key(SSL *ssl, CRYPTO_BUFFER *const *certs, |
| 799 | size_t num_certs, EVP_PKEY *privkey, |
| 800 | const SSL_PRIVATE_KEY_METHOD *privkey_method) { |
| 801 | return cert_set_chain_and_key(ssl->cert, certs, num_certs, privkey, |
| 802 | privkey_method); |
| 803 | } |
| 804 | |
| 805 | int SSL_CTX_set_chain_and_key(SSL_CTX *ctx, CRYPTO_BUFFER *const *certs, |
| 806 | size_t num_certs, EVP_PKEY *privkey, |
| 807 | const SSL_PRIVATE_KEY_METHOD *privkey_method) { |
| 808 | return cert_set_chain_and_key(ctx->cert, certs, num_certs, privkey, |
| 809 | privkey_method); |
| 810 | } |
| 811 | |
| 812 | int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, size_t der_len, |
| 813 | const uint8_t *der) { |
| 814 | CRYPTO_BUFFER *buffer = CRYPTO_BUFFER_new(der, der_len, NULL); |
| 815 | if (buffer == NULL) { |
| 816 | return 0; |
| 817 | } |
| 818 | |
| 819 | const int ok = ssl_set_cert(ctx->cert, buffer); |
| 820 | CRYPTO_BUFFER_free(buffer); |
| 821 | return ok; |
| 822 | } |
| 823 | |
| 824 | int SSL_use_certificate_ASN1(SSL *ssl, const uint8_t *der, size_t der_len) { |
| 825 | CRYPTO_BUFFER *buffer = CRYPTO_BUFFER_new(der, der_len, NULL); |
| 826 | if (buffer == NULL) { |
| 827 | return 0; |
| 828 | } |
| 829 | |
| 830 | const int ok = ssl_set_cert(ssl->cert, buffer); |
| 831 | CRYPTO_BUFFER_free(buffer); |
| 832 | return ok; |
| 833 | } |
| 834 | |
| 835 | void SSL_CTX_set_cert_cb(SSL_CTX *ctx, int (*cb)(SSL *ssl, void *arg), |
| 836 | void *arg) { |
| 837 | ssl_cert_set_cert_cb(ctx->cert, cb, arg); |
| 838 | } |
| 839 | |
| 840 | void SSL_set_cert_cb(SSL *ssl, int (*cb)(SSL *ssl, void *arg), void *arg) { |
| 841 | ssl_cert_set_cert_cb(ssl->cert, cb, arg); |
| 842 | } |
| 843 | |
| 844 | STACK_OF(CRYPTO_BUFFER) *SSL_get0_peer_certificates(const SSL *ssl) { |
| 845 | SSL_SESSION *session = SSL_get_session(ssl); |
| 846 | if (session == NULL) { |
| 847 | return NULL; |
| 848 | } |
| 849 | |
| 850 | return session->certs; |
| 851 | } |
| 852 | |
| 853 | STACK_OF(CRYPTO_BUFFER) *SSL_get0_server_requested_CAs(const SSL *ssl) { |
| 854 | if (ssl->s3->hs == NULL) { |
| 855 | return NULL; |
| 856 | } |
David Benjamin | 31b0c9b | 2017-07-20 14:49:15 -0400 | [diff] [blame] | 857 | return ssl->s3->hs->ca_names.get(); |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 858 | } |
| 859 | |
David Benjamin | 83a3212 | 2017-02-14 18:34:54 -0500 | [diff] [blame] | 860 | static int set_signed_cert_timestamp_list(CERT *cert, const uint8_t *list, |
| 861 | size_t list_len) { |
| 862 | CBS sct_list; |
| 863 | CBS_init(&sct_list, list, list_len); |
| 864 | if (!ssl_is_sct_list_valid(&sct_list)) { |
| 865 | OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SCT_LIST); |
| 866 | return 0; |
| 867 | } |
| 868 | |
| 869 | CRYPTO_BUFFER_free(cert->signed_cert_timestamp_list); |
| 870 | cert->signed_cert_timestamp_list = |
| 871 | CRYPTO_BUFFER_new(CBS_data(&sct_list), CBS_len(&sct_list), NULL); |
| 872 | return cert->signed_cert_timestamp_list != NULL; |
| 873 | } |
| 874 | |
| 875 | int SSL_CTX_set_signed_cert_timestamp_list(SSL_CTX *ctx, const uint8_t *list, |
| 876 | size_t list_len) { |
| 877 | return set_signed_cert_timestamp_list(ctx->cert, list, list_len); |
| 878 | } |
| 879 | |
| 880 | int SSL_set_signed_cert_timestamp_list(SSL *ssl, const uint8_t *list, |
| 881 | size_t list_len) { |
| 882 | return set_signed_cert_timestamp_list(ssl->cert, list, list_len); |
| 883 | } |
| 884 | |
| 885 | int SSL_CTX_set_ocsp_response(SSL_CTX *ctx, const uint8_t *response, |
| 886 | size_t response_len) { |
| 887 | CRYPTO_BUFFER_free(ctx->cert->ocsp_response); |
| 888 | ctx->cert->ocsp_response = CRYPTO_BUFFER_new(response, response_len, NULL); |
| 889 | return ctx->cert->ocsp_response != NULL; |
| 890 | } |
| 891 | |
| 892 | int SSL_set_ocsp_response(SSL *ssl, const uint8_t *response, |
| 893 | size_t response_len) { |
| 894 | CRYPTO_BUFFER_free(ssl->cert->ocsp_response); |
| 895 | ssl->cert->ocsp_response = CRYPTO_BUFFER_new(response, response_len, NULL); |
| 896 | return ssl->cert->ocsp_response != NULL; |
| 897 | } |
David Benjamin | 71dfad4 | 2017-07-16 17:27:39 -0400 | [diff] [blame] | 898 | |
| 899 | void SSL_CTX_set0_client_CAs(SSL_CTX *ctx, STACK_OF(CRYPTO_BUFFER) *name_list) { |
| 900 | ctx->x509_method->ssl_ctx_flush_cached_client_CA(ctx); |
| 901 | sk_CRYPTO_BUFFER_pop_free(ctx->client_CA, CRYPTO_BUFFER_free); |
| 902 | ctx->client_CA = name_list; |
| 903 | } |
| 904 | |
| 905 | void SSL_set0_client_CAs(SSL *ssl, STACK_OF(CRYPTO_BUFFER) *name_list) { |
| 906 | ssl->ctx->x509_method->ssl_flush_cached_client_CA(ssl); |
| 907 | sk_CRYPTO_BUFFER_pop_free(ssl->client_CA, CRYPTO_BUFFER_free); |
| 908 | ssl->client_CA = name_list; |
| 909 | } |