blob: 7d112245b3cfcffe7912acafc8860dca8491c5bf [file] [log] [blame]
nharper6ebe83b2019-06-13 17:43:52 -07001// 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
7namespace quic {
8
9TlsClientConnection::TlsClientConnection(SSL_CTX* ssl_ctx, Delegate* delegate)
10 : TlsConnection(ssl_ctx, delegate->ConnectionDelegate()),
11 delegate_(delegate) {}
12
13// static
14bssl::UniquePtr<SSL_CTX> TlsClientConnection::CreateSslCtx() {
15 bssl::UniquePtr<SSL_CTX> ssl_ctx = TlsConnection::CreateSslCtx();
16 // Configure certificate verification.
nharper6ebe83b2019-06-13 17:43:52 -070017 SSL_CTX_set_custom_verify(ssl_ctx.get(), SSL_VERIFY_PEER, &VerifyCallback);
nharper1473c092019-11-11 13:13:19 -080018 int reverify_on_resume_enabled = 1;
19 SSL_CTX_set_reverify_on_resume(ssl_ctx.get(), reverify_on_resume_enabled);
nharperdf7a77b2019-11-11 13:12:45 -080020
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);
nharper6ebe83b2019-06-13 17:43:52 -070025 return ssl_ctx;
26}
27
28// static
29enum 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
nharperdf7a77b2019-11-11 13:12:45 -080036// static
37int 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
nharper6ebe83b2019-06-13 17:43:52 -070043} // namespace quic