Chromium Code Reviews| 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_client_stream.h" | 5 #include "net/quic/quic_crypto_client_stream.h" |
| 6 | 6 |
| 7 #include "net/base/completion_callback.h" | 7 #include "net/base/completion_callback.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.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" |
| 11 #include "net/quic/crypto/null_encrypter.h" | 11 #include "net/quic/crypto/null_encrypter.h" |
| 12 #include "net/quic/crypto/proof_verifier.h" | 12 #include "net/quic/crypto/proof_verifier.h" |
| 13 #include "net/quic/crypto/proof_verifier_chromium.h" | 13 #include "net/quic/crypto/proof_verifier_chromium.h" |
| 14 #include "net/quic/crypto/quic_server_info.h" | |
| 14 #include "net/quic/quic_protocol.h" | 15 #include "net/quic/quic_protocol.h" |
| 15 #include "net/quic/quic_session.h" | 16 #include "net/quic/quic_session.h" |
| 16 #include "net/ssl/ssl_connection_status_flags.h" | 17 #include "net/ssl/ssl_connection_status_flags.h" |
| 17 #include "net/ssl/ssl_info.h" | 18 #include "net/ssl/ssl_info.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // Copies CertVerifyResult from |verify_details| to |cert_verify_result|. | 24 // Copies CertVerifyResult from |verify_details| to |cert_verify_result|. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 QuicCryptoClientStream::QuicCryptoClientStream( | 68 QuicCryptoClientStream::QuicCryptoClientStream( |
| 68 const string& server_hostname, | 69 const string& server_hostname, |
| 69 QuicSession* session, | 70 QuicSession* session, |
| 70 QuicCryptoClientConfig* crypto_config) | 71 QuicCryptoClientConfig* crypto_config) |
| 71 : QuicCryptoStream(session), | 72 : QuicCryptoStream(session), |
| 72 next_state_(STATE_IDLE), | 73 next_state_(STATE_IDLE), |
| 73 num_client_hellos_(0), | 74 num_client_hellos_(0), |
| 74 crypto_config_(crypto_config), | 75 crypto_config_(crypto_config), |
| 75 server_hostname_(server_hostname), | 76 server_hostname_(server_hostname), |
| 76 generation_counter_(0), | 77 generation_counter_(0), |
| 77 proof_verify_callback_(NULL) { | 78 proof_verify_callback_(NULL) { |
|
wtc
2014/02/13 23:48:43
We should initialize quic_server_info_data_ready_r
ramant (doing other things)
2014/02/15 00:36:12
Done.
| |
| 78 } | 79 } |
| 79 | 80 |
| 80 QuicCryptoClientStream::~QuicCryptoClientStream() { | 81 QuicCryptoClientStream::~QuicCryptoClientStream() { |
| 81 if (proof_verify_callback_) { | 82 if (proof_verify_callback_) { |
| 82 proof_verify_callback_->Cancel(); | 83 proof_verify_callback_->Cancel(); |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 | 86 |
| 86 void QuicCryptoClientStream::OnHandshakeMessage( | 87 void QuicCryptoClientStream::OnHandshakeMessage( |
| 87 const CryptoHandshakeMessage& message) { | 88 const CryptoHandshakeMessage& message) { |
| 88 QuicCryptoStream::OnHandshakeMessage(message); | 89 QuicCryptoStream::OnHandshakeMessage(message); |
| 89 | 90 |
| 90 DoHandshakeLoop(&message); | 91 DoHandshakeLoop(&message); |
| 91 } | 92 } |
| 92 | 93 |
| 93 bool QuicCryptoClientStream::CryptoConnect() { | 94 bool QuicCryptoClientStream::CryptoConnect() { |
| 94 next_state_ = STATE_SEND_CHLO; | 95 next_state_ = STATE_LOAD_QUIC_SERVER_INFO; |
| 95 DoHandshakeLoop(NULL); | 96 DoHandshakeLoop(NULL); |
| 96 return true; | 97 return true; |
| 97 } | 98 } |
| 98 | 99 |
| 99 int QuicCryptoClientStream::num_sent_client_hellos() const { | 100 int QuicCryptoClientStream::num_sent_client_hellos() const { |
| 100 return num_client_hellos_; | 101 return num_client_hellos_; |
| 101 } | 102 } |
| 102 | 103 |
| 103 // TODO(rtenneti): Add unittests for GetSSLInfo which exercise the various ways | 104 // TODO(rtenneti): Add unittests for GetSSLInfo which exercise the various ways |
| 104 // we learn about SSL info (sync vs async vs cached). | 105 // we learn about SSL info (sync vs async vs cached). |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 crypto_config_->LookupOrCreate(server_hostname_); | 153 crypto_config_->LookupOrCreate(server_hostname_); |
| 153 | 154 |
| 154 if (in != NULL) { | 155 if (in != NULL) { |
| 155 DVLOG(1) << "Client: Received " << in->DebugString(); | 156 DVLOG(1) << "Client: Received " << in->DebugString(); |
| 156 } | 157 } |
| 157 | 158 |
| 158 for (;;) { | 159 for (;;) { |
| 159 const State state = next_state_; | 160 const State state = next_state_; |
| 160 next_state_ = STATE_IDLE; | 161 next_state_ = STATE_IDLE; |
| 161 switch (state) { | 162 switch (state) { |
| 163 case STATE_LOAD_QUIC_SERVER_INFO: { | |
| 164 if (DoLoadQuicServerInfo(cached) == ERR_IO_PENDING) { | |
| 165 return; | |
| 166 } | |
| 167 break; | |
| 168 } | |
| 169 case STATE_LOAD_QUIC_SERVER_INFO_COMPLETE: { | |
| 170 DoLoadQuicServerInfoComplete(cached); | |
| 171 break; | |
| 172 } | |
| 162 case STATE_SEND_CHLO: { | 173 case STATE_SEND_CHLO: { |
| 163 // Send the client hello in plaintext. | 174 // Send the client hello in plaintext. |
| 164 session()->connection()->SetDefaultEncryptionLevel(ENCRYPTION_NONE); | 175 session()->connection()->SetDefaultEncryptionLevel(ENCRYPTION_NONE); |
| 165 if (num_client_hellos_ > kMaxClientHellos) { | 176 if (num_client_hellos_ > kMaxClientHellos) { |
| 166 CloseConnection(QUIC_CRYPTO_TOO_MANY_REJECTS); | 177 CloseConnection(QUIC_CRYPTO_TOO_MANY_REJECTS); |
| 167 return; | 178 return; |
| 168 } | 179 } |
| 169 num_client_hellos_++; | 180 num_client_hellos_++; |
| 170 | 181 |
| 171 if (!cached->IsComplete(session()->connection()->clock()->WallNow())) { | 182 if (!cached->IsComplete(session()->connection()->clock()->WallNow())) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 return; | 398 return; |
| 388 } | 399 } |
| 389 case STATE_IDLE: | 400 case STATE_IDLE: |
| 390 // This means that the peer sent us a message that we weren't expecting. | 401 // This means that the peer sent us a message that we weren't expecting. |
| 391 CloseConnection(QUIC_INVALID_CRYPTO_MESSAGE_TYPE); | 402 CloseConnection(QUIC_INVALID_CRYPTO_MESSAGE_TYPE); |
| 392 return; | 403 return; |
| 393 } | 404 } |
| 394 } | 405 } |
| 395 } | 406 } |
| 396 | 407 |
| 408 void QuicCryptoClientStream::OnIOComplete(int result) { | |
| 409 DCHECK_EQ(STATE_LOAD_QUIC_SERVER_INFO_COMPLETE, next_state_); | |
| 410 DCHECK_NE(ERR_IO_PENDING, result); | |
| 411 quic_server_info_data_ready_result_ = result; | |
| 412 DoHandshakeLoop(NULL); | |
| 413 } | |
| 414 | |
| 415 int QuicCryptoClientStream::DoLoadQuicServerInfo( | |
| 416 QuicCryptoClientConfig::CachedState* cached) { | |
| 417 next_state_ = STATE_SEND_CHLO; | |
| 418 QuicServerInfo* quic_server_info = cached->quic_server_info(); | |
| 419 if (!quic_server_info) { | |
| 420 return OK; | |
| 421 } | |
| 422 | |
| 423 quic_server_info_data_ready_result_ = OK; | |
| 424 generation_counter_ = cached->generation_counter(); | |
|
wtc
2014/02/13 23:48:43
I think we should set next_state_ to STATE_LOAD_QU
ramant (doing other things)
2014/02/15 00:36:12
Done.
| |
| 425 | |
| 426 // We read the QuicServeInfo's data from disk cache only once. | |
| 427 if (cached->quic_server_info()->IsDataReady()) { | |
| 428 next_state_ = STATE_LOAD_QUIC_SERVER_INFO_COMPLETE; | |
| 429 return OK; | |
| 430 } | |
| 431 | |
| 432 // TODO(rtenneti): If multiple tabs load the same URL, all requests except for | |
| 433 // the first request send InchoateClientHello. Fix the code to handle multiple | |
| 434 // requests. A possible solution is to wait for the first request to finish | |
| 435 // and use the data from the disk cache for all requests. | |
| 436 int rv = quic_server_info->WaitForDataReady( | |
| 437 base::Bind(&QuicCryptoClientStream::OnIOComplete, | |
| 438 base::Unretained(this))); | |
| 439 | |
| 440 if (rv != OK) { | |
| 441 if (rv == ERR_IO_PENDING) { | |
| 442 next_state_ = STATE_LOAD_QUIC_SERVER_INFO_COMPLETE; | |
| 443 return rv; | |
| 444 } | |
| 445 // It is ok to proceed to STATE_SEND_CHLO when we cannot load QuicServerInfo | |
| 446 // from the disk cache. | |
| 447 DVLOG(1) << "QuicServerInfo's WaitForDataReady failed"; | |
| 448 } | |
| 449 return OK; | |
|
wtc
2014/02/13 23:48:43
I think lines 440-449 can be replaced by:
if (r
ramant (doing other things)
2014/02/15 00:36:12
Done.
| |
| 450 } | |
| 451 | |
| 452 void QuicCryptoClientStream::DoLoadQuicServerInfoComplete( | |
|
wtc
2014/02/13 23:48:43
The logic of this method probably should be (omitt
wtc
2014/02/14 01:46:13
void QuicCryptoClientStream::DoLoadQuicServerInfoC
ramant (doing other things)
2014/02/15 00:36:12
Done.
ramant (doing other things)
2014/02/15 00:36:12
As we had talked implemented the second comment.
| |
| 453 QuicCryptoClientConfig::CachedState* cached) { | |
| 454 next_state_ = STATE_SEND_CHLO; | |
| 455 | |
| 456 if (quic_server_info_data_ready_result_ != OK) { | |
| 457 DVLOG(1) << "WaitForDataReady failed result: " | |
| 458 << quic_server_info_data_ready_result_; | |
| 459 return; | |
| 460 } | |
| 461 | |
| 462 // Check if generation_counter has changed between STATE_LOAD_QUIC_SERVER_INFO | |
| 463 // and STATE_LOAD_QUIC_SERVER_INFO_COMPLETE state changes. | |
| 464 if (generation_counter_ != cached->generation_counter()) { | |
| 465 DVLOG(1) << "generation_counter_ has changed: " << generation_counter_ | |
| 466 << " cached's generation_counter_" << cached->generation_counter(); | |
| 467 return; | |
| 468 } | |
| 469 | |
| 470 if (!cached->quic_server_info()->IsDataReady()) { | |
| 471 // It is ok to proceed to STATE_SEND_CHLO when we cannot load QuicServerInfo | |
| 472 // from the disk cache. | |
| 473 DVLOG(1) << "Loading of QuicServerInfo failed"; | |
| 474 return; | |
| 475 } | |
| 476 | |
| 477 cached->LoadQuicServerInfo(); | |
| 478 | |
| 479 if (cached->proof_valid()) { | |
| 480 return; | |
| 481 } | |
| 482 | |
| 483 ProofVerifier* verifier = crypto_config_->proof_verifier(); | |
| 484 if (!verifier) { | |
| 485 // If no verifier is set then we don't check the certificates. | |
| 486 cached->SetProofValid(); | |
| 487 } else if (!cached->signature().empty()) { | |
| 488 next_state_ = STATE_VERIFY_PROOF; | |
| 489 } | |
| 490 } | |
| 491 | |
| 397 } // namespace net | 492 } // namespace net |
| OLD | NEW |