| 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" | |
| 10 #include "net/quic/core/crypto/crypto_protocol.h" | 9 #include "net/quic/core/crypto/crypto_protocol.h" |
| 11 #include "net/quic/core/crypto/crypto_utils.h" | 10 #include "net/quic/core/crypto/crypto_utils.h" |
| 12 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 11 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
| 13 #include "net/quic/core/crypto/quic_random.h" | 12 #include "net/quic/core/crypto/quic_random.h" |
| 14 #include "net/quic/core/proto/cached_network_parameters.pb.h" | 13 #include "net/quic/core/proto/cached_network_parameters.pb.h" |
| 15 #include "net/quic/core/quic_config.h" | 14 #include "net/quic/core/quic_config.h" |
| 16 #include "net/quic/core/quic_flags.h" | 15 #include "net/quic/core/quic_flags.h" |
| 17 #include "net/quic/core/quic_packets.h" | 16 #include "net/quic/core/quic_packets.h" |
| 18 #include "net/quic/core/quic_session.h" | 17 #include "net/quic/core/quic_session.h" |
| 19 #include "net/quic/platform/api/quic_logging.h" | 18 #include "net/quic/platform/api/quic_logging.h" |
| 20 #include "net/quic/platform/api/quic_text_utils.h" | 19 #include "net/quic/platform/api/quic_text_utils.h" |
| 20 #include "third_party/boringssl/src/include/openssl/sha.h" |
| 21 | 21 |
| 22 using base::StringPiece; | 22 using base::StringPiece; |
| 23 using std::string; | 23 using std::string; |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 | 26 |
| 27 class QuicCryptoServerStream::ProcessClientHelloCallback | 27 class QuicCryptoServerStream::ProcessClientHelloCallback |
| 28 : public ProcessClientHelloResultCallback { | 28 : public ProcessClientHelloResultCallback { |
| 29 public: | 29 public: |
| 30 ProcessClientHelloCallback( | 30 ProcessClientHelloCallback( |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 handshake_confirmed_ = true; | 277 handshake_confirmed_ = true; |
| 278 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED); | 278 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void QuicCryptoServerStream::SendServerConfigUpdate( | 281 void QuicCryptoServerStream::SendServerConfigUpdate( |
| 282 const CachedNetworkParameters* cached_network_params) { | 282 const CachedNetworkParameters* cached_network_params) { |
| 283 if (!handshake_confirmed_) { | 283 if (!handshake_confirmed_) { |
| 284 return; | 284 return; |
| 285 } | 285 } |
| 286 | 286 |
| 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 QUIC_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"; | |
| 291 return; | |
| 292 } | |
| 293 | |
| 294 std::unique_ptr<SendServerConfigUpdateCallback> cb( | |
| 295 new SendServerConfigUpdateCallback(this)); | |
| 296 send_server_config_update_cb_ = cb.get(); | |
| 297 | |
| 298 crypto_config_->BuildServerConfigUpdateMessage( | |
| 299 session()->connection()->version(), chlo_hash_, | |
| 300 previous_source_address_tokens_, | |
| 301 session()->connection()->self_address(), | |
| 302 session()->connection()->peer_address().host(), | |
| 303 session()->connection()->clock(), | |
| 304 session()->connection()->random_generator(), compressed_certs_cache_, | |
| 305 *crypto_negotiated_params_, cached_network_params, | |
| 306 (session()->config()->HasReceivedConnectionOptions() | |
| 307 ? session()->config()->ReceivedConnectionOptions() | |
| 308 : QuicTagVector()), | |
| 309 std::move(cb)); | |
| 310 return; | 290 return; |
| 311 } | 291 } |
| 312 | 292 |
| 313 CryptoHandshakeMessage server_config_update_message; | 293 std::unique_ptr<SendServerConfigUpdateCallback> cb( |
| 314 if (!crypto_config_->BuildServerConfigUpdateMessage( | 294 new SendServerConfigUpdateCallback(this)); |
| 315 session()->connection()->version(), chlo_hash_, | 295 send_server_config_update_cb_ = cb.get(); |
| 316 previous_source_address_tokens_, | |
| 317 session()->connection()->self_address(), | |
| 318 session()->connection()->peer_address().host(), | |
| 319 session()->connection()->clock(), | |
| 320 session()->connection()->random_generator(), compressed_certs_cache_, | |
| 321 *crypto_negotiated_params_, cached_network_params, | |
| 322 (session()->config()->HasReceivedConnectionOptions() | |
| 323 ? session()->config()->ReceivedConnectionOptions() | |
| 324 : QuicTagVector()), | |
| 325 &server_config_update_message)) { | |
| 326 QUIC_DVLOG(1) << "Server: Failed to build server config update (SCUP)!"; | |
| 327 return; | |
| 328 } | |
| 329 | 296 |
| 330 QUIC_DVLOG(1) << "Server: Sending server config update: " | 297 crypto_config_->BuildServerConfigUpdateMessage( |
| 331 << server_config_update_message.DebugString(); | 298 session()->connection()->version(), chlo_hash_, |
| 332 const QuicData& data = server_config_update_message.GetSerialized(); | 299 previous_source_address_tokens_, session()->connection()->self_address(), |
| 333 WriteOrBufferData(StringPiece(data.data(), data.length()), false, nullptr); | 300 session()->connection()->peer_address().host(), |
| 334 | 301 session()->connection()->clock(), |
| 335 ++num_server_config_update_messages_sent_; | 302 session()->connection()->random_generator(), compressed_certs_cache_, |
| 303 *crypto_negotiated_params_, cached_network_params, |
| 304 (session()->config()->HasReceivedConnectionOptions() |
| 305 ? session()->config()->ReceivedConnectionOptions() |
| 306 : QuicTagVector()), |
| 307 std::move(cb)); |
| 336 } | 308 } |
| 337 | 309 |
| 338 QuicCryptoServerStream::SendServerConfigUpdateCallback:: | 310 QuicCryptoServerStream::SendServerConfigUpdateCallback:: |
| 339 SendServerConfigUpdateCallback(QuicCryptoServerStream* parent) | 311 SendServerConfigUpdateCallback(QuicCryptoServerStream* parent) |
| 340 : parent_(parent) {} | 312 : parent_(parent) {} |
| 341 | 313 |
| 342 void QuicCryptoServerStream::SendServerConfigUpdateCallback::Cancel() { | 314 void QuicCryptoServerStream::SendServerConfigUpdateCallback::Cancel() { |
| 343 parent_ = nullptr; | 315 parent_ = nullptr; |
| 344 } | 316 } |
| 345 | 317 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 382 } |
| 411 | 383 |
| 412 bool QuicCryptoServerStream::GetBase64SHA256ClientChannelID( | 384 bool QuicCryptoServerStream::GetBase64SHA256ClientChannelID( |
| 413 string* output) const { | 385 string* output) const { |
| 414 if (!encryption_established_ || | 386 if (!encryption_established_ || |
| 415 crypto_negotiated_params_->channel_id.empty()) { | 387 crypto_negotiated_params_->channel_id.empty()) { |
| 416 return false; | 388 return false; |
| 417 } | 389 } |
| 418 | 390 |
| 419 const string& channel_id(crypto_negotiated_params_->channel_id); | 391 const string& channel_id(crypto_negotiated_params_->channel_id); |
| 420 std::unique_ptr<crypto::SecureHash> hash( | 392 uint8_t digest[SHA256_DIGEST_LENGTH]; |
| 421 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); | 393 SHA256(reinterpret_cast<const uint8_t*>(channel_id.data()), channel_id.size(), |
| 422 hash->Update(channel_id.data(), channel_id.size()); | 394 digest); |
| 423 uint8_t digest[32]; | |
| 424 hash->Finish(digest, sizeof(digest)); | |
| 425 | 395 |
| 426 QuicTextUtils::Base64Encode(digest, arraysize(digest), output); | 396 QuicTextUtils::Base64Encode(digest, arraysize(digest), output); |
| 427 return true; | 397 return true; |
| 428 } | 398 } |
| 429 | 399 |
| 430 void QuicCryptoServerStream::ProcessClientHello( | 400 void QuicCryptoServerStream::ProcessClientHello( |
| 431 QuicReferenceCountedPointer<ValidateClientHelloResultCallback::Result> | 401 QuicReferenceCountedPointer<ValidateClientHelloResultCallback::Result> |
| 432 result, | 402 result, |
| 433 std::unique_ptr<ProofSource::Details> proof_source_details, | 403 std::unique_ptr<ProofSource::Details> proof_source_details, |
| 434 std::unique_ptr<ProcessClientHelloResultCallback> done_cb) { | 404 std::unique_ptr<ProcessClientHelloResultCallback> done_cb) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 QuicConnectionId QuicCryptoServerStream::GenerateConnectionIdForReject( | 460 QuicConnectionId QuicCryptoServerStream::GenerateConnectionIdForReject( |
| 491 bool use_stateless_rejects) { | 461 bool use_stateless_rejects) { |
| 492 if (!use_stateless_rejects) { | 462 if (!use_stateless_rejects) { |
| 493 return 0; | 463 return 0; |
| 494 } | 464 } |
| 495 return helper_->GenerateConnectionIdForReject( | 465 return helper_->GenerateConnectionIdForReject( |
| 496 session()->connection()->connection_id()); | 466 session()->connection()->connection_id()); |
| 497 } | 467 } |
| 498 | 468 |
| 499 } // namespace net | 469 } // namespace net |
| OLD | NEW |