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_client_session.h" | 5 #include "net/quic/quic_client_session.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "net/quic/crypto/proof_verifier_chromium.h" | 16 #include "net/quic/crypto/proof_verifier_chromium.h" |
17 #include "net/quic/crypto/quic_server_info.h" | 17 #include "net/quic/crypto/quic_server_info.h" |
18 #include "net/quic/quic_connection_helper.h" | 18 #include "net/quic/quic_connection_helper.h" |
19 #include "net/quic/quic_crypto_client_stream_factory.h" | 19 #include "net/quic/quic_crypto_client_stream_factory.h" |
20 #include "net/quic/quic_default_packet_writer.h" | 20 #include "net/quic/quic_default_packet_writer.h" |
21 #include "net/quic/quic_server_id.h" | 21 #include "net/quic/quic_server_id.h" |
22 #include "net/quic/quic_stream_factory.h" | 22 #include "net/quic/quic_stream_factory.h" |
23 #include "net/ssl/channel_id_service.h" | |
23 #include "net/ssl/ssl_connection_status_flags.h" | 24 #include "net/ssl/ssl_connection_status_flags.h" |
24 #include "net/ssl/ssl_info.h" | 25 #include "net/ssl/ssl_info.h" |
25 #include "net/udp/datagram_client_socket.h" | 26 #include "net/udp/datagram_client_socket.h" |
26 | 27 |
27 namespace net { | 28 namespace net { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 // The length of time to wait for a 0-RTT handshake to complete | 32 // The length of time to wait for a 0-RTT handshake to complete |
32 // before allowing the requests to possibly proceed over TCP. | 33 // before allowing the requests to possibly proceed over TCP. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 *stream_ = stream; | 126 *stream_ = stream; |
126 ResetAndReturn(&callback_).Run(OK); | 127 ResetAndReturn(&callback_).Run(OK); |
127 } | 128 } |
128 | 129 |
129 void QuicClientSession::StreamRequest::OnRequestCompleteFailure(int rv) { | 130 void QuicClientSession::StreamRequest::OnRequestCompleteFailure(int rv) { |
130 session_.reset(); | 131 session_.reset(); |
131 ResetAndReturn(&callback_).Run(rv); | 132 ResetAndReturn(&callback_).Run(rv); |
132 } | 133 } |
133 | 134 |
134 QuicClientSession::QuicClientSession( | 135 QuicClientSession::QuicClientSession( |
136 const HostPortPair& server_host_port, | |
135 QuicConnection* connection, | 137 QuicConnection* connection, |
136 scoped_ptr<DatagramClientSocket> socket, | 138 scoped_ptr<DatagramClientSocket> socket, |
137 scoped_ptr<QuicDefaultPacketWriter> writer, | 139 scoped_ptr<QuicDefaultPacketWriter> writer, |
138 QuicStreamFactory* stream_factory, | 140 QuicStreamFactory* stream_factory, |
139 QuicCryptoClientStreamFactory* crypto_client_stream_factory, | 141 QuicCryptoClientStreamFactory* crypto_client_stream_factory, |
140 scoped_ptr<QuicServerInfo> server_info, | 142 scoped_ptr<QuicServerInfo> server_info, |
141 const QuicServerId& server_id, | 143 const QuicServerId& server_id, |
142 const QuicConfig& config, | 144 const QuicConfig& config, |
143 QuicCryptoClientConfig* crypto_config, | 145 QuicCryptoClientConfig* crypto_config, |
144 base::TaskRunner* task_runner, | 146 base::TaskRunner* task_runner, |
145 NetLog* net_log) | 147 NetLog* net_log) |
146 : QuicClientSessionBase(connection, | 148 : QuicClientSessionBase(connection, |
147 config), | 149 config), |
150 server_host_port_(server_host_port), | |
148 require_confirmation_(false), | 151 require_confirmation_(false), |
149 stream_factory_(stream_factory), | 152 stream_factory_(stream_factory), |
150 socket_(socket.Pass()), | 153 socket_(socket.Pass()), |
151 writer_(writer.Pass()), | 154 writer_(writer.Pass()), |
152 read_buffer_(new IOBufferWithSize(kMaxPacketSize)), | 155 read_buffer_(new IOBufferWithSize(kMaxPacketSize)), |
153 server_info_(server_info.Pass()), | 156 server_info_(server_info.Pass()), |
154 read_pending_(false), | 157 read_pending_(false), |
155 num_total_streams_(0), | 158 num_total_streams_(0), |
156 task_runner_(task_runner), | 159 task_runner_(task_runner), |
157 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), | 160 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 ssl_connection_status |= | 420 ssl_connection_status |= |
418 (SSL_CONNECTION_VERSION_QUIC & SSL_CONNECTION_VERSION_MASK) << | 421 (SSL_CONNECTION_VERSION_QUIC & SSL_CONNECTION_VERSION_MASK) << |
419 SSL_CONNECTION_VERSION_SHIFT; | 422 SSL_CONNECTION_VERSION_SHIFT; |
420 | 423 |
421 ssl_info->public_key_hashes = cert_verify_result_->public_key_hashes; | 424 ssl_info->public_key_hashes = cert_verify_result_->public_key_hashes; |
422 ssl_info->is_issued_by_known_root = | 425 ssl_info->is_issued_by_known_root = |
423 cert_verify_result_->is_issued_by_known_root; | 426 cert_verify_result_->is_issued_by_known_root; |
424 | 427 |
425 ssl_info->connection_status = ssl_connection_status; | 428 ssl_info->connection_status = ssl_connection_status; |
426 ssl_info->client_cert_sent = false; | 429 ssl_info->client_cert_sent = false; |
427 ssl_info->channel_id_sent = false; | 430 ssl_info->channel_id_sent = crypto_stream_->WasChannelIDSent(); |
428 ssl_info->security_bits = security_bits; | 431 ssl_info->security_bits = security_bits; |
429 ssl_info->handshake_type = SSLInfo::HANDSHAKE_FULL; | 432 ssl_info->handshake_type = SSLInfo::HANDSHAKE_FULL; |
430 return true; | 433 return true; |
431 } | 434 } |
432 | 435 |
433 int QuicClientSession::CryptoConnect(bool require_confirmation, | 436 int QuicClientSession::CryptoConnect(bool require_confirmation, |
434 const CompletionCallback& callback) { | 437 const CompletionCallback& callback) { |
435 require_confirmation_ = require_confirmation; | 438 require_confirmation_ = require_confirmation; |
436 handshake_start_ = base::TimeTicks::Now(); | 439 handshake_start_ = base::TimeTicks::Now(); |
437 RecordHandshakeState(STATE_STARTED); | 440 RecordHandshakeState(STATE_STARTED); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 | 475 |
473 callback_ = callback; | 476 callback_ = callback; |
474 return ERR_IO_PENDING; | 477 return ERR_IO_PENDING; |
475 } | 478 } |
476 | 479 |
477 int QuicClientSession::GetNumSentClientHellos() const { | 480 int QuicClientSession::GetNumSentClientHellos() const { |
478 return crypto_stream_->num_sent_client_hellos(); | 481 return crypto_stream_->num_sent_client_hellos(); |
479 } | 482 } |
480 | 483 |
481 bool QuicClientSession::CanPool(const std::string& hostname) const { | 484 bool QuicClientSession::CanPool(const std::string& hostname) const { |
482 // TODO(rch): When QUIC supports channel ID or client certificates, this | |
483 // logic will need to be revised. | |
484 DCHECK(connection()->connected()); | 485 DCHECK(connection()->connected()); |
485 SSLInfo ssl_info; | 486 SSLInfo ssl_info; |
486 bool unused = false; | |
487 if (!GetSSLInfo(&ssl_info) || !ssl_info.cert) { | 487 if (!GetSSLInfo(&ssl_info) || !ssl_info.cert) { |
488 // We can always pool with insecure QUIC sessions. | 488 // We can always pool with insecure QUIC sessions. |
489 return true; | 489 return true; |
490 } | 490 } |
491 // Only pool secure QUIC sessions if the cert matches the new hostname. | 491 |
492 return ssl_info.cert->VerifyNameMatch(hostname, &unused); | 492 bool unused = false; |
493 // Pooling is prohibited for connections on which client certs were | |
494 // sent. It is also prohibited for when channel ID was sent if the | |
495 // hosts are from different ETLDs. And of course, it is prohibited | |
wtc
2014/07/01 23:00:14
ETLDs => eTLDs
Ryan Hamilton
2014/07/01 23:26:19
Done.
| |
496 // if the cert is not valid for the new domain. | |
wtc
2014/07/01 23:00:14
cert => server cert
Ryan Hamilton
2014/07/01 23:26:19
Done.
| |
497 return | |
498 !ssl_info.client_cert_sent && | |
499 (!ssl_info.channel_id_sent || | |
500 (ChannelIDService::GetDomainForHost(hostname) == | |
501 ChannelIDService::GetDomainForHost(server_host_port_.host()))) && | |
502 ssl_info.cert->VerifyNameMatch(hostname, &unused); | |
493 } | 503 } |
494 | 504 |
495 QuicDataStream* QuicClientSession::CreateIncomingDataStream( | 505 QuicDataStream* QuicClientSession::CreateIncomingDataStream( |
496 QuicStreamId id) { | 506 QuicStreamId id) { |
497 DLOG(ERROR) << "Server push not supported"; | 507 DLOG(ERROR) << "Server push not supported"; |
498 return NULL; | 508 return NULL; |
499 } | 509 } |
500 | 510 |
501 void QuicClientSession::CloseStream(QuicStreamId stream_id) { | 511 void QuicClientSession::CloseStream(QuicStreamId stream_id) { |
502 ReliableQuicStream* stream = GetStream(stream_id); | 512 ReliableQuicStream* stream = GetStream(stream_id); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 while (!observers_.empty()) { | 728 while (!observers_.empty()) { |
719 Observer* observer = *observers_.begin(); | 729 Observer* observer = *observers_.begin(); |
720 observers_.erase(observer); | 730 observers_.erase(observer); |
721 observer->OnSessionClosed(net_error); | 731 observer->OnSessionClosed(net_error); |
722 } | 732 } |
723 } | 733 } |
724 | 734 |
725 base::Value* QuicClientSession::GetInfoAsValue( | 735 base::Value* QuicClientSession::GetInfoAsValue( |
726 const std::set<HostPortPair>& aliases) { | 736 const std::set<HostPortPair>& aliases) { |
727 base::DictionaryValue* dict = new base::DictionaryValue(); | 737 base::DictionaryValue* dict = new base::DictionaryValue(); |
728 // TODO(rch): remove "host_port_pair" when Chrome 34 is stable. | |
729 dict->SetString("host_port_pair", aliases.begin()->ToString()); | |
730 dict->SetString("version", QuicVersionToString(connection()->version())); | 738 dict->SetString("version", QuicVersionToString(connection()->version())); |
731 dict->SetInteger("open_streams", GetNumOpenStreams()); | 739 dict->SetInteger("open_streams", GetNumOpenStreams()); |
732 base::ListValue* stream_list = new base::ListValue(); | 740 base::ListValue* stream_list = new base::ListValue(); |
733 for (base::hash_map<QuicStreamId, QuicDataStream*>::const_iterator it | 741 for (base::hash_map<QuicStreamId, QuicDataStream*>::const_iterator it |
734 = streams()->begin(); | 742 = streams()->begin(); |
735 it != streams()->end(); | 743 it != streams()->end(); |
736 ++it) { | 744 ++it) { |
737 stream_list->Append(new base::StringValue( | 745 stream_list->Append(new base::StringValue( |
738 base::Uint64ToString(it->second->id()))); | 746 base::Uint64ToString(it->second->id()))); |
739 } | 747 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 return; | 845 return; |
838 | 846 |
839 // TODO(rch): re-enable this code once beta is cut. | 847 // TODO(rch): re-enable this code once beta is cut. |
840 // if (stream_factory_) | 848 // if (stream_factory_) |
841 // stream_factory_->OnSessionConnectTimeout(this); | 849 // stream_factory_->OnSessionConnectTimeout(this); |
842 // CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED); | 850 // CloseAllStreams(ERR_QUIC_HANDSHAKE_FAILED); |
843 // DCHECK_EQ(0u, GetNumOpenStreams()); | 851 // DCHECK_EQ(0u, GetNumOpenStreams()); |
844 } | 852 } |
845 | 853 |
846 } // namespace net | 854 } // namespace net |
OLD | NEW |