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/test_tools/crypto_test_utils.h" | 5 #include "net/quic/test_tools/crypto_test_utils.h" |
6 | 6 |
7 #include "net/quic/crypto/channel_id.h" | 7 #include "net/quic/crypto/channel_id.h" |
8 #include "net/quic/crypto/common_cert_set.h" | 8 #include "net/quic/crypto/common_cert_set.h" |
9 #include "net/quic/crypto/crypto_handshake.h" | 9 #include "net/quic/crypto/crypto_handshake.h" |
10 #include "net/quic/crypto/quic_crypto_server_config.h" | 10 #include "net/quic/crypto/quic_crypto_server_config.h" |
11 #include "net/quic/crypto/quic_decrypter.h" | 11 #include "net/quic/crypto/quic_decrypter.h" |
12 #include "net/quic/crypto/quic_encrypter.h" | 12 #include "net/quic/crypto/quic_encrypter.h" |
13 #include "net/quic/crypto/quic_random.h" | 13 #include "net/quic/crypto/quic_random.h" |
14 #include "net/quic/quic_clock.h" | 14 #include "net/quic/quic_clock.h" |
15 #include "net/quic/quic_crypto_client_stream.h" | 15 #include "net/quic/quic_crypto_client_stream.h" |
16 #include "net/quic/quic_crypto_server_stream.h" | 16 #include "net/quic/quic_crypto_server_stream.h" |
17 #include "net/quic/quic_crypto_stream.h" | 17 #include "net/quic/quic_crypto_stream.h" |
| 18 #include "net/quic/quic_session_key.h" |
18 #include "net/quic/test_tools/quic_connection_peer.h" | 19 #include "net/quic/test_tools/quic_connection_peer.h" |
19 #include "net/quic/test_tools/quic_test_utils.h" | 20 #include "net/quic/test_tools/quic_test_utils.h" |
20 #include "net/quic/test_tools/simple_quic_framer.h" | 21 #include "net/quic/test_tools/simple_quic_framer.h" |
21 | 22 |
22 using base::StringPiece; | 23 using base::StringPiece; |
23 using std::make_pair; | 24 using std::make_pair; |
24 using std::pair; | 25 using std::pair; |
25 using std::string; | 26 using std::string; |
26 using std::vector; | 27 using std::vector; |
27 | 28 |
28 namespace net { | 29 namespace net { |
29 namespace test { | 30 namespace test { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
| 34 const char kServerHostname[] = "test.example.com"; |
| 35 const uint16 kServerPort = 80; |
| 36 |
33 // CryptoFramerVisitor is a framer visitor that records handshake messages. | 37 // CryptoFramerVisitor is a framer visitor that records handshake messages. |
34 class CryptoFramerVisitor : public CryptoFramerVisitorInterface { | 38 class CryptoFramerVisitor : public CryptoFramerVisitorInterface { |
35 public: | 39 public: |
36 CryptoFramerVisitor() | 40 CryptoFramerVisitor() |
37 : error_(false) { | 41 : error_(false) { |
38 } | 42 } |
39 | 43 |
40 virtual void OnError(CryptoFramer* framer) OVERRIDE { | 44 virtual void OnError(CryptoFramer* framer) OVERRIDE { |
41 error_ = true; | 45 error_ = true; |
42 } | 46 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 172 |
169 client_session.config()->SetDefaults(); | 173 client_session.config()->SetDefaults(); |
170 crypto_config.SetDefaults(); | 174 crypto_config.SetDefaults(); |
171 // TODO(rtenneti): Enable testing of ProofVerifier. | 175 // TODO(rtenneti): Enable testing of ProofVerifier. |
172 // if (!options.dont_verify_certs) { | 176 // if (!options.dont_verify_certs) { |
173 // crypto_config.SetProofVerifier(ProofVerifierForTesting()); | 177 // crypto_config.SetProofVerifier(ProofVerifierForTesting()); |
174 // } | 178 // } |
175 if (options.channel_id_enabled) { | 179 if (options.channel_id_enabled) { |
176 crypto_config.SetChannelIDSigner(ChannelIDSignerForTesting()); | 180 crypto_config.SetChannelIDSigner(ChannelIDSignerForTesting()); |
177 } | 181 } |
178 QuicCryptoClientStream client("test.example.com", &client_session, | 182 QuicSessionKey server_key(kServerHostname, kServerPort, false); |
179 &crypto_config); | 183 QuicCryptoClientStream client(server_key, &client_session, &crypto_config); |
180 client_session.SetCryptoStream(&client); | 184 client_session.SetCryptoStream(&client); |
181 | 185 |
182 CHECK(client.CryptoConnect()); | 186 CHECK(client.CryptoConnect()); |
183 CHECK_EQ(1u, client_conn->packets_.size()); | 187 CHECK_EQ(1u, client_conn->packets_.size()); |
184 | 188 |
185 CommunicateHandshakeMessages(client_conn, &client, server_conn, server); | 189 CommunicateHandshakeMessages(client_conn, &client, server_conn, server); |
186 | 190 |
187 CompareClientAndServerKeys(&client, server); | 191 CompareClientAndServerKeys(&client, server); |
188 | 192 |
189 if (options.channel_id_enabled) { | 193 if (options.channel_id_enabled) { |
190 EXPECT_EQ(crypto_config.channel_id_signer()->GetKeyForHostname( | 194 EXPECT_EQ(crypto_config.channel_id_signer()->GetKeyForHostname( |
191 "test.example.com"), | 195 kServerHostname), |
192 server->crypto_negotiated_params().channel_id); | 196 server->crypto_negotiated_params().channel_id); |
193 } | 197 } |
194 | 198 |
195 return client.num_sent_client_hellos(); | 199 return client.num_sent_client_hellos(); |
196 } | 200 } |
197 | 201 |
198 // static | 202 // static |
199 void CryptoTestUtils::SetupCryptoServerConfigForTest( | 203 void CryptoTestUtils::SetupCryptoServerConfigForTest( |
200 const QuicClock* clock, | 204 const QuicClock* clock, |
201 QuicRandom* rand, | 205 QuicRandom* rand, |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 scoped_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); | 515 scoped_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); |
512 scoped_ptr<CryptoHandshakeMessage> parsed( | 516 scoped_ptr<CryptoHandshakeMessage> parsed( |
513 CryptoFramer::ParseMessage(bytes->AsStringPiece())); | 517 CryptoFramer::ParseMessage(bytes->AsStringPiece())); |
514 CHECK(parsed.get()); | 518 CHECK(parsed.get()); |
515 | 519 |
516 return *parsed; | 520 return *parsed; |
517 } | 521 } |
518 | 522 |
519 } // namespace test | 523 } // namespace test |
520 } // namespace net | 524 } // namespace net |
OLD | NEW |