diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-29 16:10:57 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-29 16:10:57 +0000 |
commit | 41d6b17ed3a5b9ef98be8b6362e4ba0153255e09 (patch) | |
tree | 253578b9f3aefaef3751f6d74c5ed5fc50dd820f /net/quic | |
parent | 8d194f73c83ffb277a6f9c9796b906def56785e4 (diff) | |
download | chromium_src-41d6b17ed3a5b9ef98be8b6362e4ba0153255e09.zip chromium_src-41d6b17ed3a5b9ef98be8b6362e4ba0153255e09.tar.gz chromium_src-41d6b17ed3a5b9ef98be8b6362e4ba0153255e09.tar.bz2 |
Add the server name indication (SNI) field to ClientHello.
This requires adding a server_hostname argument to the
QuicClientSession constructor.
Merge internal CL: 39881592
R=rch@chromium.org
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/12079012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179340 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/quic')
-rw-r--r-- | net/quic/crypto/crypto_utils.cc | 10 | ||||
-rw-r--r-- | net/quic/crypto/crypto_utils.h | 1 | ||||
-rw-r--r-- | net/quic/quic_client_session.cc | 5 | ||||
-rw-r--r-- | net/quic/quic_client_session.h | 5 | ||||
-rw-r--r-- | net/quic/quic_client_session_test.cc | 7 | ||||
-rw-r--r-- | net/quic/quic_crypto_client_stream.cc | 9 | ||||
-rw-r--r-- | net/quic/quic_crypto_client_stream.h | 4 | ||||
-rw-r--r-- | net/quic/quic_crypto_client_stream_test.cc | 9 | ||||
-rw-r--r-- | net/quic/quic_http_stream_test.cc | 3 | ||||
-rw-r--r-- | net/quic/quic_stream_factory.cc | 11 | ||||
-rw-r--r-- | net/quic/quic_stream_factory.h | 6 | ||||
-rw-r--r-- | net/quic/quic_stream_factory_test.cc | 4 | ||||
-rw-r--r-- | net/quic/test_tools/quic_test_utils.cc | 6 | ||||
-rw-r--r-- | net/quic/test_tools/quic_test_utils.h | 3 |
14 files changed, 59 insertions, 24 deletions
diff --git a/net/quic/crypto/crypto_utils.cc b/net/quic/crypto/crypto_utils.cc index 15b3b68..976e93d 100644 --- a/net/quic/crypto/crypto_utils.cc +++ b/net/quic/crypto/crypto_utils.cc @@ -5,6 +5,7 @@ #include "net/quic/crypto/crypto_utils.h" #include "base/string_piece.h" +#include "net/base/net_util.h" #include "net/quic/crypto/crypto_protocol.h" #include "net/quic/crypto/quic_random.h" #include "net/quic/quic_clock.h" @@ -29,6 +30,7 @@ void CryptoUtils::GenerateNonce(const QuicClock* clock, void CryptoUtils::FillClientHelloMessage(const QuicClientCryptoConfig& config, const string& nonce, + const string& server_hostname, CryptoHandshakeMessage* message) { message->tag = kCHLO; @@ -69,8 +71,12 @@ void CryptoUtils::FillClientHelloMessage(const QuicClientCryptoConfig& config, message->tag_value_map[kNONC] = nonce; // Server name indication. - // TODO(wtc): if server_hostname_ is a DNS name, store it in - // message->tag_value_map[kSNI]. + // If server_hostname is not an IP address literal, it is a DNS hostname. + IPAddressNumber ip_number; + if (!server_hostname.empty() && + !ParseIPLiteralToNumber(server_hostname, &ip_number)) { + message->tag_value_map[kSNI] = server_hostname; + } } } // namespace net diff --git a/net/quic/crypto/crypto_utils.h b/net/quic/crypto/crypto_utils.h index 949aee3..90f5c96 100644 --- a/net/quic/crypto/crypto_utils.h +++ b/net/quic/crypto/crypto_utils.h @@ -27,6 +27,7 @@ class NET_EXPORT_PRIVATE CryptoUtils { static void FillClientHelloMessage(const QuicClientCryptoConfig& config, const std::string& nonce, + const std::string& server_hostname, CryptoHandshakeMessage* message); }; diff --git a/net/quic/quic_client_session.cc b/net/quic/quic_client_session.cc index 04d11a0..90b44e5 100644 --- a/net/quic/quic_client_session.cc +++ b/net/quic/quic_client_session.cc @@ -18,10 +18,11 @@ namespace net { QuicClientSession::QuicClientSession(QuicConnection* connection, QuicConnectionHelper* helper, - QuicStreamFactory* stream_factory) + QuicStreamFactory* stream_factory, + const string& server_hostname) : QuicSession(connection, false), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), - ALLOW_THIS_IN_INITIALIZER_LIST(crypto_stream_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(crypto_stream_(this, server_hostname)), helper_(helper), stream_factory_(stream_factory), read_buffer_(new IOBufferWithSize(kMaxPacketSize)), diff --git a/net/quic/quic_client_session.h b/net/quic/quic_client_session.h index a09e737c..637514f 100644 --- a/net/quic/quic_client_session.h +++ b/net/quic/quic_client_session.h @@ -10,6 +10,8 @@ #ifndef NET_QUIC_QUIC_CLIENT_SESSION_H_ #define NET_QUIC_QUIC_CLIENT_SESSION_H_ +#include <string> + #include "base/hash_tables.h" #include "net/base/completion_callback.h" #include "net/quic/quic_crypto_client_stream.h" @@ -28,7 +30,8 @@ class NET_EXPORT_PRIVATE QuicClientSession : public QuicSession { // TODO(rch): decouple the factory from the session via a Delegate interface. QuicClientSession(QuicConnection* connection, QuicConnectionHelper* helper, - QuicStreamFactory* stream_factory); + QuicStreamFactory* stream_factory, + const std::string& server_hostname); virtual ~QuicClientSession(); diff --git a/net/quic/quic_client_session_test.cc b/net/quic/quic_client_session_test.cc index 5d55c40..4d5b795 100644 --- a/net/quic/quic_client_session_test.cc +++ b/net/quic/quic_client_session_test.cc @@ -17,12 +17,14 @@ namespace net { namespace test { namespace { +const char kServerHostname[] = "www.example.com"; + class QuicClientSessionTest : public ::testing::Test { protected: QuicClientSessionTest() : guid_(1), connection_(new PacketSavingConnection(guid_, IPEndPoint())), - session_(connection_, NULL, NULL) { + session_(connection_, NULL, NULL, kServerHostname) { } QuicGuid guid_; @@ -36,7 +38,8 @@ TEST_F(QuicClientSessionTest, CryptoConnectSendsCorrectData) { EXPECT_EQ(ERR_IO_PENDING, session_.CryptoConnect(callback_.callback())); ASSERT_EQ(1u, connection_->packets_.size()); scoped_ptr<QuicPacket> chlo(ConstructClientHelloPacket( - guid_, connection_->clock(), connection_->random_generator())); + guid_, connection_->clock(), connection_->random_generator(), + kServerHostname)); CompareQuicDataWithHexError("CHLO", connection_->packets_[0], chlo.get()); } diff --git a/net/quic/quic_crypto_client_stream.cc b/net/quic/quic_crypto_client_stream.cc index 783928a..ce366a9 100644 --- a/net/quic/quic_crypto_client_stream.cc +++ b/net/quic/quic_crypto_client_stream.cc @@ -11,8 +11,10 @@ namespace net { -QuicCryptoClientStream::QuicCryptoClientStream(QuicSession* session) - : QuicCryptoStream(session) { +QuicCryptoClientStream::QuicCryptoClientStream(QuicSession* session, + const string& server_hostname) + : QuicCryptoStream(session), + server_hostname_(server_hostname) { } @@ -40,7 +42,8 @@ bool QuicCryptoClientStream::CryptoConnect() { session()->connection()->random_generator(), &nonce_); CryptoHandshakeMessage message; - CryptoUtils::FillClientHelloMessage(client_crypto_config_, nonce_, &message); + CryptoUtils::FillClientHelloMessage(client_crypto_config_, nonce_, + server_hostname_, &message); SendHandshakeMessage(message); return true; } diff --git a/net/quic/quic_crypto_client_stream.h b/net/quic/quic_crypto_client_stream.h index e8913a2..9eb112b 100644 --- a/net/quic/quic_crypto_client_stream.h +++ b/net/quic/quic_crypto_client_stream.h @@ -17,7 +17,7 @@ struct CryptoHandshakeMessage; class NET_EXPORT_PRIVATE QuicCryptoClientStream : public QuicCryptoStream { public: - explicit QuicCryptoClientStream(QuicSession* session); + QuicCryptoClientStream(QuicSession* session, const string& server_hostname); // CryptoFramerVisitorInterface implementation virtual void OnHandshakeMessage( @@ -31,6 +31,8 @@ class NET_EXPORT_PRIVATE QuicCryptoClientStream : public QuicCryptoStream { QuicClientCryptoConfig client_crypto_config_; // Client's connection nonce (4-byte timestamp + 28 random bytes) std::string nonce_; + // Server's hostname + std::string server_hostname_; DISALLOW_COPY_AND_ASSIGN(QuicCryptoClientStream); }; diff --git a/net/quic/quic_crypto_client_stream_test.cc b/net/quic/quic_crypto_client_stream_test.cc index 21cb140..2ef645b 100644 --- a/net/quic/quic_crypto_client_stream_test.cc +++ b/net/quic/quic_crypto_client_stream_test.cc @@ -13,6 +13,8 @@ namespace net { namespace test { namespace { +const char kServerHostname[] = "localhost"; + class TestQuicVisitor : public NoOpFramerVisitor { public: TestQuicVisitor() {} @@ -99,7 +101,10 @@ void TestMockHelper::CheckClientHelloPacket( CryptoTagValueMap& tag_value_map = crypto_visitor.messages_[0].tag_value_map; - ASSERT_EQ(7u, tag_value_map.size()); + ASSERT_EQ(8u, tag_value_map.size()); + + // kSNI + EXPECT_EQ(kServerHostname, tag_value_map[kSNI]); // kNONC // TODO(wtc): check the nonce. @@ -165,7 +170,7 @@ class QuicCryptoClientStreamTest : public ::testing::Test { QuicCryptoClientStreamTest() : connection_(new MockConnection(1, addr_, new TestMockHelper())), session_(connection_, true), - stream_(&session_) { + stream_(&session_, kServerHostname) { message_.tag = kSHLO; message_.tag_value_map[1] = "abc"; message_.tag_value_map[2] = "def"; diff --git a/net/quic/quic_http_stream_test.cc b/net/quic/quic_http_stream_test.cc index ee35d6d..8ca25c0 100644 --- a/net/quic/quic_http_stream_test.cc +++ b/net/quic/quic_http_stream_test.cc @@ -172,7 +172,8 @@ class QuicHttpStreamTest : public ::testing::TestWithParam<bool> { connection_->set_visitor(&visitor_); connection_->SetScheduler(scheduler_); connection_->SetCollector(collector_); - session_.reset(new QuicClientSession(connection_, helper_, NULL)); + session_.reset(new QuicClientSession(connection_, helper_, NULL, + "www.google.com")); CryptoHandshakeMessage message; message.tag = kSHLO; session_->GetCryptoStream()->OnHandshakeMessage(message); diff --git a/net/quic/quic_stream_factory.cc b/net/quic/quic_stream_factory.cc index db84d74..f9bb6e8 100644 --- a/net/quic/quic_stream_factory.cc +++ b/net/quic/quic_stream_factory.cc @@ -197,7 +197,8 @@ scoped_ptr<QuicHttpStream> QuicStreamRequest::ReleaseStream() { int QuicStreamFactory::Job::DoConnect() { io_state_ = STATE_CONNECT_COMPLETE; - session_ = factory_->CreateSession(address_list_, net_log_); + session_ = factory_->CreateSession(host_port_proxy_pair_.first.host(), + address_list_, net_log_); session_->StartReading(); int rv = session_->CryptoConnect( base::Bind(&QuicStreamFactory::Job::OnIOComplete, @@ -359,10 +360,11 @@ bool QuicStreamFactory::HasActiveSession( } QuicClientSession* QuicStreamFactory::CreateSession( - const AddressList& address_list_, + const std::string& host, + const AddressList& address_list, const BoundNetLog& net_log) { QuicGuid guid = random_generator_->RandUint64(); - IPEndPoint addr = *address_list_.begin(); + IPEndPoint addr = *address_list.begin(); DatagramClientSocket* socket = client_socket_factory_->CreateDatagramClientSocket( DatagramSocket::DEFAULT_BIND, base::Bind(&base::RandInt), @@ -375,7 +377,8 @@ QuicClientSession* QuicStreamFactory::CreateSession( clock_.get(), random_generator_, socket); QuicConnection* connection = new QuicConnection(guid, addr, helper); - QuicClientSession* session = new QuicClientSession(connection, helper, this); + QuicClientSession* session = new QuicClientSession(connection, helper, this, + host); all_sessions_.insert(session); // owning pointer return session; } diff --git a/net/quic/quic_stream_factory.h b/net/quic/quic_stream_factory.h index 073286c..e019944 100644 --- a/net/quic/quic_stream_factory.h +++ b/net/quic/quic_stream_factory.h @@ -6,6 +6,7 @@ #define NET_QUIC_QUIC_STREAM_FACTORY_H_ #include <map> +#include <string> #include "base/memory/weak_ptr.h" #include "net/base/address_list.h" @@ -111,8 +112,9 @@ class NET_EXPORT_PRIVATE QuicStreamFactory { void OnJobComplete(Job* job, int rv); bool HasActiveSession(const HostPortProxyPair& host_port_proxy_pair); bool HasActiveJob(const HostPortProxyPair& host_port_proxy_pair); - QuicClientSession* CreateSession(const AddressList& address_list_, - const BoundNetLog& net_log); + QuicClientSession* CreateSession(const std::string& host, + const AddressList& address_list, + const BoundNetLog& net_log); void ActivateSession(const HostPortProxyPair& host_port_proxy_pair, QuicClientSession* session); diff --git a/net/quic/quic_stream_factory_test.cc b/net/quic/quic_stream_factory_test.cc index 3c88467..f18e3b3 100644 --- a/net/quic/quic_stream_factory_test.cc +++ b/net/quic/quic_stream_factory_test.cc @@ -31,9 +31,11 @@ class QuicStreamFactoryTest : public ::testing::Test { } scoped_ptr<QuicEncryptedPacket> ConstructChlo() { + const std::string& host = host_port_proxy_pair_.first.host(); scoped_ptr<QuicPacket> chlo(ConstructClientHelloPacket(0xDEADBEEF, clock_, - &random_generator_)); + &random_generator_, + host)); QuicFramer framer(QuicDecrypter::Create(kNULL), QuicEncrypter::Create(kNULL)); return scoped_ptr<QuicEncryptedPacket>(framer.EncryptPacket(*chlo)); diff --git a/net/quic/test_tools/quic_test_utils.cc b/net/quic/test_tools/quic_test_utils.cc index 9935096..8f7feeb 100644 --- a/net/quic/test_tools/quic_test_utils.cc +++ b/net/quic/test_tools/quic_test_utils.cc @@ -227,14 +227,16 @@ QuicPacket* ConstructHandshakePacket(QuicGuid guid, CryptoTag tag) { QuicPacket* ConstructClientHelloPacket(QuicGuid guid, const QuicClock* clock, - QuicRandom* random_generator) { + QuicRandom* random_generator, + const string& server_hostname) { QuicClientCryptoConfig config; config.SetDefaults(); string nonce; CryptoUtils::GenerateNonce(clock, random_generator, &nonce); CryptoHandshakeMessage message; - CryptoUtils::FillClientHelloMessage(config, nonce, &message); + CryptoUtils::FillClientHelloMessage(config, nonce, server_hostname, + &message); CryptoFramer crypto_framer; scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message)); QuicFramer quic_framer(QuicDecrypter::Create(kNULL), diff --git a/net/quic/test_tools/quic_test_utils.h b/net/quic/test_tools/quic_test_utils.h index 61d204b..b15c480 100644 --- a/net/quic/test_tools/quic_test_utils.h +++ b/net/quic/test_tools/quic_test_utils.h @@ -35,7 +35,8 @@ QuicPacket* ConstructHandshakePacket(QuicGuid guid, CryptoTag tag); // Constructs a ClientHello crypto handshake message QuicPacket* ConstructClientHelloPacket(QuicGuid guid, const QuicClock* clock, - QuicRandom* random_generator); + QuicRandom* random_generator, + const std::string& server_hostname); class MockFramerVisitor : public QuicFramerVisitorInterface { public: |