OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_ | 5 #ifndef NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_ |
6 #define NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_ | 6 #define NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "net/quic/crypto/channel_id.h" | 13 #include "net/quic/crypto/channel_id.h" |
14 #include "net/quic/crypto/proof_verifier.h" | 14 #include "net/quic/crypto/proof_verifier.h" |
15 #include "net/quic/crypto/quic_crypto_client_config.h" | 15 #include "net/quic/crypto/quic_crypto_client_config.h" |
16 #include "net/quic/quic_config.h" | 16 #include "net/quic/quic_config.h" |
17 #include "net/quic/quic_crypto_stream.h" | 17 #include "net/quic/quic_crypto_stream.h" |
18 #include "net/quic/quic_server_id.h" | 18 #include "net/quic/quic_server_id.h" |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 | 21 |
22 class QuicClientSessionBase; | |
23 | |
24 namespace test { | 22 namespace test { |
25 class CryptoTestUtils; | 23 class CryptoTestUtils; |
26 class QuicChromiumClientSessionPeer; | 24 class QuicChromiumClientSessionPeer; |
27 } // namespace test | 25 } // namespace test |
28 | 26 |
29 class NET_EXPORT_PRIVATE QuicCryptoClientStreamBase : public QuicCryptoStream { | 27 class NET_EXPORT_PRIVATE QuicCryptoClientStreamBase : public QuicCryptoStream { |
30 public: | 28 public: |
31 explicit QuicCryptoClientStreamBase(QuicClientSessionBase* session); | 29 explicit QuicCryptoClientStreamBase(QuicSession* session); |
32 | 30 |
33 ~QuicCryptoClientStreamBase() override{}; | 31 ~QuicCryptoClientStreamBase() override{}; |
34 | 32 |
35 // Performs a crypto handshake with the server. | 33 // Performs a crypto handshake with the server. |
36 virtual void CryptoConnect() = 0; | 34 virtual void CryptoConnect() = 0; |
37 | 35 |
38 // num_sent_client_hellos returns the number of client hello messages that | 36 // num_sent_client_hellos returns the number of client hello messages that |
39 // have been sent. If the handshake has completed then this is one greater | 37 // have been sent. If the handshake has completed then this is one greater |
40 // than the number of round-trips needed for the handshake. | 38 // than the number of round-trips needed for the handshake. |
41 virtual int num_sent_client_hellos() const = 0; | 39 virtual int num_sent_client_hellos() const = 0; |
42 }; | 40 }; |
43 | 41 |
44 class NET_EXPORT_PRIVATE QuicCryptoClientStream | 42 class NET_EXPORT_PRIVATE QuicCryptoClientStream |
45 : public QuicCryptoClientStreamBase { | 43 : public QuicCryptoClientStreamBase { |
46 public: | 44 public: |
47 // kMaxClientHellos is the maximum number of times that we'll send a client | 45 // kMaxClientHellos is the maximum number of times that we'll send a client |
48 // hello. The value 3 accounts for: | 46 // hello. The value 3 accounts for: |
49 // * One failure due to an incorrect or missing source-address token. | 47 // * One failure due to an incorrect or missing source-address token. |
50 // * One failure due the server's certificate chain being unavailible and | 48 // * One failure due the server's certificate chain being unavailible and |
51 // the server being unwilling to send it without a valid source-address | 49 // the server being unwilling to send it without a valid source-address |
52 // token. | 50 // token. |
53 static const int kMaxClientHellos = 3; | 51 static const int kMaxClientHellos = 3; |
| 52 |
| 53 // ProofHandler is an interface that handles callbacks from the crypto |
| 54 // stream when the client has proof verification details of the server. |
| 55 class NET_EXPORT_PRIVATE ProofHandler { |
| 56 public: |
| 57 virtual ~ProofHandler() {} |
| 58 |
| 59 // Called when the proof in |cached| is marked valid. If this is a secure |
| 60 // QUIC session, then this will happen only after the proof verifier |
| 61 // completes. |
| 62 virtual void OnProofValid( |
| 63 const QuicCryptoClientConfig::CachedState& cached) = 0; |
| 64 |
| 65 // Called when proof verification details become available, either because |
| 66 // proof verification is complete, or when cached details are used. This |
| 67 // will only be called for secure QUIC connections. |
| 68 virtual void OnProofVerifyDetailsAvailable( |
| 69 const ProofVerifyDetails& verify_details) = 0; |
| 70 }; |
| 71 |
54 QuicCryptoClientStream(const QuicServerId& server_id, | 72 QuicCryptoClientStream(const QuicServerId& server_id, |
55 QuicClientSessionBase* session, | 73 QuicSession* session, |
56 ProofVerifyContext* verify_context, | 74 ProofVerifyContext* verify_context, |
57 QuicCryptoClientConfig* crypto_config); | 75 QuicCryptoClientConfig* crypto_config, |
| 76 ProofHandler* proof_handler); |
58 | 77 |
59 ~QuicCryptoClientStream() override; | 78 ~QuicCryptoClientStream() override; |
60 | 79 |
61 // From QuicCryptoClientStreamBase | 80 // From QuicCryptoClientStreamBase |
62 void CryptoConnect() override; | 81 void CryptoConnect() override; |
63 int num_sent_client_hellos() const override; | 82 int num_sent_client_hellos() const override; |
64 | 83 |
65 // CryptoFramerVisitorInterface implementation | 84 // CryptoFramerVisitorInterface implementation |
66 void OnHandshakeMessage(const CryptoHandshakeMessage& message) override; | 85 void OnHandshakeMessage(const CryptoHandshakeMessage& message) override; |
67 | 86 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 QuicCryptoClientConfig::CachedState* cached); | 195 QuicCryptoClientConfig::CachedState* cached); |
177 | 196 |
178 // Called to set the proof of |cached| valid. Also invokes the session's | 197 // Called to set the proof of |cached| valid. Also invokes the session's |
179 // OnProofValid() method. | 198 // OnProofValid() method. |
180 void SetCachedProofValid(QuicCryptoClientConfig::CachedState* cached); | 199 void SetCachedProofValid(QuicCryptoClientConfig::CachedState* cached); |
181 | 200 |
182 // Returns true if the server crypto config in |cached| requires a ChannelID | 201 // Returns true if the server crypto config in |cached| requires a ChannelID |
183 // and the client config settings also allow sending a ChannelID. | 202 // and the client config settings also allow sending a ChannelID. |
184 bool RequiresChannelID(QuicCryptoClientConfig::CachedState* cached); | 203 bool RequiresChannelID(QuicCryptoClientConfig::CachedState* cached); |
185 | 204 |
186 QuicClientSessionBase* client_session(); | |
187 | |
188 State next_state_; | 205 State next_state_; |
189 // num_client_hellos_ contains the number of client hello messages that this | 206 // num_client_hellos_ contains the number of client hello messages that this |
190 // connection has sent. | 207 // connection has sent. |
191 int num_client_hellos_; | 208 int num_client_hellos_; |
192 | 209 |
193 QuicCryptoClientConfig* const crypto_config_; | 210 QuicCryptoClientConfig* const crypto_config_; |
194 | 211 |
195 // Client's connection nonce (4-byte timestamp + 28 random bytes) | 212 // Client's connection nonce (4-byte timestamp + 28 random bytes) |
196 std::string nonce_; | 213 std::string nonce_; |
197 // Server's (hostname, port, is_https, privacy_mode) tuple. | 214 // Server's (hostname, port, is_https, privacy_mode) tuple. |
(...skipping 18 matching lines...) Expand all Loading... |
216 // STATE_GET_CHANNEL_ID_COMPLETE. | 233 // STATE_GET_CHANNEL_ID_COMPLETE. |
217 scoped_ptr<ChannelIDKey> channel_id_key_; | 234 scoped_ptr<ChannelIDKey> channel_id_key_; |
218 | 235 |
219 // verify_context_ contains the context object that we pass to asynchronous | 236 // verify_context_ contains the context object that we pass to asynchronous |
220 // proof verifications. | 237 // proof verifications. |
221 scoped_ptr<ProofVerifyContext> verify_context_; | 238 scoped_ptr<ProofVerifyContext> verify_context_; |
222 | 239 |
223 // proof_verify_callback_ contains the callback object that we passed to an | 240 // proof_verify_callback_ contains the callback object that we passed to an |
224 // asynchronous proof verification. The ProofVerifier owns this object. | 241 // asynchronous proof verification. The ProofVerifier owns this object. |
225 ProofVerifierCallbackImpl* proof_verify_callback_; | 242 ProofVerifierCallbackImpl* proof_verify_callback_; |
| 243 // proof_handler_ contains the callback object used by a quic client |
| 244 // for proof verification. It is not owned by this class. |
| 245 ProofHandler* proof_handler_; |
226 | 246 |
227 // These members are used to store the result of an asynchronous proof | 247 // These members are used to store the result of an asynchronous proof |
228 // verification. These members must not be used after | 248 // verification. These members must not be used after |
229 // STATE_VERIFY_PROOF_COMPLETE. | 249 // STATE_VERIFY_PROOF_COMPLETE. |
230 bool verify_ok_; | 250 bool verify_ok_; |
231 std::string verify_error_details_; | 251 std::string verify_error_details_; |
232 scoped_ptr<ProofVerifyDetails> verify_details_; | 252 scoped_ptr<ProofVerifyDetails> verify_details_; |
233 | 253 |
234 // True if the server responded to a previous CHLO with a stateless | 254 // True if the server responded to a previous CHLO with a stateless |
235 // reject. Used for book-keeping between the STATE_RECV_REJ, | 255 // reject. Used for book-keeping between the STATE_RECV_REJ, |
236 // STATE_VERIFY_PROOF*, and subsequent STATE_SEND_CHLO state. | 256 // STATE_VERIFY_PROOF*, and subsequent STATE_SEND_CHLO state. |
237 bool stateless_reject_received_; | 257 bool stateless_reject_received_; |
238 | 258 |
239 base::TimeTicks proof_verify_start_time_; | 259 base::TimeTicks proof_verify_start_time_; |
240 | 260 |
241 DISALLOW_COPY_AND_ASSIGN(QuicCryptoClientStream); | 261 DISALLOW_COPY_AND_ASSIGN(QuicCryptoClientStream); |
242 }; | 262 }; |
243 | 263 |
244 } // namespace net | 264 } // namespace net |
245 | 265 |
246 #endif // NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_ | 266 #endif // NET_QUIC_QUIC_CRYPTO_CLIENT_STREAM_H_ |
OLD | NEW |