/src/boringssl/ssl/ssl_x509.cc
Line | Count | Source (jump to first uncovered line) |
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 | | |
141 | | #include <openssl/ssl.h> |
142 | | |
143 | | #include <assert.h> |
144 | | |
145 | | #include <openssl/asn1.h> |
146 | | #include <openssl/bytestring.h> |
147 | | #include <openssl/err.h> |
148 | | #include <openssl/pem.h> |
149 | | #include <openssl/stack.h> |
150 | | #include <openssl/x509.h> |
151 | | #include <openssl/x509v3.h> |
152 | | |
153 | | #include "internal.h" |
154 | | #include "../crypto/internal.h" |
155 | | |
156 | | |
157 | | BSSL_NAMESPACE_BEGIN |
158 | | |
159 | | // check_ssl_x509_method asserts that |ssl| has the X509-based method |
160 | | // installed. Calling an X509-based method on an |ssl| with a different method |
161 | | // will likely misbehave and possibly crash or leak memory. |
162 | 0 | static void check_ssl_x509_method(const SSL *ssl) { |
163 | 0 | assert(ssl == NULL || ssl->ctx->x509_method == &ssl_crypto_x509_method); |
164 | 0 | } |
165 | | |
166 | | // check_ssl_ctx_x509_method acts like |check_ssl_x509_method|, but for an |
167 | | // |SSL_CTX|. |
168 | 0 | static void check_ssl_ctx_x509_method(const SSL_CTX *ctx) { |
169 | 0 | assert(ctx == NULL || ctx->x509_method == &ssl_crypto_x509_method); |
170 | 0 | } |
171 | | |
172 | | // x509_to_buffer returns a |CRYPTO_BUFFER| that contains the serialised |
173 | | // contents of |x509|. |
174 | 0 | static UniquePtr<CRYPTO_BUFFER> x509_to_buffer(X509 *x509) { |
175 | 0 | uint8_t *buf = NULL; |
176 | 0 | int cert_len = i2d_X509(x509, &buf); |
177 | 0 | if (cert_len <= 0) { |
178 | 0 | return 0; |
179 | 0 | } |
180 | | |
181 | 0 | UniquePtr<CRYPTO_BUFFER> buffer(CRYPTO_BUFFER_new(buf, cert_len, NULL)); |
182 | 0 | OPENSSL_free(buf); |
183 | |
|
184 | 0 | return buffer; |
185 | 0 | } |
186 | | |
187 | | // new_leafless_chain returns a fresh stack of buffers set to {NULL}. |
188 | 0 | static UniquePtr<STACK_OF(CRYPTO_BUFFER)> new_leafless_chain(void) { |
189 | 0 | UniquePtr<STACK_OF(CRYPTO_BUFFER)> chain(sk_CRYPTO_BUFFER_new_null()); |
190 | 0 | if (!chain || |
191 | 0 | !sk_CRYPTO_BUFFER_push(chain.get(), nullptr)) { |
192 | 0 | return nullptr; |
193 | 0 | } |
194 | | |
195 | 0 | return chain; |
196 | 0 | } |
197 | | |
198 | | // ssl_cert_set_chain sets elements 1.. of |cert->chain| to the serialised |
199 | | // forms of elements of |chain|. It returns one on success or zero on error, in |
200 | | // which case no change to |cert->chain| is made. It preverses the existing |
201 | | // leaf from |cert->chain|, if any. |
202 | 0 | static bool ssl_cert_set_chain(CERT *cert, STACK_OF(X509) *chain) { |
203 | 0 | UniquePtr<STACK_OF(CRYPTO_BUFFER)> new_chain; |
204 | |
|
205 | 0 | if (cert->chain != nullptr) { |
206 | 0 | new_chain.reset(sk_CRYPTO_BUFFER_new_null()); |
207 | 0 | if (!new_chain) { |
208 | 0 | return false; |
209 | 0 | } |
210 | | |
211 | | // |leaf| might be NULL if it's a “leafless” chain. |
212 | 0 | CRYPTO_BUFFER *leaf = sk_CRYPTO_BUFFER_value(cert->chain.get(), 0); |
213 | 0 | if (!PushToStack(new_chain.get(), UpRef(leaf))) { |
214 | 0 | return false; |
215 | 0 | } |
216 | 0 | } |
217 | | |
218 | 0 | for (X509 *x509 : chain) { |
219 | 0 | if (!new_chain) { |
220 | 0 | new_chain = new_leafless_chain(); |
221 | 0 | if (!new_chain) { |
222 | 0 | return false; |
223 | 0 | } |
224 | 0 | } |
225 | | |
226 | 0 | UniquePtr<CRYPTO_BUFFER> buffer = x509_to_buffer(x509); |
227 | 0 | if (!buffer || |
228 | 0 | !PushToStack(new_chain.get(), std::move(buffer))) { |
229 | 0 | return false; |
230 | 0 | } |
231 | 0 | } |
232 | | |
233 | 0 | cert->chain = std::move(new_chain); |
234 | 0 | return true; |
235 | 0 | } |
236 | | |
237 | 0 | static void ssl_crypto_x509_cert_flush_cached_leaf(CERT *cert) { |
238 | 0 | X509_free(cert->x509_leaf); |
239 | 0 | cert->x509_leaf = nullptr; |
240 | 0 | } |
241 | | |
242 | 0 | static void ssl_crypto_x509_cert_flush_cached_chain(CERT *cert) { |
243 | 0 | sk_X509_pop_free(cert->x509_chain, X509_free); |
244 | 0 | cert->x509_chain = nullptr; |
245 | 0 | } |
246 | | |
247 | | static bool ssl_crypto_x509_check_client_CA_list( |
248 | 0 | STACK_OF(CRYPTO_BUFFER) *names) { |
249 | 0 | for (const CRYPTO_BUFFER *buffer : names) { |
250 | 0 | const uint8_t *inp = CRYPTO_BUFFER_data(buffer); |
251 | 0 | UniquePtr<X509_NAME> name( |
252 | 0 | d2i_X509_NAME(nullptr, &inp, CRYPTO_BUFFER_len(buffer))); |
253 | 0 | if (name == nullptr || |
254 | 0 | inp != CRYPTO_BUFFER_data(buffer) + CRYPTO_BUFFER_len(buffer)) { |
255 | 0 | return false; |
256 | 0 | } |
257 | 0 | } |
258 | | |
259 | 0 | return true; |
260 | 0 | } |
261 | | |
262 | 0 | static void ssl_crypto_x509_cert_clear(CERT *cert) { |
263 | 0 | ssl_crypto_x509_cert_flush_cached_leaf(cert); |
264 | 0 | ssl_crypto_x509_cert_flush_cached_chain(cert); |
265 | |
|
266 | 0 | X509_free(cert->x509_stash); |
267 | 0 | cert->x509_stash = nullptr; |
268 | 0 | } |
269 | | |
270 | 0 | static void ssl_crypto_x509_cert_free(CERT *cert) { |
271 | 0 | ssl_crypto_x509_cert_clear(cert); |
272 | 0 | X509_STORE_free(cert->verify_store); |
273 | 0 | } |
274 | | |
275 | 0 | static void ssl_crypto_x509_cert_dup(CERT *new_cert, const CERT *cert) { |
276 | 0 | if (cert->verify_store != nullptr) { |
277 | 0 | X509_STORE_up_ref(cert->verify_store); |
278 | 0 | new_cert->verify_store = cert->verify_store; |
279 | 0 | } |
280 | 0 | } |
281 | | |
282 | 1.76k | static bool ssl_crypto_x509_session_cache_objects(SSL_SESSION *sess) { |
283 | 1.76k | bssl::UniquePtr<STACK_OF(X509)> chain, chain_without_leaf; |
284 | 1.76k | if (sk_CRYPTO_BUFFER_num(sess->certs.get()) > 0) { |
285 | 1.26k | chain.reset(sk_X509_new_null()); |
286 | 1.26k | if (!chain) { |
287 | 0 | return false; |
288 | 0 | } |
289 | 1.26k | if (sess->is_server) { |
290 | | // chain_without_leaf is only needed for server sessions. See |
291 | | // |SSL_get_peer_cert_chain|. |
292 | 1.25k | chain_without_leaf.reset(sk_X509_new_null()); |
293 | 1.25k | if (!chain_without_leaf) { |
294 | 0 | return false; |
295 | 0 | } |
296 | 1.25k | } |
297 | 1.26k | } |
298 | | |
299 | 1.76k | bssl::UniquePtr<X509> leaf; |
300 | 1.76k | for (CRYPTO_BUFFER *cert : sess->certs.get()) { |
301 | 1.43k | UniquePtr<X509> x509(X509_parse_from_buffer(cert)); |
302 | 1.43k | if (!x509) { |
303 | 1.24k | OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR); |
304 | 1.24k | return false; |
305 | 1.24k | } |
306 | 182 | if (leaf == nullptr) { |
307 | 82 | leaf = UpRef(x509); |
308 | 100 | } else if (chain_without_leaf && |
309 | 100 | !PushToStack(chain_without_leaf.get(), UpRef(x509))) { |
310 | 0 | return false; |
311 | 0 | } |
312 | 182 | if (!PushToStack(chain.get(), std::move(x509))) { |
313 | 0 | return false; |
314 | 0 | } |
315 | 182 | } |
316 | | |
317 | 513 | sk_X509_pop_free(sess->x509_chain, X509_free); |
318 | 513 | sess->x509_chain = chain.release(); |
319 | | |
320 | 513 | sk_X509_pop_free(sess->x509_chain_without_leaf, X509_free); |
321 | 513 | sess->x509_chain_without_leaf = chain_without_leaf.release(); |
322 | | |
323 | 513 | X509_free(sess->x509_peer); |
324 | 513 | sess->x509_peer = leaf.release(); |
325 | 513 | return true; |
326 | 1.76k | } |
327 | | |
328 | | static bool ssl_crypto_x509_session_dup(SSL_SESSION *new_session, |
329 | 0 | const SSL_SESSION *session) { |
330 | 0 | new_session->x509_peer = UpRef(session->x509_peer).release(); |
331 | 0 | if (session->x509_chain != nullptr) { |
332 | 0 | new_session->x509_chain = X509_chain_up_ref(session->x509_chain); |
333 | 0 | if (new_session->x509_chain == nullptr) { |
334 | 0 | return false; |
335 | 0 | } |
336 | 0 | } |
337 | 0 | if (session->x509_chain_without_leaf != nullptr) { |
338 | 0 | new_session->x509_chain_without_leaf = |
339 | 0 | X509_chain_up_ref(session->x509_chain_without_leaf); |
340 | 0 | if (new_session->x509_chain_without_leaf == nullptr) { |
341 | 0 | return false; |
342 | 0 | } |
343 | 0 | } |
344 | | |
345 | 0 | return true; |
346 | 0 | } |
347 | | |
348 | 3.78k | static void ssl_crypto_x509_session_clear(SSL_SESSION *session) { |
349 | 3.78k | X509_free(session->x509_peer); |
350 | 3.78k | session->x509_peer = nullptr; |
351 | 3.78k | sk_X509_pop_free(session->x509_chain, X509_free); |
352 | 3.78k | session->x509_chain = nullptr; |
353 | 3.78k | sk_X509_pop_free(session->x509_chain_without_leaf, X509_free); |
354 | 3.78k | session->x509_chain_without_leaf = nullptr; |
355 | 3.78k | } |
356 | | |
357 | | static bool ssl_crypto_x509_session_verify_cert_chain(SSL_SESSION *session, |
358 | | SSL_HANDSHAKE *hs, |
359 | 0 | uint8_t *out_alert) { |
360 | 0 | *out_alert = SSL_AD_INTERNAL_ERROR; |
361 | 0 | STACK_OF(X509) *const cert_chain = session->x509_chain; |
362 | 0 | if (cert_chain == nullptr || sk_X509_num(cert_chain) == 0) { |
363 | 0 | return false; |
364 | 0 | } |
365 | | |
366 | 0 | SSL *const ssl = hs->ssl; |
367 | 0 | SSL_CTX *ssl_ctx = ssl->ctx.get(); |
368 | 0 | X509_STORE *verify_store = ssl_ctx->cert_store; |
369 | 0 | if (hs->config->cert->verify_store != nullptr) { |
370 | 0 | verify_store = hs->config->cert->verify_store; |
371 | 0 | } |
372 | |
|
373 | 0 | X509 *leaf = sk_X509_value(cert_chain, 0); |
374 | 0 | const char *name; |
375 | 0 | size_t name_len; |
376 | 0 | SSL_get0_ech_name_override(ssl, &name, &name_len); |
377 | 0 | UniquePtr<X509_STORE_CTX> ctx(X509_STORE_CTX_new()); |
378 | 0 | if (!ctx || |
379 | 0 | !X509_STORE_CTX_init(ctx.get(), verify_store, leaf, cert_chain) || |
380 | 0 | !X509_STORE_CTX_set_ex_data(ctx.get(), |
381 | 0 | SSL_get_ex_data_X509_STORE_CTX_idx(), ssl) || |
382 | | // We need to inherit the verify parameters. These can be determined by |
383 | | // the context: if its a server it will verify SSL client certificates or |
384 | | // vice versa. |
385 | 0 | !X509_STORE_CTX_set_default(ctx.get(), |
386 | 0 | ssl->server ? "ssl_client" : "ssl_server") || |
387 | | // Anything non-default in "param" should overwrite anything in the ctx. |
388 | 0 | !X509_VERIFY_PARAM_set1(X509_STORE_CTX_get0_param(ctx.get()), |
389 | 0 | hs->config->param) || |
390 | | // ClientHelloOuter connections use a different name. |
391 | 0 | (name_len != 0 && |
392 | 0 | !X509_VERIFY_PARAM_set1_host(X509_STORE_CTX_get0_param(ctx.get()), name, |
393 | 0 | name_len))) { |
394 | 0 | OPENSSL_PUT_ERROR(SSL, ERR_R_X509_LIB); |
395 | 0 | return false; |
396 | 0 | } |
397 | | |
398 | 0 | if (hs->config->verify_callback) { |
399 | 0 | X509_STORE_CTX_set_verify_cb(ctx.get(), hs->config->verify_callback); |
400 | 0 | } |
401 | |
|
402 | 0 | int verify_ret; |
403 | 0 | if (ssl_ctx->app_verify_callback != nullptr) { |
404 | 0 | verify_ret = |
405 | 0 | ssl_ctx->app_verify_callback(ctx.get(), ssl_ctx->app_verify_arg); |
406 | 0 | } else { |
407 | 0 | verify_ret = X509_verify_cert(ctx.get()); |
408 | 0 | } |
409 | |
|
410 | 0 | session->verify_result = X509_STORE_CTX_get_error(ctx.get()); |
411 | | |
412 | | // If |SSL_VERIFY_NONE|, the error is non-fatal, but we keep the result. |
413 | 0 | if (verify_ret <= 0 && hs->config->verify_mode != SSL_VERIFY_NONE) { |
414 | 0 | *out_alert = SSL_alert_from_verify_result(session->verify_result); |
415 | 0 | return false; |
416 | 0 | } |
417 | | |
418 | 0 | ERR_clear_error(); |
419 | 0 | return true; |
420 | 0 | } |
421 | | |
422 | 0 | static void ssl_crypto_x509_hs_flush_cached_ca_names(SSL_HANDSHAKE *hs) { |
423 | 0 | sk_X509_NAME_pop_free(hs->cached_x509_ca_names, X509_NAME_free); |
424 | 0 | hs->cached_x509_ca_names = nullptr; |
425 | 0 | } |
426 | | |
427 | 0 | static bool ssl_crypto_x509_ssl_new(SSL_HANDSHAKE *hs) { |
428 | 0 | hs->config->param = X509_VERIFY_PARAM_new(); |
429 | 0 | if (hs->config->param == nullptr) { |
430 | 0 | return false; |
431 | 0 | } |
432 | 0 | X509_VERIFY_PARAM_inherit(hs->config->param, hs->ssl->ctx->param); |
433 | 0 | return true; |
434 | 0 | } |
435 | | |
436 | 0 | static void ssl_crypto_x509_ssl_flush_cached_client_CA(SSL_CONFIG *cfg) { |
437 | 0 | sk_X509_NAME_pop_free(cfg->cached_x509_client_CA, X509_NAME_free); |
438 | 0 | cfg->cached_x509_client_CA = nullptr; |
439 | 0 | } |
440 | | |
441 | 0 | static void ssl_crypto_x509_ssl_config_free(SSL_CONFIG *cfg) { |
442 | 0 | sk_X509_NAME_pop_free(cfg->cached_x509_client_CA, X509_NAME_free); |
443 | 0 | cfg->cached_x509_client_CA = nullptr; |
444 | 0 | X509_VERIFY_PARAM_free(cfg->param); |
445 | 0 | } |
446 | | |
447 | 0 | static bool ssl_crypto_x509_ssl_auto_chain_if_needed(SSL_HANDSHAKE *hs) { |
448 | | // Only build a chain if there are no intermediates configured and the feature |
449 | | // isn't disabled. |
450 | 0 | if ((hs->ssl->mode & SSL_MODE_NO_AUTO_CHAIN) || |
451 | 0 | !ssl_has_certificate(hs) || hs->config->cert->chain == NULL || |
452 | 0 | sk_CRYPTO_BUFFER_num(hs->config->cert->chain.get()) > 1) { |
453 | 0 | return true; |
454 | 0 | } |
455 | | |
456 | 0 | UniquePtr<X509> leaf(X509_parse_from_buffer( |
457 | 0 | sk_CRYPTO_BUFFER_value(hs->config->cert->chain.get(), 0))); |
458 | 0 | if (!leaf) { |
459 | 0 | OPENSSL_PUT_ERROR(SSL, ERR_R_X509_LIB); |
460 | 0 | return false; |
461 | 0 | } |
462 | | |
463 | 0 | UniquePtr<X509_STORE_CTX> ctx(X509_STORE_CTX_new()); |
464 | 0 | if (!ctx || !X509_STORE_CTX_init(ctx.get(), hs->ssl->ctx->cert_store, |
465 | 0 | leaf.get(), nullptr)) { |
466 | 0 | OPENSSL_PUT_ERROR(SSL, ERR_R_X509_LIB); |
467 | 0 | return false; |
468 | 0 | } |
469 | | |
470 | | // Attempt to build a chain, ignoring the result. |
471 | 0 | X509_verify_cert(ctx.get()); |
472 | 0 | ERR_clear_error(); |
473 | | |
474 | | // Remove the leaf from the generated chain. |
475 | 0 | UniquePtr<STACK_OF(X509)> chain(X509_STORE_CTX_get1_chain(ctx.get())); |
476 | 0 | if (!chain) { |
477 | 0 | return false; |
478 | 0 | } |
479 | 0 | X509_free(sk_X509_shift(chain.get())); |
480 | |
|
481 | 0 | if (!ssl_cert_set_chain(hs->config->cert.get(), chain.get())) { |
482 | 0 | return false; |
483 | 0 | } |
484 | | |
485 | 0 | ssl_crypto_x509_cert_flush_cached_chain(hs->config->cert.get()); |
486 | |
|
487 | 0 | return true; |
488 | 0 | } |
489 | | |
490 | 0 | static void ssl_crypto_x509_ssl_ctx_flush_cached_client_CA(SSL_CTX *ctx) { |
491 | 0 | sk_X509_NAME_pop_free(ctx->cached_x509_client_CA, X509_NAME_free); |
492 | 0 | ctx->cached_x509_client_CA = nullptr; |
493 | 0 | } |
494 | | |
495 | 2 | static bool ssl_crypto_x509_ssl_ctx_new(SSL_CTX *ctx) { |
496 | 2 | ctx->cert_store = X509_STORE_new(); |
497 | 2 | ctx->param = X509_VERIFY_PARAM_new(); |
498 | 2 | return (ctx->cert_store != nullptr && ctx->param != nullptr); |
499 | 2 | } |
500 | | |
501 | 0 | static void ssl_crypto_x509_ssl_ctx_free(SSL_CTX *ctx) { |
502 | 0 | ssl_crypto_x509_ssl_ctx_flush_cached_client_CA(ctx); |
503 | 0 | X509_VERIFY_PARAM_free(ctx->param); |
504 | 0 | X509_STORE_free(ctx->cert_store); |
505 | 0 | } |
506 | | |
507 | | const SSL_X509_METHOD ssl_crypto_x509_method = { |
508 | | ssl_crypto_x509_check_client_CA_list, |
509 | | ssl_crypto_x509_cert_clear, |
510 | | ssl_crypto_x509_cert_free, |
511 | | ssl_crypto_x509_cert_dup, |
512 | | ssl_crypto_x509_cert_flush_cached_chain, |
513 | | ssl_crypto_x509_cert_flush_cached_leaf, |
514 | | ssl_crypto_x509_session_cache_objects, |
515 | | ssl_crypto_x509_session_dup, |
516 | | ssl_crypto_x509_session_clear, |
517 | | ssl_crypto_x509_session_verify_cert_chain, |
518 | | ssl_crypto_x509_hs_flush_cached_ca_names, |
519 | | ssl_crypto_x509_ssl_new, |
520 | | ssl_crypto_x509_ssl_config_free, |
521 | | ssl_crypto_x509_ssl_flush_cached_client_CA, |
522 | | ssl_crypto_x509_ssl_auto_chain_if_needed, |
523 | | ssl_crypto_x509_ssl_ctx_new, |
524 | | ssl_crypto_x509_ssl_ctx_free, |
525 | | ssl_crypto_x509_ssl_ctx_flush_cached_client_CA, |
526 | | }; |
527 | | |
528 | | BSSL_NAMESPACE_END |
529 | | |
530 | | using namespace bssl; |
531 | | |
532 | 0 | X509 *SSL_get_peer_certificate(const SSL *ssl) { |
533 | 0 | check_ssl_x509_method(ssl); |
534 | 0 | if (ssl == NULL) { |
535 | 0 | return NULL; |
536 | 0 | } |
537 | 0 | SSL_SESSION *session = SSL_get_session(ssl); |
538 | 0 | if (session == NULL || session->x509_peer == NULL) { |
539 | 0 | return NULL; |
540 | 0 | } |
541 | 0 | X509_up_ref(session->x509_peer); |
542 | 0 | return session->x509_peer; |
543 | 0 | } |
544 | | |
545 | 0 | STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *ssl) { |
546 | 0 | check_ssl_x509_method(ssl); |
547 | 0 | if (ssl == nullptr) { |
548 | 0 | return nullptr; |
549 | 0 | } |
550 | 0 | SSL_SESSION *session = SSL_get_session(ssl); |
551 | 0 | if (session == nullptr) { |
552 | 0 | return nullptr; |
553 | 0 | } |
554 | | |
555 | | // OpenSSL historically didn't include the leaf certificate in the returned |
556 | | // certificate chain, but only for servers. |
557 | 0 | return ssl->server ? session->x509_chain_without_leaf : session->x509_chain; |
558 | 0 | } |
559 | | |
560 | 0 | STACK_OF(X509) *SSL_get_peer_full_cert_chain(const SSL *ssl) { |
561 | 0 | check_ssl_x509_method(ssl); |
562 | 0 | SSL_SESSION *session = SSL_get_session(ssl); |
563 | 0 | if (session == NULL) { |
564 | 0 | return NULL; |
565 | 0 | } |
566 | | |
567 | 0 | return session->x509_chain; |
568 | 0 | } |
569 | | |
570 | 0 | int SSL_CTX_set_purpose(SSL_CTX *ctx, int purpose) { |
571 | 0 | check_ssl_ctx_x509_method(ctx); |
572 | 0 | return X509_VERIFY_PARAM_set_purpose(ctx->param, purpose); |
573 | 0 | } |
574 | | |
575 | 0 | int SSL_set_purpose(SSL *ssl, int purpose) { |
576 | 0 | check_ssl_x509_method(ssl); |
577 | 0 | if (!ssl->config) { |
578 | 0 | return 0; |
579 | 0 | } |
580 | 0 | return X509_VERIFY_PARAM_set_purpose(ssl->config->param, purpose); |
581 | 0 | } |
582 | | |
583 | 0 | int SSL_CTX_set_trust(SSL_CTX *ctx, int trust) { |
584 | 0 | check_ssl_ctx_x509_method(ctx); |
585 | 0 | return X509_VERIFY_PARAM_set_trust(ctx->param, trust); |
586 | 0 | } |
587 | | |
588 | 0 | int SSL_set_trust(SSL *ssl, int trust) { |
589 | 0 | check_ssl_x509_method(ssl); |
590 | 0 | if (!ssl->config) { |
591 | 0 | return 0; |
592 | 0 | } |
593 | 0 | return X509_VERIFY_PARAM_set_trust(ssl->config->param, trust); |
594 | 0 | } |
595 | | |
596 | 0 | int SSL_CTX_set1_param(SSL_CTX *ctx, const X509_VERIFY_PARAM *param) { |
597 | 0 | check_ssl_ctx_x509_method(ctx); |
598 | 0 | return X509_VERIFY_PARAM_set1(ctx->param, param); |
599 | 0 | } |
600 | | |
601 | 0 | int SSL_set1_param(SSL *ssl, const X509_VERIFY_PARAM *param) { |
602 | 0 | check_ssl_x509_method(ssl); |
603 | 0 | if (!ssl->config) { |
604 | 0 | return 0; |
605 | 0 | } |
606 | 0 | return X509_VERIFY_PARAM_set1(ssl->config->param, param); |
607 | 0 | } |
608 | | |
609 | 0 | X509_VERIFY_PARAM *SSL_CTX_get0_param(SSL_CTX *ctx) { |
610 | 0 | check_ssl_ctx_x509_method(ctx); |
611 | 0 | return ctx->param; |
612 | 0 | } |
613 | | |
614 | 0 | X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl) { |
615 | 0 | check_ssl_x509_method(ssl); |
616 | 0 | if (!ssl->config) { |
617 | 0 | assert(ssl->config); |
618 | 0 | return 0; |
619 | 0 | } |
620 | 0 | return ssl->config->param; |
621 | 0 | } |
622 | | |
623 | 0 | int SSL_get_verify_depth(const SSL *ssl) { |
624 | 0 | check_ssl_x509_method(ssl); |
625 | 0 | if (!ssl->config) { |
626 | 0 | assert(ssl->config); |
627 | 0 | return 0; |
628 | 0 | } |
629 | 0 | return X509_VERIFY_PARAM_get_depth(ssl->config->param); |
630 | 0 | } |
631 | | |
632 | 0 | int (*SSL_get_verify_callback(const SSL *ssl))(int, X509_STORE_CTX *) { |
633 | 0 | check_ssl_x509_method(ssl); |
634 | 0 | if (!ssl->config) { |
635 | 0 | assert(ssl->config); |
636 | 0 | return 0; |
637 | 0 | } |
638 | 0 | return ssl->config->verify_callback; |
639 | 0 | } |
640 | | |
641 | 0 | int SSL_CTX_get_verify_mode(const SSL_CTX *ctx) { |
642 | 0 | check_ssl_ctx_x509_method(ctx); |
643 | 0 | return ctx->verify_mode; |
644 | 0 | } |
645 | | |
646 | 0 | int SSL_CTX_get_verify_depth(const SSL_CTX *ctx) { |
647 | 0 | check_ssl_ctx_x509_method(ctx); |
648 | 0 | return X509_VERIFY_PARAM_get_depth(ctx->param); |
649 | 0 | } |
650 | | |
651 | | int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))( |
652 | 0 | int ok, X509_STORE_CTX *store_ctx) { |
653 | 0 | check_ssl_ctx_x509_method(ctx); |
654 | 0 | return ctx->default_verify_callback; |
655 | 0 | } |
656 | | |
657 | | void SSL_set_verify(SSL *ssl, int mode, |
658 | 0 | int (*callback)(int ok, X509_STORE_CTX *store_ctx)) { |
659 | 0 | check_ssl_x509_method(ssl); |
660 | 0 | if (!ssl->config) { |
661 | 0 | return; |
662 | 0 | } |
663 | 0 | ssl->config->verify_mode = mode; |
664 | 0 | if (callback != NULL) { |
665 | 0 | ssl->config->verify_callback = callback; |
666 | 0 | } |
667 | 0 | } |
668 | | |
669 | 0 | void SSL_set_verify_depth(SSL *ssl, int depth) { |
670 | 0 | check_ssl_x509_method(ssl); |
671 | 0 | if (!ssl->config) { |
672 | 0 | return; |
673 | 0 | } |
674 | 0 | X509_VERIFY_PARAM_set_depth(ssl->config->param, depth); |
675 | 0 | } |
676 | | |
677 | | void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, |
678 | | int (*cb)(X509_STORE_CTX *store_ctx, |
679 | | void *arg), |
680 | 0 | void *arg) { |
681 | 0 | check_ssl_ctx_x509_method(ctx); |
682 | 0 | ctx->app_verify_callback = cb; |
683 | 0 | ctx->app_verify_arg = arg; |
684 | 0 | } |
685 | | |
686 | | void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, |
687 | 0 | int (*cb)(int, X509_STORE_CTX *)) { |
688 | 0 | check_ssl_ctx_x509_method(ctx); |
689 | 0 | ctx->verify_mode = mode; |
690 | 0 | ctx->default_verify_callback = cb; |
691 | 0 | } |
692 | | |
693 | 0 | void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth) { |
694 | 0 | check_ssl_ctx_x509_method(ctx); |
695 | 0 | X509_VERIFY_PARAM_set_depth(ctx->param, depth); |
696 | 0 | } |
697 | | |
698 | 0 | int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx) { |
699 | 0 | check_ssl_ctx_x509_method(ctx); |
700 | 0 | return X509_STORE_set_default_paths(ctx->cert_store); |
701 | 0 | } |
702 | | |
703 | | int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *ca_file, |
704 | 0 | const char *ca_dir) { |
705 | 0 | check_ssl_ctx_x509_method(ctx); |
706 | 0 | return X509_STORE_load_locations(ctx->cert_store, ca_file, ca_dir); |
707 | 0 | } |
708 | | |
709 | 0 | long SSL_get_verify_result(const SSL *ssl) { |
710 | 0 | check_ssl_x509_method(ssl); |
711 | 0 | SSL_SESSION *session = SSL_get_session(ssl); |
712 | 0 | if (session == NULL) { |
713 | 0 | return X509_V_ERR_INVALID_CALL; |
714 | 0 | } |
715 | 0 | return session->verify_result; |
716 | 0 | } |
717 | | |
718 | 0 | X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx) { |
719 | 0 | check_ssl_ctx_x509_method(ctx); |
720 | 0 | return ctx->cert_store; |
721 | 0 | } |
722 | | |
723 | 0 | void SSL_CTX_set_cert_store(SSL_CTX *ctx, X509_STORE *store) { |
724 | 0 | check_ssl_ctx_x509_method(ctx); |
725 | 0 | X509_STORE_free(ctx->cert_store); |
726 | 0 | ctx->cert_store = store; |
727 | 0 | } |
728 | | |
729 | 0 | static int ssl_use_certificate(CERT *cert, X509 *x) { |
730 | 0 | if (x == NULL) { |
731 | 0 | OPENSSL_PUT_ERROR(SSL, ERR_R_PASSED_NULL_PARAMETER); |
732 | 0 | return 0; |
733 | 0 | } |
734 | | |
735 | 0 | UniquePtr<CRYPTO_BUFFER> buffer = x509_to_buffer(x); |
736 | 0 | if (!buffer) { |
737 | 0 | return 0; |
738 | 0 | } |
739 | | |
740 | 0 | return ssl_set_cert(cert, std::move(buffer)); |
741 | 0 | } |
742 | | |
743 | 0 | int SSL_use_certificate(SSL *ssl, X509 *x) { |
744 | 0 | check_ssl_x509_method(ssl); |
745 | 0 | if (!ssl->config) { |
746 | 0 | return 0; |
747 | 0 | } |
748 | 0 | return ssl_use_certificate(ssl->config->cert.get(), x); |
749 | 0 | } |
750 | | |
751 | 0 | int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x) { |
752 | 0 | check_ssl_ctx_x509_method(ctx); |
753 | 0 | return ssl_use_certificate(ctx->cert.get(), x); |
754 | 0 | } |
755 | | |
756 | | // ssl_cert_cache_leaf_cert sets |cert->x509_leaf|, if currently NULL, from the |
757 | | // first element of |cert->chain|. |
758 | 0 | static int ssl_cert_cache_leaf_cert(CERT *cert) { |
759 | 0 | assert(cert->x509_method); |
760 | | |
761 | 0 | if (cert->x509_leaf != NULL || |
762 | 0 | cert->chain == NULL) { |
763 | 0 | return 1; |
764 | 0 | } |
765 | | |
766 | 0 | CRYPTO_BUFFER *leaf = sk_CRYPTO_BUFFER_value(cert->chain.get(), 0); |
767 | 0 | if (!leaf) { |
768 | 0 | return 1; |
769 | 0 | } |
770 | | |
771 | 0 | cert->x509_leaf = X509_parse_from_buffer(leaf); |
772 | 0 | return cert->x509_leaf != NULL; |
773 | 0 | } |
774 | | |
775 | 0 | static X509 *ssl_cert_get0_leaf(CERT *cert) { |
776 | 0 | if (cert->x509_leaf == NULL && |
777 | 0 | !ssl_cert_cache_leaf_cert(cert)) { |
778 | 0 | return NULL; |
779 | 0 | } |
780 | | |
781 | 0 | return cert->x509_leaf; |
782 | 0 | } |
783 | | |
784 | 0 | X509 *SSL_get_certificate(const SSL *ssl) { |
785 | 0 | check_ssl_x509_method(ssl); |
786 | 0 | if (!ssl->config) { |
787 | 0 | assert(ssl->config); |
788 | 0 | return 0; |
789 | 0 | } |
790 | 0 | return ssl_cert_get0_leaf(ssl->config->cert.get()); |
791 | 0 | } |
792 | | |
793 | 0 | X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx) { |
794 | 0 | check_ssl_ctx_x509_method(ctx); |
795 | 0 | MutexWriteLock lock(const_cast<CRYPTO_MUTEX*>(&ctx->lock)); |
796 | 0 | return ssl_cert_get0_leaf(ctx->cert.get()); |
797 | 0 | } |
798 | | |
799 | 0 | static int ssl_cert_set0_chain(CERT *cert, STACK_OF(X509) *chain) { |
800 | 0 | if (!ssl_cert_set_chain(cert, chain)) { |
801 | 0 | return 0; |
802 | 0 | } |
803 | | |
804 | 0 | sk_X509_pop_free(chain, X509_free); |
805 | 0 | ssl_crypto_x509_cert_flush_cached_chain(cert); |
806 | 0 | return 1; |
807 | 0 | } |
808 | | |
809 | 0 | static int ssl_cert_set1_chain(CERT *cert, STACK_OF(X509) *chain) { |
810 | 0 | if (!ssl_cert_set_chain(cert, chain)) { |
811 | 0 | return 0; |
812 | 0 | } |
813 | | |
814 | 0 | ssl_crypto_x509_cert_flush_cached_chain(cert); |
815 | 0 | return 1; |
816 | 0 | } |
817 | | |
818 | 0 | static int ssl_cert_append_cert(CERT *cert, X509 *x509) { |
819 | 0 | assert(cert->x509_method); |
820 | | |
821 | 0 | UniquePtr<CRYPTO_BUFFER> buffer = x509_to_buffer(x509); |
822 | 0 | if (!buffer) { |
823 | 0 | return 0; |
824 | 0 | } |
825 | | |
826 | 0 | if (cert->chain != NULL) { |
827 | 0 | return PushToStack(cert->chain.get(), std::move(buffer)); |
828 | 0 | } |
829 | | |
830 | 0 | cert->chain = new_leafless_chain(); |
831 | 0 | if (!cert->chain || |
832 | 0 | !PushToStack(cert->chain.get(), std::move(buffer))) { |
833 | 0 | cert->chain.reset(); |
834 | 0 | return 0; |
835 | 0 | } |
836 | | |
837 | 0 | return 1; |
838 | 0 | } |
839 | | |
840 | 0 | static int ssl_cert_add0_chain_cert(CERT *cert, X509 *x509) { |
841 | 0 | if (!ssl_cert_append_cert(cert, x509)) { |
842 | 0 | return 0; |
843 | 0 | } |
844 | | |
845 | 0 | X509_free(cert->x509_stash); |
846 | 0 | cert->x509_stash = x509; |
847 | 0 | ssl_crypto_x509_cert_flush_cached_chain(cert); |
848 | 0 | return 1; |
849 | 0 | } |
850 | | |
851 | 0 | static int ssl_cert_add1_chain_cert(CERT *cert, X509 *x509) { |
852 | 0 | if (!ssl_cert_append_cert(cert, x509)) { |
853 | 0 | return 0; |
854 | 0 | } |
855 | | |
856 | 0 | ssl_crypto_x509_cert_flush_cached_chain(cert); |
857 | 0 | return 1; |
858 | 0 | } |
859 | | |
860 | 0 | int SSL_CTX_set0_chain(SSL_CTX *ctx, STACK_OF(X509) *chain) { |
861 | 0 | check_ssl_ctx_x509_method(ctx); |
862 | 0 | return ssl_cert_set0_chain(ctx->cert.get(), chain); |
863 | 0 | } |
864 | | |
865 | 0 | int SSL_CTX_set1_chain(SSL_CTX *ctx, STACK_OF(X509) *chain) { |
866 | 0 | check_ssl_ctx_x509_method(ctx); |
867 | 0 | return ssl_cert_set1_chain(ctx->cert.get(), chain); |
868 | 0 | } |
869 | | |
870 | 0 | int SSL_set0_chain(SSL *ssl, STACK_OF(X509) *chain) { |
871 | 0 | check_ssl_x509_method(ssl); |
872 | 0 | if (!ssl->config) { |
873 | 0 | return 0; |
874 | 0 | } |
875 | 0 | return ssl_cert_set0_chain(ssl->config->cert.get(), chain); |
876 | 0 | } |
877 | | |
878 | 0 | int SSL_set1_chain(SSL *ssl, STACK_OF(X509) *chain) { |
879 | 0 | check_ssl_x509_method(ssl); |
880 | 0 | if (!ssl->config) { |
881 | 0 | return 0; |
882 | 0 | } |
883 | 0 | return ssl_cert_set1_chain(ssl->config->cert.get(), chain); |
884 | 0 | } |
885 | | |
886 | 0 | int SSL_CTX_add0_chain_cert(SSL_CTX *ctx, X509 *x509) { |
887 | 0 | check_ssl_ctx_x509_method(ctx); |
888 | 0 | return ssl_cert_add0_chain_cert(ctx->cert.get(), x509); |
889 | 0 | } |
890 | | |
891 | 0 | int SSL_CTX_add1_chain_cert(SSL_CTX *ctx, X509 *x509) { |
892 | 0 | check_ssl_ctx_x509_method(ctx); |
893 | 0 | return ssl_cert_add1_chain_cert(ctx->cert.get(), x509); |
894 | 0 | } |
895 | | |
896 | 0 | int SSL_CTX_add_extra_chain_cert(SSL_CTX *ctx, X509 *x509) { |
897 | 0 | check_ssl_ctx_x509_method(ctx); |
898 | 0 | return SSL_CTX_add0_chain_cert(ctx, x509); |
899 | 0 | } |
900 | | |
901 | 0 | int SSL_add0_chain_cert(SSL *ssl, X509 *x509) { |
902 | 0 | check_ssl_x509_method(ssl); |
903 | 0 | if (!ssl->config) { |
904 | 0 | return 0; |
905 | 0 | } |
906 | 0 | return ssl_cert_add0_chain_cert(ssl->config->cert.get(), x509); |
907 | 0 | } |
908 | | |
909 | 0 | int SSL_add1_chain_cert(SSL *ssl, X509 *x509) { |
910 | 0 | check_ssl_x509_method(ssl); |
911 | 0 | if (!ssl->config) { |
912 | 0 | return 0; |
913 | 0 | } |
914 | 0 | return ssl_cert_add1_chain_cert(ssl->config->cert.get(), x509); |
915 | 0 | } |
916 | | |
917 | 0 | int SSL_CTX_clear_chain_certs(SSL_CTX *ctx) { |
918 | 0 | check_ssl_ctx_x509_method(ctx); |
919 | 0 | return SSL_CTX_set0_chain(ctx, NULL); |
920 | 0 | } |
921 | | |
922 | 0 | int SSL_CTX_clear_extra_chain_certs(SSL_CTX *ctx) { |
923 | 0 | check_ssl_ctx_x509_method(ctx); |
924 | 0 | return SSL_CTX_clear_chain_certs(ctx); |
925 | 0 | } |
926 | | |
927 | 0 | int SSL_clear_chain_certs(SSL *ssl) { |
928 | 0 | check_ssl_x509_method(ssl); |
929 | 0 | return SSL_set0_chain(ssl, NULL); |
930 | 0 | } |
931 | | |
932 | | // ssl_cert_cache_chain_certs fills in |cert->x509_chain| from elements 1.. of |
933 | | // |cert->chain|. |
934 | 0 | static int ssl_cert_cache_chain_certs(CERT *cert) { |
935 | 0 | assert(cert->x509_method); |
936 | | |
937 | 0 | if (cert->x509_chain != nullptr || |
938 | 0 | cert->chain == nullptr || |
939 | 0 | sk_CRYPTO_BUFFER_num(cert->chain.get()) < 2) { |
940 | 0 | return 1; |
941 | 0 | } |
942 | | |
943 | 0 | UniquePtr<STACK_OF(X509)> chain(sk_X509_new_null()); |
944 | 0 | if (!chain) { |
945 | 0 | return 0; |
946 | 0 | } |
947 | | |
948 | 0 | for (size_t i = 1; i < sk_CRYPTO_BUFFER_num(cert->chain.get()); i++) { |
949 | 0 | CRYPTO_BUFFER *buffer = sk_CRYPTO_BUFFER_value(cert->chain.get(), i); |
950 | 0 | UniquePtr<X509> x509(X509_parse_from_buffer(buffer)); |
951 | 0 | if (!x509 || |
952 | 0 | !PushToStack(chain.get(), std::move(x509))) { |
953 | 0 | return 0; |
954 | 0 | } |
955 | 0 | } |
956 | | |
957 | 0 | cert->x509_chain = chain.release(); |
958 | 0 | return 1; |
959 | 0 | } |
960 | | |
961 | 0 | int SSL_CTX_get0_chain_certs(const SSL_CTX *ctx, STACK_OF(X509) **out_chain) { |
962 | 0 | check_ssl_ctx_x509_method(ctx); |
963 | 0 | MutexWriteLock lock(const_cast<CRYPTO_MUTEX*>(&ctx->lock)); |
964 | 0 | if (!ssl_cert_cache_chain_certs(ctx->cert.get())) { |
965 | 0 | *out_chain = NULL; |
966 | 0 | return 0; |
967 | 0 | } |
968 | | |
969 | 0 | *out_chain = ctx->cert->x509_chain; |
970 | 0 | return 1; |
971 | 0 | } |
972 | | |
973 | | int SSL_CTX_get_extra_chain_certs(const SSL_CTX *ctx, |
974 | 0 | STACK_OF(X509) **out_chain) { |
975 | 0 | return SSL_CTX_get0_chain_certs(ctx, out_chain); |
976 | 0 | } |
977 | | |
978 | 0 | int SSL_get0_chain_certs(const SSL *ssl, STACK_OF(X509) **out_chain) { |
979 | 0 | check_ssl_x509_method(ssl); |
980 | 0 | if (!ssl->config) { |
981 | 0 | assert(ssl->config); |
982 | 0 | return 0; |
983 | 0 | } |
984 | 0 | if (!ssl_cert_cache_chain_certs(ssl->config->cert.get())) { |
985 | 0 | *out_chain = NULL; |
986 | 0 | return 0; |
987 | 0 | } |
988 | | |
989 | 0 | *out_chain = ssl->config->cert->x509_chain; |
990 | 0 | return 1; |
991 | 0 | } |
992 | | |
993 | 0 | SSL_SESSION *d2i_SSL_SESSION_bio(BIO *bio, SSL_SESSION **out) { |
994 | 0 | uint8_t *data; |
995 | 0 | size_t len; |
996 | 0 | if (!BIO_read_asn1(bio, &data, &len, 1024 * 1024)) { |
997 | 0 | return 0; |
998 | 0 | } |
999 | 0 | bssl::UniquePtr<uint8_t> free_data(data); |
1000 | 0 | const uint8_t *ptr = data; |
1001 | 0 | return d2i_SSL_SESSION(out, &ptr, static_cast<long>(len)); |
1002 | 0 | } |
1003 | | |
1004 | 0 | int i2d_SSL_SESSION_bio(BIO *bio, const SSL_SESSION *session) { |
1005 | 0 | uint8_t *data; |
1006 | 0 | size_t len; |
1007 | 0 | if (!SSL_SESSION_to_bytes(session, &data, &len)) { |
1008 | 0 | return 0; |
1009 | 0 | } |
1010 | 0 | bssl::UniquePtr<uint8_t> free_data(data); |
1011 | 0 | return BIO_write_all(bio, data, len); |
1012 | 0 | } |
1013 | | |
1014 | | IMPLEMENT_PEM_rw(SSL_SESSION, SSL_SESSION, PEM_STRING_SSL_SESSION, SSL_SESSION) |
1015 | | |
1016 | 0 | SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const uint8_t **pp, long length) { |
1017 | 0 | if (length < 0) { |
1018 | 0 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
1019 | 0 | return NULL; |
1020 | 0 | } |
1021 | | |
1022 | 0 | CBS cbs; |
1023 | 0 | CBS_init(&cbs, *pp, length); |
1024 | |
|
1025 | 0 | UniquePtr<SSL_SESSION> ret = SSL_SESSION_parse(&cbs, &ssl_crypto_x509_method, |
1026 | 0 | NULL /* no buffer pool */); |
1027 | 0 | if (!ret) { |
1028 | 0 | return NULL; |
1029 | 0 | } |
1030 | | |
1031 | 0 | if (a) { |
1032 | 0 | SSL_SESSION_free(*a); |
1033 | 0 | *a = ret.get(); |
1034 | 0 | } |
1035 | 0 | *pp = CBS_data(&cbs); |
1036 | 0 | return ret.release(); |
1037 | 0 | } |
1038 | | |
1039 | 0 | STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *list) { |
1040 | | // TODO(https://crbug.com/boringssl/407): |X509_NAME_dup| should be const. |
1041 | 0 | auto name_dup = [](const X509_NAME *name) { |
1042 | 0 | return X509_NAME_dup(const_cast<X509_NAME *>(name)); |
1043 | 0 | }; |
1044 | 0 | return sk_X509_NAME_deep_copy(list, name_dup, X509_NAME_free); |
1045 | 0 | } |
1046 | | |
1047 | | static void set_client_CA_list(UniquePtr<STACK_OF(CRYPTO_BUFFER)> *ca_list, |
1048 | | const STACK_OF(X509_NAME) *name_list, |
1049 | 0 | CRYPTO_BUFFER_POOL *pool) { |
1050 | 0 | UniquePtr<STACK_OF(CRYPTO_BUFFER)> buffers(sk_CRYPTO_BUFFER_new_null()); |
1051 | 0 | if (!buffers) { |
1052 | 0 | return; |
1053 | 0 | } |
1054 | | |
1055 | 0 | for (X509_NAME *name : name_list) { |
1056 | 0 | uint8_t *outp = NULL; |
1057 | 0 | int len = i2d_X509_NAME(name, &outp); |
1058 | 0 | if (len < 0) { |
1059 | 0 | return; |
1060 | 0 | } |
1061 | | |
1062 | 0 | UniquePtr<CRYPTO_BUFFER> buffer(CRYPTO_BUFFER_new(outp, len, pool)); |
1063 | 0 | OPENSSL_free(outp); |
1064 | 0 | if (!buffer || |
1065 | 0 | !PushToStack(buffers.get(), std::move(buffer))) { |
1066 | 0 | return; |
1067 | 0 | } |
1068 | 0 | } |
1069 | | |
1070 | 0 | *ca_list = std::move(buffers); |
1071 | 0 | } |
1072 | | |
1073 | 0 | void SSL_set_client_CA_list(SSL *ssl, STACK_OF(X509_NAME) *name_list) { |
1074 | 0 | check_ssl_x509_method(ssl); |
1075 | 0 | if (!ssl->config) { |
1076 | 0 | return; |
1077 | 0 | } |
1078 | 0 | ssl->ctx->x509_method->ssl_flush_cached_client_CA(ssl->config.get()); |
1079 | 0 | set_client_CA_list(&ssl->config->client_CA, name_list, ssl->ctx->pool); |
1080 | 0 | sk_X509_NAME_pop_free(name_list, X509_NAME_free); |
1081 | 0 | } |
1082 | | |
1083 | 0 | void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list) { |
1084 | 0 | check_ssl_ctx_x509_method(ctx); |
1085 | 0 | ctx->x509_method->ssl_ctx_flush_cached_client_CA(ctx); |
1086 | 0 | set_client_CA_list(&ctx->client_CA, name_list, ctx->pool); |
1087 | 0 | sk_X509_NAME_pop_free(name_list, X509_NAME_free); |
1088 | 0 | } |
1089 | | |
1090 | | static STACK_OF(X509_NAME) * |
1091 | | buffer_names_to_x509(const STACK_OF(CRYPTO_BUFFER) *names, |
1092 | 0 | STACK_OF(X509_NAME) **cached) { |
1093 | 0 | if (names == NULL) { |
1094 | 0 | return NULL; |
1095 | 0 | } |
1096 | | |
1097 | 0 | if (*cached != NULL) { |
1098 | 0 | return *cached; |
1099 | 0 | } |
1100 | | |
1101 | 0 | UniquePtr<STACK_OF(X509_NAME)> new_cache(sk_X509_NAME_new_null()); |
1102 | 0 | if (!new_cache) { |
1103 | 0 | return NULL; |
1104 | 0 | } |
1105 | | |
1106 | 0 | for (const CRYPTO_BUFFER *buffer : names) { |
1107 | 0 | const uint8_t *inp = CRYPTO_BUFFER_data(buffer); |
1108 | 0 | UniquePtr<X509_NAME> name( |
1109 | 0 | d2i_X509_NAME(nullptr, &inp, CRYPTO_BUFFER_len(buffer))); |
1110 | 0 | if (!name || |
1111 | 0 | inp != CRYPTO_BUFFER_data(buffer) + CRYPTO_BUFFER_len(buffer) || |
1112 | 0 | !PushToStack(new_cache.get(), std::move(name))) { |
1113 | 0 | return NULL; |
1114 | 0 | } |
1115 | 0 | } |
1116 | | |
1117 | 0 | *cached = new_cache.release(); |
1118 | 0 | return *cached; |
1119 | 0 | } |
1120 | | |
1121 | 0 | STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *ssl) { |
1122 | 0 | check_ssl_x509_method(ssl); |
1123 | 0 | if (!ssl->config) { |
1124 | 0 | assert(ssl->config); |
1125 | 0 | return NULL; |
1126 | 0 | } |
1127 | | // For historical reasons, this function is used both to query configuration |
1128 | | // state on a server as well as handshake state on a client. However, whether |
1129 | | // |ssl| is a client or server is not known until explicitly configured with |
1130 | | // |SSL_set_connect_state|. If |do_handshake| is NULL, |ssl| is in an |
1131 | | // indeterminate mode and |ssl->server| is unset. |
1132 | 0 | if (ssl->do_handshake != NULL && !ssl->server) { |
1133 | 0 | if (ssl->s3->hs != NULL) { |
1134 | 0 | return buffer_names_to_x509(ssl->s3->hs->ca_names.get(), |
1135 | 0 | &ssl->s3->hs->cached_x509_ca_names); |
1136 | 0 | } |
1137 | | |
1138 | 0 | return NULL; |
1139 | 0 | } |
1140 | | |
1141 | 0 | if (ssl->config->client_CA != NULL) { |
1142 | 0 | return buffer_names_to_x509( |
1143 | 0 | ssl->config->client_CA.get(), |
1144 | 0 | (STACK_OF(X509_NAME) **)&ssl->config->cached_x509_client_CA); |
1145 | 0 | } |
1146 | 0 | return SSL_CTX_get_client_CA_list(ssl->ctx.get()); |
1147 | 0 | } |
1148 | | |
1149 | 0 | STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *ctx) { |
1150 | 0 | check_ssl_ctx_x509_method(ctx); |
1151 | | // This is a logically const operation that may be called on multiple threads, |
1152 | | // so it needs to lock around updating |cached_x509_client_CA|. |
1153 | 0 | MutexWriteLock lock(const_cast<CRYPTO_MUTEX *>(&ctx->lock)); |
1154 | 0 | return buffer_names_to_x509( |
1155 | 0 | ctx->client_CA.get(), |
1156 | 0 | const_cast<STACK_OF(X509_NAME) **>(&ctx->cached_x509_client_CA)); |
1157 | 0 | } |
1158 | | |
1159 | | static int add_client_CA(UniquePtr<STACK_OF(CRYPTO_BUFFER)> *names, X509 *x509, |
1160 | 0 | CRYPTO_BUFFER_POOL *pool) { |
1161 | 0 | if (x509 == NULL) { |
1162 | 0 | return 0; |
1163 | 0 | } |
1164 | | |
1165 | 0 | uint8_t *outp = NULL; |
1166 | 0 | int len = i2d_X509_NAME(X509_get_subject_name(x509), &outp); |
1167 | 0 | if (len < 0) { |
1168 | 0 | return 0; |
1169 | 0 | } |
1170 | | |
1171 | 0 | UniquePtr<CRYPTO_BUFFER> buffer(CRYPTO_BUFFER_new(outp, len, pool)); |
1172 | 0 | OPENSSL_free(outp); |
1173 | 0 | if (!buffer) { |
1174 | 0 | return 0; |
1175 | 0 | } |
1176 | | |
1177 | 0 | int alloced = 0; |
1178 | 0 | if (*names == nullptr) { |
1179 | 0 | names->reset(sk_CRYPTO_BUFFER_new_null()); |
1180 | 0 | alloced = 1; |
1181 | |
|
1182 | 0 | if (*names == NULL) { |
1183 | 0 | return 0; |
1184 | 0 | } |
1185 | 0 | } |
1186 | | |
1187 | 0 | if (!PushToStack(names->get(), std::move(buffer))) { |
1188 | 0 | if (alloced) { |
1189 | 0 | names->reset(); |
1190 | 0 | } |
1191 | 0 | return 0; |
1192 | 0 | } |
1193 | | |
1194 | 0 | return 1; |
1195 | 0 | } |
1196 | | |
1197 | 0 | int SSL_add_client_CA(SSL *ssl, X509 *x509) { |
1198 | 0 | check_ssl_x509_method(ssl); |
1199 | 0 | if (!ssl->config) { |
1200 | 0 | return 0; |
1201 | 0 | } |
1202 | 0 | if (!add_client_CA(&ssl->config->client_CA, x509, ssl->ctx->pool)) { |
1203 | 0 | return 0; |
1204 | 0 | } |
1205 | | |
1206 | 0 | ssl_crypto_x509_ssl_flush_cached_client_CA(ssl->config.get()); |
1207 | 0 | return 1; |
1208 | 0 | } |
1209 | | |
1210 | 0 | int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x509) { |
1211 | 0 | check_ssl_ctx_x509_method(ctx); |
1212 | 0 | if (!add_client_CA(&ctx->client_CA, x509, ctx->pool)) { |
1213 | 0 | return 0; |
1214 | 0 | } |
1215 | | |
1216 | 0 | ssl_crypto_x509_ssl_ctx_flush_cached_client_CA(ctx); |
1217 | 0 | return 1; |
1218 | 0 | } |
1219 | | |
1220 | 0 | static int do_client_cert_cb(SSL *ssl, void *arg) { |
1221 | | // Should only be called during handshake, but check to be sure. |
1222 | 0 | if (!ssl->config) { |
1223 | 0 | assert(ssl->config); |
1224 | 0 | return -1; |
1225 | 0 | } |
1226 | | |
1227 | 0 | if (ssl_has_certificate(ssl->s3->hs.get()) || |
1228 | 0 | ssl->ctx->client_cert_cb == NULL) { |
1229 | 0 | return 1; |
1230 | 0 | } |
1231 | | |
1232 | 0 | X509 *x509 = NULL; |
1233 | 0 | EVP_PKEY *pkey = NULL; |
1234 | 0 | int ret = ssl->ctx->client_cert_cb(ssl, &x509, &pkey); |
1235 | 0 | if (ret < 0) { |
1236 | 0 | return -1; |
1237 | 0 | } |
1238 | 0 | UniquePtr<X509> free_x509(x509); |
1239 | 0 | UniquePtr<EVP_PKEY> free_pkey(pkey); |
1240 | |
|
1241 | 0 | if (ret != 0) { |
1242 | 0 | if (!SSL_use_certificate(ssl, x509) || |
1243 | 0 | !SSL_use_PrivateKey(ssl, pkey)) { |
1244 | 0 | return 0; |
1245 | 0 | } |
1246 | 0 | } |
1247 | | |
1248 | 0 | return 1; |
1249 | 0 | } |
1250 | | |
1251 | | void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx, int (*cb)(SSL *ssl, |
1252 | | X509 **out_x509, |
1253 | 0 | EVP_PKEY **out_pkey)) { |
1254 | 0 | check_ssl_ctx_x509_method(ctx); |
1255 | | // Emulate the old client certificate callback with the new one. |
1256 | 0 | SSL_CTX_set_cert_cb(ctx, do_client_cert_cb, NULL); |
1257 | 0 | ctx->client_cert_cb = cb; |
1258 | 0 | } |
1259 | | |
1260 | | static int set_cert_store(X509_STORE **store_ptr, X509_STORE *new_store, |
1261 | 0 | int take_ref) { |
1262 | 0 | X509_STORE_free(*store_ptr); |
1263 | 0 | *store_ptr = new_store; |
1264 | |
|
1265 | 0 | if (new_store != NULL && take_ref) { |
1266 | 0 | X509_STORE_up_ref(new_store); |
1267 | 0 | } |
1268 | |
|
1269 | 0 | return 1; |
1270 | 0 | } |
1271 | | |
1272 | 0 | int SSL_get_ex_data_X509_STORE_CTX_idx(void) { |
1273 | | // The ex_data index to go from |X509_STORE_CTX| to |SSL| always uses the |
1274 | | // reserved app_data slot. Before ex_data was introduced, app_data was used. |
1275 | | // Avoid breaking any software which assumes |X509_STORE_CTX_get_app_data| |
1276 | | // works. |
1277 | 0 | return 0; |
1278 | 0 | } |
1279 | | |
1280 | 0 | int SSL_CTX_set0_verify_cert_store(SSL_CTX *ctx, X509_STORE *store) { |
1281 | 0 | check_ssl_ctx_x509_method(ctx); |
1282 | 0 | return set_cert_store(&ctx->cert->verify_store, store, 0); |
1283 | 0 | } |
1284 | | |
1285 | 0 | int SSL_CTX_set1_verify_cert_store(SSL_CTX *ctx, X509_STORE *store) { |
1286 | 0 | check_ssl_ctx_x509_method(ctx); |
1287 | 0 | return set_cert_store(&ctx->cert->verify_store, store, 1); |
1288 | 0 | } |
1289 | | |
1290 | 0 | int SSL_set0_verify_cert_store(SSL *ssl, X509_STORE *store) { |
1291 | 0 | check_ssl_x509_method(ssl); |
1292 | 0 | if (!ssl->config) { |
1293 | 0 | return 0; |
1294 | 0 | } |
1295 | 0 | return set_cert_store(&ssl->config->cert->verify_store, store, 0); |
1296 | 0 | } |
1297 | | |
1298 | 0 | int SSL_set1_verify_cert_store(SSL *ssl, X509_STORE *store) { |
1299 | 0 | check_ssl_x509_method(ssl); |
1300 | 0 | if (!ssl->config) { |
1301 | 0 | return 0; |
1302 | 0 | } |
1303 | 0 | return set_cert_store(&ssl->config->cert->verify_store, store, 1); |
1304 | 0 | } |
1305 | | |
1306 | 0 | int SSL_set1_host(SSL *ssl, const char *hostname) { |
1307 | 0 | check_ssl_x509_method(ssl); |
1308 | 0 | if (!ssl->config) { |
1309 | 0 | return 0; |
1310 | 0 | } |
1311 | 0 | return X509_VERIFY_PARAM_set1_host(ssl->config->param, hostname, |
1312 | 0 | strlen(hostname)); |
1313 | 0 | } |
1314 | | |
1315 | 0 | void SSL_set_hostflags(SSL *ssl, unsigned flags) { |
1316 | 0 | check_ssl_x509_method(ssl); |
1317 | 0 | if (!ssl->config) { |
1318 | 0 | return; |
1319 | 0 | } |
1320 | 0 | X509_VERIFY_PARAM_set_hostflags(ssl->config->param, flags); |
1321 | 0 | } |
1322 | | |
1323 | 0 | int SSL_alert_from_verify_result(long result) { |
1324 | 0 | switch (result) { |
1325 | 0 | case X509_V_ERR_CERT_CHAIN_TOO_LONG: |
1326 | 0 | case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: |
1327 | 0 | case X509_V_ERR_INVALID_CA: |
1328 | 0 | case X509_V_ERR_PATH_LENGTH_EXCEEDED: |
1329 | 0 | case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: |
1330 | 0 | case X509_V_ERR_UNABLE_TO_GET_CRL: |
1331 | 0 | case X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER: |
1332 | 0 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: |
1333 | 0 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: |
1334 | 0 | case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: |
1335 | 0 | return SSL_AD_UNKNOWN_CA; |
1336 | | |
1337 | 0 | case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: |
1338 | 0 | case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: |
1339 | 0 | case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: |
1340 | 0 | case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: |
1341 | 0 | case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: |
1342 | 0 | case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: |
1343 | 0 | case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: |
1344 | 0 | case X509_V_ERR_CERT_UNTRUSTED: |
1345 | 0 | case X509_V_ERR_CERT_REJECTED: |
1346 | 0 | case X509_V_ERR_HOSTNAME_MISMATCH: |
1347 | 0 | case X509_V_ERR_EMAIL_MISMATCH: |
1348 | 0 | case X509_V_ERR_IP_ADDRESS_MISMATCH: |
1349 | 0 | return SSL_AD_BAD_CERTIFICATE; |
1350 | | |
1351 | 0 | case X509_V_ERR_CERT_SIGNATURE_FAILURE: |
1352 | 0 | case X509_V_ERR_CRL_SIGNATURE_FAILURE: |
1353 | 0 | return SSL_AD_DECRYPT_ERROR; |
1354 | | |
1355 | 0 | case X509_V_ERR_CERT_HAS_EXPIRED: |
1356 | 0 | case X509_V_ERR_CERT_NOT_YET_VALID: |
1357 | 0 | case X509_V_ERR_CRL_HAS_EXPIRED: |
1358 | 0 | case X509_V_ERR_CRL_NOT_YET_VALID: |
1359 | 0 | return SSL_AD_CERTIFICATE_EXPIRED; |
1360 | | |
1361 | 0 | case X509_V_ERR_CERT_REVOKED: |
1362 | 0 | return SSL_AD_CERTIFICATE_REVOKED; |
1363 | | |
1364 | 0 | case X509_V_ERR_UNSPECIFIED: |
1365 | 0 | case X509_V_ERR_OUT_OF_MEM: |
1366 | 0 | case X509_V_ERR_INVALID_CALL: |
1367 | 0 | case X509_V_ERR_STORE_LOOKUP: |
1368 | 0 | return SSL_AD_INTERNAL_ERROR; |
1369 | | |
1370 | 0 | case X509_V_ERR_APPLICATION_VERIFICATION: |
1371 | 0 | return SSL_AD_HANDSHAKE_FAILURE; |
1372 | | |
1373 | 0 | case X509_V_ERR_INVALID_PURPOSE: |
1374 | 0 | return SSL_AD_UNSUPPORTED_CERTIFICATE; |
1375 | | |
1376 | 0 | default: |
1377 | 0 | return SSL_AD_CERTIFICATE_UNKNOWN; |
1378 | 0 | } |
1379 | 0 | } |