blob: b8dff7e9d34b9c1754ddc7581093019293d3de15 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2012 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_QUIC_CRYPTO_CLIENT_STREAM_H_
6#define QUICHE_QUIC_CORE_QUIC_CRYPTO_CLIENT_STREAM_H_
7
8#include <cstdint>
9#include <memory>
vasilvv872e7a32019-03-12 16:42:44 -070010#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050011
QUICHE teama6ef0a62019-03-07 20:34:33 -050012#include "net/third_party/quiche/src/quic/core/crypto/proof_verifier.h"
13#include "net/third_party/quiche/src/quic/core/crypto/quic_crypto_client_config.h"
14#include "net/third_party/quiche/src/quic/core/quic_config.h"
15#include "net/third_party/quiche/src/quic/core/quic_crypto_handshaker.h"
16#include "net/third_party/quiche/src/quic/core/quic_crypto_stream.h"
17#include "net/third_party/quiche/src/quic/core/quic_server_id.h"
18#include "net/third_party/quiche/src/quic/core/quic_session.h"
19#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050020
21namespace quic {
22
23class QUIC_EXPORT_PRIVATE QuicCryptoClientStreamBase : public QuicCryptoStream {
24 public:
25 explicit QuicCryptoClientStreamBase(QuicSession* session);
26
27 ~QuicCryptoClientStreamBase() override {}
28
29 // Performs a crypto handshake with the server. Returns true if the connection
30 // is still connected.
31 virtual bool CryptoConnect() = 0;
32
33 // num_sent_client_hellos returns the number of client hello messages that
34 // have been sent. If the handshake has completed then this is one greater
35 // than the number of round-trips needed for the handshake.
36 virtual int num_sent_client_hellos() const = 0;
37
38 // The number of server config update messages received by the
39 // client. Does not count update messages that were received prior
40 // to handshake confirmation.
41 virtual int num_scup_messages_received() const = 0;
42};
43
44class QUIC_EXPORT_PRIVATE QuicCryptoClientStream
45 : public QuicCryptoClientStreamBase {
46 public:
47 // kMaxClientHellos is the maximum number of times that we'll send a client
QUICHE team8b353f32019-04-09 13:49:10 -070048 // hello. The value 4 accounts for:
QUICHE teama6ef0a62019-03-07 20:34:33 -050049 // * One failure due to an incorrect or missing source-address token.
50 // * One failure due the server's certificate chain being unavailible and
51 // the server being unwilling to send it without a valid source-address
52 // token.
QUICHE team8b353f32019-04-09 13:49:10 -070053 // * One failure due to the ServerConfig private key being located on a
54 // remote oracle which has become unavailable, forcing the server to send
55 // the client a fallback ServerConfig.
56 static const int kMaxClientHellos = 4;
QUICHE teama6ef0a62019-03-07 20:34:33 -050057
58 // QuicCryptoClientStream creates a HandshakerDelegate at construction time
59 // based on the QuicTransportVersion of the connection. Different
60 // HandshakerDelegates provide implementations of different crypto handshake
61 // protocols. Currently QUIC crypto is the only protocol implemented; a future
62 // HandshakerDelegate will use TLS as the handshake protocol.
63 // QuicCryptoClientStream delegates all of its public methods to its
64 // HandshakerDelegate.
65 //
66 // This setup of the crypto stream delegating its implementation to the
67 // handshaker results in the handshaker reading and writing bytes on the
68 // crypto stream, instead of the handshaker passing the stream bytes to send.
69 class QUIC_EXPORT_PRIVATE HandshakerDelegate {
70 public:
71 virtual ~HandshakerDelegate() {}
72
73 // Performs a crypto handshake with the server. Returns true if the
74 // connection is still connected.
75 virtual bool CryptoConnect() = 0;
76
77 // num_sent_client_hellos returns the number of client hello messages that
78 // have been sent. If the handshake has completed then this is one greater
79 // than the number of round-trips needed for the handshake.
80 virtual int num_sent_client_hellos() const = 0;
81
82 // The number of server config update messages received by the
83 // client. Does not count update messages that were received prior
84 // to handshake confirmation.
85 virtual int num_scup_messages_received() const = 0;
86
vasilvvc48c8712019-03-11 13:38:16 -070087 virtual std::string chlo_hash() const = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -050088
89 // Returns true once any encrypter (initial/0RTT or final/1RTT) has been set
90 // for the connection.
91 virtual bool encryption_established() const = 0;
92
93 // Returns true once the crypto handshake has completed.
94 virtual bool handshake_confirmed() const = 0;
95
96 // Returns the parameters negotiated in the crypto handshake.
97 virtual const QuicCryptoNegotiatedParameters& crypto_negotiated_params()
98 const = 0;
99
100 // Used by QuicCryptoStream to parse data received on this stream.
101 virtual CryptoMessageParser* crypto_message_parser() = 0;
102 };
103
104 // ProofHandler is an interface that handles callbacks from the crypto
105 // stream when the client has proof verification details of the server.
106 class QUIC_EXPORT_PRIVATE ProofHandler {
107 public:
108 virtual ~ProofHandler() {}
109
110 // Called when the proof in |cached| is marked valid. If this is a secure
111 // QUIC session, then this will happen only after the proof verifier
112 // completes.
113 virtual void OnProofValid(
114 const QuicCryptoClientConfig::CachedState& cached) = 0;
115
116 // Called when proof verification details become available, either because
117 // proof verification is complete, or when cached details are used. This
118 // will only be called for secure QUIC connections.
119 virtual void OnProofVerifyDetailsAvailable(
120 const ProofVerifyDetails& verify_details) = 0;
121 };
122
123 QuicCryptoClientStream(const QuicServerId& server_id,
124 QuicSession* session,
125 std::unique_ptr<ProofVerifyContext> verify_context,
126 QuicCryptoClientConfig* crypto_config,
127 ProofHandler* proof_handler);
128 QuicCryptoClientStream(const QuicCryptoClientStream&) = delete;
129 QuicCryptoClientStream& operator=(const QuicCryptoClientStream&) = delete;
130
131 ~QuicCryptoClientStream() override;
132
133 // From QuicCryptoClientStreamBase
134 bool CryptoConnect() override;
135 int num_sent_client_hellos() const override;
136
137 int num_scup_messages_received() const override;
138
139 // From QuicCryptoStream
140 bool encryption_established() const override;
141 bool handshake_confirmed() const override;
142 const QuicCryptoNegotiatedParameters& crypto_negotiated_params()
143 const override;
144 CryptoMessageParser* crypto_message_parser() override;
145
vasilvvc48c8712019-03-11 13:38:16 -0700146 std::string chlo_hash() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500147
148 protected:
149 void set_handshaker(std::unique_ptr<HandshakerDelegate> handshaker) {
150 handshaker_ = std::move(handshaker);
151 }
152
153 private:
154 std::unique_ptr<HandshakerDelegate> handshaker_;
155};
156
157} // namespace quic
158
159#endif // QUICHE_QUIC_CORE_QUIC_CRYPTO_CLIENT_STREAM_H_