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 #include "net/quic/quic_crypto_server_stream.h" | 5 #include "net/quic/quic_crypto_server_stream.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "crypto/secure_hash.h" | 8 #include "crypto/secure_hash.h" |
9 #include "net/quic/crypto/crypto_protocol.h" | 9 #include "net/quic/crypto/crypto_protocol.h" |
10 #include "net/quic/crypto/crypto_utils.h" | 10 #include "net/quic/crypto/crypto_utils.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 QuicCryptoServerStream::QuicCryptoServerStream( | 32 QuicCryptoServerStream::QuicCryptoServerStream( |
33 const QuicCryptoServerConfig* crypto_config, | 33 const QuicCryptoServerConfig* crypto_config, |
34 QuicSession* session) | 34 QuicSession* session) |
35 : QuicCryptoStream(session), | 35 : QuicCryptoStream(session), |
36 crypto_config_(crypto_config), | 36 crypto_config_(crypto_config), |
37 validate_client_hello_cb_(nullptr), | 37 validate_client_hello_cb_(nullptr), |
38 num_handshake_messages_(0), | 38 num_handshake_messages_(0), |
39 num_handshake_messages_with_server_nonces_(0), | 39 num_handshake_messages_with_server_nonces_(0), |
40 num_server_config_update_messages_sent_(0), | 40 num_server_config_update_messages_sent_(0), |
41 use_stateless_rejects_if_peer_supported_(false), | 41 use_stateless_rejects_if_peer_supported_( |
| 42 FLAGS_enable_quic_stateless_reject_support), |
42 peer_supports_stateless_rejects_(false) { | 43 peer_supports_stateless_rejects_(false) { |
43 DCHECK_EQ(Perspective::IS_SERVER, session->connection()->perspective()); | 44 DCHECK_EQ(Perspective::IS_SERVER, session->connection()->perspective()); |
44 } | 45 } |
45 | 46 |
46 QuicCryptoServerStream::~QuicCryptoServerStream() { | 47 QuicCryptoServerStream::~QuicCryptoServerStream() { |
47 CancelOutstandingCallbacks(); | 48 CancelOutstandingCallbacks(); |
48 } | 49 } |
49 | 50 |
50 void QuicCryptoServerStream::CancelOutstandingCallbacks() { | 51 void QuicCryptoServerStream::CancelOutstandingCallbacks() { |
51 // Detach from the validation callback. Calling this multiple times is safe. | 52 // Detach from the validation callback. Calling this multiple times is safe. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 validate_client_hello_cb_); | 87 validate_client_hello_cb_); |
87 } | 88 } |
88 | 89 |
89 void QuicCryptoServerStream::FinishProcessingHandshakeMessage( | 90 void QuicCryptoServerStream::FinishProcessingHandshakeMessage( |
90 const CryptoHandshakeMessage& message, | 91 const CryptoHandshakeMessage& message, |
91 const ValidateClientHelloResultCallback::Result& result) { | 92 const ValidateClientHelloResultCallback::Result& result) { |
92 // Clear the callback that got us here. | 93 // Clear the callback that got us here. |
93 DCHECK(validate_client_hello_cb_ != nullptr); | 94 DCHECK(validate_client_hello_cb_ != nullptr); |
94 validate_client_hello_cb_ = nullptr; | 95 validate_client_hello_cb_ = nullptr; |
95 | 96 |
96 if (FLAGS_enable_quic_stateless_reject_support) { | 97 if (use_stateless_rejects_if_peer_supported_) { |
97 peer_supports_stateless_rejects_ = DoesPeerSupportStatelessRejects(message); | 98 peer_supports_stateless_rejects_ = DoesPeerSupportStatelessRejects(message); |
98 } | 99 } |
99 | 100 |
100 CryptoHandshakeMessage reply; | 101 CryptoHandshakeMessage reply; |
101 string error_details; | 102 string error_details; |
102 QuicErrorCode error = | 103 QuicErrorCode error = |
103 ProcessClientHello(message, result, &reply, &error_details); | 104 ProcessClientHello(message, result, &reply, &error_details); |
104 | 105 |
105 if (error != QUIC_NO_ERROR) { | 106 if (error != QUIC_NO_ERROR) { |
106 CloseConnectionWithDetails(error, error_details); | 107 CloseConnectionWithDetails(error, error_details); |
107 return; | 108 return; |
108 } | 109 } |
109 | 110 |
110 if (reply.tag() != kSHLO) { | 111 if (reply.tag() != kSHLO) { |
| 112 if (reply.tag() == kSREJ) { |
| 113 DCHECK(use_stateless_rejects_if_peer_supported()); |
| 114 DCHECK(peer_supports_stateless_rejects()); |
| 115 // Before sending the SREJ, cause the connection to save crypto packets |
| 116 // so that they can be added to the time wait list manager and |
| 117 // retransmitted. |
| 118 session()->connection()->EnableSavingCryptoPackets(); |
| 119 } |
111 SendHandshakeMessage(reply); | 120 SendHandshakeMessage(reply); |
112 | 121 |
113 if (FLAGS_enable_quic_stateless_reject_support && reply.tag() == kSREJ) { | 122 if (reply.tag() == kSREJ) { |
114 DCHECK(use_stateless_rejects_if_peer_supported()); | 123 DCHECK(use_stateless_rejects_if_peer_supported()); |
115 DCHECK(peer_supports_stateless_rejects()); | 124 DCHECK(peer_supports_stateless_rejects()); |
116 DCHECK(!handshake_confirmed()); | 125 DCHECK(!handshake_confirmed()); |
117 DVLOG(1) << "Closing connection " | 126 DVLOG(1) << "Closing connection " |
118 << session()->connection()->connection_id() | 127 << session()->connection()->connection_id() |
119 << " because of a stateless reject."; | 128 << " because of a stateless reject."; |
120 session()->connection()->CloseConnection( | 129 session()->connection()->CloseConnection( |
121 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, /* from_peer */ false); | 130 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, /* from_peer */ false); |
122 } | 131 } |
123 return; | 132 return; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 182 } |
174 | 183 |
175 void QuicCryptoServerStream::SendServerConfigUpdate( | 184 void QuicCryptoServerStream::SendServerConfigUpdate( |
176 const CachedNetworkParameters* cached_network_params) { | 185 const CachedNetworkParameters* cached_network_params) { |
177 if (!handshake_confirmed_) { | 186 if (!handshake_confirmed_) { |
178 return; | 187 return; |
179 } | 188 } |
180 | 189 |
181 CryptoHandshakeMessage server_config_update_message; | 190 CryptoHandshakeMessage server_config_update_message; |
182 if (!crypto_config_->BuildServerConfigUpdateMessage( | 191 if (!crypto_config_->BuildServerConfigUpdateMessage( |
183 previous_source_address_tokens_, | 192 session()->connection()->version(), previous_source_address_tokens_, |
184 session()->connection()->self_address().address(), | 193 session()->connection()->self_address().address(), |
185 session()->connection()->peer_address().address(), | 194 session()->connection()->peer_address().address(), |
186 session()->connection()->clock(), | 195 session()->connection()->clock(), |
187 session()->connection()->random_generator(), | 196 session()->connection()->random_generator(), |
188 crypto_negotiated_params_, cached_network_params, | 197 crypto_negotiated_params_, cached_network_params, |
189 &server_config_update_message)) { | 198 &server_config_update_message)) { |
190 DVLOG(1) << "Server: Failed to build server config update (SCUP)!"; | 199 DVLOG(1) << "Server: Failed to build server config update (SCUP)!"; |
191 return; | 200 return; |
192 } | 201 } |
193 | 202 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 ++num_handshake_messages_with_server_nonces_; | 257 ++num_handshake_messages_with_server_nonces_; |
249 } | 258 } |
250 // Store the bandwidth estimate from the client. | 259 // Store the bandwidth estimate from the client. |
251 if (result.cached_network_params.bandwidth_estimate_bytes_per_second() > 0) { | 260 if (result.cached_network_params.bandwidth_estimate_bytes_per_second() > 0) { |
252 previous_cached_network_params_.reset( | 261 previous_cached_network_params_.reset( |
253 new CachedNetworkParameters(result.cached_network_params)); | 262 new CachedNetworkParameters(result.cached_network_params)); |
254 } | 263 } |
255 previous_source_address_tokens_ = result.info.source_address_tokens; | 264 previous_source_address_tokens_ = result.info.source_address_tokens; |
256 | 265 |
257 const bool use_stateless_rejects_in_crypto_config = | 266 const bool use_stateless_rejects_in_crypto_config = |
258 FLAGS_enable_quic_stateless_reject_support && | |
259 use_stateless_rejects_if_peer_supported_ && | 267 use_stateless_rejects_if_peer_supported_ && |
260 peer_supports_stateless_rejects_; | 268 peer_supports_stateless_rejects_; |
261 QuicConnection* connection = session()->connection(); | 269 QuicConnection* connection = session()->connection(); |
262 const QuicConnectionId server_designated_connection_id = | 270 const QuicConnectionId server_designated_connection_id = |
263 use_stateless_rejects_in_crypto_config | 271 use_stateless_rejects_in_crypto_config |
264 ? GenerateConnectionIdForReject(connection->connection_id()) | 272 ? GenerateConnectionIdForReject(connection->connection_id()) |
265 : 0; | 273 : 0; |
266 return crypto_config_->ProcessClientHello( | 274 return crypto_config_->ProcessClientHello( |
267 result, connection->connection_id(), connection->self_address().address(), | 275 result, connection->connection_id(), connection->self_address().address(), |
268 connection->peer_address(), version(), connection->supported_versions(), | 276 connection->peer_address(), version(), connection->supported_versions(), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 } | 320 } |
313 for (size_t i = 0; i < received_tags_length; ++i) { | 321 for (size_t i = 0; i < received_tags_length; ++i) { |
314 if (received_tags[i] == kSREJ) { | 322 if (received_tags[i] == kSREJ) { |
315 return true; | 323 return true; |
316 } | 324 } |
317 } | 325 } |
318 return false; | 326 return false; |
319 } | 327 } |
320 | 328 |
321 } // namespace net | 329 } // namespace net |
OLD | NEW |