blob: a9212ff2a729439898833afa4a576e4cf3a2650e [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#ifndef QUICHE_QUIC_CORE_CRYPTO_TLS_CLIENT_CONNECTION_H_
6#define QUICHE_QUIC_CORE_CRYPTO_TLS_CLIENT_CONNECTION_H_
7
8#include "net/third_party/quiche/src/quic/core/crypto/tls_connection.h"
9
10namespace quic {
11
12// TlsClientConnection receives calls for client-specific BoringSSL callbacks
13// and calls its Delegate for the implementation of those callbacks.
renjietang96c17672019-06-14 12:50:14 -070014class QUIC_EXPORT_PRIVATE TlsClientConnection : public TlsConnection {
nharper6ebe83b2019-06-13 17:43:52 -070015 public:
16 // A TlsClientConnection::Delegate implements the client-specific methods that
17 // are set as callbacks for an SSL object.
18 class Delegate {
19 public:
20 virtual ~Delegate() {}
21
22 protected:
23 // Verifies the peer's certificate chain. It may use
24 // SSL_get0_peer_certificates to get the cert chain. This method returns
25 // ssl_verify_ok if the cert is valid, ssl_verify_invalid if it is invalid,
26 // or ssl_verify_retry if verification is happening asynchronously.
27 virtual enum ssl_verify_result_t VerifyCert(uint8_t* out_alert) = 0;
28
29 // Provides the delegate for callbacks that are shared between client and
30 // server.
31 virtual TlsConnection::Delegate* ConnectionDelegate() = 0;
32
33 friend class TlsClientConnection;
34 };
35
36 TlsClientConnection(SSL_CTX* ssl_ctx, Delegate* delegate);
37
38 // Creates and configures an SSL_CTX that is appropriate for clients to use.
39 static bssl::UniquePtr<SSL_CTX> CreateSslCtx();
40
41 private:
42 // Registered as the callback for SSL_CTX_set_custom_verify. The
43 // implementation is delegated to Delegate::VerifyCert.
44 static enum ssl_verify_result_t VerifyCallback(SSL* ssl, uint8_t* out_alert);
45
46 Delegate* delegate_;
47};
48
49} // namespace quic
50
51#endif // QUICHE_QUIC_CORE_CRYPTO_TLS_CLIENT_CONNECTION_H_