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/quic_server_id.h" |
19 #include "net/quic/test_tools/quic_connection_peer.h" | 19 #include "net/quic/test_tools/quic_connection_peer.h" |
20 #include "net/quic/test_tools/quic_test_utils.h" | 20 #include "net/quic/test_tools/quic_test_utils.h" |
21 #include "net/quic/test_tools/simple_quic_framer.h" | 21 #include "net/quic/test_tools/simple_quic_framer.h" |
22 | 22 |
23 using base::StringPiece; | 23 using base::StringPiece; |
24 using std::make_pair; | 24 using std::make_pair; |
25 using std::pair; | 25 using std::pair; |
26 using std::string; | 26 using std::string; |
27 using std::vector; | 27 using std::vector; |
28 | 28 |
29 namespace net { | 29 namespace net { |
30 namespace test { | 30 namespace test { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const char kServerHostname[] = "test.example.com"; | 34 const char kServerHostname[] = "test.example.com"; |
35 const uint16 kServerPort = 80; | 35 const uint16 kServerPort = 80; |
36 | 36 |
37 // CryptoFramerVisitor is a framer visitor that records handshake messages. | 37 // CryptoFramerVisitor is a framer visitor that records handshake messages. |
38 class CryptoFramerVisitor : public CryptoFramerVisitorInterface { | 38 class CryptoFramerVisitor : public CryptoFramerVisitorInterface { |
39 public: | 39 public: |
40 CryptoFramerVisitor() | 40 CryptoFramerVisitor() |
41 : error_(false) { | 41 : error_(false) { |
42 } | 42 } |
43 | 43 |
44 virtual void OnError(CryptoFramer* framer) OVERRIDE { | 44 virtual void OnError(CryptoFramer* framer) OVERRIDE { error_ = true; } |
45 error_ = true; | |
46 } | |
47 | 45 |
48 virtual void OnHandshakeMessage( | 46 virtual void OnHandshakeMessage( |
49 const CryptoHandshakeMessage& message) OVERRIDE { | 47 const CryptoHandshakeMessage& message) OVERRIDE { |
50 messages_.push_back(message); | 48 messages_.push_back(message); |
51 } | 49 } |
52 | 50 |
53 bool error() const { | 51 bool error() const { |
54 return error_; | 52 return error_; |
55 } | 53 } |
56 | 54 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 170 |
173 client_session.config()->SetDefaults(); | 171 client_session.config()->SetDefaults(); |
174 crypto_config.SetDefaults(); | 172 crypto_config.SetDefaults(); |
175 // TODO(rtenneti): Enable testing of ProofVerifier. | 173 // TODO(rtenneti): Enable testing of ProofVerifier. |
176 // if (!options.dont_verify_certs) { | 174 // if (!options.dont_verify_certs) { |
177 // crypto_config.SetProofVerifier(ProofVerifierForTesting()); | 175 // crypto_config.SetProofVerifier(ProofVerifierForTesting()); |
178 // } | 176 // } |
179 if (options.channel_id_enabled) { | 177 if (options.channel_id_enabled) { |
180 crypto_config.SetChannelIDSigner(ChannelIDSignerForTesting()); | 178 crypto_config.SetChannelIDSigner(ChannelIDSignerForTesting()); |
181 } | 179 } |
182 QuicSessionKey server_key(kServerHostname, kServerPort, false, | 180 QuicServerId server_id(kServerHostname, kServerPort, false, |
183 kPrivacyModeDisabled); | 181 kPrivacyModeDisabled); |
184 QuicCryptoClientStream client(server_key, &client_session, NULL, | 182 QuicCryptoClientStream client(server_id, &client_session, NULL, |
185 &crypto_config); | 183 &crypto_config); |
186 client_session.SetCryptoStream(&client); | 184 client_session.SetCryptoStream(&client); |
187 | 185 |
188 CHECK(client.CryptoConnect()); | 186 CHECK(client.CryptoConnect()); |
189 CHECK_EQ(1u, client_conn->packets_.size()); | 187 CHECK_EQ(1u, client_conn->packets_.size()); |
190 | 188 |
191 CommunicateHandshakeMessages(client_conn, &client, server_conn, server); | 189 CommunicateHandshakeMessages(client_conn, &client, server_conn, server); |
192 | 190 |
193 CompareClientAndServerKeys(&client, server); | 191 CompareClientAndServerKeys(&client, server); |
194 | 192 |
195 if (options.channel_id_enabled) { | 193 if (options.channel_id_enabled) { |
196 EXPECT_EQ(crypto_config.channel_id_signer()->GetKeyForHostname( | 194 EXPECT_EQ( |
197 kServerHostname), | 195 crypto_config.channel_id_signer()->GetKeyForHostname(kServerHostname), |
198 server->crypto_negotiated_params().channel_id); | 196 server->crypto_negotiated_params().channel_id); |
199 } | 197 } |
200 | 198 |
201 return client.num_sent_client_hellos(); | 199 return client.num_sent_client_hellos(); |
202 } | 200 } |
203 | 201 |
204 // static | 202 // static |
205 void CryptoTestUtils::SetupCryptoServerConfigForTest( | 203 void CryptoTestUtils::SetupCryptoServerConfigForTest( |
206 const QuicClock* clock, | 204 const QuicClock* clock, |
207 QuicRandom* rand, | 205 QuicRandom* rand, |
208 QuicConfig* config, | 206 QuicConfig* config, |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 } | 485 } |
488 | 486 |
489 const QuicTag tag = ParseTag(tagstr); | 487 const QuicTag tag = ParseTag(tagstr); |
490 const char* valuestr = va_arg(ap, const char*); | 488 const char* valuestr = va_arg(ap, const char*); |
491 | 489 |
492 size_t len = strlen(valuestr); | 490 size_t len = strlen(valuestr); |
493 if (len > 0 && valuestr[0] == '#') { | 491 if (len > 0 && valuestr[0] == '#') { |
494 valuestr++; | 492 valuestr++; |
495 len--; | 493 len--; |
496 | 494 |
497 CHECK(len % 2 == 0); | 495 CHECK_EQ(0u, len % 2); |
498 scoped_ptr<uint8[]> buf(new uint8[len/2]); | 496 scoped_ptr<uint8[]> buf(new uint8[len/2]); |
499 | 497 |
500 for (size_t i = 0; i < len/2; i++) { | 498 for (size_t i = 0; i < len/2; i++) { |
501 uint8 v = 0; | 499 uint8 v = 0; |
502 CHECK(HexChar(valuestr[i*2], &v)); | 500 CHECK(HexChar(valuestr[i*2], &v)); |
503 buf[i] = v << 4; | 501 buf[i] = v << 4; |
504 CHECK(HexChar(valuestr[i*2 + 1], &v)); | 502 CHECK(HexChar(valuestr[i*2 + 1], &v)); |
505 buf[i] |= v; | 503 buf[i] |= v; |
506 } | 504 } |
507 | 505 |
(...skipping 10 matching lines...) Expand all Loading... |
518 scoped_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); | 516 scoped_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); |
519 scoped_ptr<CryptoHandshakeMessage> parsed( | 517 scoped_ptr<CryptoHandshakeMessage> parsed( |
520 CryptoFramer::ParseMessage(bytes->AsStringPiece())); | 518 CryptoFramer::ParseMessage(bytes->AsStringPiece())); |
521 CHECK(parsed.get()); | 519 CHECK(parsed.get()); |
522 | 520 |
523 return *parsed; | 521 return *parsed; |
524 } | 522 } |
525 | 523 |
526 } // namespace test | 524 } // namespace test |
527 } // namespace net | 525 } // namespace net |
OLD | NEW |