blob: 3f9b0af77475b628599d7588fa8d86e982868889 [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
nharper02703962019-11-07 12:23:13 -080038 // Returns true if the handshake performed was a resumption instead of a full
39 // handshake. Resumption only makes sense for TLS handshakes - there is no
40 // concept of resumption for QUIC crypto even though it supports a 0-RTT
41 // handshake. This function only returns valid results once the handshake is
42 // complete.
43 virtual bool IsResumption() const = 0;
44
QUICHE teama6ef0a62019-03-07 20:34:33 -050045 // The number of server config update messages received by the
46 // client. Does not count update messages that were received prior
47 // to handshake confirmation.
48 virtual int num_scup_messages_received() const = 0;
49};
50
51class QUIC_EXPORT_PRIVATE QuicCryptoClientStream
52 : public QuicCryptoClientStreamBase {
53 public:
54 // kMaxClientHellos is the maximum number of times that we'll send a client
QUICHE team8b353f32019-04-09 13:49:10 -070055 // hello. The value 4 accounts for:
QUICHE teama6ef0a62019-03-07 20:34:33 -050056 // * One failure due to an incorrect or missing source-address token.
57 // * One failure due the server's certificate chain being unavailible and
58 // the server being unwilling to send it without a valid source-address
59 // token.
QUICHE team8b353f32019-04-09 13:49:10 -070060 // * One failure due to the ServerConfig private key being located on a
61 // remote oracle which has become unavailable, forcing the server to send
62 // the client a fallback ServerConfig.
63 static const int kMaxClientHellos = 4;
QUICHE teama6ef0a62019-03-07 20:34:33 -050064
65 // QuicCryptoClientStream creates a HandshakerDelegate at construction time
66 // based on the QuicTransportVersion of the connection. Different
67 // HandshakerDelegates provide implementations of different crypto handshake
68 // protocols. Currently QUIC crypto is the only protocol implemented; a future
69 // HandshakerDelegate will use TLS as the handshake protocol.
70 // QuicCryptoClientStream delegates all of its public methods to its
71 // HandshakerDelegate.
72 //
73 // This setup of the crypto stream delegating its implementation to the
74 // handshaker results in the handshaker reading and writing bytes on the
75 // crypto stream, instead of the handshaker passing the stream bytes to send.
76 class QUIC_EXPORT_PRIVATE HandshakerDelegate {
77 public:
78 virtual ~HandshakerDelegate() {}
79
80 // Performs a crypto handshake with the server. Returns true if the
81 // connection is still connected.
82 virtual bool CryptoConnect() = 0;
83
84 // num_sent_client_hellos returns the number of client hello messages that
85 // have been sent. If the handshake has completed then this is one greater
86 // than the number of round-trips needed for the handshake.
87 virtual int num_sent_client_hellos() const = 0;
88
nharper02703962019-11-07 12:23:13 -080089 // Returns true if the handshake performed was a resumption instead of a
90 // full handshake. Resumption only makes sense for TLS handshakes - there is
91 // no concept of resumption for QUIC crypto even though it supports a 0-RTT
92 // handshake. This function only returns valid results once the handshake is
93 // complete.
94 virtual bool IsResumption() const = 0;
95
QUICHE teama6ef0a62019-03-07 20:34:33 -050096 // The number of server config update messages received by the
97 // client. Does not count update messages that were received prior
98 // to handshake confirmation.
99 virtual int num_scup_messages_received() const = 0;
100
vasilvvc48c8712019-03-11 13:38:16 -0700101 virtual std::string chlo_hash() const = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500102
103 // Returns true once any encrypter (initial/0RTT or final/1RTT) has been set
104 // for the connection.
105 virtual bool encryption_established() const = 0;
106
107 // Returns true once the crypto handshake has completed.
108 virtual bool handshake_confirmed() const = 0;
109
110 // Returns the parameters negotiated in the crypto handshake.
111 virtual const QuicCryptoNegotiatedParameters& crypto_negotiated_params()
112 const = 0;
113
114 // Used by QuicCryptoStream to parse data received on this stream.
115 virtual CryptoMessageParser* crypto_message_parser() = 0;
nharper486a8a92019-08-28 16:25:10 -0700116
117 // Used by QuicCryptoStream to know how much unprocessed data can be
118 // buffered at each encryption level.
119 virtual size_t BufferSizeLimitForLevel(EncryptionLevel level) const = 0;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500120 };
121
122 // ProofHandler is an interface that handles callbacks from the crypto
123 // stream when the client has proof verification details of the server.
124 class QUIC_EXPORT_PRIVATE ProofHandler {
125 public:
126 virtual ~ProofHandler() {}
127
128 // Called when the proof in |cached| is marked valid. If this is a secure
129 // QUIC session, then this will happen only after the proof verifier
130 // completes.
131 virtual void OnProofValid(
132 const QuicCryptoClientConfig::CachedState& cached) = 0;
133
134 // Called when proof verification details become available, either because
135 // proof verification is complete, or when cached details are used. This
136 // will only be called for secure QUIC connections.
137 virtual void OnProofVerifyDetailsAvailable(
138 const ProofVerifyDetails& verify_details) = 0;
139 };
140
141 QuicCryptoClientStream(const QuicServerId& server_id,
142 QuicSession* session,
143 std::unique_ptr<ProofVerifyContext> verify_context,
144 QuicCryptoClientConfig* crypto_config,
145 ProofHandler* proof_handler);
146 QuicCryptoClientStream(const QuicCryptoClientStream&) = delete;
147 QuicCryptoClientStream& operator=(const QuicCryptoClientStream&) = delete;
148
149 ~QuicCryptoClientStream() override;
150
151 // From QuicCryptoClientStreamBase
152 bool CryptoConnect() override;
153 int num_sent_client_hellos() const override;
nharper02703962019-11-07 12:23:13 -0800154 bool IsResumption() const override;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500155
156 int num_scup_messages_received() const override;
157
158 // From QuicCryptoStream
159 bool encryption_established() const override;
160 bool handshake_confirmed() const override;
161 const QuicCryptoNegotiatedParameters& crypto_negotiated_params()
162 const override;
163 CryptoMessageParser* crypto_message_parser() override;
fayangd58736d2019-11-27 13:35:31 -0800164 void OnPacketDecrypted(EncryptionLevel /*level*/) override {}
nharper486a8a92019-08-28 16:25:10 -0700165 size_t BufferSizeLimitForLevel(EncryptionLevel level) const override;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500166
vasilvvc48c8712019-03-11 13:38:16 -0700167 std::string chlo_hash() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500168
169 protected:
170 void set_handshaker(std::unique_ptr<HandshakerDelegate> handshaker) {
171 handshaker_ = std::move(handshaker);
172 }
173
174 private:
175 std::unique_ptr<HandshakerDelegate> handshaker_;
176};
177
178} // namespace quic
179
180#endif // QUICHE_QUIC_CORE_QUIC_CRYPTO_CLIENT_STREAM_H_