OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/crypto/quic_crypto_client_config.h" | 5 #include "net/quic/crypto/quic_crypto_client_config.h" |
6 | 6 |
7 #include "net/quic/test_tools/quic_test_utils.h" | 7 #include "net/quic/test_tools/quic_test_utils.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 using std::string; | 10 using std::string; |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 namespace test { | 13 namespace test { |
14 | 14 |
15 TEST(QuicCryptoClientConfigTest, InchoateChlo) { | 15 TEST(QuicCryptoClientConfigTest, InchoateChlo) { |
16 QuicCryptoClientConfig::CachedState state; | 16 QuicCryptoClientConfig::CachedState state; |
17 QuicCryptoClientConfig config; | 17 QuicCryptoClientConfig config; |
18 QuicCryptoNegotiatedParameters params; | 18 QuicCryptoNegotiatedParameters params; |
19 CryptoHandshakeMessage msg; | 19 CryptoHandshakeMessage msg; |
20 config.FillInchoateClientHello("www.google.com", QuicVersionMax(), &state, | 20 config.FillInchoateClientHello("www.google.com", QuicVersionMax(), &state, |
21 ¶ms, &msg); | 21 ¶ms, &msg); |
22 | 22 |
23 QuicTag cver; | 23 QuicTag cver; |
24 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kVER, &cver)); | 24 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kVER, &cver)); |
25 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); | 25 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); |
26 | |
27 // TODO(rch): Remove once we remove QUIC_VERSION_12. | |
28 uint16 vers; | |
29 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint16(kVERS, &vers)); | |
30 EXPECT_EQ(0u, vers); | |
31 } | 26 } |
32 | 27 |
33 TEST(QuicCryptoClientConfigTest, ProcessServerDowngradeAttack) { | 28 TEST(QuicCryptoClientConfigTest, ProcessServerDowngradeAttack) { |
34 QuicVersionVector supported_versions = QuicSupportedVersions(); | 29 QuicVersionVector supported_versions = QuicSupportedVersions(); |
35 if (supported_versions.size() == 1) { | 30 if (supported_versions.size() == 1) { |
36 // No downgrade attack is possible if the client only supports one version. | 31 // No downgrade attack is possible if the client only supports one version. |
37 return; | 32 return; |
38 } | 33 } |
39 QuicTagVector supported_version_tags; | 34 QuicTagVector supported_version_tags; |
40 for (size_t i = supported_versions.size(); i > 0; --i) { | 35 for (size_t i = supported_versions.size(); i > 0; --i) { |
41 supported_version_tags.push_back( | 36 supported_version_tags.push_back( |
42 QuicVersionToQuicTag(supported_versions[i - 1])); | 37 QuicVersionToQuicTag(supported_versions[i - 1])); |
43 } | 38 } |
44 CryptoHandshakeMessage msg; | 39 CryptoHandshakeMessage msg; |
45 msg.set_tag(kSHLO); | 40 msg.set_tag(kSHLO); |
46 msg.SetVector(kVER, supported_version_tags); | 41 msg.SetVector(kVER, supported_version_tags); |
47 | 42 |
48 QuicCryptoClientConfig::CachedState cached; | 43 QuicCryptoClientConfig::CachedState cached; |
49 QuicCryptoNegotiatedParameters out_params; | 44 QuicCryptoNegotiatedParameters out_params; |
50 string error; | 45 string error; |
51 QuicCryptoClientConfig config; | 46 QuicCryptoClientConfig config; |
52 EXPECT_EQ(QUIC_VERSION_NEGOTIATION_MISMATCH, | 47 EXPECT_EQ(QUIC_VERSION_NEGOTIATION_MISMATCH, |
53 config.ProcessServerHello(msg, 0, supported_versions, | 48 config.ProcessServerHello(msg, 0, supported_versions, |
54 &cached, &out_params, &error)); | 49 &cached, &out_params, &error)); |
55 EXPECT_EQ("Downgrade attack detected", error); | 50 EXPECT_EQ("Downgrade attack detected", error); |
56 } | 51 } |
57 | 52 |
58 } // namespace test | 53 } // namespace test |
59 } // namespace net | 54 } // namespace net |
OLD | NEW |