| 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/core/quic_crypto_server_stream.h" | 5 #include "net/quic/core/quic_crypto_server_stream.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "crypto/secure_hash.h" | 9 #include "crypto/secure_hash.h" |
| 10 #include "net/quic/core/crypto/crypto_protocol.h" | 10 #include "net/quic/core/crypto/crypto_protocol.h" |
| 11 #include "net/quic/core/crypto/crypto_utils.h" | 11 #include "net/quic/core/crypto/crypto_utils.h" |
| 12 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 12 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
| 13 #include "net/quic/core/crypto/quic_random.h" | 13 #include "net/quic/core/crypto/quic_random.h" |
| 14 #include "net/quic/core/proto/cached_network_parameters.pb.h" | 14 #include "net/quic/core/proto/cached_network_parameters.pb.h" |
| 15 #include "net/quic/core/quic_config.h" | 15 #include "net/quic/core/quic_config.h" |
| 16 #include "net/quic/core/quic_flags.h" | 16 #include "net/quic/core/quic_flags.h" |
| 17 #include "net/quic/core/quic_packets.h" | 17 #include "net/quic/core/quic_packets.h" |
| 18 #include "net/quic/core/quic_session.h" | 18 #include "net/quic/core/quic_session.h" |
| 19 #include "net/quic/platform/api/quic_logging.h" |
| 19 #include "net/quic/platform/api/quic_text_utils.h" | 20 #include "net/quic/platform/api/quic_text_utils.h" |
| 20 | 21 |
| 21 using base::StringPiece; | 22 using base::StringPiece; |
| 22 using std::string; | 23 using std::string; |
| 23 | 24 |
| 24 namespace net { | 25 namespace net { |
| 25 | 26 |
| 26 class QuicCryptoServerStream::ProcessClientHelloCallback | 27 class QuicCryptoServerStream::ProcessClientHelloCallback |
| 27 : public ProcessClientHelloResultCallback { | 28 : public ProcessClientHelloResultCallback { |
| 28 public: | 29 public: |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // so that they can be added to the time wait list manager and | 211 // so that they can be added to the time wait list manager and |
| 211 // retransmitted. | 212 // retransmitted. |
| 212 session()->connection()->EnableSavingCryptoPackets(); | 213 session()->connection()->EnableSavingCryptoPackets(); |
| 213 } | 214 } |
| 214 SendHandshakeMessage(*reply); | 215 SendHandshakeMessage(*reply); |
| 215 | 216 |
| 216 if (reply->tag() == kSREJ) { | 217 if (reply->tag() == kSREJ) { |
| 217 DCHECK(use_stateless_rejects_if_peer_supported_); | 218 DCHECK(use_stateless_rejects_if_peer_supported_); |
| 218 DCHECK(peer_supports_stateless_rejects_); | 219 DCHECK(peer_supports_stateless_rejects_); |
| 219 DCHECK(!handshake_confirmed()); | 220 DCHECK(!handshake_confirmed()); |
| 220 DVLOG(1) << "Closing connection " | 221 QUIC_DLOG(INFO) << "Closing connection " |
| 221 << session()->connection()->connection_id() | 222 << session()->connection()->connection_id() |
| 222 << " because of a stateless reject."; | 223 << " because of a stateless reject."; |
| 223 session()->connection()->CloseConnection( | 224 session()->connection()->CloseConnection( |
| 224 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, "stateless reject", | 225 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, "stateless reject", |
| 225 ConnectionCloseBehavior::SILENT_CLOSE); | 226 ConnectionCloseBehavior::SILENT_CLOSE); |
| 226 } | 227 } |
| 227 return; | 228 return; |
| 228 } | 229 } |
| 229 | 230 |
| 230 // If we are returning a SHLO then we accepted the handshake. Now | 231 // If we are returning a SHLO then we accepted the handshake. Now |
| 231 // process the negotiated configuration options as part of the | 232 // process the negotiated configuration options as part of the |
| 232 // session config. | 233 // session config. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 } | 279 } |
| 279 | 280 |
| 280 void QuicCryptoServerStream::SendServerConfigUpdate( | 281 void QuicCryptoServerStream::SendServerConfigUpdate( |
| 281 const CachedNetworkParameters* cached_network_params) { | 282 const CachedNetworkParameters* cached_network_params) { |
| 282 if (!handshake_confirmed_) { | 283 if (!handshake_confirmed_) { |
| 283 return; | 284 return; |
| 284 } | 285 } |
| 285 | 286 |
| 286 if (FLAGS_quic_reloadable_flag_enable_async_get_proof) { | 287 if (FLAGS_quic_reloadable_flag_enable_async_get_proof) { |
| 287 if (send_server_config_update_cb_ != nullptr) { | 288 if (send_server_config_update_cb_ != nullptr) { |
| 288 DVLOG(1) | 289 QUIC_DVLOG(1) |
| 289 << "Skipped server config update since one is already in progress"; | 290 << "Skipped server config update since one is already in progress"; |
| 290 return; | 291 return; |
| 291 } | 292 } |
| 292 | 293 |
| 293 std::unique_ptr<SendServerConfigUpdateCallback> cb( | 294 std::unique_ptr<SendServerConfigUpdateCallback> cb( |
| 294 new SendServerConfigUpdateCallback(this)); | 295 new SendServerConfigUpdateCallback(this)); |
| 295 send_server_config_update_cb_ = cb.get(); | 296 send_server_config_update_cb_ = cb.get(); |
| 296 | 297 |
| 297 crypto_config_->BuildServerConfigUpdateMessage( | 298 crypto_config_->BuildServerConfigUpdateMessage( |
| 298 session()->connection()->version(), chlo_hash_, | 299 session()->connection()->version(), chlo_hash_, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 315 previous_source_address_tokens_, | 316 previous_source_address_tokens_, |
| 316 session()->connection()->self_address(), | 317 session()->connection()->self_address(), |
| 317 session()->connection()->peer_address().host(), | 318 session()->connection()->peer_address().host(), |
| 318 session()->connection()->clock(), | 319 session()->connection()->clock(), |
| 319 session()->connection()->random_generator(), compressed_certs_cache_, | 320 session()->connection()->random_generator(), compressed_certs_cache_, |
| 320 *crypto_negotiated_params_, cached_network_params, | 321 *crypto_negotiated_params_, cached_network_params, |
| 321 (session()->config()->HasReceivedConnectionOptions() | 322 (session()->config()->HasReceivedConnectionOptions() |
| 322 ? session()->config()->ReceivedConnectionOptions() | 323 ? session()->config()->ReceivedConnectionOptions() |
| 323 : QuicTagVector()), | 324 : QuicTagVector()), |
| 324 &server_config_update_message)) { | 325 &server_config_update_message)) { |
| 325 DVLOG(1) << "Server: Failed to build server config update (SCUP)!"; | 326 QUIC_DVLOG(1) << "Server: Failed to build server config update (SCUP)!"; |
| 326 return; | 327 return; |
| 327 } | 328 } |
| 328 | 329 |
| 329 DVLOG(1) << "Server: Sending server config update: " | 330 QUIC_DVLOG(1) << "Server: Sending server config update: " |
| 330 << server_config_update_message.DebugString(); | 331 << server_config_update_message.DebugString(); |
| 331 const QuicData& data = server_config_update_message.GetSerialized(); | 332 const QuicData& data = server_config_update_message.GetSerialized(); |
| 332 WriteOrBufferData(StringPiece(data.data(), data.length()), false, nullptr); | 333 WriteOrBufferData(StringPiece(data.data(), data.length()), false, nullptr); |
| 333 | 334 |
| 334 ++num_server_config_update_messages_sent_; | 335 ++num_server_config_update_messages_sent_; |
| 335 } | 336 } |
| 336 | 337 |
| 337 QuicCryptoServerStream::SendServerConfigUpdateCallback:: | 338 QuicCryptoServerStream::SendServerConfigUpdateCallback:: |
| 338 SendServerConfigUpdateCallback(QuicCryptoServerStream* parent) | 339 SendServerConfigUpdateCallback(QuicCryptoServerStream* parent) |
| 339 : parent_(parent) {} | 340 : parent_(parent) {} |
| 340 | 341 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 353 } | 354 } |
| 354 | 355 |
| 355 void QuicCryptoServerStream::FinishSendServerConfigUpdate( | 356 void QuicCryptoServerStream::FinishSendServerConfigUpdate( |
| 356 bool ok, | 357 bool ok, |
| 357 const CryptoHandshakeMessage& message) { | 358 const CryptoHandshakeMessage& message) { |
| 358 // Clear the callback that got us here. | 359 // Clear the callback that got us here. |
| 359 DCHECK(send_server_config_update_cb_ != nullptr); | 360 DCHECK(send_server_config_update_cb_ != nullptr); |
| 360 send_server_config_update_cb_ = nullptr; | 361 send_server_config_update_cb_ = nullptr; |
| 361 | 362 |
| 362 if (!ok) { | 363 if (!ok) { |
| 363 DVLOG(1) << "Server: Failed to build server config update (SCUP)!"; | 364 QUIC_DVLOG(1) << "Server: Failed to build server config update (SCUP)!"; |
| 364 return; | 365 return; |
| 365 } | 366 } |
| 366 | 367 |
| 367 DVLOG(1) << "Server: Sending server config update: " << message.DebugString(); | 368 QUIC_DVLOG(1) << "Server: Sending server config update: " |
| 369 << message.DebugString(); |
| 368 const QuicData& data = message.GetSerialized(); | 370 const QuicData& data = message.GetSerialized(); |
| 369 WriteOrBufferData(StringPiece(data.data(), data.length()), false, nullptr); | 371 WriteOrBufferData(StringPiece(data.data(), data.length()), false, nullptr); |
| 370 | 372 |
| 371 ++num_server_config_update_messages_sent_; | 373 ++num_server_config_update_messages_sent_; |
| 372 } | 374 } |
| 373 | 375 |
| 374 uint8_t QuicCryptoServerStream::NumHandshakeMessages() const { | 376 uint8_t QuicCryptoServerStream::NumHandshakeMessages() const { |
| 375 return num_handshake_messages_; | 377 return num_handshake_messages_; |
| 376 } | 378 } |
| 377 | 379 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 QuicConnectionId QuicCryptoServerStream::GenerateConnectionIdForReject( | 490 QuicConnectionId QuicCryptoServerStream::GenerateConnectionIdForReject( |
| 489 bool use_stateless_rejects) { | 491 bool use_stateless_rejects) { |
| 490 if (!use_stateless_rejects) { | 492 if (!use_stateless_rejects) { |
| 491 return 0; | 493 return 0; |
| 492 } | 494 } |
| 493 return helper_->GenerateConnectionIdForReject( | 495 return helper_->GenerateConnectionIdForReject( |
| 494 session()->connection()->connection_id()); | 496 session()->connection()->connection_id()); |
| 495 } | 497 } |
| 496 | 498 |
| 497 } // namespace net | 499 } // namespace net |
| OLD | NEW |