| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base64.h" | |
| 10 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 11 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 12 #include "net/base/capturing_net_log.h" | 11 #include "net/base/capturing_net_log.h" |
| 13 #include "net/base/test_completion_callback.h" | 12 #include "net/base/test_completion_callback.h" |
| 14 #include "net/base/test_data_directory.h" | 13 #include "net/base/test_data_directory.h" |
| 15 #include "net/cert/cert_verify_result.h" | 14 #include "net/cert/cert_verify_result.h" |
| 16 #include "net/http/transport_security_state.h" | |
| 17 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 15 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
| 18 #include "net/quic/crypto/crypto_protocol.h" | 16 #include "net/quic/crypto/crypto_protocol.h" |
| 19 #include "net/quic/crypto/proof_verifier_chromium.h" | 17 #include "net/quic/crypto/proof_verifier_chromium.h" |
| 20 #include "net/quic/crypto/quic_decrypter.h" | 18 #include "net/quic/crypto/quic_decrypter.h" |
| 21 #include "net/quic/crypto/quic_encrypter.h" | 19 #include "net/quic/crypto/quic_encrypter.h" |
| 22 #include "net/quic/crypto/quic_server_info.h" | 20 #include "net/quic/crypto/quic_server_info.h" |
| 23 #include "net/quic/quic_default_packet_writer.h" | 21 #include "net/quic/quic_default_packet_writer.h" |
| 24 #include "net/quic/test_tools/crypto_test_utils.h" | 22 #include "net/quic/test_tools/crypto_test_utils.h" |
| 25 #include "net/quic/test_tools/quic_client_session_peer.h" | 23 #include "net/quic/test_tools/quic_client_session_peer.h" |
| 26 #include "net/quic/test_tools/quic_test_utils.h" | 24 #include "net/quic/test_tools/quic_test_utils.h" |
| 27 #include "net/quic/test_tools/simple_quic_framer.h" | 25 #include "net/quic/test_tools/simple_quic_framer.h" |
| 28 #include "net/socket/socket_test_util.h" | 26 #include "net/socket/socket_test_util.h" |
| 29 #include "net/spdy/spdy_test_utils.h" | |
| 30 #include "net/test/cert_test_util.h" | 27 #include "net/test/cert_test_util.h" |
| 31 #include "net/udp/datagram_client_socket.h" | 28 #include "net/udp/datagram_client_socket.h" |
| 32 | 29 |
| 33 using testing::_; | 30 using testing::_; |
| 34 | 31 |
| 35 namespace net { | 32 namespace net { |
| 36 namespace test { | 33 namespace test { |
| 37 namespace { | 34 namespace { |
| 38 | 35 |
| 39 const char kServerHostname[] = "www.example.org"; | 36 const char kServerHostname[] = "www.example.org"; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 69 QuicPacketHeader header_; | 66 QuicPacketHeader header_; |
| 70 }; | 67 }; |
| 71 | 68 |
| 72 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> { | 69 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> { |
| 73 protected: | 70 protected: |
| 74 QuicClientSessionTest() | 71 QuicClientSessionTest() |
| 75 : writer_(new TestPacketWriter(GetParam())), | 72 : writer_(new TestPacketWriter(GetParam())), |
| 76 connection_( | 73 connection_( |
| 77 new PacketSavingConnection(false, SupportedVersions(GetParam()))), | 74 new PacketSavingConnection(false, SupportedVersions(GetParam()))), |
| 78 session_(connection_, GetSocket().Pass(), writer_.Pass(), NULL, NULL, | 75 session_(connection_, GetSocket().Pass(), writer_.Pass(), NULL, NULL, |
| 79 &transport_security_state_, | |
| 80 make_scoped_ptr((QuicServerInfo*)NULL), | 76 make_scoped_ptr((QuicServerInfo*)NULL), |
| 81 QuicServerId(kServerHostname, kServerPort, false, | 77 QuicServerId(kServerHostname, kServerPort, false, |
| 82 PRIVACY_MODE_DISABLED), | 78 PRIVACY_MODE_DISABLED), |
| 83 DefaultQuicConfig(), &crypto_config_, | 79 DefaultQuicConfig(), &crypto_config_, |
| 84 base::MessageLoop::current()->message_loop_proxy().get(), | 80 base::MessageLoop::current()->message_loop_proxy().get(), |
| 85 &net_log_) { | 81 &net_log_) { |
| 86 session_.InitializeSession(); | 82 session_.InitializeSession(); |
| 87 session_.config()->SetDefaults(); | 83 session_.config()->SetDefaults(); |
| 88 crypto_config_.SetDefaults(); | 84 crypto_config_.SetDefaults(); |
| 89 } | 85 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 105 CryptoTestUtils::HandshakeWithFakeServer( | 101 CryptoTestUtils::HandshakeWithFakeServer( |
| 106 connection_, session_.GetCryptoStream()); | 102 connection_, session_.GetCryptoStream()); |
| 107 ASSERT_EQ(OK, callback_.WaitForResult()); | 103 ASSERT_EQ(OK, callback_.WaitForResult()); |
| 108 } | 104 } |
| 109 | 105 |
| 110 scoped_ptr<QuicDefaultPacketWriter> writer_; | 106 scoped_ptr<QuicDefaultPacketWriter> writer_; |
| 111 PacketSavingConnection* connection_; | 107 PacketSavingConnection* connection_; |
| 112 CapturingNetLog net_log_; | 108 CapturingNetLog net_log_; |
| 113 MockClientSocketFactory socket_factory_; | 109 MockClientSocketFactory socket_factory_; |
| 114 StaticSocketDataProvider socket_data_; | 110 StaticSocketDataProvider socket_data_; |
| 115 TransportSecurityState transport_security_state_; | |
| 116 QuicClientSession session_; | 111 QuicClientSession session_; |
| 117 MockClock clock_; | 112 MockClock clock_; |
| 118 MockRandom random_; | 113 MockRandom random_; |
| 119 QuicConnectionVisitorInterface* visitor_; | 114 QuicConnectionVisitorInterface* visitor_; |
| 120 TestCompletionCallback callback_; | 115 TestCompletionCallback callback_; |
| 121 QuicCryptoClientConfig crypto_config_; | 116 QuicCryptoClientConfig crypto_config_; |
| 122 }; | 117 }; |
| 123 | 118 |
| 124 INSTANTIATE_TEST_CASE_P(Tests, QuicClientSessionTest, | 119 INSTANTIATE_TEST_CASE_P(Tests, QuicClientSessionTest, |
| 125 ::testing::ValuesIn(QuicSupportedVersions())); | 120 ::testing::ValuesIn(QuicSupportedVersions())); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 165 |
| 171 TEST_P(QuicClientSessionTest, GoAwayReceived) { | 166 TEST_P(QuicClientSessionTest, GoAwayReceived) { |
| 172 CompleteCryptoHandshake(); | 167 CompleteCryptoHandshake(); |
| 173 | 168 |
| 174 // After receiving a GoAway, I should no longer be able to create outgoing | 169 // After receiving a GoAway, I should no longer be able to create outgoing |
| 175 // streams. | 170 // streams. |
| 176 session_.OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); | 171 session_.OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); |
| 177 EXPECT_EQ(NULL, session_.CreateOutgoingDataStream()); | 172 EXPECT_EQ(NULL, session_.CreateOutgoingDataStream()); |
| 178 } | 173 } |
| 179 | 174 |
| 180 TEST_P(QuicClientSessionTest, CanPool) { | 175 // TODO(rch): re-enable this. |
| 176 TEST_P(QuicClientSessionTest, DISABLED_CanPool) { |
| 181 // Load a cert that is valid for: | 177 // Load a cert that is valid for: |
| 182 // www.example.org | 178 // www.example.org |
| 183 // mail.example.org | 179 // mail.example.org |
| 184 // www.example.com | 180 // www.example.com |
| 181 base::FilePath certs_dir = GetTestCertsDirectory(); |
| 185 | 182 |
| 183 CertVerifyResult result; |
| 186 ProofVerifyDetailsChromium details; | 184 ProofVerifyDetailsChromium details; |
| 187 details.cert_verify_result.verified_cert = | 185 details.cert_verify_result.verified_cert = |
| 188 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); | 186 ImportCertFromFile(certs_dir, "spdy_pooling.pem"); |
| 189 ASSERT_TRUE(details.cert_verify_result.verified_cert); | 187 ASSERT_TRUE(details.cert_verify_result.verified_cert); |
| 190 | 188 |
| 191 session_.OnProofVerifyDetailsAvailable(details); | 189 session_.OnProofVerifyDetailsAvailable(details); |
| 192 CompleteCryptoHandshake(); | 190 CompleteCryptoHandshake(); |
| 193 | 191 |
| 194 | 192 |
| 195 EXPECT_TRUE(session_.CanPool("www.example.org")); | 193 EXPECT_TRUE(session_.CanPool("www.example.org")); |
| 196 EXPECT_TRUE(session_.CanPool("mail.example.org")); | 194 EXPECT_TRUE(session_.CanPool("mail.example.org")); |
| 197 EXPECT_TRUE(session_.CanPool("mail.example.com")); | 195 EXPECT_TRUE(session_.CanPool("mail.example.com")); |
| 198 EXPECT_FALSE(session_.CanPool("mail.google.com")); | 196 EXPECT_FALSE(session_.CanPool("mail.google.com")); |
| 199 } | 197 } |
| 200 | 198 |
| 201 TEST_P(QuicClientSessionTest, ConnectionPooledWithTlsChannelId) { | 199 // TODO(rch): re-enable this. |
| 200 TEST_P(QuicClientSessionTest, DISABLED_ConnectionPooledWithTlsChannelId) { |
| 202 // Load a cert that is valid for: | 201 // Load a cert that is valid for: |
| 203 // www.example.org | 202 // www.example.org |
| 204 // mail.example.org | 203 // mail.example.org |
| 205 // www.example.com | 204 // www.example.com |
| 205 base::FilePath certs_dir = GetTestCertsDirectory(); |
| 206 | 206 |
| 207 CertVerifyResult result; |
| 207 ProofVerifyDetailsChromium details; | 208 ProofVerifyDetailsChromium details; |
| 208 details.cert_verify_result.verified_cert = | 209 details.cert_verify_result.verified_cert = |
| 209 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); | 210 ImportCertFromFile(certs_dir, "spdy_pooling.pem"); |
| 210 ASSERT_TRUE(details.cert_verify_result.verified_cert); | 211 ASSERT_TRUE(details.cert_verify_result.verified_cert); |
| 211 | 212 |
| 212 session_.OnProofVerifyDetailsAvailable(details); | 213 session_.OnProofVerifyDetailsAvailable(details); |
| 213 CompleteCryptoHandshake(); | 214 CompleteCryptoHandshake(); |
| 214 QuicClientSessionPeer::SetChannelIDSent(&session_, true); | 215 QuicClientSessionPeer::SetChannelIDSent(&session_, true); |
| 215 | 216 |
| 216 EXPECT_TRUE(session_.CanPool("www.example.org")); | 217 EXPECT_TRUE(session_.CanPool("www.example.org")); |
| 217 EXPECT_TRUE(session_.CanPool("mail.example.org")); | 218 EXPECT_TRUE(session_.CanPool("mail.example.org")); |
| 218 EXPECT_FALSE(session_.CanPool("mail.example.com")); | 219 EXPECT_FALSE(session_.CanPool("mail.example.com")); |
| 219 EXPECT_FALSE(session_.CanPool("mail.google.com")); | 220 EXPECT_FALSE(session_.CanPool("mail.google.com")); |
| 220 } | 221 } |
| 221 | 222 |
| 222 TEST_P(QuicClientSessionTest, ConnectionNotPooledWithDifferentPin) { | |
| 223 uint8 primary_pin = 1; | |
| 224 uint8 backup_pin = 2; | |
| 225 uint8 bad_pin = 3; | |
| 226 AddPin(&transport_security_state_, "mail.example.org", primary_pin, | |
| 227 backup_pin); | |
| 228 | |
| 229 ProofVerifyDetailsChromium details; | |
| 230 details.cert_verify_result.verified_cert = | |
| 231 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 232 details.cert_verify_result.is_issued_by_known_root = true; | |
| 233 details.cert_verify_result.public_key_hashes.push_back( | |
| 234 GetTestHashValue(bad_pin)); | |
| 235 | |
| 236 ASSERT_TRUE(details.cert_verify_result.verified_cert); | |
| 237 | |
| 238 session_.OnProofVerifyDetailsAvailable(details); | |
| 239 CompleteCryptoHandshake(); | |
| 240 QuicClientSessionPeer::SetChannelIDSent(&session_, true); | |
| 241 | |
| 242 EXPECT_FALSE(session_.CanPool("mail.example.org")); | |
| 243 } | |
| 244 | |
| 245 TEST_P(QuicClientSessionTest, ConnectionPooledWithMatchingPin) { | |
| 246 uint8 primary_pin = 1; | |
| 247 uint8 backup_pin = 2; | |
| 248 AddPin(&transport_security_state_, "mail.example.org", primary_pin, | |
| 249 backup_pin); | |
| 250 | |
| 251 ProofVerifyDetailsChromium details; | |
| 252 details.cert_verify_result.verified_cert = | |
| 253 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); | |
| 254 details.cert_verify_result.is_issued_by_known_root = true; | |
| 255 details.cert_verify_result.public_key_hashes.push_back( | |
| 256 GetTestHashValue(primary_pin)); | |
| 257 | |
| 258 ASSERT_TRUE(details.cert_verify_result.verified_cert); | |
| 259 | |
| 260 session_.OnProofVerifyDetailsAvailable(details); | |
| 261 CompleteCryptoHandshake(); | |
| 262 QuicClientSessionPeer::SetChannelIDSent(&session_, true); | |
| 263 | |
| 264 EXPECT_TRUE(session_.CanPool("mail.example.org")); | |
| 265 } | |
| 266 | |
| 267 } // namespace | 223 } // namespace |
| 268 } // namespace test | 224 } // namespace test |
| 269 } // namespace net | 225 } // namespace net |
| OLD | NEW |