nharper | 6ebe83b | 2019-06-13 17:43:52 -0700 | [diff] [blame] | 1 | // Copyright (c) 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/core/crypto/tls_client_connection.h" |
| 6 | |
| 7 | namespace quic { |
| 8 | |
| 9 | TlsClientConnection::TlsClientConnection(SSL_CTX* ssl_ctx, Delegate* delegate) |
| 10 | : TlsConnection(ssl_ctx, delegate->ConnectionDelegate()), |
| 11 | delegate_(delegate) {} |
| 12 | |
| 13 | // static |
nharper | d25cd65 | 2020-05-20 13:10:26 -0700 | [diff] [blame] | 14 | bssl::UniquePtr<SSL_CTX> TlsClientConnection::CreateSslCtx( |
| 15 | bool enable_early_data) { |
nharper | 6ebe83b | 2019-06-13 17:43:52 -0700 | [diff] [blame] | 16 | bssl::UniquePtr<SSL_CTX> ssl_ctx = TlsConnection::CreateSslCtx(); |
| 17 | // Configure certificate verification. |
nharper | 6ebe83b | 2019-06-13 17:43:52 -0700 | [diff] [blame] | 18 | SSL_CTX_set_custom_verify(ssl_ctx.get(), SSL_VERIFY_PEER, &VerifyCallback); |
nharper | 1473c09 | 2019-11-11 13:13:19 -0800 | [diff] [blame] | 19 | int reverify_on_resume_enabled = 1; |
| 20 | SSL_CTX_set_reverify_on_resume(ssl_ctx.get(), reverify_on_resume_enabled); |
nharper | df7a77b | 2019-11-11 13:12:45 -0800 | [diff] [blame] | 21 | |
| 22 | // Configure session caching. |
| 23 | SSL_CTX_set_session_cache_mode( |
| 24 | ssl_ctx.get(), SSL_SESS_CACHE_CLIENT | SSL_SESS_CACHE_NO_INTERNAL); |
| 25 | SSL_CTX_sess_set_new_cb(ssl_ctx.get(), NewSessionCallback); |
nharper | d25cd65 | 2020-05-20 13:10:26 -0700 | [diff] [blame] | 26 | |
| 27 | SSL_CTX_set_early_data_enabled(ssl_ctx.get(), enable_early_data); |
nharper | 6ebe83b | 2019-06-13 17:43:52 -0700 | [diff] [blame] | 28 | return ssl_ctx; |
| 29 | } |
| 30 | |
| 31 | // static |
| 32 | enum ssl_verify_result_t TlsClientConnection::VerifyCallback( |
| 33 | SSL* ssl, |
| 34 | uint8_t* out_alert) { |
| 35 | return static_cast<TlsClientConnection*>(ConnectionFromSsl(ssl)) |
| 36 | ->delegate_->VerifyCert(out_alert); |
| 37 | } |
| 38 | |
nharper | df7a77b | 2019-11-11 13:12:45 -0800 | [diff] [blame] | 39 | // static |
| 40 | int TlsClientConnection::NewSessionCallback(SSL* ssl, SSL_SESSION* session) { |
| 41 | static_cast<TlsClientConnection*>(ConnectionFromSsl(ssl)) |
| 42 | ->delegate_->InsertSession(bssl::UniquePtr<SSL_SESSION>(session)); |
| 43 | return 1; |
| 44 | } |
| 45 | |
nharper | 6ebe83b | 2019-06-13 17:43:52 -0700 | [diff] [blame] | 46 | } // namespace quic |