| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <cstdint> | 6 #include <cstdint> |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "net/quic/core/crypto/cert_compressor.h" | 11 #include "net/quic/core/crypto/cert_compressor.h" |
| 12 #include "net/quic/core/crypto/common_cert_set.h" | 12 #include "net/quic/core/crypto/common_cert_set.h" |
| 13 #include "net/quic/core/crypto/crypto_handshake.h" | 13 #include "net/quic/core/crypto/crypto_handshake.h" |
| 14 #include "net/quic/core/crypto/crypto_server_config_protobuf.h" | 14 #include "net/quic/core/crypto/crypto_server_config_protobuf.h" |
| 15 #include "net/quic/core/crypto/crypto_utils.h" | 15 #include "net/quic/core/crypto/crypto_utils.h" |
| 16 #include "net/quic/core/crypto/proof_source.h" | 16 #include "net/quic/core/crypto/proof_source.h" |
| 17 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 17 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
| 18 #include "net/quic/core/crypto/quic_random.h" | 18 #include "net/quic/core/crypto/quic_random.h" |
| 19 #include "net/quic/core/quic_socket_address_coder.h" | 19 #include "net/quic/core/quic_socket_address_coder.h" |
| 20 #include "net/quic/core/quic_utils.h" | 20 #include "net/quic/core/quic_utils.h" |
| 21 #include "net/quic/platform/api/quic_endian.h" | 21 #include "net/quic/platform/api/quic_endian.h" |
| 22 #include "net/quic/platform/api/quic_flags.h" | 22 #include "net/quic/platform/api/quic_flags.h" |
| 23 #include "net/quic/platform/api/quic_string_piece.h" | 23 #include "net/quic/platform/api/quic_string_piece.h" |
| 24 #include "net/quic/platform/api/quic_test.h" |
| 24 #include "net/quic/platform/api/quic_text_utils.h" | 25 #include "net/quic/platform/api/quic_text_utils.h" |
| 25 #include "net/quic/test_tools/crypto_test_utils.h" | 26 #include "net/quic/test_tools/crypto_test_utils.h" |
| 26 #include "net/quic/test_tools/delayed_verify_strike_register_client.h" | 27 #include "net/quic/test_tools/delayed_verify_strike_register_client.h" |
| 27 #include "net/quic/test_tools/failing_proof_source.h" | 28 #include "net/quic/test_tools/failing_proof_source.h" |
| 28 #include "net/quic/test_tools/mock_clock.h" | 29 #include "net/quic/test_tools/mock_clock.h" |
| 29 #include "net/quic/test_tools/mock_random.h" | 30 #include "net/quic/test_tools/mock_random.h" |
| 30 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" | 31 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" |
| 31 #include "net/quic/test_tools/quic_test_utils.h" | 32 #include "net/quic/test_tools/quic_test_utils.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | |
| 33 #include "third_party/boringssl/src/include/openssl/sha.h" | 33 #include "third_party/boringssl/src/include/openssl/sha.h" |
| 34 | 34 |
| 35 using std::string; | 35 using std::string; |
| 36 | 36 |
| 37 namespace net { | 37 namespace net { |
| 38 namespace test { | 38 namespace test { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 class DummyProofVerifierCallback : public ProofVerifierCallback { | 42 class DummyProofVerifierCallback : public ProofVerifierCallback { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 while (!supported_versions.empty()) { | 94 while (!supported_versions.empty()) { |
| 95 params.push_back(TestParams(enable_stateless_rejects, | 95 params.push_back(TestParams(enable_stateless_rejects, |
| 96 use_stateless_rejects, supported_versions)); | 96 use_stateless_rejects, supported_versions)); |
| 97 supported_versions.erase(supported_versions.begin()); | 97 supported_versions.erase(supported_versions.begin()); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 return params; | 101 return params; |
| 102 } | 102 } |
| 103 | 103 |
| 104 class CryptoServerTest : public ::testing::TestWithParam<TestParams> { | 104 class CryptoServerTest : public QuicTestWithParam<TestParams> { |
| 105 public: | 105 public: |
| 106 CryptoServerTest() | 106 CryptoServerTest() |
| 107 : rand_(QuicRandom::GetInstance()), | 107 : rand_(QuicRandom::GetInstance()), |
| 108 client_address_(QuicIpAddress::Loopback4(), 1234), | 108 client_address_(QuicIpAddress::Loopback4(), 1234), |
| 109 config_(QuicCryptoServerConfig::TESTING, | 109 config_(QuicCryptoServerConfig::TESTING, |
| 110 rand_, | 110 rand_, |
| 111 crypto_test_utils::ProofSourceForTesting()), | 111 crypto_test_utils::ProofSourceForTesting()), |
| 112 peer_(&config_), | 112 peer_(&config_), |
| 113 compressed_certs_cache_( | 113 compressed_certs_cache_( |
| 114 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize), | 114 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize), |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 GetParam().use_stateless_rejects; | 388 GetParam().use_stateless_rejects; |
| 389 } | 389 } |
| 390 | 390 |
| 391 string XlctHexString() { | 391 string XlctHexString() { |
| 392 uint64_t xlct = crypto_test_utils::LeafCertHashForTesting(); | 392 uint64_t xlct = crypto_test_utils::LeafCertHashForTesting(); |
| 393 return "#" + QuicTextUtils::HexEncode(reinterpret_cast<char*>(&xlct), | 393 return "#" + QuicTextUtils::HexEncode(reinterpret_cast<char*>(&xlct), |
| 394 sizeof(xlct)); | 394 sizeof(xlct)); |
| 395 } | 395 } |
| 396 | 396 |
| 397 protected: | 397 protected: |
| 398 QuicFlagSaver flags_; // Save/restore all QUIC flag values. | |
| 399 QuicRandom* const rand_; | 398 QuicRandom* const rand_; |
| 400 MockRandom rand_for_id_generation_; | 399 MockRandom rand_for_id_generation_; |
| 401 MockClock clock_; | 400 MockClock clock_; |
| 402 QuicSocketAddress client_address_; | 401 QuicSocketAddress client_address_; |
| 403 QuicVersionVector supported_versions_; | 402 QuicVersionVector supported_versions_; |
| 404 QuicVersion client_version_; | 403 QuicVersion client_version_; |
| 405 string client_version_string_; | 404 string client_version_string_; |
| 406 QuicCryptoServerConfig config_; | 405 QuicCryptoServerConfig config_; |
| 407 QuicCryptoServerConfigPeer peer_; | 406 QuicCryptoServerConfigPeer peer_; |
| 408 QuicCompressedCertsCache compressed_certs_cache_; | 407 QuicCompressedCertsCache compressed_certs_cache_; |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 {"PUBS", pub_hex_}, | 940 {"PUBS", pub_hex_}, |
| 942 {"NONC", nonce_hex_}, | 941 {"NONC", nonce_hex_}, |
| 943 {"PDMD", "X509"}, | 942 {"PDMD", "X509"}, |
| 944 {"VER\0", client_version_string_}}, | 943 {"VER\0", client_version_string_}}, |
| 945 kClientHelloMinimumSize); | 944 kClientHelloMinimumSize); |
| 946 | 945 |
| 947 // Just ensure that we don't crash as occurred in b/33916924. | 946 // Just ensure that we don't crash as occurred in b/33916924. |
| 948 ShouldFailMentioning("", msg); | 947 ShouldFailMentioning("", msg); |
| 949 } | 948 } |
| 950 | 949 |
| 951 TEST(CryptoServerConfigGenerationTest, Determinism) { | 950 class CryptoServerConfigGenerationTest : public QuicTest {}; |
| 951 |
| 952 TEST_F(CryptoServerConfigGenerationTest, Determinism) { |
| 952 // Test that using a deterministic PRNG causes the server-config to be | 953 // Test that using a deterministic PRNG causes the server-config to be |
| 953 // deterministic. | 954 // deterministic. |
| 954 | 955 |
| 955 MockRandom rand_a, rand_b; | 956 MockRandom rand_a, rand_b; |
| 956 const QuicCryptoServerConfig::ConfigOptions options; | 957 const QuicCryptoServerConfig::ConfigOptions options; |
| 957 MockClock clock; | 958 MockClock clock; |
| 958 | 959 |
| 959 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, | 960 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, |
| 960 crypto_test_utils::ProofSourceForTesting()); | 961 crypto_test_utils::ProofSourceForTesting()); |
| 961 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, | 962 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, |
| 962 crypto_test_utils::ProofSourceForTesting()); | 963 crypto_test_utils::ProofSourceForTesting()); |
| 963 std::unique_ptr<CryptoHandshakeMessage> scfg_a( | 964 std::unique_ptr<CryptoHandshakeMessage> scfg_a( |
| 964 a.AddDefaultConfig(&rand_a, &clock, options)); | 965 a.AddDefaultConfig(&rand_a, &clock, options)); |
| 965 std::unique_ptr<CryptoHandshakeMessage> scfg_b( | 966 std::unique_ptr<CryptoHandshakeMessage> scfg_b( |
| 966 b.AddDefaultConfig(&rand_b, &clock, options)); | 967 b.AddDefaultConfig(&rand_b, &clock, options)); |
| 967 | 968 |
| 968 ASSERT_EQ(scfg_a->DebugString(Perspective::IS_SERVER), | 969 ASSERT_EQ(scfg_a->DebugString(Perspective::IS_SERVER), |
| 969 scfg_b->DebugString(Perspective::IS_SERVER)); | 970 scfg_b->DebugString(Perspective::IS_SERVER)); |
| 970 } | 971 } |
| 971 | 972 |
| 972 TEST(CryptoServerConfigGenerationTest, SCIDVaries) { | 973 TEST_F(CryptoServerConfigGenerationTest, SCIDVaries) { |
| 973 // This test ensures that the server config ID varies for different server | 974 // This test ensures that the server config ID varies for different server |
| 974 // configs. | 975 // configs. |
| 975 | 976 |
| 976 MockRandom rand_a, rand_b; | 977 MockRandom rand_a, rand_b; |
| 977 const QuicCryptoServerConfig::ConfigOptions options; | 978 const QuicCryptoServerConfig::ConfigOptions options; |
| 978 MockClock clock; | 979 MockClock clock; |
| 979 | 980 |
| 980 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, | 981 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, |
| 981 crypto_test_utils::ProofSourceForTesting()); | 982 crypto_test_utils::ProofSourceForTesting()); |
| 982 rand_b.ChangeValue(); | 983 rand_b.ChangeValue(); |
| 983 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, | 984 QuicCryptoServerConfig b(QuicCryptoServerConfig::TESTING, &rand_b, |
| 984 crypto_test_utils::ProofSourceForTesting()); | 985 crypto_test_utils::ProofSourceForTesting()); |
| 985 std::unique_ptr<CryptoHandshakeMessage> scfg_a( | 986 std::unique_ptr<CryptoHandshakeMessage> scfg_a( |
| 986 a.AddDefaultConfig(&rand_a, &clock, options)); | 987 a.AddDefaultConfig(&rand_a, &clock, options)); |
| 987 std::unique_ptr<CryptoHandshakeMessage> scfg_b( | 988 std::unique_ptr<CryptoHandshakeMessage> scfg_b( |
| 988 b.AddDefaultConfig(&rand_b, &clock, options)); | 989 b.AddDefaultConfig(&rand_b, &clock, options)); |
| 989 | 990 |
| 990 QuicStringPiece scid_a, scid_b; | 991 QuicStringPiece scid_a, scid_b; |
| 991 EXPECT_TRUE(scfg_a->GetStringPiece(kSCID, &scid_a)); | 992 EXPECT_TRUE(scfg_a->GetStringPiece(kSCID, &scid_a)); |
| 992 EXPECT_TRUE(scfg_b->GetStringPiece(kSCID, &scid_b)); | 993 EXPECT_TRUE(scfg_b->GetStringPiece(kSCID, &scid_b)); |
| 993 | 994 |
| 994 EXPECT_NE(scid_a, scid_b); | 995 EXPECT_NE(scid_a, scid_b); |
| 995 } | 996 } |
| 996 | 997 |
| 997 TEST(CryptoServerConfigGenerationTest, SCIDIsHashOfServerConfig) { | 998 TEST_F(CryptoServerConfigGenerationTest, SCIDIsHashOfServerConfig) { |
| 998 MockRandom rand_a; | 999 MockRandom rand_a; |
| 999 const QuicCryptoServerConfig::ConfigOptions options; | 1000 const QuicCryptoServerConfig::ConfigOptions options; |
| 1000 MockClock clock; | 1001 MockClock clock; |
| 1001 | 1002 |
| 1002 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, | 1003 QuicCryptoServerConfig a(QuicCryptoServerConfig::TESTING, &rand_a, |
| 1003 crypto_test_utils::ProofSourceForTesting()); | 1004 crypto_test_utils::ProofSourceForTesting()); |
| 1004 std::unique_ptr<CryptoHandshakeMessage> scfg( | 1005 std::unique_ptr<CryptoHandshakeMessage> scfg( |
| 1005 a.AddDefaultConfig(&rand_a, &clock, options)); | 1006 a.AddDefaultConfig(&rand_a, &clock, options)); |
| 1006 | 1007 |
| 1007 QuicStringPiece scid; | 1008 QuicStringPiece scid; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false | 1090 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false |
| 1090 // and cause ProcessClientHello to exit early (and generate a REJ message). | 1091 // and cause ProcessClientHello to exit early (and generate a REJ message). |
| 1091 config_.set_replay_protection(false); | 1092 config_.set_replay_protection(false); |
| 1092 | 1093 |
| 1093 ShouldSucceed(msg); | 1094 ShouldSucceed(msg); |
| 1094 EXPECT_EQ(kSHLO, out_.tag()); | 1095 EXPECT_EQ(kSHLO, out_.tag()); |
| 1095 } | 1096 } |
| 1096 | 1097 |
| 1097 } // namespace test | 1098 } // namespace test |
| 1098 } // namespace net | 1099 } // namespace net |
| OLD | NEW |