| 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 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 public: | 105 public: |
| 106 CryptoServerTest() | 106 CryptoServerTest() |
| 107 : rand_(QuicRandom::GetInstance()), | 107 : rand_(QuicRandom::GetInstance()), |
| 108 client_address_(Loopback4(), 1234), | 108 client_address_(Loopback4(), 1234), |
| 109 config_(QuicCryptoServerConfig::TESTING, | 109 config_(QuicCryptoServerConfig::TESTING, |
| 110 rand_, | 110 rand_, |
| 111 CryptoTestUtils::ProofSourceForTesting()), | 111 CryptoTestUtils::ProofSourceForTesting()), |
| 112 compressed_certs_cache_( | 112 compressed_certs_cache_( |
| 113 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize), | 113 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize), |
| 114 params_(new QuicCryptoNegotiatedParameters), | 114 params_(new QuicCryptoNegotiatedParameters), |
| 115 crypto_proof_(new QuicCryptoProof), | 115 signed_config_(new QuicSignedServerConfig), |
| 116 chlo_packet_size_(kDefaultMaxPacketSize) { | 116 chlo_packet_size_(kDefaultMaxPacketSize) { |
| 117 supported_versions_ = GetParam().supported_versions; | 117 supported_versions_ = GetParam().supported_versions; |
| 118 config_.set_enable_serving_sct(true); | 118 config_.set_enable_serving_sct(true); |
| 119 | 119 |
| 120 client_version_ = supported_versions_.front(); | 120 client_version_ = supported_versions_.front(); |
| 121 client_version_string_ = | 121 client_version_string_ = |
| 122 QuicUtils::TagToString(QuicVersionToQuicTag(client_version_)); | 122 QuicUtils::TagToString(QuicVersionToQuicTag(client_version_)); |
| 123 | 123 |
| 124 FLAGS_quic_require_handshake_confirmation_pre33 = false; | 124 FLAGS_quic_require_handshake_confirmation_pre33 = false; |
| 125 FLAGS_enable_quic_stateless_reject_support = | 125 FLAGS_enable_quic_stateless_reject_support = |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 srct_hex_ = "#" + QuicUtils::HexEncode(srct); | 176 srct_hex_ = "#" + QuicUtils::HexEncode(srct); |
| 177 | 177 |
| 178 StringPiece scfg; | 178 StringPiece scfg; |
| 179 ASSERT_TRUE(out_.GetStringPiece(kSCFG, &scfg)); | 179 ASSERT_TRUE(out_.GetStringPiece(kSCFG, &scfg)); |
| 180 server_config_.reset(CryptoFramer::ParseMessage(scfg)); | 180 server_config_.reset(CryptoFramer::ParseMessage(scfg)); |
| 181 | 181 |
| 182 StringPiece scid; | 182 StringPiece scid; |
| 183 ASSERT_TRUE(server_config_->GetStringPiece(kSCID, &scid)); | 183 ASSERT_TRUE(server_config_->GetStringPiece(kSCID, &scid)); |
| 184 scid_hex_ = "#" + QuicUtils::HexEncode(scid); | 184 scid_hex_ = "#" + QuicUtils::HexEncode(scid); |
| 185 | 185 |
| 186 crypto_proof_ = scoped_refptr<QuicCryptoProof>(new QuicCryptoProof()); | 186 signed_config_ = |
| 187 DCHECK(crypto_proof_->chain.get() == nullptr); | 187 scoped_refptr<QuicSignedServerConfig>(new QuicSignedServerConfig()); |
| 188 DCHECK(signed_config_->chain.get() == nullptr); |
| 188 } | 189 } |
| 189 | 190 |
| 190 // Helper used to accept the result of ValidateClientHello and pass | 191 // Helper used to accept the result of ValidateClientHello and pass |
| 191 // it on to ProcessClientHello. | 192 // it on to ProcessClientHello. |
| 192 class ValidateCallback : public ValidateClientHelloResultCallback { | 193 class ValidateCallback : public ValidateClientHelloResultCallback { |
| 193 public: | 194 public: |
| 194 ValidateCallback(CryptoServerTest* test, | 195 ValidateCallback(CryptoServerTest* test, |
| 195 bool should_succeed, | 196 bool should_succeed, |
| 196 const char* error_substr, | 197 const char* error_substr, |
| 197 bool* called) | 198 bool* called) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 ASSERT_TRUE(decoder.Decode(address.data(), address.size())); | 242 ASSERT_TRUE(decoder.Decode(address.data(), address.size())); |
| 242 EXPECT_EQ(client_address_.address(), decoder.ip()); | 243 EXPECT_EQ(client_address_.address(), decoder.ip()); |
| 243 EXPECT_EQ(client_address_.port(), decoder.port()); | 244 EXPECT_EQ(client_address_.port(), decoder.port()); |
| 244 } | 245 } |
| 245 | 246 |
| 246 void ShouldSucceed(const CryptoHandshakeMessage& message) { | 247 void ShouldSucceed(const CryptoHandshakeMessage& message) { |
| 247 bool called = false; | 248 bool called = false; |
| 248 IPAddress server_ip; | 249 IPAddress server_ip; |
| 249 config_.ValidateClientHello( | 250 config_.ValidateClientHello( |
| 250 message, client_address_.address(), server_ip, | 251 message, client_address_.address(), server_ip, |
| 251 supported_versions_.front(), &clock_, crypto_proof_, | 252 supported_versions_.front(), &clock_, signed_config_, |
| 252 std::unique_ptr<ValidateCallback>( | 253 std::unique_ptr<ValidateCallback>( |
| 253 new ValidateCallback(this, true, "", &called))); | 254 new ValidateCallback(this, true, "", &called))); |
| 254 EXPECT_TRUE(called); | 255 EXPECT_TRUE(called); |
| 255 } | 256 } |
| 256 | 257 |
| 257 void ShouldFailMentioning(const char* error_substr, | 258 void ShouldFailMentioning(const char* error_substr, |
| 258 const CryptoHandshakeMessage& message) { | 259 const CryptoHandshakeMessage& message) { |
| 259 bool called = false; | 260 bool called = false; |
| 260 ShouldFailMentioning(error_substr, message, &called); | 261 ShouldFailMentioning(error_substr, message, &called); |
| 261 EXPECT_TRUE(called); | 262 EXPECT_TRUE(called); |
| 262 } | 263 } |
| 263 | 264 |
| 264 void ShouldFailMentioning(const char* error_substr, | 265 void ShouldFailMentioning(const char* error_substr, |
| 265 const CryptoHandshakeMessage& message, | 266 const CryptoHandshakeMessage& message, |
| 266 bool* called) { | 267 bool* called) { |
| 267 IPAddress server_ip; | 268 IPAddress server_ip; |
| 268 config_.ValidateClientHello( | 269 config_.ValidateClientHello( |
| 269 message, client_address_.address(), server_ip, | 270 message, client_address_.address(), server_ip, |
| 270 supported_versions_.front(), &clock_, crypto_proof_, | 271 supported_versions_.front(), &clock_, signed_config_, |
| 271 std::unique_ptr<ValidateCallback>( | 272 std::unique_ptr<ValidateCallback>( |
| 272 new ValidateCallback(this, false, error_substr, called))); | 273 new ValidateCallback(this, false, error_substr, called))); |
| 273 } | 274 } |
| 274 | 275 |
| 275 class ProcessCallback : public ProcessClientHelloResultCallback { | 276 class ProcessCallback : public ProcessClientHelloResultCallback { |
| 276 public: | 277 public: |
| 277 ProcessCallback(scoped_refptr<ValidateCallback::Result> result, | 278 ProcessCallback(scoped_refptr<ValidateCallback::Result> result, |
| 278 bool should_succeed, | 279 bool should_succeed, |
| 279 const char* error_substr, | 280 const char* error_substr, |
| 280 bool* called, | 281 bool* called, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 bool should_succeed, | 323 bool should_succeed, |
| 323 const char* error_substr) { | 324 const char* error_substr) { |
| 324 IPAddress server_ip; | 325 IPAddress server_ip; |
| 325 QuicConnectionId server_designated_connection_id = | 326 QuicConnectionId server_designated_connection_id = |
| 326 rand_for_id_generation_.RandUint64(); | 327 rand_for_id_generation_.RandUint64(); |
| 327 bool called; | 328 bool called; |
| 328 config_.ProcessClientHello( | 329 config_.ProcessClientHello( |
| 329 result, /*reject_only=*/false, /*connection_id=*/1, server_ip, | 330 result, /*reject_only=*/false, /*connection_id=*/1, server_ip, |
| 330 client_address_, supported_versions_.front(), supported_versions_, | 331 client_address_, supported_versions_.front(), supported_versions_, |
| 331 use_stateless_rejects_, server_designated_connection_id, &clock_, rand_, | 332 use_stateless_rejects_, server_designated_connection_id, &clock_, rand_, |
| 332 &compressed_certs_cache_, params_, crypto_proof_, | 333 &compressed_certs_cache_, params_, signed_config_, |
| 333 /*total_framing_overhead=*/50, chlo_packet_size_, | 334 /*total_framing_overhead=*/50, chlo_packet_size_, |
| 334 std::unique_ptr<ProcessCallback>(new ProcessCallback( | 335 std::unique_ptr<ProcessCallback>(new ProcessCallback( |
| 335 result, should_succeed, error_substr, &called, &out_))); | 336 result, should_succeed, error_substr, &called, &out_))); |
| 336 EXPECT_TRUE(called); | 337 EXPECT_TRUE(called); |
| 337 } | 338 } |
| 338 | 339 |
| 339 string GenerateNonce() { | 340 string GenerateNonce() { |
| 340 string nonce; | 341 string nonce; |
| 341 CryptoUtils::GenerateNonce( | 342 CryptoUtils::GenerateNonce( |
| 342 clock_.WallNow(), rand_, | 343 clock_.WallNow(), rand_, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 MockRandom rand_for_id_generation_; | 404 MockRandom rand_for_id_generation_; |
| 404 MockClock clock_; | 405 MockClock clock_; |
| 405 IPEndPoint client_address_; | 406 IPEndPoint client_address_; |
| 406 QuicVersionVector supported_versions_; | 407 QuicVersionVector supported_versions_; |
| 407 QuicVersion client_version_; | 408 QuicVersion client_version_; |
| 408 string client_version_string_; | 409 string client_version_string_; |
| 409 QuicCryptoServerConfig config_; | 410 QuicCryptoServerConfig config_; |
| 410 QuicCompressedCertsCache compressed_certs_cache_; | 411 QuicCompressedCertsCache compressed_certs_cache_; |
| 411 QuicCryptoServerConfig::ConfigOptions config_options_; | 412 QuicCryptoServerConfig::ConfigOptions config_options_; |
| 412 scoped_refptr<QuicCryptoNegotiatedParameters> params_; | 413 scoped_refptr<QuicCryptoNegotiatedParameters> params_; |
| 413 scoped_refptr<QuicCryptoProof> crypto_proof_; | 414 scoped_refptr<QuicSignedServerConfig> signed_config_; |
| 414 CryptoHandshakeMessage out_; | 415 CryptoHandshakeMessage out_; |
| 415 uint8_t orbit_[kOrbitSize]; | 416 uint8_t orbit_[kOrbitSize]; |
| 416 bool use_stateless_rejects_; | 417 bool use_stateless_rejects_; |
| 417 size_t chlo_packet_size_; | 418 size_t chlo_packet_size_; |
| 418 | 419 |
| 419 // These strings contain hex escaped values from the server suitable for using | 420 // These strings contain hex escaped values from the server suitable for using |
| 420 // when constructing client hello messages. | 421 // when constructing client hello messages. |
| 421 string nonce_hex_, pub_hex_, srct_hex_, scid_hex_; | 422 string nonce_hex_, pub_hex_, srct_hex_, scid_hex_; |
| 422 std::unique_ptr<CryptoHandshakeMessage> server_config_; | 423 std::unique_ptr<CryptoHandshakeMessage> server_config_; |
| 423 }; | 424 }; |
| (...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 nullptr); | 1213 nullptr); |
| 1213 // clang-format on | 1214 // clang-format on |
| 1214 | 1215 |
| 1215 // Clear the message tag. | 1216 // Clear the message tag. |
| 1216 out_.set_tag(0); | 1217 out_.set_tag(0); |
| 1217 | 1218 |
| 1218 bool called = false; | 1219 bool called = false; |
| 1219 IPAddress server_ip; | 1220 IPAddress server_ip; |
| 1220 config_.ValidateClientHello( | 1221 config_.ValidateClientHello( |
| 1221 msg, client_address_.address(), server_ip, client_version_, &clock_, | 1222 msg, client_address_.address(), server_ip, client_version_, &clock_, |
| 1222 crypto_proof_, std::unique_ptr<ValidateCallback>( | 1223 signed_config_, std::unique_ptr<ValidateCallback>( |
| 1223 new ValidateCallback(this, true, "", &called))); | 1224 new ValidateCallback(this, true, "", &called))); |
| 1224 // The verification request was queued. | 1225 // The verification request was queued. |
| 1225 ASSERT_FALSE(called); | 1226 ASSERT_FALSE(called); |
| 1226 EXPECT_EQ(0u, out_.tag()); | 1227 EXPECT_EQ(0u, out_.tag()); |
| 1227 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); | 1228 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); |
| 1228 | 1229 |
| 1229 // Continue processing the verification request. | 1230 // Continue processing the verification request. |
| 1230 strike_register_client_->RunPendingVerifications(); | 1231 strike_register_client_->RunPendingVerifications(); |
| 1231 ASSERT_TRUE(called); | 1232 ASSERT_TRUE(called); |
| 1232 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 1233 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
| 1233 // The message should be accepted now. | 1234 // The message should be accepted now. |
| 1234 EXPECT_EQ(kSHLO, out_.tag()); | 1235 EXPECT_EQ(kSHLO, out_.tag()); |
| 1235 | 1236 |
| 1236 // Rejected if replayed. | 1237 // Rejected if replayed. |
| 1237 config_.ValidateClientHello( | 1238 config_.ValidateClientHello( |
| 1238 msg, client_address_.address(), server_ip, client_version_, &clock_, | 1239 msg, client_address_.address(), server_ip, client_version_, &clock_, |
| 1239 crypto_proof_, std::unique_ptr<ValidateCallback>( | 1240 signed_config_, std::unique_ptr<ValidateCallback>( |
| 1240 new ValidateCallback(this, true, "", &called))); | 1241 new ValidateCallback(this, true, "", &called))); |
| 1241 // The verification request was queued. | 1242 // The verification request was queued. |
| 1242 ASSERT_FALSE(called); | 1243 ASSERT_FALSE(called); |
| 1243 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); | 1244 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); |
| 1244 | 1245 |
| 1245 strike_register_client_->RunPendingVerifications(); | 1246 strike_register_client_->RunPendingVerifications(); |
| 1246 ASSERT_TRUE(called); | 1247 ASSERT_TRUE(called); |
| 1247 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 1248 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
| 1248 // The message should be rejected now. | 1249 // The message should be rejected now. |
| 1249 CheckRejectTag(); | 1250 CheckRejectTag(); |
| 1250 } | 1251 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1281 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 1282 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
| 1282 } else { | 1283 } else { |
| 1283 // version 33. | 1284 // version 33. |
| 1284 ASSERT_EQ(kSHLO, out_.tag()); | 1285 ASSERT_EQ(kSHLO, out_.tag()); |
| 1285 CheckServerHello(out_); | 1286 CheckServerHello(out_); |
| 1286 } | 1287 } |
| 1287 } | 1288 } |
| 1288 | 1289 |
| 1289 } // namespace test | 1290 } // namespace test |
| 1290 } // namespace net | 1291 } // namespace net |
| OLD | NEW |