OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/core/quic_crypto_server_stream.h" | 5 #include "net/quic/core/quic_crypto_server_stream.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 QuicRandom::GetInstance(), | 64 QuicRandom::GetInstance(), |
65 std::move(proof_source)), | 65 std::move(proof_source)), |
66 server_compressed_certs_cache_( | 66 server_compressed_certs_cache_( |
67 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize), | 67 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize), |
68 server_id_(kServerHostname, kServerPort, PRIVACY_MODE_DISABLED), | 68 server_id_(kServerHostname, kServerPort, PRIVACY_MODE_DISABLED), |
69 client_crypto_config_(CryptoTestUtils::ProofVerifierForTesting()) { | 69 client_crypto_config_(CryptoTestUtils::ProofVerifierForTesting()) { |
70 FLAGS_enable_quic_stateless_reject_support = false; | 70 FLAGS_enable_quic_stateless_reject_support = false; |
71 server_crypto_config_.set_strike_register_no_startup_period(); | 71 server_crypto_config_.set_strike_register_no_startup_period(); |
72 } | 72 } |
73 | 73 |
74 void Initialize() { | 74 void Initialize() { InitializeServer(); } |
75 InitializeServer(); | |
76 | |
77 if (AsyncStrikeRegisterVerification()) { | |
78 QuicCryptoServerConfigPeer peer(&server_crypto_config_); | |
79 strike_register_client_ = new DelayedVerifyStrikeRegisterClient( | |
80 10000, // strike_register_max_entries | |
81 static_cast<uint32_t>( | |
82 server_connection_->clock()->WallNow().ToUNIXSeconds()), | |
83 60, // strike_register_window_secs | |
84 peer.GetPrimaryConfig()->orbit, | |
85 StrikeRegister::NO_STARTUP_PERIOD_NEEDED); | |
86 strike_register_client_->StartDelayingVerification(); | |
87 server_crypto_config_.SetStrikeRegisterClient(strike_register_client_); | |
88 } | |
89 } | |
90 | 75 |
91 ~QuicCryptoServerStreamTest() override { | 76 ~QuicCryptoServerStreamTest() override { |
92 // Ensure that anything that might reference |helpers_| is destroyed before | 77 // Ensure that anything that might reference |helpers_| is destroyed before |
93 // |helpers_| is destroyed. | 78 // |helpers_| is destroyed. |
94 server_session_.reset(); | 79 server_session_.reset(); |
95 client_session_.reset(); | 80 client_session_.reset(); |
96 helpers_.clear(); | 81 helpers_.clear(); |
97 alarm_factories_.clear(); | 82 alarm_factories_.clear(); |
98 } | 83 } |
99 | 84 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 alarm_factories_.push_back(base::MakeUnique<MockAlarmFactory>()); | 118 alarm_factories_.push_back(base::MakeUnique<MockAlarmFactory>()); |
134 CreateClientSessionForTest( | 119 CreateClientSessionForTest( |
135 server_id_, supports_stateless_rejects, | 120 server_id_, supports_stateless_rejects, |
136 QuicTime::Delta::FromSeconds(100000), supported_versions_, | 121 QuicTime::Delta::FromSeconds(100000), supported_versions_, |
137 helpers_.back().get(), alarm_factories_.back().get(), | 122 helpers_.back().get(), alarm_factories_.back().get(), |
138 &client_crypto_config_, &client_connection_, &client_session); | 123 &client_crypto_config_, &client_connection_, &client_session); |
139 CHECK(client_session); | 124 CHECK(client_session); |
140 client_session_.reset(client_session); | 125 client_session_.reset(client_session); |
141 } | 126 } |
142 | 127 |
143 bool AsyncStrikeRegisterVerification() { | |
144 if (server_connection_->version() > QUIC_VERSION_32) { | |
145 return false; | |
146 } | |
147 return GetParam(); | |
148 } | |
149 | |
150 void ConstructHandshakeMessage() { | 128 void ConstructHandshakeMessage() { |
151 CryptoFramer framer; | 129 CryptoFramer framer; |
152 message_data_.reset(framer.ConstructHandshakeMessage(message_)); | 130 message_data_.reset(framer.ConstructHandshakeMessage(message_)); |
153 } | 131 } |
154 | 132 |
155 int CompleteCryptoHandshake() { | 133 int CompleteCryptoHandshake() { |
156 CHECK(server_connection_); | 134 CHECK(server_connection_); |
157 CHECK(server_session_ != nullptr); | 135 CHECK(server_session_ != nullptr); |
158 return CryptoTestUtils::HandshakeWithFakeClient( | 136 return CryptoTestUtils::HandshakeWithFakeClient( |
159 helpers_.back().get(), alarm_factories_.back().get(), | 137 helpers_.back().get(), alarm_factories_.back().get(), |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 server_connection_->random_generator()->RandUint64(); | 285 server_connection_->random_generator()->RandUint64(); |
308 EXPECT_EQ(expected_id, server_designated_connection_id); | 286 EXPECT_EQ(expected_id, server_designated_connection_id); |
309 EXPECT_FALSE(client_state->has_server_designated_connection_id()); | 287 EXPECT_FALSE(client_state->has_server_designated_connection_id()); |
310 ASSERT_TRUE(client_state->IsComplete(QuicWallTime::FromUNIXSeconds(0))); | 288 ASSERT_TRUE(client_state->IsComplete(QuicWallTime::FromUNIXSeconds(0))); |
311 | 289 |
312 // Now create new client and server streams with the existing config | 290 // Now create new client and server streams with the existing config |
313 // and try the handshake again (0-RTT handshake). | 291 // and try the handshake again (0-RTT handshake). |
314 InitializeServer(); | 292 InitializeServer(); |
315 | 293 |
316 InitializeFakeClient(/* supports_stateless_rejects= */ true); | 294 InitializeFakeClient(/* supports_stateless_rejects= */ true); |
317 | |
318 // In the stateless case, the second handshake contains a server-nonce, so the | 295 // In the stateless case, the second handshake contains a server-nonce, so the |
319 // AsyncStrikeRegisterVerification() case will still succeed (unlike a 0-RTT | 296 // AsyncStrikeRegisterVerification() case will still succeed (unlike a 0-RTT |
320 // handshake). | 297 // handshake). |
321 AdvanceHandshakeWithFakeClient(); | 298 AdvanceHandshakeWithFakeClient(); |
322 | 299 |
323 // On the second round, encryption will be established. | 300 // On the second round, encryption will be established. |
324 EXPECT_TRUE(server_stream()->encryption_established()); | 301 EXPECT_TRUE(server_stream()->encryption_established()); |
325 EXPECT_TRUE(server_stream()->handshake_confirmed()); | 302 EXPECT_TRUE(server_stream()->handshake_confirmed()); |
326 EXPECT_EQ(1, server_stream()->NumHandshakeMessages()); | 303 EXPECT_EQ(1, server_stream()->NumHandshakeMessages()); |
327 EXPECT_EQ(1, server_stream()->NumHandshakeMessagesWithServerNonces()); | 304 EXPECT_EQ(1, server_stream()->NumHandshakeMessagesWithServerNonces()); |
(...skipping 30 matching lines...) Expand all Loading... |
358 // information. | 335 // information. |
359 AdvanceHandshakeWithFakeClient(); | 336 AdvanceHandshakeWithFakeClient(); |
360 | 337 |
361 // Now do another handshake, hopefully in 0-RTT. | 338 // Now do another handshake, hopefully in 0-RTT. |
362 DVLOG(1) << "Resetting for 0-RTT handshake attempt"; | 339 DVLOG(1) << "Resetting for 0-RTT handshake attempt"; |
363 InitializeFakeClient(/* supports_stateless_rejects= */ false); | 340 InitializeFakeClient(/* supports_stateless_rejects= */ false); |
364 InitializeServer(); | 341 InitializeServer(); |
365 | 342 |
366 client_stream()->CryptoConnect(); | 343 client_stream()->CryptoConnect(); |
367 | 344 |
368 if (AsyncStrikeRegisterVerification()) { | 345 CryptoTestUtils::CommunicateHandshakeMessages( |
369 EXPECT_FALSE(client_stream()->handshake_confirmed()); | 346 client_connection_, client_stream(), server_connection_, server_stream()); |
370 EXPECT_FALSE(server_stream()->handshake_confirmed()); | |
371 | |
372 // Advance the handshake. Expect that the server will be stuck waiting for | |
373 // client nonce verification to complete. | |
374 std::pair<size_t, size_t> messages_moved = | |
375 CryptoTestUtils::AdvanceHandshake(client_connection_, client_stream(), | |
376 0, server_connection_, | |
377 server_stream(), 0); | |
378 EXPECT_EQ(1u, messages_moved.first); | |
379 EXPECT_EQ(0u, messages_moved.second); | |
380 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); | |
381 EXPECT_FALSE(client_stream()->handshake_confirmed()); | |
382 EXPECT_FALSE(server_stream()->handshake_confirmed()); | |
383 | |
384 // The server handshake completes once the nonce verification completes. | |
385 strike_register_client_->RunPendingVerifications(); | |
386 EXPECT_FALSE(client_stream()->handshake_confirmed()); | |
387 EXPECT_TRUE(server_stream()->handshake_confirmed()); | |
388 | |
389 messages_moved = CryptoTestUtils::AdvanceHandshake( | |
390 client_connection_, client_stream(), messages_moved.first, | |
391 server_connection_, server_stream(), messages_moved.second); | |
392 EXPECT_EQ(1u, messages_moved.first); | |
393 EXPECT_EQ(1u, messages_moved.second); | |
394 EXPECT_TRUE(client_stream()->handshake_confirmed()); | |
395 EXPECT_TRUE(server_stream()->handshake_confirmed()); | |
396 } else { | |
397 CryptoTestUtils::CommunicateHandshakeMessages( | |
398 client_connection_, client_stream(), server_connection_, | |
399 server_stream()); | |
400 } | |
401 | 347 |
402 EXPECT_EQ(1, client_stream()->num_sent_client_hellos()); | 348 EXPECT_EQ(1, client_stream()->num_sent_client_hellos()); |
403 } | 349 } |
404 | 350 |
405 TEST_P(QuicCryptoServerStreamTest, FailByPolicy) { | 351 TEST_P(QuicCryptoServerStreamTest, FailByPolicy) { |
406 Initialize(); | 352 Initialize(); |
407 InitializeFakeClient(/* supports_stateless_rejects= */ false); | 353 InitializeFakeClient(/* supports_stateless_rejects= */ false); |
408 | 354 |
409 EXPECT_CALL(*server_session_->helper(), CanAcceptClientHello(_, _, _)) | 355 EXPECT_CALL(*server_session_->helper(), CanAcceptClientHello(_, _, _)) |
410 .WillOnce(testing::Return(false)); | 356 .WillOnce(testing::Return(false)); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 TEST_P(QuicCryptoServerStreamTest, NoTokenBindingWithoutClientSupport) { | 472 TEST_P(QuicCryptoServerStreamTest, NoTokenBindingWithoutClientSupport) { |
527 Initialize(); | 473 Initialize(); |
528 | 474 |
529 CompleteCryptoHandshake(); | 475 CompleteCryptoHandshake(); |
530 EXPECT_EQ( | 476 EXPECT_EQ( |
531 0u, server_stream()->crypto_negotiated_params().token_binding_key_param); | 477 0u, server_stream()->crypto_negotiated_params().token_binding_key_param); |
532 EXPECT_TRUE(server_stream()->encryption_established()); | 478 EXPECT_TRUE(server_stream()->encryption_established()); |
533 EXPECT_TRUE(server_stream()->handshake_confirmed()); | 479 EXPECT_TRUE(server_stream()->handshake_confirmed()); |
534 } | 480 } |
535 | 481 |
536 TEST_P(QuicCryptoServerStreamTest, CancelRPCBeforeVerificationCompletes) { | |
537 FLAGS_quic_require_handshake_confirmation_pre33 = false; | |
538 // Tests that the client can close the connection while the remote strike | |
539 // register verification RPC is still pending. | |
540 | |
541 // Set version to QUIC_VERSION_32 as QUIC_VERSION_33 and later don't support | |
542 // asynchronous strike register RPCs. | |
543 supported_versions_ = {QUIC_VERSION_32}; | |
544 Initialize(); | |
545 if (!AsyncStrikeRegisterVerification()) { | |
546 return; | |
547 } | |
548 InitializeFakeClient(/* supports_stateless_rejects= */ false); | |
549 | |
550 // Do a first handshake in order to prime the client config with the server's | |
551 // information. | |
552 AdvanceHandshakeWithFakeClient(); | |
553 | |
554 // Now start another handshake, this time the server will attempt to verify | |
555 // the client's nonce with the strike registers. | |
556 InitializeFakeClient(/* supports_stateless_rejects= */ false); | |
557 InitializeServer(); | |
558 client_stream()->CryptoConnect(); | |
559 EXPECT_FALSE(client_stream()->handshake_confirmed()); | |
560 EXPECT_FALSE(server_stream()->handshake_confirmed()); | |
561 | |
562 // Advance the handshake. Expect that the server will be stuck waiting for | |
563 // client nonce verification to complete. | |
564 CryptoTestUtils::AdvanceHandshake(client_connection_, client_stream(), 0, | |
565 server_connection_, server_stream(), 0); | |
566 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); | |
567 EXPECT_FALSE(client_stream()->handshake_confirmed()); | |
568 EXPECT_FALSE(server_stream()->handshake_confirmed()); | |
569 | |
570 // While waiting for the asynchronous verification to complete, the client | |
571 // decides to close the connection. | |
572 server_session_->connection()->CloseConnection( | |
573 QUIC_NO_ERROR, "", ConnectionCloseBehavior::SILENT_CLOSE); | |
574 | |
575 // The outstanding nonce verification RPC now completes. | |
576 strike_register_client_->RunPendingVerifications(); | |
577 } | |
578 | |
579 class FailingProofSource : public ProofSource { | 482 class FailingProofSource : public ProofSource { |
580 public: | 483 public: |
581 bool GetProof(const IPAddress& server_ip, | 484 bool GetProof(const IPAddress& server_ip, |
582 const string& hostname, | 485 const string& hostname, |
583 const string& server_config, | 486 const string& server_config, |
584 QuicVersion quic_version, | 487 QuicVersion quic_version, |
585 StringPiece chlo_hash, | 488 StringPiece chlo_hash, |
586 const QuicTagVector& connection_options, | 489 const QuicTagVector& connection_options, |
587 scoped_refptr<ProofSource::Chain>* out_chain, | 490 scoped_refptr<ProofSource::Chain>* out_chain, |
588 QuicCryptoProof* out_proof) override { | 491 QuicCryptoProof* out_proof) override { |
(...skipping 30 matching lines...) Expand all Loading... |
619 // Regression test for b/31521252, in which a crash would happen here. | 522 // Regression test for b/31521252, in which a crash would happen here. |
620 AdvanceHandshakeWithFakeClient(); | 523 AdvanceHandshakeWithFakeClient(); |
621 EXPECT_FALSE(server_stream()->encryption_established()); | 524 EXPECT_FALSE(server_stream()->encryption_established()); |
622 EXPECT_FALSE(server_stream()->handshake_confirmed()); | 525 EXPECT_FALSE(server_stream()->handshake_confirmed()); |
623 } | 526 } |
624 | 527 |
625 } // namespace | 528 } // namespace |
626 | 529 |
627 } // namespace test | 530 } // namespace test |
628 } // namespace net | 531 } // namespace net |
OLD | NEW |