| 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 "crypto/secure_hash.h" | |
| 12 #include "net/quic/core/crypto/cert_compressor.h" | 11 #include "net/quic/core/crypto/cert_compressor.h" |
| 13 #include "net/quic/core/crypto/common_cert_set.h" | 12 #include "net/quic/core/crypto/common_cert_set.h" |
| 14 #include "net/quic/core/crypto/crypto_handshake.h" | 13 #include "net/quic/core/crypto/crypto_handshake.h" |
| 15 #include "net/quic/core/crypto/crypto_server_config_protobuf.h" | 14 #include "net/quic/core/crypto/crypto_server_config_protobuf.h" |
| 16 #include "net/quic/core/crypto/crypto_utils.h" | 15 #include "net/quic/core/crypto/crypto_utils.h" |
| 17 #include "net/quic/core/crypto/proof_source.h" | 16 #include "net/quic/core/crypto/proof_source.h" |
| 18 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 17 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
| 19 #include "net/quic/core/crypto/quic_random.h" | 18 #include "net/quic/core/crypto/quic_random.h" |
| 20 #include "net/quic/core/quic_flags.h" | 19 #include "net/quic/core/quic_flags.h" |
| 21 #include "net/quic/core/quic_socket_address_coder.h" | 20 #include "net/quic/core/quic_socket_address_coder.h" |
| 22 #include "net/quic/core/quic_utils.h" | 21 #include "net/quic/core/quic_utils.h" |
| 23 #include "net/quic/platform/api/quic_text_utils.h" | 22 #include "net/quic/platform/api/quic_text_utils.h" |
| 24 #include "net/quic/test_tools/crypto_test_utils.h" | 23 #include "net/quic/test_tools/crypto_test_utils.h" |
| 25 #include "net/quic/test_tools/delayed_verify_strike_register_client.h" | 24 #include "net/quic/test_tools/delayed_verify_strike_register_client.h" |
| 26 #include "net/quic/test_tools/failing_proof_source.h" | 25 #include "net/quic/test_tools/failing_proof_source.h" |
| 27 #include "net/quic/test_tools/mock_clock.h" | 26 #include "net/quic/test_tools/mock_clock.h" |
| 28 #include "net/quic/test_tools/mock_random.h" | 27 #include "net/quic/test_tools/mock_random.h" |
| 29 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" | 28 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" |
| 30 #include "net/quic/test_tools/quic_test_utils.h" | 29 #include "net/quic/test_tools/quic_test_utils.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "third_party/boringssl/src/include/openssl/sha.h" |
| 32 | 32 |
| 33 using base::StringPiece; | 33 using base::StringPiece; |
| 34 using std::string; | 34 using std::string; |
| 35 | 35 |
| 36 namespace net { | 36 namespace net { |
| 37 namespace test { | 37 namespace test { |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 class DummyProofVerifierCallback : public ProofVerifierCallback { | 41 class DummyProofVerifierCallback : public ProofVerifierCallback { |
| (...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 | 1078 |
| 1079 StringPiece scid; | 1079 StringPiece scid; |
| 1080 EXPECT_TRUE(scfg->GetStringPiece(kSCID, &scid)); | 1080 EXPECT_TRUE(scfg->GetStringPiece(kSCID, &scid)); |
| 1081 // Need to take a copy of |scid| has we're about to call |Erase|. | 1081 // Need to take a copy of |scid| has we're about to call |Erase|. |
| 1082 const string scid_str(scid.as_string()); | 1082 const string scid_str(scid.as_string()); |
| 1083 | 1083 |
| 1084 scfg->Erase(kSCID); | 1084 scfg->Erase(kSCID); |
| 1085 scfg->MarkDirty(); | 1085 scfg->MarkDirty(); |
| 1086 const QuicData& serialized(scfg->GetSerialized()); | 1086 const QuicData& serialized(scfg->GetSerialized()); |
| 1087 | 1087 |
| 1088 std::unique_ptr<crypto::SecureHash> hash( | 1088 uint8_t digest[SHA256_DIGEST_LENGTH]; |
| 1089 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); | 1089 SHA256(reinterpret_cast<const uint8_t*>(serialized.data()), |
| 1090 hash->Update(serialized.data(), serialized.length()); | 1090 serialized.length(), digest); |
| 1091 uint8_t digest[16]; | |
| 1092 hash->Finish(digest, sizeof(digest)); | |
| 1093 | 1091 |
| 1094 ASSERT_EQ(scid.size(), sizeof(digest)); | 1092 // scid is a SHA-256 hash, truncated to 16 bytes. |
| 1095 EXPECT_EQ(0, memcmp(digest, scid_str.c_str(), sizeof(digest))); | 1093 ASSERT_EQ(scid.size(), 16u); |
| 1094 EXPECT_EQ(0, memcmp(digest, scid_str.c_str(), scid.size())); |
| 1096 } | 1095 } |
| 1097 | 1096 |
| 1098 class CryptoServerTestNoConfig : public CryptoServerTest { | 1097 class CryptoServerTestNoConfig : public CryptoServerTest { |
| 1099 public: | 1098 public: |
| 1100 void SetUp() override { | 1099 void SetUp() override { |
| 1101 // Deliberately don't add a config so that we can test this situation. | 1100 // Deliberately don't add a config so that we can test this situation. |
| 1102 } | 1101 } |
| 1103 }; | 1102 }; |
| 1104 | 1103 |
| 1105 TEST_P(CryptoServerTestNoConfig, DontCrash) { | 1104 TEST_P(CryptoServerTestNoConfig, DontCrash) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false | 1171 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false |
| 1173 // and cause ProcessClientHello to exit early (and generate a REJ message). | 1172 // and cause ProcessClientHello to exit early (and generate a REJ message). |
| 1174 config_.set_replay_protection(false); | 1173 config_.set_replay_protection(false); |
| 1175 | 1174 |
| 1176 ShouldSucceed(msg); | 1175 ShouldSucceed(msg); |
| 1177 EXPECT_EQ(kSHLO, out_.tag()); | 1176 EXPECT_EQ(kSHLO, out_.tag()); |
| 1178 } | 1177 } |
| 1179 | 1178 |
| 1180 } // namespace test | 1179 } // namespace test |
| 1181 } // namespace net | 1180 } // namespace net |
| OLD | NEW |