Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Side by Side Diff: net/quic/quic_crypto_client_stream.cc

Issue 1665743003: Refactor QuicCryptoClientStream to use QuicSession directly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@113297234
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_crypto_client_stream.h ('k') | net/quic/quic_crypto_client_stream_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <vector> 7 #include <vector>
8 8
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/metrics/sparse_histogram.h" 10 #include "base/metrics/sparse_histogram.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "net/quic/crypto/crypto_protocol.h" 12 #include "net/quic/crypto/crypto_protocol.h"
13 #include "net/quic/crypto/crypto_utils.h" 13 #include "net/quic/crypto/crypto_utils.h"
14 #include "net/quic/crypto/null_encrypter.h" 14 #include "net/quic/crypto/null_encrypter.h"
15 #include "net/quic/quic_client_session_base.h"
16 #include "net/quic/quic_flags.h" 15 #include "net/quic/quic_flags.h"
17 #include "net/quic/quic_protocol.h" 16 #include "net/quic/quic_protocol.h"
18 #include "net/quic/quic_session.h" 17 #include "net/quic/quic_session.h"
19 18
20 using std::string; 19 using std::string;
21 using std::vector; 20 using std::vector;
22 21
23 namespace net { 22 namespace net {
24 23
25 namespace { 24 namespace {
26 25
27 void AppendFixed(CryptoHandshakeMessage* message) { 26 void AppendFixed(CryptoHandshakeMessage* message) {
28 vector<QuicTag> tags; 27 vector<QuicTag> tags;
29 tags.push_back(kFIXD); 28 tags.push_back(kFIXD);
30 29
31 const QuicTag* received_tags; 30 const QuicTag* received_tags;
32 size_t received_tags_length; 31 size_t received_tags_length;
33 QuicErrorCode error = 32 QuicErrorCode error =
34 message->GetTaglist(kCOPT, &received_tags, &received_tags_length); 33 message->GetTaglist(kCOPT, &received_tags, &received_tags_length);
35 if (error == QUIC_NO_ERROR) { 34 if (error == QUIC_NO_ERROR) {
36 for (size_t i = 0; i < received_tags_length; ++i) { 35 for (size_t i = 0; i < received_tags_length; ++i) {
37 tags.push_back(received_tags[i]); 36 tags.push_back(received_tags[i]);
38 } 37 }
39 } 38 }
40 message->SetVector(kCOPT, tags); 39 message->SetVector(kCOPT, tags);
41 } 40 }
42 41
43 } // namespace 42 } // namespace
44 43
45 QuicCryptoClientStreamBase::QuicCryptoClientStreamBase( 44 QuicCryptoClientStreamBase::QuicCryptoClientStreamBase(QuicSession* session)
46 QuicClientSessionBase* session)
47 : QuicCryptoStream(session) {} 45 : QuicCryptoStream(session) {}
48 46
49 QuicCryptoClientStream::ChannelIDSourceCallbackImpl:: 47 QuicCryptoClientStream::ChannelIDSourceCallbackImpl::
50 ChannelIDSourceCallbackImpl(QuicCryptoClientStream* stream) 48 ChannelIDSourceCallbackImpl(QuicCryptoClientStream* stream)
51 : stream_(stream) {} 49 : stream_(stream) {}
52 50
53 QuicCryptoClientStream::ChannelIDSourceCallbackImpl:: 51 QuicCryptoClientStream::ChannelIDSourceCallbackImpl::
54 ~ChannelIDSourceCallbackImpl() {} 52 ~ChannelIDSourceCallbackImpl() {}
55 53
56 void QuicCryptoClientStream::ChannelIDSourceCallbackImpl::Run( 54 void QuicCryptoClientStream::ChannelIDSourceCallbackImpl::Run(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // The ProofVerifier owns this object and will delete it when this method 94 // The ProofVerifier owns this object and will delete it when this method
97 // returns. 95 // returns.
98 } 96 }
99 97
100 void QuicCryptoClientStream::ProofVerifierCallbackImpl::Cancel() { 98 void QuicCryptoClientStream::ProofVerifierCallbackImpl::Cancel() {
101 stream_ = nullptr; 99 stream_ = nullptr;
102 } 100 }
103 101
104 QuicCryptoClientStream::QuicCryptoClientStream( 102 QuicCryptoClientStream::QuicCryptoClientStream(
105 const QuicServerId& server_id, 103 const QuicServerId& server_id,
106 QuicClientSessionBase* session, 104 QuicSession* session,
107 ProofVerifyContext* verify_context, 105 ProofVerifyContext* verify_context,
108 QuicCryptoClientConfig* crypto_config) 106 QuicCryptoClientConfig* crypto_config,
107 ProofHandler* proof_handler)
109 : QuicCryptoClientStreamBase(session), 108 : QuicCryptoClientStreamBase(session),
110 next_state_(STATE_IDLE), 109 next_state_(STATE_IDLE),
111 num_client_hellos_(0), 110 num_client_hellos_(0),
112 crypto_config_(crypto_config), 111 crypto_config_(crypto_config),
113 server_id_(server_id), 112 server_id_(server_id),
114 generation_counter_(0), 113 generation_counter_(0),
115 channel_id_sent_(false), 114 channel_id_sent_(false),
116 channel_id_source_callback_run_(false), 115 channel_id_source_callback_run_(false),
117 channel_id_source_callback_(nullptr), 116 channel_id_source_callback_(nullptr),
118 verify_context_(verify_context), 117 verify_context_(verify_context),
119 proof_verify_callback_(nullptr), 118 proof_verify_callback_(nullptr),
119 proof_handler_(proof_handler),
120 stateless_reject_received_(false) { 120 stateless_reject_received_(false) {
121 DCHECK_EQ(Perspective::IS_CLIENT, session->connection()->perspective()); 121 DCHECK_EQ(Perspective::IS_CLIENT, session->connection()->perspective());
122 } 122 }
123 123
124 QuicCryptoClientStream::~QuicCryptoClientStream() { 124 QuicCryptoClientStream::~QuicCryptoClientStream() {
125 if (channel_id_source_callback_) { 125 if (channel_id_source_callback_) {
126 channel_id_source_callback_->Cancel(); 126 channel_id_source_callback_->Cancel();
127 } 127 }
128 if (proof_verify_callback_) { 128 if (proof_verify_callback_) {
129 proof_verify_callback_->Cancel(); 129 proof_verify_callback_->Cancel();
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 349
350 if (error != QUIC_NO_ERROR) { 350 if (error != QUIC_NO_ERROR) {
351 // Flush the cached config so that, if it's bad, the server has a 351 // Flush the cached config so that, if it's bad, the server has a
352 // chance to send us another in the future. 352 // chance to send us another in the future.
353 cached->InvalidateServerConfig(); 353 cached->InvalidateServerConfig();
354 CloseConnectionWithDetails(error, error_details); 354 CloseConnectionWithDetails(error, error_details);
355 return; 355 return;
356 } 356 }
357 channel_id_sent_ = (channel_id_key_.get() != nullptr); 357 channel_id_sent_ = (channel_id_key_.get() != nullptr);
358 if (cached->proof_verify_details()) { 358 if (cached->proof_verify_details()) {
359 client_session()->OnProofVerifyDetailsAvailable( 359 proof_handler_->OnProofVerifyDetailsAvailable(
360 *cached->proof_verify_details()); 360 *cached->proof_verify_details());
361 } 361 }
362 next_state_ = STATE_RECV_SHLO; 362 next_state_ = STATE_RECV_SHLO;
363 SendHandshakeMessage(out); 363 SendHandshakeMessage(out);
364 // Be prepared to decrypt with the new server write key. 364 // Be prepared to decrypt with the new server write key.
365 session()->connection()->SetAlternativeDecrypter( 365 session()->connection()->SetAlternativeDecrypter(
366 ENCRYPTION_INITIAL, 366 ENCRYPTION_INITIAL,
367 crypto_negotiated_params_.initial_crypters.decrypter.release(), 367 crypto_negotiated_params_.initial_crypters.decrypter.release(),
368 true /* latch once used */); 368 true /* latch once used */);
369 // Send subsequent packets under encryption on the assumption that the 369 // Send subsequent packets under encryption on the assumption that the
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 479 }
480 480
481 void QuicCryptoClientStream::DoVerifyProofComplete( 481 void QuicCryptoClientStream::DoVerifyProofComplete(
482 QuicCryptoClientConfig::CachedState* cached) { 482 QuicCryptoClientConfig::CachedState* cached) {
483 if (!proof_verify_start_time_.is_null()) { 483 if (!proof_verify_start_time_.is_null()) {
484 UMA_HISTOGRAM_TIMES("Net.QuicSession.VerifyProofTime.CachedServerConfig", 484 UMA_HISTOGRAM_TIMES("Net.QuicSession.VerifyProofTime.CachedServerConfig",
485 base::TimeTicks::Now() - proof_verify_start_time_); 485 base::TimeTicks::Now() - proof_verify_start_time_);
486 } 486 }
487 if (!verify_ok_) { 487 if (!verify_ok_) {
488 if (verify_details_.get()) { 488 if (verify_details_.get()) {
489 client_session()->OnProofVerifyDetailsAvailable(*verify_details_); 489 proof_handler_->OnProofVerifyDetailsAvailable(*verify_details_);
490 } 490 }
491 if (num_client_hellos_ == 0) { 491 if (num_client_hellos_ == 0) {
492 cached->Clear(); 492 cached->Clear();
493 next_state_ = STATE_INITIALIZE; 493 next_state_ = STATE_INITIALIZE;
494 return; 494 return;
495 } 495 }
496 next_state_ = STATE_NONE; 496 next_state_ = STATE_NONE;
497 UMA_HISTOGRAM_BOOLEAN("Net.QuicVerifyProofFailed.HandshakeConfirmed", 497 UMA_HISTOGRAM_BOOLEAN("Net.QuicVerifyProofFailed.HandshakeConfirmed",
498 handshake_confirmed()); 498 handshake_confirmed());
499 CloseConnectionWithDetails(QUIC_PROOF_INVALID, 499 CloseConnectionWithDetails(QUIC_PROOF_INVALID,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 update_ignored = true; 642 update_ignored = true;
643 next_state_ = STATE_NONE; 643 next_state_ = STATE_NONE;
644 } 644 }
645 UMA_HISTOGRAM_COUNTS("Net.QuicNumServerConfig.UpdateMessagesIgnored", 645 UMA_HISTOGRAM_COUNTS("Net.QuicNumServerConfig.UpdateMessagesIgnored",
646 update_ignored); 646 update_ignored);
647 } 647 }
648 648
649 void QuicCryptoClientStream::SetCachedProofValid( 649 void QuicCryptoClientStream::SetCachedProofValid(
650 QuicCryptoClientConfig::CachedState* cached) { 650 QuicCryptoClientConfig::CachedState* cached) {
651 cached->SetProofValid(); 651 cached->SetProofValid();
652 client_session()->OnProofValid(*cached); 652 proof_handler_->OnProofValid(*cached);
653 } 653 }
654 654
655 bool QuicCryptoClientStream::RequiresChannelID( 655 bool QuicCryptoClientStream::RequiresChannelID(
656 QuicCryptoClientConfig::CachedState* cached) { 656 QuicCryptoClientConfig::CachedState* cached) {
657 if (server_id_.privacy_mode() == PRIVACY_MODE_ENABLED || 657 if (server_id_.privacy_mode() == PRIVACY_MODE_ENABLED ||
658 !crypto_config_->channel_id_source()) { 658 !crypto_config_->channel_id_source()) {
659 return false; 659 return false;
660 } 660 }
661 const CryptoHandshakeMessage* scfg = cached->GetServerConfig(); 661 const CryptoHandshakeMessage* scfg = cached->GetServerConfig();
662 if (!scfg) { // scfg may be null then we send an inchoate CHLO. 662 if (!scfg) { // scfg may be null then we send an inchoate CHLO.
663 return false; 663 return false;
664 } 664 }
665 const QuicTag* their_proof_demands; 665 const QuicTag* their_proof_demands;
666 size_t num_their_proof_demands; 666 size_t num_their_proof_demands;
667 if (scfg->GetTaglist(kPDMD, &their_proof_demands, &num_their_proof_demands) != 667 if (scfg->GetTaglist(kPDMD, &their_proof_demands, &num_their_proof_demands) !=
668 QUIC_NO_ERROR) { 668 QUIC_NO_ERROR) {
669 return false; 669 return false;
670 } 670 }
671 for (size_t i = 0; i < num_their_proof_demands; i++) { 671 for (size_t i = 0; i < num_their_proof_demands; i++) {
672 if (their_proof_demands[i] == kCHID) { 672 if (their_proof_demands[i] == kCHID) {
673 return true; 673 return true;
674 } 674 }
675 } 675 }
676 return false; 676 return false;
677 } 677 }
678 678
679 QuicClientSessionBase* QuicCryptoClientStream::client_session() {
680 return reinterpret_cast<QuicClientSessionBase*>(session());
681 }
682
683 } // namespace net 679 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_crypto_client_stream.h ('k') | net/quic/quic_crypto_client_stream_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698