| 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_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "net/base/test_data_directory.h" | 9 #include "net/base/test_data_directory.h" |
| 10 #include "net/cert/cert_verifier.h" | 10 #include "net/cert/cert_verifier.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 const char kDefaultServerHostName[] = "www.google.com"; | 37 const char kDefaultServerHostName[] = "www.google.com"; |
| 38 const int kDefaultServerPort = 443; | 38 const int kDefaultServerPort = 443; |
| 39 } // namespace anonymous | 39 } // namespace anonymous |
| 40 | 40 |
| 41 class QuicStreamFactoryPeer { | 41 class QuicStreamFactoryPeer { |
| 42 public: | 42 public: |
| 43 static QuicCryptoClientConfig* GetOrCreateCryptoConfig( | 43 static QuicCryptoClientConfig* GetOrCreateCryptoConfig( |
| 44 QuicStreamFactory* factory, | 44 QuicStreamFactory* factory, |
| 45 const HostPortPair& host_port_pair, | 45 const HostPortPair& host_port_pair, |
| 46 bool is_https) { | 46 bool is_https) { |
| 47 QuicSessionKey session_key(host_port_pair, is_https); | 47 QuicSessionKey server_key(host_port_pair, is_https); |
| 48 return factory->GetOrCreateCryptoConfig(session_key); | 48 return factory->GetOrCreateCryptoConfig(server_key); |
| 49 } | 49 } |
| 50 | 50 |
| 51 static bool HasActiveSession(QuicStreamFactory* factory, | 51 static bool HasActiveSession(QuicStreamFactory* factory, |
| 52 const HostPortPair& host_port_pair, | 52 const HostPortPair& host_port_pair, |
| 53 bool is_https) { | 53 bool is_https) { |
| 54 QuicSessionKey session_key(host_port_pair, is_https); | 54 QuicSessionKey server_key(host_port_pair, is_https); |
| 55 return factory->HasActiveSession(session_key); | 55 return factory->HasActiveSession(server_key); |
| 56 } | 56 } |
| 57 | 57 |
| 58 static QuicClientSession* GetActiveSession( | 58 static QuicClientSession* GetActiveSession( |
| 59 QuicStreamFactory* factory, | 59 QuicStreamFactory* factory, |
| 60 const HostPortPair& host_port_pair, | 60 const HostPortPair& host_port_pair, |
| 61 bool is_https) { | 61 bool is_https) { |
| 62 QuicSessionKey session_key(host_port_pair, is_https); | 62 QuicSessionKey server_key(host_port_pair, is_https); |
| 63 DCHECK(factory->HasActiveSession(session_key)); | 63 DCHECK(factory->HasActiveSession(server_key)); |
| 64 return factory->active_sessions_[session_key]; | 64 return factory->active_sessions_[server_key]; |
| 65 } | 65 } |
| 66 | 66 |
| 67 static scoped_ptr<QuicHttpStream> CreateIfSessionExists( | 67 static scoped_ptr<QuicHttpStream> CreateIfSessionExists( |
| 68 QuicStreamFactory* factory, | 68 QuicStreamFactory* factory, |
| 69 const HostPortPair& host_port_pair, | 69 const HostPortPair& host_port_pair, |
| 70 bool is_https, | 70 bool is_https, |
| 71 const BoundNetLog& net_log) { | 71 const BoundNetLog& net_log) { |
| 72 QuicSessionKey session_key(host_port_pair, is_https); | 72 QuicSessionKey server_key(host_port_pair, is_https); |
| 73 return factory->CreateIfSessionExists(session_key, net_log); | 73 return factory->CreateIfSessionExists(server_key, net_log); |
| 74 } | 74 } |
| 75 | 75 |
| 76 static bool IsLiveSession(QuicStreamFactory* factory, | 76 static bool IsLiveSession(QuicStreamFactory* factory, |
| 77 QuicClientSession* session) { | 77 QuicClientSession* session) { |
| 78 for (QuicStreamFactory::SessionSet::iterator it = | 78 for (QuicStreamFactory::SessionSet::iterator it = |
| 79 factory->all_sessions_.begin(); | 79 factory->all_sessions_.begin(); |
| 80 it != factory->all_sessions_.end(); ++it) { | 80 it != factory->all_sessions_.end(); ++it) { |
| 81 if (*it == session) | 81 if (*it == session) |
| 82 return true; | 82 return true; |
| 83 } | 83 } |
| (...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 string r1_host_name("r1"); | 1022 string r1_host_name("r1"); |
| 1023 string r2_host_name("r2"); | 1023 string r2_host_name("r2"); |
| 1024 r1_host_name.append(cannoncial_suffixes[i]); | 1024 r1_host_name.append(cannoncial_suffixes[i]); |
| 1025 r2_host_name.append(cannoncial_suffixes[i]); | 1025 r2_host_name.append(cannoncial_suffixes[i]); |
| 1026 | 1026 |
| 1027 HostPortPair host_port_pair1(r1_host_name, 80); | 1027 HostPortPair host_port_pair1(r1_host_name, 80); |
| 1028 QuicCryptoClientConfig* crypto_config1 = | 1028 QuicCryptoClientConfig* crypto_config1 = |
| 1029 QuicStreamFactoryPeer::GetOrCreateCryptoConfig( | 1029 QuicStreamFactoryPeer::GetOrCreateCryptoConfig( |
| 1030 &factory_, host_port_pair1, is_https_); | 1030 &factory_, host_port_pair1, is_https_); |
| 1031 DCHECK(crypto_config1); | 1031 DCHECK(crypto_config1); |
| 1032 QuicSessionKey server_key1(host_port_pair1, is_https_); |
| 1032 QuicCryptoClientConfig::CachedState* cached1 = | 1033 QuicCryptoClientConfig::CachedState* cached1 = |
| 1033 crypto_config1->LookupOrCreate(host_port_pair1.host()); | 1034 crypto_config1->LookupOrCreate(server_key1); |
| 1034 EXPECT_FALSE(cached1->proof_valid()); | 1035 EXPECT_FALSE(cached1->proof_valid()); |
| 1035 EXPECT_TRUE(cached1->source_address_token().empty()); | 1036 EXPECT_TRUE(cached1->source_address_token().empty()); |
| 1036 | 1037 |
| 1037 // Mutate the cached1 to have different data. | 1038 // Mutate the cached1 to have different data. |
| 1038 // TODO(rtenneti): mutate other members of CachedState. | 1039 // TODO(rtenneti): mutate other members of CachedState. |
| 1039 cached1->set_source_address_token(r1_host_name); | 1040 cached1->set_source_address_token(r1_host_name); |
| 1040 cached1->SetProofValid(); | 1041 cached1->SetProofValid(); |
| 1041 | 1042 |
| 1042 HostPortPair host_port_pair2(r2_host_name, 80); | 1043 HostPortPair host_port_pair2(r2_host_name, 80); |
| 1043 QuicCryptoClientConfig* crypto_config2 = | 1044 QuicCryptoClientConfig* crypto_config2 = |
| 1044 QuicStreamFactoryPeer::GetOrCreateCryptoConfig( | 1045 QuicStreamFactoryPeer::GetOrCreateCryptoConfig( |
| 1045 &factory_, host_port_pair2, is_https_); | 1046 &factory_, host_port_pair2, is_https_); |
| 1046 DCHECK(crypto_config2); | 1047 DCHECK(crypto_config2); |
| 1048 QuicSessionKey server_key2(host_port_pair2, is_https_); |
| 1047 QuicCryptoClientConfig::CachedState* cached2 = | 1049 QuicCryptoClientConfig::CachedState* cached2 = |
| 1048 crypto_config2->LookupOrCreate(host_port_pair2.host()); | 1050 crypto_config2->LookupOrCreate(server_key2); |
| 1049 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); | 1051 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
| 1050 EXPECT_TRUE(cached2->proof_valid()); | 1052 EXPECT_TRUE(cached2->proof_valid()); |
| 1051 } | 1053 } |
| 1052 } | 1054 } |
| 1053 | 1055 |
| 1054 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { | 1056 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
| 1055 vector<string> cannoncial_suffixes; | 1057 vector<string> cannoncial_suffixes; |
| 1056 cannoncial_suffixes.push_back(string(".c.youtube.com")); | 1058 cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 1057 cannoncial_suffixes.push_back(string(".googlevideo.com")); | 1059 cannoncial_suffixes.push_back(string(".googlevideo.com")); |
| 1058 | 1060 |
| 1059 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { | 1061 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 1060 string r3_host_name("r3"); | 1062 string r3_host_name("r3"); |
| 1061 string r4_host_name("r4"); | 1063 string r4_host_name("r4"); |
| 1062 r3_host_name.append(cannoncial_suffixes[i]); | 1064 r3_host_name.append(cannoncial_suffixes[i]); |
| 1063 r4_host_name.append(cannoncial_suffixes[i]); | 1065 r4_host_name.append(cannoncial_suffixes[i]); |
| 1064 | 1066 |
| 1065 HostPortPair host_port_pair1(r3_host_name, 80); | 1067 HostPortPair host_port_pair1(r3_host_name, 80); |
| 1066 QuicCryptoClientConfig* crypto_config1 = | 1068 QuicCryptoClientConfig* crypto_config1 = |
| 1067 QuicStreamFactoryPeer::GetOrCreateCryptoConfig( | 1069 QuicStreamFactoryPeer::GetOrCreateCryptoConfig( |
| 1068 &factory_, host_port_pair1, is_https_); | 1070 &factory_, host_port_pair1, is_https_); |
| 1069 DCHECK(crypto_config1); | 1071 DCHECK(crypto_config1); |
| 1072 QuicSessionKey server_key1(host_port_pair1, is_https_); |
| 1070 QuicCryptoClientConfig::CachedState* cached1 = | 1073 QuicCryptoClientConfig::CachedState* cached1 = |
| 1071 crypto_config1->LookupOrCreate(host_port_pair1.host()); | 1074 crypto_config1->LookupOrCreate(server_key1); |
| 1072 EXPECT_FALSE(cached1->proof_valid()); | 1075 EXPECT_FALSE(cached1->proof_valid()); |
| 1073 EXPECT_TRUE(cached1->source_address_token().empty()); | 1076 EXPECT_TRUE(cached1->source_address_token().empty()); |
| 1074 | 1077 |
| 1075 // Mutate the cached1 to have different data. | 1078 // Mutate the cached1 to have different data. |
| 1076 // TODO(rtenneti): mutate other members of CachedState. | 1079 // TODO(rtenneti): mutate other members of CachedState. |
| 1077 cached1->set_source_address_token(r3_host_name); | 1080 cached1->set_source_address_token(r3_host_name); |
| 1078 cached1->SetProofInvalid(); | 1081 cached1->SetProofInvalid(); |
| 1079 | 1082 |
| 1080 HostPortPair host_port_pair2(r4_host_name, 80); | 1083 HostPortPair host_port_pair2(r4_host_name, 80); |
| 1081 QuicCryptoClientConfig* crypto_config2 = | 1084 QuicCryptoClientConfig* crypto_config2 = |
| 1082 QuicStreamFactoryPeer::GetOrCreateCryptoConfig( | 1085 QuicStreamFactoryPeer::GetOrCreateCryptoConfig( |
| 1083 &factory_, host_port_pair2, is_https_); | 1086 &factory_, host_port_pair2, is_https_); |
| 1084 DCHECK(crypto_config2); | 1087 DCHECK(crypto_config2); |
| 1088 QuicSessionKey server_key2(host_port_pair2, is_https_); |
| 1085 QuicCryptoClientConfig::CachedState* cached2 = | 1089 QuicCryptoClientConfig::CachedState* cached2 = |
| 1086 crypto_config2->LookupOrCreate(host_port_pair2.host()); | 1090 crypto_config2->LookupOrCreate(server_key2); |
| 1087 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); | 1091 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
| 1088 EXPECT_TRUE(cached2->source_address_token().empty()); | 1092 EXPECT_TRUE(cached2->source_address_token().empty()); |
| 1089 EXPECT_FALSE(cached2->proof_valid()); | 1093 EXPECT_FALSE(cached2->proof_valid()); |
| 1090 } | 1094 } |
| 1091 } | 1095 } |
| 1092 | 1096 |
| 1093 } // namespace test | 1097 } // namespace test |
| 1094 } // namespace net | 1098 } // namespace net |
| OLD | NEW |