| 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" | 11 #include "crypto/secure_hash.h" |
| 12 #include "net/quic/core/crypto/cert_compressor.h" | 12 #include "net/quic/core/crypto/cert_compressor.h" |
| 13 #include "net/quic/core/crypto/common_cert_set.h" | 13 #include "net/quic/core/crypto/common_cert_set.h" |
| 14 #include "net/quic/core/crypto/crypto_handshake.h" | 14 #include "net/quic/core/crypto/crypto_handshake.h" |
| 15 #include "net/quic/core/crypto/crypto_server_config_protobuf.h" | 15 #include "net/quic/core/crypto/crypto_server_config_protobuf.h" |
| 16 #include "net/quic/core/crypto/crypto_utils.h" | 16 #include "net/quic/core/crypto/crypto_utils.h" |
| 17 #include "net/quic/core/crypto/proof_source.h" | 17 #include "net/quic/core/crypto/proof_source.h" |
| 18 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 18 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
| 19 #include "net/quic/core/crypto/quic_random.h" | 19 #include "net/quic/core/crypto/quic_random.h" |
| 20 #include "net/quic/core/quic_flags.h" | 20 #include "net/quic/core/quic_flags.h" |
| 21 #include "net/quic/core/quic_socket_address_coder.h" | 21 #include "net/quic/core/quic_socket_address_coder.h" |
| 22 #include "net/quic/core/quic_utils.h" | 22 #include "net/quic/core/quic_utils.h" |
| 23 #include "net/quic/platform/api/quic_text_utils.h" |
| 23 #include "net/quic/test_tools/crypto_test_utils.h" | 24 #include "net/quic/test_tools/crypto_test_utils.h" |
| 24 #include "net/quic/test_tools/delayed_verify_strike_register_client.h" | 25 #include "net/quic/test_tools/delayed_verify_strike_register_client.h" |
| 25 #include "net/quic/test_tools/mock_clock.h" | 26 #include "net/quic/test_tools/mock_clock.h" |
| 26 #include "net/quic/test_tools/mock_random.h" | 27 #include "net/quic/test_tools/mock_random.h" |
| 27 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" | 28 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" |
| 28 #include "net/quic/test_tools/quic_test_utils.h" | 29 #include "net/quic/test_tools/quic_test_utils.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 31 |
| 31 using base::StringPiece; | 32 using base::StringPiece; |
| 32 using std::string; | 33 using std::string; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 config_.AddConfig(std::move(primary_config), clock_.WallNow())); | 136 config_.AddConfig(std::move(primary_config), clock_.WallNow())); |
| 136 | 137 |
| 137 StringPiece orbit; | 138 StringPiece orbit; |
| 138 CHECK(msg->GetStringPiece(kORBT, &orbit)); | 139 CHECK(msg->GetStringPiece(kORBT, &orbit)); |
| 139 CHECK_EQ(sizeof(orbit_), orbit.size()); | 140 CHECK_EQ(sizeof(orbit_), orbit.size()); |
| 140 memcpy(orbit_, orbit.data(), orbit.size()); | 141 memcpy(orbit_, orbit.data(), orbit.size()); |
| 141 | 142 |
| 142 char public_value[32]; | 143 char public_value[32]; |
| 143 memset(public_value, 42, sizeof(public_value)); | 144 memset(public_value, 42, sizeof(public_value)); |
| 144 | 145 |
| 145 nonce_hex_ = "#" + QuicUtils::HexEncode(GenerateNonce()); | 146 nonce_hex_ = "#" + QuicTextUtils::HexEncode(GenerateNonce()); |
| 146 pub_hex_ = "#" + QuicUtils::HexEncode(public_value, sizeof(public_value)); | 147 pub_hex_ = |
| 148 "#" + QuicTextUtils::HexEncode(public_value, sizeof(public_value)); |
| 147 | 149 |
| 148 // clang-format off | 150 // clang-format off |
| 149 CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( | 151 CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( |
| 150 "CHLO", | 152 "CHLO", |
| 151 "PDMD", "X509", | 153 "PDMD", "X509", |
| 152 "AEAD", "AESG", | 154 "AEAD", "AESG", |
| 153 "KEXS", "C255", | 155 "KEXS", "C255", |
| 154 "PUBS", pub_hex_.c_str(), | 156 "PUBS", pub_hex_.c_str(), |
| 155 "NONC", nonce_hex_.c_str(), | 157 "NONC", nonce_hex_.c_str(), |
| 156 "CSCT", "", | 158 "CSCT", "", |
| 157 "VER\0", client_version_string_.c_str(), | 159 "VER\0", client_version_string_.c_str(), |
| 158 "$padding", static_cast<int>(kClientHelloMinimumSize), | 160 "$padding", static_cast<int>(kClientHelloMinimumSize), |
| 159 nullptr); | 161 nullptr); |
| 160 // clang-format on | 162 // clang-format on |
| 161 ShouldSucceed(client_hello); | 163 ShouldSucceed(client_hello); |
| 162 // The message should be rejected because the source-address token is | 164 // The message should be rejected because the source-address token is |
| 163 // missing. | 165 // missing. |
| 164 CheckRejectTag(); | 166 CheckRejectTag(); |
| 165 const HandshakeFailureReason kRejectReasons[] = { | 167 const HandshakeFailureReason kRejectReasons[] = { |
| 166 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; | 168 SERVER_CONFIG_INCHOATE_HELLO_FAILURE}; |
| 167 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); | 169 CheckRejectReasons(kRejectReasons, arraysize(kRejectReasons)); |
| 168 CheckForServerDesignatedConnectionId(); | 170 CheckForServerDesignatedConnectionId(); |
| 169 | 171 |
| 170 StringPiece srct; | 172 StringPiece srct; |
| 171 ASSERT_TRUE(out_.GetStringPiece(kSourceAddressTokenTag, &srct)); | 173 ASSERT_TRUE(out_.GetStringPiece(kSourceAddressTokenTag, &srct)); |
| 172 srct_hex_ = "#" + QuicUtils::HexEncode(srct); | 174 srct_hex_ = "#" + QuicTextUtils::HexEncode(srct); |
| 173 | 175 |
| 174 StringPiece scfg; | 176 StringPiece scfg; |
| 175 ASSERT_TRUE(out_.GetStringPiece(kSCFG, &scfg)); | 177 ASSERT_TRUE(out_.GetStringPiece(kSCFG, &scfg)); |
| 176 server_config_ = CryptoFramer::ParseMessage(scfg); | 178 server_config_ = CryptoFramer::ParseMessage(scfg); |
| 177 | 179 |
| 178 StringPiece scid; | 180 StringPiece scid; |
| 179 ASSERT_TRUE(server_config_->GetStringPiece(kSCID, &scid)); | 181 ASSERT_TRUE(server_config_->GetStringPiece(kSCID, &scid)); |
| 180 scid_hex_ = "#" + QuicUtils::HexEncode(scid); | 182 scid_hex_ = "#" + QuicTextUtils::HexEncode(scid); |
| 181 | 183 |
| 182 signed_config_ = QuicReferenceCountedPointer<QuicSignedServerConfig>( | 184 signed_config_ = QuicReferenceCountedPointer<QuicSignedServerConfig>( |
| 183 new QuicSignedServerConfig()); | 185 new QuicSignedServerConfig()); |
| 184 DCHECK(signed_config_->chain.get() == nullptr); | 186 DCHECK(signed_config_->chain.get() == nullptr); |
| 185 } | 187 } |
| 186 | 188 |
| 187 // Helper used to accept the result of ValidateClientHello and pass | 189 // Helper used to accept the result of ValidateClientHello and pass |
| 188 // it on to ProcessClientHello. | 190 // it on to ProcessClientHello. |
| 189 class ValidateCallback : public ValidateClientHelloResultCallback { | 191 class ValidateCallback : public ValidateClientHelloResultCallback { |
| 190 public: | 192 public: |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 *called_ = false; | 278 *called_ = false; |
| 277 } | 279 } |
| 278 | 280 |
| 279 void Run( | 281 void Run( |
| 280 QuicErrorCode error, | 282 QuicErrorCode error, |
| 281 const string& error_details, | 283 const string& error_details, |
| 282 std::unique_ptr<CryptoHandshakeMessage> message, | 284 std::unique_ptr<CryptoHandshakeMessage> message, |
| 283 std::unique_ptr<DiversificationNonce> diversification_nonce, | 285 std::unique_ptr<DiversificationNonce> diversification_nonce, |
| 284 std::unique_ptr<ProofSource::Details> proof_source_details) override { | 286 std::unique_ptr<ProofSource::Details> proof_source_details) override { |
| 285 if (should_succeed_) { | 287 if (should_succeed_) { |
| 286 ASSERT_EQ(error, QUIC_NO_ERROR) << "Message failed with error " | 288 ASSERT_EQ(error, QUIC_NO_ERROR) |
| 287 << error_details << ": " | 289 << "Message failed with error " << error_details << ": " |
| 288 << result_->client_hello.DebugString(); | 290 << result_->client_hello.DebugString(); |
| 289 } else { | 291 } else { |
| 290 ASSERT_NE(error, QUIC_NO_ERROR) << "Message didn't fail: " | 292 ASSERT_NE(error, QUIC_NO_ERROR) |
| 291 << result_->client_hello.DebugString(); | 293 << "Message didn't fail: " << result_->client_hello.DebugString(); |
| 292 | 294 |
| 293 EXPECT_TRUE(error_details.find(error_substr_) != string::npos) | 295 EXPECT_TRUE(error_details.find(error_substr_) != string::npos) |
| 294 << error_substr_ << " not in " << error_details; | 296 << error_substr_ << " not in " << error_details; |
| 295 } | 297 } |
| 296 if (message != nullptr) { | 298 if (message != nullptr) { |
| 297 *out_ = *message; | 299 *out_ = *message; |
| 298 } | 300 } |
| 299 *called_ = true; | 301 *called_ = true; |
| 300 } | 302 } |
| 301 | 303 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } | 378 } |
| 377 } | 379 } |
| 378 | 380 |
| 379 bool RejectsAreStateless() { | 381 bool RejectsAreStateless() { |
| 380 return GetParam().enable_stateless_rejects && | 382 return GetParam().enable_stateless_rejects && |
| 381 GetParam().use_stateless_rejects; | 383 GetParam().use_stateless_rejects; |
| 382 } | 384 } |
| 383 | 385 |
| 384 string XlctHexString() { | 386 string XlctHexString() { |
| 385 uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting(); | 387 uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting(); |
| 386 return "#" + | 388 return "#" + QuicTextUtils::HexEncode(reinterpret_cast<char*>(&xlct), |
| 387 QuicUtils::HexEncode(reinterpret_cast<char*>(&xlct), sizeof(xlct)); | 389 sizeof(xlct)); |
| 388 } | 390 } |
| 389 | 391 |
| 390 protected: | 392 protected: |
| 391 QuicFlagSaver flags_; // Save/restore all QUIC flag values. | 393 QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
| 392 QuicRandom* const rand_; | 394 QuicRandom* const rand_; |
| 393 MockRandom rand_for_id_generation_; | 395 MockRandom rand_for_id_generation_; |
| 394 MockClock clock_; | 396 MockClock clock_; |
| 395 QuicSocketAddress client_address_; | 397 QuicSocketAddress client_address_; |
| 396 QuicVersionVector supported_versions_; | 398 QuicVersionVector supported_versions_; |
| 397 QuicVersion client_version_; | 399 QuicVersion client_version_; |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false | 1147 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false |
| 1146 // and cause ProcessClientHello to exit early (and generate a REJ message). | 1148 // and cause ProcessClientHello to exit early (and generate a REJ message). |
| 1147 config_.set_replay_protection(false); | 1149 config_.set_replay_protection(false); |
| 1148 | 1150 |
| 1149 ShouldSucceed(msg); | 1151 ShouldSucceed(msg); |
| 1150 EXPECT_EQ(kSHLO, out_.tag()); | 1152 EXPECT_EQ(kSHLO, out_.tag()); |
| 1151 } | 1153 } |
| 1152 | 1154 |
| 1153 } // namespace test | 1155 } // namespace test |
| 1154 } // namespace net | 1156 } // namespace net |
| OLD | NEW |