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 | |
David Benjamin | f0ae170 | 2015-04-07 23:05:04 -0400 | [diff] [blame] | 117 | #include <string.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 118 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 119 | #include <openssl/bn.h> |
David Benjamin | 676d1e7 | 2014-07-08 14:34:10 -0400 | [diff] [blame] | 120 | #include <openssl/buf.h> |
David Benjamin | 680ca96 | 2015-06-18 12:37:23 -0400 | [diff] [blame] | 121 | #include <openssl/ec_key.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 122 | #include <openssl/dh.h> |
| 123 | #include <openssl/err.h> |
| 124 | #include <openssl/mem.h> |
David Benjamin | 680ca96 | 2015-06-18 12:37:23 -0400 | [diff] [blame] | 125 | #include <openssl/x509.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 126 | #include <openssl/x509v3.h> |
| 127 | |
| 128 | #include "../crypto/dh/internal.h" |
Adam Langley | 0da323a | 2015-05-15 12:49:30 -0700 | [diff] [blame] | 129 | #include "../crypto/internal.h" |
David Benjamin | 2ee94aa | 2015-04-07 22:38:30 -0400 | [diff] [blame] | 130 | #include "internal.h" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 131 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 132 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 133 | int SSL_get_ex_data_X509_STORE_CTX_idx(void) { |
David Benjamin | aa58513 | 2015-06-29 23:36:17 -0400 | [diff] [blame] | 134 | /* The ex_data index to go from |X509_STORE_CTX| to |SSL| always uses the |
| 135 | * reserved app_data slot. Before ex_data was introduced, app_data was used. |
| 136 | * Avoid breaking any software which assumes |X509_STORE_CTX_get_app_data| |
| 137 | * works. */ |
| 138 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 139 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 140 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 141 | CERT *ssl_cert_new(void) { |
Brian Smith | 5ba0689 | 2016-02-07 09:36:04 -1000 | [diff] [blame] | 142 | CERT *ret = OPENSSL_malloc(sizeof(CERT)); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 143 | if (ret == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 144 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 145 | return NULL; |
| 146 | } |
| 147 | memset(ret, 0, sizeof(CERT)); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 148 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 149 | return ret; |
| 150 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 151 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 152 | CERT *ssl_cert_dup(CERT *cert) { |
Brian Smith | 5ba0689 | 2016-02-07 09:36:04 -1000 | [diff] [blame] | 153 | CERT *ret = OPENSSL_malloc(sizeof(CERT)); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 154 | if (ret == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 155 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 156 | return NULL; |
| 157 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 158 | memset(ret, 0, sizeof(CERT)); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 159 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 160 | ret->mask_k = cert->mask_k; |
| 161 | ret->mask_a = cert->mask_a; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 162 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 163 | if (cert->dh_tmp != NULL) { |
| 164 | ret->dh_tmp = DHparams_dup(cert->dh_tmp); |
| 165 | if (ret->dh_tmp == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 166 | OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 167 | goto err; |
| 168 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 169 | } |
| 170 | ret->dh_tmp_cb = cert->dh_tmp_cb; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 171 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 172 | if (cert->x509 != NULL) { |
| 173 | ret->x509 = X509_up_ref(cert->x509); |
| 174 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 175 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 176 | if (cert->privatekey != NULL) { |
Adam Langley | 310d3f6 | 2016-07-12 10:39:20 -0700 | [diff] [blame^] | 177 | EVP_PKEY_up_ref(cert->privatekey); |
| 178 | ret->privatekey = cert->privatekey; |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 179 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 180 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 181 | if (cert->chain) { |
| 182 | ret->chain = X509_chain_up_ref(cert->chain); |
| 183 | if (!ret->chain) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 184 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 185 | goto err; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 186 | } |
| 187 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 188 | |
Tom Thorogood | 66b2fe8 | 2016-03-06 20:08:38 +1030 | [diff] [blame] | 189 | ret->key_method = cert->key_method; |
| 190 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 191 | ret->cert_cb = cert->cert_cb; |
| 192 | ret->cert_cb_arg = cert->cert_cb_arg; |
| 193 | |
Adam Langley | d323f4b | 2016-03-01 15:58:14 -0800 | [diff] [blame] | 194 | if (cert->verify_store != NULL) { |
| 195 | X509_STORE_up_ref(cert->verify_store); |
| 196 | ret->verify_store = cert->verify_store; |
| 197 | } |
| 198 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 199 | return ret; |
| 200 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 201 | err: |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 202 | ssl_cert_free(ret); |
| 203 | return NULL; |
| 204 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 205 | |
| 206 | /* Free up and clear all certificates and chains */ |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 207 | void ssl_cert_clear_certs(CERT *cert) { |
| 208 | if (cert == NULL) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 209 | return; |
| 210 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 211 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 212 | X509_free(cert->x509); |
| 213 | cert->x509 = NULL; |
| 214 | EVP_PKEY_free(cert->privatekey); |
| 215 | cert->privatekey = NULL; |
| 216 | sk_X509_pop_free(cert->chain, X509_free); |
| 217 | cert->chain = NULL; |
David Benjamin | 71d2e54 | 2015-07-06 00:30:25 -0400 | [diff] [blame] | 218 | cert->key_method = NULL; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 219 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 220 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 221 | void ssl_cert_free(CERT *c) { |
| 222 | if (c == NULL) { |
| 223 | return; |
| 224 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 225 | |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 226 | DH_free(c->dh_tmp); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 227 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 228 | ssl_cert_clear_certs(c); |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 229 | OPENSSL_free(c->peer_sigalgs); |
David Benjamin | d246b81 | 2016-07-08 15:07:02 -0700 | [diff] [blame] | 230 | OPENSSL_free(c->sigalgs); |
Adam Langley | d323f4b | 2016-03-01 15:58:14 -0800 | [diff] [blame] | 231 | X509_STORE_free(c->verify_store); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 232 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 233 | OPENSSL_free(c); |
| 234 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 235 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 236 | int ssl_cert_set0_chain(CERT *cert, STACK_OF(X509) *chain) { |
| 237 | sk_X509_pop_free(cert->chain, X509_free); |
| 238 | cert->chain = chain; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 239 | return 1; |
| 240 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 241 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 242 | int ssl_cert_set1_chain(CERT *cert, STACK_OF(X509) *chain) { |
David Benjamin | 60da0cd | 2015-05-03 15:21:28 -0400 | [diff] [blame] | 243 | STACK_OF(X509) *dchain; |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 244 | if (chain == NULL) { |
| 245 | return ssl_cert_set0_chain(cert, NULL); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 246 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 247 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 248 | dchain = X509_chain_up_ref(chain); |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 249 | if (dchain == NULL) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 250 | return 0; |
| 251 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 252 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 253 | if (!ssl_cert_set0_chain(cert, dchain)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 254 | sk_X509_pop_free(dchain, X509_free); |
| 255 | return 0; |
| 256 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 257 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 258 | return 1; |
| 259 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 260 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 261 | int ssl_cert_add0_chain_cert(CERT *cert, X509 *x509) { |
| 262 | if (cert->chain == NULL) { |
| 263 | cert->chain = sk_X509_new_null(); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 264 | } |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 265 | if (cert->chain == NULL || !sk_X509_push(cert->chain, x509)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 266 | return 0; |
| 267 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 268 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 269 | return 1; |
| 270 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 271 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 272 | int ssl_cert_add1_chain_cert(CERT *cert, X509 *x509) { |
| 273 | if (!ssl_cert_add0_chain_cert(cert, x509)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 274 | return 0; |
| 275 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 276 | |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 277 | X509_up_ref(x509); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 278 | return 1; |
| 279 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 280 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 281 | void ssl_cert_set_cert_cb(CERT *c, int (*cb)(SSL *ssl, void *arg), void *arg) { |
| 282 | c->cert_cb = cb; |
| 283 | c->cert_cb_arg = arg; |
| 284 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 285 | |
David Benjamin | 306ece3 | 2015-09-17 13:46:22 -0400 | [diff] [blame] | 286 | int ssl_verify_cert_chain(SSL *ssl, STACK_OF(X509) *cert_chain) { |
| 287 | if (cert_chain == NULL || sk_X509_num(cert_chain) == 0) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 288 | return 0; |
| 289 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 290 | |
Adam Langley | d323f4b | 2016-03-01 15:58:14 -0800 | [diff] [blame] | 291 | X509_STORE *verify_store = ssl->ctx->cert_store; |
| 292 | if (ssl->cert->verify_store != NULL) { |
| 293 | verify_store = ssl->cert->verify_store; |
| 294 | } |
| 295 | |
David Benjamin | 306ece3 | 2015-09-17 13:46:22 -0400 | [diff] [blame] | 296 | X509 *leaf = sk_X509_value(cert_chain, 0); |
| 297 | int ret = 0; |
| 298 | X509_STORE_CTX ctx; |
Adam Langley | d323f4b | 2016-03-01 15:58:14 -0800 | [diff] [blame] | 299 | if (!X509_STORE_CTX_init(&ctx, verify_store, leaf, cert_chain)) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 300 | OPENSSL_PUT_ERROR(SSL, ERR_R_X509_LIB); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 301 | return 0; |
| 302 | } |
David Benjamin | 306ece3 | 2015-09-17 13:46:22 -0400 | [diff] [blame] | 303 | if (!X509_STORE_CTX_set_ex_data(&ctx, SSL_get_ex_data_X509_STORE_CTX_idx(), |
| 304 | ssl)) { |
| 305 | goto err; |
| 306 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 307 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 308 | /* We need to inherit the verify parameters. These can be determined by the |
| 309 | * context: if its a server it will verify SSL client certificates or vice |
| 310 | * versa. */ |
David Benjamin | 306ece3 | 2015-09-17 13:46:22 -0400 | [diff] [blame] | 311 | X509_STORE_CTX_set_default(&ctx, ssl->server ? "ssl_client" : "ssl_server"); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 312 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 313 | /* Anything non-default in "param" should overwrite anything in the ctx. */ |
David Benjamin | 306ece3 | 2015-09-17 13:46:22 -0400 | [diff] [blame] | 314 | X509_VERIFY_PARAM_set1(X509_STORE_CTX_get0_param(&ctx), ssl->param); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 315 | |
David Benjamin | 306ece3 | 2015-09-17 13:46:22 -0400 | [diff] [blame] | 316 | if (ssl->verify_callback) { |
| 317 | X509_STORE_CTX_set_verify_cb(&ctx, ssl->verify_callback); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 318 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 319 | |
David Benjamin | 306ece3 | 2015-09-17 13:46:22 -0400 | [diff] [blame] | 320 | if (ssl->ctx->app_verify_callback != NULL) { |
| 321 | ret = ssl->ctx->app_verify_callback(&ctx, ssl->ctx->app_verify_arg); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 322 | } else { |
David Benjamin | 306ece3 | 2015-09-17 13:46:22 -0400 | [diff] [blame] | 323 | ret = X509_verify_cert(&ctx); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 324 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 325 | |
David Benjamin | 306ece3 | 2015-09-17 13:46:22 -0400 | [diff] [blame] | 326 | ssl->verify_result = ctx.error; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 327 | |
David Benjamin | 306ece3 | 2015-09-17 13:46:22 -0400 | [diff] [blame] | 328 | err: |
| 329 | X509_STORE_CTX_cleanup(&ctx); |
| 330 | return ret; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 331 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 332 | |
David Benjamin | 60da0cd | 2015-05-03 15:21:28 -0400 | [diff] [blame] | 333 | static void set_client_CA_list(STACK_OF(X509_NAME) **ca_list, |
| 334 | STACK_OF(X509_NAME) *name_list) { |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 335 | sk_X509_NAME_pop_free(*ca_list, X509_NAME_free); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 336 | *ca_list = name_list; |
| 337 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 338 | |
David Benjamin | 5993704 | 2015-09-19 13:04:22 -0400 | [diff] [blame] | 339 | STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *list) { |
| 340 | STACK_OF(X509_NAME) *ret = sk_X509_NAME_new_null(); |
| 341 | if (ret == NULL) { |
| 342 | return NULL; |
| 343 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 344 | |
David Benjamin | 5993704 | 2015-09-19 13:04:22 -0400 | [diff] [blame] | 345 | size_t i; |
| 346 | for (i = 0; i < sk_X509_NAME_num(list); i++) { |
| 347 | X509_NAME *name = X509_NAME_dup(sk_X509_NAME_value(list, i)); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 348 | if (name == NULL || !sk_X509_NAME_push(ret, name)) { |
David Benjamin | 5993704 | 2015-09-19 13:04:22 -0400 | [diff] [blame] | 349 | X509_NAME_free(name); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 350 | sk_X509_NAME_pop_free(ret, X509_NAME_free); |
| 351 | return NULL; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | return ret; |
| 356 | } |
| 357 | |
David Benjamin | 5993704 | 2015-09-19 13:04:22 -0400 | [diff] [blame] | 358 | void SSL_set_client_CA_list(SSL *ssl, STACK_OF(X509_NAME) *name_list) { |
| 359 | set_client_CA_list(&ssl->client_CA, name_list); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 360 | } |
| 361 | |
David Benjamin | 60da0cd | 2015-05-03 15:21:28 -0400 | [diff] [blame] | 362 | void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list) { |
David Benjamin | 5993704 | 2015-09-19 13:04:22 -0400 | [diff] [blame] | 363 | set_client_CA_list(&ctx->client_CA, name_list); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 364 | } |
| 365 | |
David Benjamin | 60da0cd | 2015-05-03 15:21:28 -0400 | [diff] [blame] | 366 | STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *ctx) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 367 | return ctx->client_CA; |
| 368 | } |
| 369 | |
David Benjamin | 1d128f3 | 2015-09-08 17:41:40 -0400 | [diff] [blame] | 370 | STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *ssl) { |
| 371 | /* For historical reasons, this function is used both to query configuration |
| 372 | * state on a server as well as handshake state on a client. However, whether |
| 373 | * |ssl| is a client or server is not known until explicitly configured with |
| 374 | * |SSL_set_connect_state|. If |handshake_func| is NULL, |ssl| is in an |
| 375 | * indeterminate mode and |ssl->server| is unset. */ |
| 376 | if (ssl->handshake_func != NULL && !ssl->server) { |
| 377 | return ssl->s3->tmp.ca_names; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 378 | } |
David Benjamin | 1d128f3 | 2015-09-08 17:41:40 -0400 | [diff] [blame] | 379 | |
| 380 | if (ssl->client_CA != NULL) { |
| 381 | return ssl->client_CA; |
| 382 | } |
| 383 | return ssl->ctx->client_CA; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 384 | } |
| 385 | |
David Benjamin | 5993704 | 2015-09-19 13:04:22 -0400 | [diff] [blame] | 386 | static int add_client_CA(STACK_OF(X509_NAME) **sk, X509 *x509) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 387 | X509_NAME *name; |
| 388 | |
David Benjamin | 5993704 | 2015-09-19 13:04:22 -0400 | [diff] [blame] | 389 | if (x509 == NULL) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 390 | return 0; |
| 391 | } |
| 392 | if (*sk == NULL) { |
| 393 | *sk = sk_X509_NAME_new_null(); |
| 394 | if (*sk == NULL) { |
| 395 | return 0; |
| 396 | } |
| 397 | } |
| 398 | |
David Benjamin | 5993704 | 2015-09-19 13:04:22 -0400 | [diff] [blame] | 399 | name = X509_NAME_dup(X509_get_subject_name(x509)); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 400 | if (name == NULL) { |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | if (!sk_X509_NAME_push(*sk, name)) { |
| 405 | X509_NAME_free(name); |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | return 1; |
| 410 | } |
| 411 | |
David Benjamin | 5993704 | 2015-09-19 13:04:22 -0400 | [diff] [blame] | 412 | int SSL_add_client_CA(SSL *ssl, X509 *x509) { |
| 413 | return add_client_CA(&ssl->client_CA, x509); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 414 | } |
| 415 | |
David Benjamin | 5993704 | 2015-09-19 13:04:22 -0400 | [diff] [blame] | 416 | int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x509) { |
| 417 | return add_client_CA(&ctx->client_CA, x509); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 418 | } |
| 419 | |
David Benjamin | 7583643 | 2016-06-17 18:48:29 -0400 | [diff] [blame] | 420 | int ssl_add_cert_to_cbb(CBB *cbb, X509 *x509) { |
| 421 | int len = i2d_X509(x509, NULL); |
| 422 | if (len < 0) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 423 | return 0; |
| 424 | } |
David Benjamin | 7583643 | 2016-06-17 18:48:29 -0400 | [diff] [blame] | 425 | uint8_t *buf; |
| 426 | if (!CBB_add_space(cbb, &buf, len)) { |
| 427 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
| 428 | return 0; |
Steven Valdez | b32a915 | 2016-04-26 12:57:22 -0400 | [diff] [blame] | 429 | } |
David Benjamin | 7583643 | 2016-06-17 18:48:29 -0400 | [diff] [blame] | 430 | if (buf != NULL && i2d_X509(x509, &buf) < 0) { |
| 431 | return 0; |
| 432 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 433 | return 1; |
| 434 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 435 | |
David Benjamin | 7583643 | 2016-06-17 18:48:29 -0400 | [diff] [blame] | 436 | static int ssl_add_cert_with_length(CBB *cbb, X509 *x509) { |
| 437 | CBB child; |
| 438 | return CBB_add_u24_length_prefixed(cbb, &child) && |
| 439 | ssl_add_cert_to_cbb(&child, x509) && |
| 440 | CBB_flush(cbb); |
| 441 | } |
| 442 | |
| 443 | int ssl_add_cert_chain(SSL *ssl, CBB *cbb) { |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 444 | CERT *cert = ssl->cert; |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 445 | X509 *x = cert->x509; |
David Benjamin | 605641e | 2015-05-03 15:14:04 -0400 | [diff] [blame] | 446 | if (x == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 447 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATE_SET); |
David Benjamin | 605641e | 2015-05-03 15:14:04 -0400 | [diff] [blame] | 448 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 449 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 450 | |
David Benjamin | 7583643 | 2016-06-17 18:48:29 -0400 | [diff] [blame] | 451 | CBB child; |
| 452 | if (!CBB_add_u24_length_prefixed(cbb, &child)) { |
| 453 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | int no_chain = 0; |
| 458 | STACK_OF(X509) *chain = cert->chain; |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 459 | if ((ssl->mode & SSL_MODE_NO_AUTO_CHAIN) || chain != NULL) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 460 | no_chain = 1; |
| 461 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 462 | |
David Benjamin | 605641e | 2015-05-03 15:14:04 -0400 | [diff] [blame] | 463 | if (no_chain) { |
Steven Valdez | 57a6f3c | 2016-06-28 15:37:37 -0400 | [diff] [blame] | 464 | if (!ssl_add_cert_with_length(&child, x)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 465 | return 0; |
| 466 | } |
David Benjamin | 605641e | 2015-05-03 15:14:04 -0400 | [diff] [blame] | 467 | |
David Benjamin | 7583643 | 2016-06-17 18:48:29 -0400 | [diff] [blame] | 468 | size_t i; |
David Benjamin | d1d8078 | 2015-07-05 11:54:09 -0400 | [diff] [blame] | 469 | for (i = 0; i < sk_X509_num(chain); i++) { |
| 470 | x = sk_X509_value(chain, i); |
David Benjamin | 7583643 | 2016-06-17 18:48:29 -0400 | [diff] [blame] | 471 | if (!ssl_add_cert_with_length(&child, x)) { |
David Benjamin | 605641e | 2015-05-03 15:14:04 -0400 | [diff] [blame] | 472 | return 0; |
| 473 | } |
| 474 | } |
| 475 | } else { |
| 476 | X509_STORE_CTX xs_ctx; |
| 477 | |
David Benjamin | d27441a | 2015-08-09 11:05:17 -0400 | [diff] [blame] | 478 | if (!X509_STORE_CTX_init(&xs_ctx, ssl->ctx->cert_store, x, NULL)) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 479 | OPENSSL_PUT_ERROR(SSL, ERR_R_X509_LIB); |
David Benjamin | 605641e | 2015-05-03 15:14:04 -0400 | [diff] [blame] | 480 | return 0; |
| 481 | } |
| 482 | X509_verify_cert(&xs_ctx); |
| 483 | /* Don't leave errors in the queue */ |
| 484 | ERR_clear_error(); |
David Benjamin | 7583643 | 2016-06-17 18:48:29 -0400 | [diff] [blame] | 485 | |
| 486 | size_t i; |
David Benjamin | 605641e | 2015-05-03 15:14:04 -0400 | [diff] [blame] | 487 | for (i = 0; i < sk_X509_num(xs_ctx.chain); i++) { |
| 488 | x = sk_X509_value(xs_ctx.chain, i); |
David Benjamin | 7583643 | 2016-06-17 18:48:29 -0400 | [diff] [blame] | 489 | if (!ssl_add_cert_with_length(&child, x)) { |
David Benjamin | 605641e | 2015-05-03 15:14:04 -0400 | [diff] [blame] | 490 | X509_STORE_CTX_cleanup(&xs_ctx); |
| 491 | return 0; |
| 492 | } |
| 493 | } |
| 494 | X509_STORE_CTX_cleanup(&xs_ctx); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 495 | } |
| 496 | |
David Benjamin | 7583643 | 2016-06-17 18:48:29 -0400 | [diff] [blame] | 497 | return CBB_flush(cbb); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 498 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 499 | |
Adam Langley | d323f4b | 2016-03-01 15:58:14 -0800 | [diff] [blame] | 500 | static int set_cert_store(X509_STORE **store_ptr, X509_STORE *new_store, int take_ref) { |
| 501 | X509_STORE_free(*store_ptr); |
| 502 | *store_ptr = new_store; |
| 503 | |
| 504 | if (new_store != NULL && take_ref) { |
| 505 | X509_STORE_up_ref(new_store); |
| 506 | } |
| 507 | |
| 508 | return 1; |
| 509 | } |
| 510 | |
| 511 | int SSL_CTX_set0_verify_cert_store(SSL_CTX *ctx, X509_STORE *store) { |
| 512 | return set_cert_store(&ctx->cert->verify_store, store, 0); |
| 513 | } |
| 514 | |
| 515 | int SSL_CTX_set1_verify_cert_store(SSL_CTX *ctx, X509_STORE *store) { |
| 516 | return set_cert_store(&ctx->cert->verify_store, store, 1); |
| 517 | } |
| 518 | |
| 519 | int SSL_set0_verify_cert_store(SSL *ssl, X509_STORE *store) { |
| 520 | return set_cert_store(&ssl->cert->verify_store, store, 0); |
| 521 | } |
| 522 | |
| 523 | int SSL_set1_verify_cert_store(SSL *ssl, X509_STORE *store) { |
| 524 | return set_cert_store(&ssl->cert->verify_store, store, 1); |
| 525 | } |
| 526 | |
David Benjamin | 11c0f8e | 2015-07-06 00:18:15 -0400 | [diff] [blame] | 527 | int SSL_CTX_set0_chain(SSL_CTX *ctx, STACK_OF(X509) *chain) { |
| 528 | return ssl_cert_set0_chain(ctx->cert, chain); |
| 529 | } |
| 530 | |
| 531 | int SSL_CTX_set1_chain(SSL_CTX *ctx, STACK_OF(X509) *chain) { |
| 532 | return ssl_cert_set1_chain(ctx->cert, chain); |
| 533 | } |
| 534 | |
| 535 | int SSL_set0_chain(SSL *ssl, STACK_OF(X509) *chain) { |
| 536 | return ssl_cert_set0_chain(ssl->cert, chain); |
| 537 | } |
| 538 | |
| 539 | int SSL_set1_chain(SSL *ssl, STACK_OF(X509) *chain) { |
| 540 | return ssl_cert_set1_chain(ssl->cert, chain); |
| 541 | } |
| 542 | |
| 543 | int SSL_CTX_add0_chain_cert(SSL_CTX *ctx, X509 *x509) { |
| 544 | return ssl_cert_add0_chain_cert(ctx->cert, x509); |
| 545 | } |
| 546 | |
| 547 | int SSL_CTX_add1_chain_cert(SSL_CTX *ctx, X509 *x509) { |
| 548 | return ssl_cert_add1_chain_cert(ctx->cert, x509); |
| 549 | } |
| 550 | |
| 551 | int SSL_CTX_add_extra_chain_cert(SSL_CTX *ctx, X509 *x509) { |
| 552 | return SSL_CTX_add0_chain_cert(ctx, x509); |
| 553 | } |
| 554 | |
| 555 | int SSL_add0_chain_cert(SSL *ssl, X509 *x509) { |
| 556 | return ssl_cert_add0_chain_cert(ssl->cert, x509); |
| 557 | } |
| 558 | |
| 559 | int SSL_add1_chain_cert(SSL *ssl, X509 *x509) { |
| 560 | return ssl_cert_add1_chain_cert(ssl->cert, x509); |
| 561 | } |
| 562 | |
| 563 | int SSL_CTX_clear_chain_certs(SSL_CTX *ctx) { |
| 564 | return SSL_CTX_set0_chain(ctx, NULL); |
| 565 | } |
| 566 | |
| 567 | int SSL_CTX_clear_extra_chain_certs(SSL_CTX *ctx) { |
| 568 | return SSL_CTX_clear_chain_certs(ctx); |
| 569 | } |
| 570 | |
| 571 | int SSL_clear_chain_certs(SSL *ssl) { |
| 572 | return SSL_set0_chain(ssl, NULL); |
| 573 | } |
| 574 | |
| 575 | int SSL_CTX_get0_chain_certs(const SSL_CTX *ctx, STACK_OF(X509) **out_chain) { |
| 576 | *out_chain = ctx->cert->chain; |
| 577 | return 1; |
| 578 | } |
| 579 | |
| 580 | int SSL_CTX_get_extra_chain_certs(const SSL_CTX *ctx, |
| 581 | STACK_OF(X509) **out_chain) { |
| 582 | return SSL_CTX_get0_chain_certs(ctx, out_chain); |
| 583 | } |
| 584 | |
| 585 | int SSL_get0_chain_certs(const SSL *ssl, STACK_OF(X509) **out_chain) { |
| 586 | *out_chain = ssl->cert->chain; |
| 587 | return 1; |
| 588 | } |