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" |
11 #include "net/dns/mock_host_resolver.h" | 11 #include "net/dns/mock_host_resolver.h" |
12 #include "net/http/http_response_headers.h" | 12 #include "net/http/http_response_headers.h" |
13 #include "net/http/http_response_info.h" | 13 #include "net/http/http_response_info.h" |
14 #include "net/http/http_util.h" | 14 #include "net/http/http_util.h" |
15 #include "net/quic/crypto/crypto_handshake.h" | 15 #include "net/quic/crypto/crypto_handshake.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_decrypter.h" | 17 #include "net/quic/crypto/quic_decrypter.h" |
18 #include "net/quic/crypto/quic_encrypter.h" | 18 #include "net/quic/crypto/quic_encrypter.h" |
19 #include "net/quic/quic_http_stream.h" | 19 #include "net/quic/quic_http_stream.h" |
20 #include "net/quic/quic_session_key.h" | 20 #include "net/quic/quic_server_id.h" |
21 #include "net/quic/test_tools/mock_clock.h" | 21 #include "net/quic/test_tools/mock_clock.h" |
22 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" | 22 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
23 #include "net/quic/test_tools/mock_random.h" | 23 #include "net/quic/test_tools/mock_random.h" |
24 #include "net/quic/test_tools/quic_test_packet_maker.h" | 24 #include "net/quic/test_tools/quic_test_packet_maker.h" |
25 #include "net/quic/test_tools/quic_test_utils.h" | 25 #include "net/quic/test_tools/quic_test_utils.h" |
26 #include "net/socket/socket_test_util.h" | 26 #include "net/socket/socket_test_util.h" |
27 #include "net/test/cert_test_util.h" | 27 #include "net/test/cert_test_util.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
29 | 29 |
30 using base::StringPiece; | 30 using base::StringPiece; |
(...skipping 10 matching lines...) Expand all Loading... |
41 | 41 |
42 class QuicStreamFactoryPeer { | 42 class QuicStreamFactoryPeer { |
43 public: | 43 public: |
44 static QuicCryptoClientConfig* GetCryptoConfig(QuicStreamFactory* factory) { | 44 static QuicCryptoClientConfig* GetCryptoConfig(QuicStreamFactory* factory) { |
45 return &factory->crypto_config_; | 45 return &factory->crypto_config_; |
46 } | 46 } |
47 | 47 |
48 static bool HasActiveSession(QuicStreamFactory* factory, | 48 static bool HasActiveSession(QuicStreamFactory* factory, |
49 const HostPortPair& host_port_pair, | 49 const HostPortPair& host_port_pair, |
50 bool is_https) { | 50 bool is_https) { |
51 QuicSessionKey server_key(host_port_pair, is_https, kPrivacyModeDisabled); | 51 QuicServerId server_id(host_port_pair, is_https, kPrivacyModeDisabled); |
52 return factory->HasActiveSession(server_key); | 52 return factory->HasActiveSession(server_id); |
53 } | 53 } |
54 | 54 |
55 static QuicClientSession* GetActiveSession( | 55 static QuicClientSession* GetActiveSession( |
56 QuicStreamFactory* factory, | 56 QuicStreamFactory* factory, |
57 const HostPortPair& host_port_pair, | 57 const HostPortPair& host_port_pair, |
58 bool is_https) { | 58 bool is_https) { |
59 QuicSessionKey server_key(host_port_pair, is_https, kPrivacyModeDisabled); | 59 QuicServerId server_id(host_port_pair, is_https, kPrivacyModeDisabled); |
60 DCHECK(factory->HasActiveSession(server_key)); | 60 DCHECK(factory->HasActiveSession(server_id)); |
61 return factory->active_sessions_[server_key]; | 61 return factory->active_sessions_[server_id]; |
62 } | 62 } |
63 | 63 |
64 static scoped_ptr<QuicHttpStream> CreateIfSessionExists( | 64 static scoped_ptr<QuicHttpStream> CreateIfSessionExists( |
65 QuicStreamFactory* factory, | 65 QuicStreamFactory* factory, |
66 const HostPortPair& host_port_pair, | 66 const HostPortPair& host_port_pair, |
67 bool is_https, | 67 bool is_https, |
68 const BoundNetLog& net_log) { | 68 const BoundNetLog& net_log) { |
69 QuicSessionKey server_key(host_port_pair, is_https, kPrivacyModeDisabled); | 69 QuicServerId server_id(host_port_pair, is_https, kPrivacyModeDisabled); |
70 return factory->CreateIfSessionExists(server_key, net_log); | 70 return factory->CreateIfSessionExists(server_id, net_log); |
71 } | 71 } |
72 | 72 |
73 static bool IsLiveSession(QuicStreamFactory* factory, | 73 static bool IsLiveSession(QuicStreamFactory* factory, |
74 QuicClientSession* session) { | 74 QuicClientSession* session) { |
75 for (QuicStreamFactory::SessionSet::iterator it = | 75 for (QuicStreamFactory::SessionSet::iterator it = |
76 factory->all_sessions_.begin(); | 76 factory->all_sessions_.begin(); |
77 it != factory->all_sessions_.end(); ++it) { | 77 it != factory->all_sessions_.end(); ++it) { |
78 if (*it == session) | 78 if (*it == session) |
79 return true; | 79 return true; |
80 } | 80 } |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 | 1085 |
1086 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { | 1086 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
1087 string r1_host_name("r1"); | 1087 string r1_host_name("r1"); |
1088 string r2_host_name("r2"); | 1088 string r2_host_name("r2"); |
1089 r1_host_name.append(cannoncial_suffixes[i]); | 1089 r1_host_name.append(cannoncial_suffixes[i]); |
1090 r2_host_name.append(cannoncial_suffixes[i]); | 1090 r2_host_name.append(cannoncial_suffixes[i]); |
1091 | 1091 |
1092 HostPortPair host_port_pair1(r1_host_name, 80); | 1092 HostPortPair host_port_pair1(r1_host_name, 80); |
1093 QuicCryptoClientConfig* crypto_config = | 1093 QuicCryptoClientConfig* crypto_config = |
1094 QuicStreamFactoryPeer::GetCryptoConfig(&factory_); | 1094 QuicStreamFactoryPeer::GetCryptoConfig(&factory_); |
1095 QuicSessionKey server_key1(host_port_pair1, is_https_, privacy_mode_); | 1095 QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_); |
1096 QuicCryptoClientConfig::CachedState* cached1 = | 1096 QuicCryptoClientConfig::CachedState* cached1 = |
1097 crypto_config->LookupOrCreate(server_key1); | 1097 crypto_config->LookupOrCreate(server_id1); |
1098 EXPECT_FALSE(cached1->proof_valid()); | 1098 EXPECT_FALSE(cached1->proof_valid()); |
1099 EXPECT_TRUE(cached1->source_address_token().empty()); | 1099 EXPECT_TRUE(cached1->source_address_token().empty()); |
1100 | 1100 |
1101 // Mutate the cached1 to have different data. | 1101 // Mutate the cached1 to have different data. |
1102 // TODO(rtenneti): mutate other members of CachedState. | 1102 // TODO(rtenneti): mutate other members of CachedState. |
1103 cached1->set_source_address_token(r1_host_name); | 1103 cached1->set_source_address_token(r1_host_name); |
1104 cached1->SetProofValid(); | 1104 cached1->SetProofValid(); |
1105 | 1105 |
1106 HostPortPair host_port_pair2(r2_host_name, 80); | 1106 HostPortPair host_port_pair2(r2_host_name, 80); |
1107 QuicSessionKey server_key2(host_port_pair2, is_https_, privacy_mode_); | 1107 QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_); |
1108 QuicCryptoClientConfig::CachedState* cached2 = | 1108 QuicCryptoClientConfig::CachedState* cached2 = |
1109 crypto_config->LookupOrCreate(server_key2); | 1109 crypto_config->LookupOrCreate(server_id2); |
1110 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); | 1110 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
1111 EXPECT_TRUE(cached2->proof_valid()); | 1111 EXPECT_TRUE(cached2->proof_valid()); |
1112 } | 1112 } |
1113 } | 1113 } |
1114 | 1114 |
1115 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { | 1115 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
1116 vector<string> cannoncial_suffixes; | 1116 vector<string> cannoncial_suffixes; |
1117 cannoncial_suffixes.push_back(string(".c.youtube.com")); | 1117 cannoncial_suffixes.push_back(string(".c.youtube.com")); |
1118 cannoncial_suffixes.push_back(string(".googlevideo.com")); | 1118 cannoncial_suffixes.push_back(string(".googlevideo.com")); |
1119 | 1119 |
1120 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { | 1120 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
1121 string r3_host_name("r3"); | 1121 string r3_host_name("r3"); |
1122 string r4_host_name("r4"); | 1122 string r4_host_name("r4"); |
1123 r3_host_name.append(cannoncial_suffixes[i]); | 1123 r3_host_name.append(cannoncial_suffixes[i]); |
1124 r4_host_name.append(cannoncial_suffixes[i]); | 1124 r4_host_name.append(cannoncial_suffixes[i]); |
1125 | 1125 |
1126 HostPortPair host_port_pair1(r3_host_name, 80); | 1126 HostPortPair host_port_pair1(r3_host_name, 80); |
1127 QuicCryptoClientConfig* crypto_config = | 1127 QuicCryptoClientConfig* crypto_config = |
1128 QuicStreamFactoryPeer::GetCryptoConfig(&factory_); | 1128 QuicStreamFactoryPeer::GetCryptoConfig(&factory_); |
1129 QuicSessionKey server_key1(host_port_pair1, is_https_, privacy_mode_); | 1129 QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_); |
1130 QuicCryptoClientConfig::CachedState* cached1 = | 1130 QuicCryptoClientConfig::CachedState* cached1 = |
1131 crypto_config->LookupOrCreate(server_key1); | 1131 crypto_config->LookupOrCreate(server_id1); |
1132 EXPECT_FALSE(cached1->proof_valid()); | 1132 EXPECT_FALSE(cached1->proof_valid()); |
1133 EXPECT_TRUE(cached1->source_address_token().empty()); | 1133 EXPECT_TRUE(cached1->source_address_token().empty()); |
1134 | 1134 |
1135 // Mutate the cached1 to have different data. | 1135 // Mutate the cached1 to have different data. |
1136 // TODO(rtenneti): mutate other members of CachedState. | 1136 // TODO(rtenneti): mutate other members of CachedState. |
1137 cached1->set_source_address_token(r3_host_name); | 1137 cached1->set_source_address_token(r3_host_name); |
1138 cached1->SetProofInvalid(); | 1138 cached1->SetProofInvalid(); |
1139 | 1139 |
1140 HostPortPair host_port_pair2(r4_host_name, 80); | 1140 HostPortPair host_port_pair2(r4_host_name, 80); |
1141 QuicSessionKey server_key2(host_port_pair2, is_https_, privacy_mode_); | 1141 QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_); |
1142 QuicCryptoClientConfig::CachedState* cached2 = | 1142 QuicCryptoClientConfig::CachedState* cached2 = |
1143 crypto_config->LookupOrCreate(server_key2); | 1143 crypto_config->LookupOrCreate(server_id2); |
1144 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); | 1144 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
1145 EXPECT_TRUE(cached2->source_address_token().empty()); | 1145 EXPECT_TRUE(cached2->source_address_token().empty()); |
1146 EXPECT_FALSE(cached2->proof_valid()); | 1146 EXPECT_FALSE(cached2->proof_valid()); |
1147 } | 1147 } |
1148 } | 1148 } |
1149 | 1149 |
1150 } // namespace test | 1150 } // namespace test |
1151 } // namespace net | 1151 } // namespace net |
OLD | NEW |