| 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 |
| 14 | bssl::UniquePtr<SSL_CTX> TlsClientConnection::CreateSslCtx() { |
| 15 | bssl::UniquePtr<SSL_CTX> ssl_ctx = TlsConnection::CreateSslCtx(); |
| 16 | // Configure certificate verification. |
| nharper | 6ebe83b | 2019-06-13 17:43:52 -0700 | [diff] [blame] | 17 | SSL_CTX_set_custom_verify(ssl_ctx.get(), SSL_VERIFY_PEER, &VerifyCallback); |
| nharper | 1473c09 | 2019-11-11 13:13:19 -0800 | [diff] [blame] | 18 | int reverify_on_resume_enabled = 1; |
| 19 | SSL_CTX_set_reverify_on_resume(ssl_ctx.get(), reverify_on_resume_enabled); |
| nharper | df7a77b | 2019-11-11 13:12:45 -0800 | [diff] [blame] | 20 | |
| 21 | // Configure session caching. |
| 22 | SSL_CTX_set_session_cache_mode( |
| 23 | ssl_ctx.get(), SSL_SESS_CACHE_CLIENT | SSL_SESS_CACHE_NO_INTERNAL); |
| 24 | SSL_CTX_sess_set_new_cb(ssl_ctx.get(), NewSessionCallback); |
| nharper | 6ebe83b | 2019-06-13 17:43:52 -0700 | [diff] [blame] | 25 | return ssl_ctx; |
| 26 | } |
| 27 | |
| 28 | // static |
| 29 | enum ssl_verify_result_t TlsClientConnection::VerifyCallback( |
| 30 | SSL* ssl, |
| 31 | uint8_t* out_alert) { |
| 32 | return static_cast<TlsClientConnection*>(ConnectionFromSsl(ssl)) |
| 33 | ->delegate_->VerifyCert(out_alert); |
| 34 | } |
| 35 | |
| nharper | df7a77b | 2019-11-11 13:12:45 -0800 | [diff] [blame] | 36 | // static |
| 37 | int TlsClientConnection::NewSessionCallback(SSL* ssl, SSL_SESSION* session) { |
| 38 | static_cast<TlsClientConnection*>(ConnectionFromSsl(ssl)) |
| 39 | ->delegate_->InsertSession(bssl::UniquePtr<SSL_SESSION>(session)); |
| 40 | return 1; |
| 41 | } |
| 42 | |
| nharper | 6ebe83b | 2019-06-13 17:43:52 -0700 | [diff] [blame] | 43 | } // namespace quic |