| 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/test_tools/crypto_test_utils.h" | 5 #include "net/quic/test_tools/crypto_test_utils.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "crypto/openssl_util.h" | 9 #include "crypto/openssl_util.h" |
| 10 #include "crypto/secure_hash.h" | 10 #include "crypto/secure_hash.h" |
| 11 #include "net/quic/core/crypto/channel_id.h" | 11 #include "net/quic/core/crypto/channel_id.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/quic_crypto_server_config.h" | 15 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
| 16 #include "net/quic/core/crypto/quic_decrypter.h" | 16 #include "net/quic/core/crypto/quic_decrypter.h" |
| 17 #include "net/quic/core/crypto/quic_encrypter.h" | 17 #include "net/quic/core/crypto/quic_encrypter.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_crypto_client_stream.h" | 19 #include "net/quic/core/quic_crypto_client_stream.h" |
| 20 #include "net/quic/core/quic_crypto_server_stream.h" | 20 #include "net/quic/core/quic_crypto_server_stream.h" |
| 21 #include "net/quic/core/quic_crypto_stream.h" | 21 #include "net/quic/core/quic_crypto_stream.h" |
| 22 #include "net/quic/core/quic_server_id.h" | 22 #include "net/quic/core/quic_server_id.h" |
| 23 #include "net/quic/core/quic_utils.h" | 23 #include "net/quic/core/quic_utils.h" |
| 24 #include "net/quic/platform/api/quic_clock.h" | 24 #include "net/quic/platform/api/quic_clock.h" |
| 25 #include "net/quic/platform/api/quic_logging.h" | 25 #include "net/quic/platform/api/quic_logging.h" |
| 26 #include "net/quic/platform/api/quic_socket_address.h" | 26 #include "net/quic/platform/api/quic_socket_address.h" |
| 27 #include "net/quic/platform/api/quic_text_utils.h" | 27 #include "net/quic/platform/api/quic_text_utils.h" |
| 28 #include "net/quic/test_tools/quic_connection_peer.h" | 28 #include "net/quic/test_tools/quic_connection_peer.h" |
| 29 #include "net/quic/test_tools/quic_framer_peer.h" | 29 #include "net/quic/test_tools/quic_framer_peer.h" |
| 30 #include "net/quic/test_tools/quic_stream_peer.h" |
| 30 #include "net/quic/test_tools/quic_test_utils.h" | 31 #include "net/quic/test_tools/quic_test_utils.h" |
| 31 #include "net/quic/test_tools/simple_quic_framer.h" | 32 #include "net/quic/test_tools/simple_quic_framer.h" |
| 32 #include "third_party/boringssl/src/include/openssl/bn.h" | 33 #include "third_party/boringssl/src/include/openssl/bn.h" |
| 33 #include "third_party/boringssl/src/include/openssl/ec.h" | 34 #include "third_party/boringssl/src/include/openssl/ec.h" |
| 34 #include "third_party/boringssl/src/include/openssl/ecdsa.h" | 35 #include "third_party/boringssl/src/include/openssl/ecdsa.h" |
| 35 #include "third_party/boringssl/src/include/openssl/evp.h" | 36 #include "third_party/boringssl/src/include/openssl/evp.h" |
| 36 #include "third_party/boringssl/src/include/openssl/obj_mac.h" | 37 #include "third_party/boringssl/src/include/openssl/obj_mac.h" |
| 37 #include "third_party/boringssl/src/include/openssl/sha.h" | 38 #include "third_party/boringssl/src/include/openssl/sha.h" |
| 38 | 39 |
| 39 using base::StringPiece; | 40 using base::StringPiece; |
| 40 using std::string; | 41 using std::string; |
| 41 | 42 |
| 42 namespace net { | 43 namespace net { |
| 43 namespace test { | 44 namespace test { |
| 45 namespace crypto_test_utils { |
| 44 | 46 |
| 45 namespace { | 47 namespace { |
| 46 | 48 |
| 47 // CryptoFramerVisitor is a framer visitor that records handshake messages. | 49 // CryptoFramerVisitor is a framer visitor that records handshake messages. |
| 48 class CryptoFramerVisitor : public CryptoFramerVisitorInterface { | 50 class CryptoFramerVisitor : public CryptoFramerVisitorInterface { |
| 49 public: | 51 public: |
| 50 CryptoFramerVisitor() : error_(false) {} | 52 CryptoFramerVisitor() : error_(false) {} |
| 51 | 53 |
| 52 void OnError(CryptoFramer* framer) override { error_ = true; } | 54 void OnError(CryptoFramer* framer) override { error_ = true; } |
| 53 | 55 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 79 } | 81 } |
| 80 if (c >= 'A' && c <= 'F') { | 82 if (c >= 'A' && c <= 'F') { |
| 81 *value = c - 'A' + 10; | 83 *value = c - 'A' + 10; |
| 82 return true; | 84 return true; |
| 83 } | 85 } |
| 84 return false; | 86 return false; |
| 85 } | 87 } |
| 86 | 88 |
| 87 // A ChannelIDSource that works in asynchronous mode unless the |callback| | 89 // A ChannelIDSource that works in asynchronous mode unless the |callback| |
| 88 // argument to GetChannelIDKey is nullptr. | 90 // argument to GetChannelIDKey is nullptr. |
| 89 class AsyncTestChannelIDSource : public ChannelIDSource, | 91 class AsyncTestChannelIDSource : public ChannelIDSource, public CallbackSource { |
| 90 public CryptoTestUtils::CallbackSource { | |
| 91 public: | 92 public: |
| 92 // Takes ownership of |sync_source|, a synchronous ChannelIDSource. | 93 // Takes ownership of |sync_source|, a synchronous ChannelIDSource. |
| 93 explicit AsyncTestChannelIDSource(ChannelIDSource* sync_source) | 94 explicit AsyncTestChannelIDSource(ChannelIDSource* sync_source) |
| 94 : sync_source_(sync_source) {} | 95 : sync_source_(sync_source) {} |
| 95 ~AsyncTestChannelIDSource() override {} | 96 ~AsyncTestChannelIDSource() override {} |
| 96 | 97 |
| 97 // ChannelIDSource implementation. | 98 // ChannelIDSource implementation. |
| 98 QuicAsyncStatus GetChannelIDKey(const string& hostname, | 99 QuicAsyncStatus GetChannelIDKey(const string& hostname, |
| 99 std::unique_ptr<ChannelIDKey>* channel_id_key, | 100 std::unique_ptr<ChannelIDKey>* channel_id_key, |
| 100 ChannelIDSourceCallback* callback) override { | 101 ChannelIDSourceCallback* callback) override { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 bssl::UniquePtr<EVP_PKEY> pkey(EVP_PKEY_new()); | 254 bssl::UniquePtr<EVP_PKEY> pkey(EVP_PKEY_new()); |
| 254 // EVP_PKEY_set1_EC_KEY takes a reference so no |release| here. | 255 // EVP_PKEY_set1_EC_KEY takes a reference so no |release| here. |
| 255 EVP_PKEY_set1_EC_KEY(pkey.get(), ecdsa_key.get()); | 256 EVP_PKEY_set1_EC_KEY(pkey.get(), ecdsa_key.get()); |
| 256 | 257 |
| 257 return pkey.release(); | 258 return pkey.release(); |
| 258 } | 259 } |
| 259 }; | 260 }; |
| 260 | 261 |
| 261 } // anonymous namespace | 262 } // anonymous namespace |
| 262 | 263 |
| 263 CryptoTestUtils::FakeServerOptions::FakeServerOptions() {} | 264 FakeServerOptions::FakeServerOptions() {} |
| 264 | 265 |
| 265 CryptoTestUtils::FakeServerOptions::~FakeServerOptions() {} | 266 FakeServerOptions::~FakeServerOptions() {} |
| 266 | 267 |
| 267 CryptoTestUtils::FakeClientOptions::FakeClientOptions() | 268 FakeClientOptions::FakeClientOptions() |
| 268 : channel_id_enabled(false), channel_id_source_async(false) {} | 269 : channel_id_enabled(false), channel_id_source_async(false) {} |
| 269 | 270 |
| 270 CryptoTestUtils::FakeClientOptions::~FakeClientOptions() {} | 271 FakeClientOptions::~FakeClientOptions() {} |
| 271 | 272 |
| 272 namespace { | 273 namespace { |
| 273 // This class is used by GenerateFullCHLO() to extract SCID and STK from | 274 // This class is used by GenerateFullCHLO() to extract SCID and STK from |
| 274 // REJ/SREJ and to construct a full CHLO with these fields and given inchoate | 275 // REJ/SREJ and to construct a full CHLO with these fields and given inchoate |
| 275 // CHLO. | 276 // CHLO. |
| 276 class FullChloGenerator { | 277 class FullChloGenerator { |
| 277 public: | 278 public: |
| 278 FullChloGenerator( | 279 FullChloGenerator( |
| 279 QuicCryptoServerConfig* crypto_config, | 280 QuicCryptoServerConfig* crypto_config, |
| 280 QuicSocketAddress server_addr, | 281 QuicSocketAddress server_addr, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 ASSERT_TRUE(rej->GetStringPiece(kSCFG, &scfg)); | 362 ASSERT_TRUE(rej->GetStringPiece(kSCFG, &scfg)); |
| 362 std::unique_ptr<CryptoHandshakeMessage> server_config( | 363 std::unique_ptr<CryptoHandshakeMessage> server_config( |
| 363 CryptoFramer::ParseMessage(scfg)); | 364 CryptoFramer::ParseMessage(scfg)); |
| 364 | 365 |
| 365 StringPiece scid; | 366 StringPiece scid; |
| 366 ASSERT_TRUE(server_config->GetStringPiece(kSCID, &scid)); | 367 ASSERT_TRUE(server_config->GetStringPiece(kSCID, &scid)); |
| 367 | 368 |
| 368 *out_ = result_->client_hello; | 369 *out_ = result_->client_hello; |
| 369 out_->SetStringPiece(kSCID, scid); | 370 out_->SetStringPiece(kSCID, scid); |
| 370 out_->SetStringPiece(kSourceAddressTokenTag, srct); | 371 out_->SetStringPiece(kSourceAddressTokenTag, srct); |
| 371 uint64_t xlct = CryptoTestUtils::LeafCertHashForTesting(); | 372 uint64_t xlct = LeafCertHashForTesting(); |
| 372 out_->SetValue(kXLCT, xlct); | 373 out_->SetValue(kXLCT, xlct); |
| 373 } | 374 } |
| 374 | 375 |
| 375 protected: | 376 protected: |
| 376 QuicCryptoServerConfig* crypto_config_; | 377 QuicCryptoServerConfig* crypto_config_; |
| 377 QuicSocketAddress server_addr_; | 378 QuicSocketAddress server_addr_; |
| 378 QuicSocketAddress client_addr_; | 379 QuicSocketAddress client_addr_; |
| 379 const QuicClock* clock_; | 380 const QuicClock* clock_; |
| 380 QuicReferenceCountedPointer<QuicSignedServerConfig> signed_config_; | 381 QuicReferenceCountedPointer<QuicSignedServerConfig> signed_config_; |
| 381 QuicCompressedCertsCache* compressed_certs_cache_; | 382 QuicCompressedCertsCache* compressed_certs_cache_; |
| 382 CryptoHandshakeMessage* out_; | 383 CryptoHandshakeMessage* out_; |
| 383 | 384 |
| 384 QuicReferenceCountedPointer<QuicCryptoNegotiatedParameters> params_; | 385 QuicReferenceCountedPointer<QuicCryptoNegotiatedParameters> params_; |
| 385 QuicReferenceCountedPointer<ValidateClientHelloResultCallback::Result> | 386 QuicReferenceCountedPointer<ValidateClientHelloResultCallback::Result> |
| 386 result_; | 387 result_; |
| 387 }; | 388 }; |
| 388 | 389 |
| 389 } // namespace | 390 } // namespace |
| 390 | 391 |
| 391 // static | 392 int HandshakeWithFakeServer(QuicConfig* server_quic_config, |
| 392 int CryptoTestUtils::HandshakeWithFakeServer( | 393 MockQuicConnectionHelper* helper, |
| 393 QuicConfig* server_quic_config, | 394 MockAlarmFactory* alarm_factory, |
| 394 MockQuicConnectionHelper* helper, | 395 PacketSavingConnection* client_conn, |
| 395 MockAlarmFactory* alarm_factory, | 396 QuicCryptoClientStream* client, |
| 396 PacketSavingConnection* client_conn, | 397 const FakeServerOptions& options) { |
| 397 QuicCryptoClientStream* client, | |
| 398 const FakeServerOptions& options) { | |
| 399 PacketSavingConnection* server_conn = | 398 PacketSavingConnection* server_conn = |
| 400 new PacketSavingConnection(helper, alarm_factory, Perspective::IS_SERVER, | 399 new PacketSavingConnection(helper, alarm_factory, Perspective::IS_SERVER, |
| 401 client_conn->supported_versions()); | 400 client_conn->supported_versions()); |
| 402 | 401 |
| 403 QuicCryptoServerConfig crypto_config(QuicCryptoServerConfig::TESTING, | 402 QuicCryptoServerConfig crypto_config(QuicCryptoServerConfig::TESTING, |
| 404 QuicRandom::GetInstance(), | 403 QuicRandom::GetInstance(), |
| 405 ProofSourceForTesting()); | 404 ProofSourceForTesting()); |
| 406 QuicCompressedCertsCache compressed_certs_cache( | 405 QuicCompressedCertsCache compressed_certs_cache( |
| 407 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize); | 406 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize); |
| 408 SetupCryptoServerConfigForTest(server_conn->clock(), | 407 SetupCryptoServerConfigForTest(server_conn->clock(), |
| 409 server_conn->random_generator(), | 408 server_conn->random_generator(), |
| 410 &crypto_config, options); | 409 &crypto_config, options); |
| 411 | 410 |
| 412 TestQuicSpdyServerSession server_session(server_conn, *server_quic_config, | 411 TestQuicSpdyServerSession server_session(server_conn, *server_quic_config, |
| 413 &crypto_config, | 412 &crypto_config, |
| 414 &compressed_certs_cache); | 413 &compressed_certs_cache); |
| 415 | 414 |
| 416 // The client's handshake must have been started already. | 415 // The client's handshake must have been started already. |
| 417 CHECK_NE(0u, client_conn->encrypted_packets_.size()); | 416 CHECK_NE(0u, client_conn->encrypted_packets_.size()); |
| 418 | 417 |
| 419 CommunicateHandshakeMessages(client_conn, client, server_conn, | 418 CommunicateHandshakeMessages(client_conn, client, server_conn, |
| 420 server_session.GetCryptoStream()); | 419 server_session.GetCryptoStream()); |
| 421 CompareClientAndServerKeys(client, server_session.GetCryptoStream()); | 420 CompareClientAndServerKeys(client, server_session.GetCryptoStream()); |
| 422 | 421 |
| 423 return client->num_sent_client_hellos(); | 422 return client->num_sent_client_hellos(); |
| 424 } | 423 } |
| 425 | 424 |
| 426 // static | 425 int HandshakeWithFakeClient(MockQuicConnectionHelper* helper, |
| 427 int CryptoTestUtils::HandshakeWithFakeClient( | 426 MockAlarmFactory* alarm_factory, |
| 428 MockQuicConnectionHelper* helper, | 427 PacketSavingConnection* server_conn, |
| 429 MockAlarmFactory* alarm_factory, | 428 QuicCryptoServerStream* server, |
| 430 PacketSavingConnection* server_conn, | 429 const QuicServerId& server_id, |
| 431 QuicCryptoServerStream* server, | 430 const FakeClientOptions& options) { |
| 432 const QuicServerId& server_id, | |
| 433 const FakeClientOptions& options) { | |
| 434 PacketSavingConnection* client_conn = | 431 PacketSavingConnection* client_conn = |
| 435 new PacketSavingConnection(helper, alarm_factory, Perspective::IS_CLIENT); | 432 new PacketSavingConnection(helper, alarm_factory, Perspective::IS_CLIENT); |
| 436 // Advance the time, because timers do not like uninitialized times. | 433 // Advance the time, because timers do not like uninitialized times. |
| 437 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 434 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 438 | 435 |
| 439 QuicCryptoClientConfig crypto_config(ProofVerifierForTesting()); | 436 QuicCryptoClientConfig crypto_config(ProofVerifierForTesting()); |
| 440 AsyncTestChannelIDSource* async_channel_id_source = nullptr; | 437 AsyncTestChannelIDSource* async_channel_id_source = nullptr; |
| 441 if (options.channel_id_enabled) { | 438 if (options.channel_id_enabled) { |
| 442 ChannelIDSource* source = ChannelIDSourceForTesting(); | 439 ChannelIDSource* source = ChannelIDSourceForTesting(); |
| 443 if (options.channel_id_source_async) { | 440 if (options.channel_id_source_async) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 474 server->crypto_negotiated_params().channel_id); | 471 server->crypto_negotiated_params().channel_id); |
| 475 EXPECT_EQ( | 472 EXPECT_EQ( |
| 476 options.channel_id_source_async, | 473 options.channel_id_source_async, |
| 477 client_session.GetCryptoStream()->WasChannelIDSourceCallbackRun()); | 474 client_session.GetCryptoStream()->WasChannelIDSourceCallbackRun()); |
| 478 } | 475 } |
| 479 } | 476 } |
| 480 | 477 |
| 481 return client_session.GetCryptoStream()->num_sent_client_hellos(); | 478 return client_session.GetCryptoStream()->num_sent_client_hellos(); |
| 482 } | 479 } |
| 483 | 480 |
| 484 // static | 481 void SetupCryptoServerConfigForTest(const QuicClock* clock, |
| 485 void CryptoTestUtils::SetupCryptoServerConfigForTest( | 482 QuicRandom* rand, |
| 486 const QuicClock* clock, | 483 QuicCryptoServerConfig* crypto_config, |
| 487 QuicRandom* rand, | 484 const FakeServerOptions& fake_options) { |
| 488 QuicCryptoServerConfig* crypto_config, | |
| 489 const FakeServerOptions& fake_options) { | |
| 490 QuicCryptoServerConfig::ConfigOptions options; | 485 QuicCryptoServerConfig::ConfigOptions options; |
| 491 options.channel_id_enabled = true; | 486 options.channel_id_enabled = true; |
| 492 options.token_binding_params = fake_options.token_binding_params; | 487 options.token_binding_params = fake_options.token_binding_params; |
| 493 std::unique_ptr<CryptoHandshakeMessage> scfg( | 488 std::unique_ptr<CryptoHandshakeMessage> scfg( |
| 494 crypto_config->AddDefaultConfig(rand, clock, options)); | 489 crypto_config->AddDefaultConfig(rand, clock, options)); |
| 495 } | 490 } |
| 496 | 491 |
| 497 // static | 492 void CommunicateHandshakeMessages(PacketSavingConnection* client_conn, |
| 498 void CryptoTestUtils::CommunicateHandshakeMessages( | 493 QuicCryptoStream* client, |
| 499 PacketSavingConnection* client_conn, | 494 PacketSavingConnection* server_conn, |
| 500 QuicCryptoStream* client, | 495 QuicCryptoStream* server) { |
| 501 PacketSavingConnection* server_conn, | |
| 502 QuicCryptoStream* server) { | |
| 503 CommunicateHandshakeMessagesAndRunCallbacks(client_conn, client, server_conn, | 496 CommunicateHandshakeMessagesAndRunCallbacks(client_conn, client, server_conn, |
| 504 server, nullptr); | 497 server, nullptr); |
| 505 } | 498 } |
| 506 | 499 |
| 507 // static | 500 void CommunicateHandshakeMessagesAndRunCallbacks( |
| 508 void CryptoTestUtils::CommunicateHandshakeMessagesAndRunCallbacks( | |
| 509 PacketSavingConnection* client_conn, | 501 PacketSavingConnection* client_conn, |
| 510 QuicCryptoStream* client, | 502 QuicCryptoStream* client, |
| 511 PacketSavingConnection* server_conn, | 503 PacketSavingConnection* server_conn, |
| 512 QuicCryptoStream* server, | 504 QuicCryptoStream* server, |
| 513 CallbackSource* callback_source) { | 505 CallbackSource* callback_source) { |
| 514 size_t client_i = 0, server_i = 0; | 506 size_t client_i = 0, server_i = 0; |
| 515 while (!client->handshake_confirmed()) { | 507 while (!client->handshake_confirmed()) { |
| 516 ASSERT_GT(client_conn->encrypted_packets_.size(), client_i); | 508 ASSERT_GT(client_conn->encrypted_packets_.size(), client_i); |
| 517 QUIC_LOG(INFO) << "Processing " | 509 QUIC_LOG(INFO) << "Processing " |
| 518 << client_conn->encrypted_packets_.size() - client_i | 510 << client_conn->encrypted_packets_.size() - client_i |
| 519 << " packets client->server"; | 511 << " packets client->server"; |
| 520 MovePackets(client_conn, &client_i, server, server_conn, | 512 MovePackets(client_conn, &client_i, server, server_conn, |
| 521 Perspective::IS_SERVER); | 513 Perspective::IS_SERVER); |
| 522 if (callback_source) { | 514 if (callback_source) { |
| 523 callback_source->RunPendingCallbacks(); | 515 callback_source->RunPendingCallbacks(); |
| 524 } | 516 } |
| 525 | 517 |
| 526 ASSERT_GT(server_conn->encrypted_packets_.size(), server_i); | 518 ASSERT_GT(server_conn->encrypted_packets_.size(), server_i); |
| 527 QUIC_LOG(INFO) << "Processing " | 519 QUIC_LOG(INFO) << "Processing " |
| 528 << server_conn->encrypted_packets_.size() - server_i | 520 << server_conn->encrypted_packets_.size() - server_i |
| 529 << " packets server->client"; | 521 << " packets server->client"; |
| 530 MovePackets(server_conn, &server_i, client, client_conn, | 522 MovePackets(server_conn, &server_i, client, client_conn, |
| 531 Perspective::IS_CLIENT); | 523 Perspective::IS_CLIENT); |
| 532 if (callback_source) { | 524 if (callback_source) { |
| 533 callback_source->RunPendingCallbacks(); | 525 callback_source->RunPendingCallbacks(); |
| 534 } | 526 } |
| 535 } | 527 } |
| 536 } | 528 } |
| 537 | 529 |
| 538 // static | 530 std::pair<size_t, size_t> AdvanceHandshake(PacketSavingConnection* client_conn, |
| 539 std::pair<size_t, size_t> CryptoTestUtils::AdvanceHandshake( | 531 QuicCryptoStream* client, |
| 540 PacketSavingConnection* client_conn, | 532 size_t client_i, |
| 541 QuicCryptoStream* client, | 533 PacketSavingConnection* server_conn, |
| 542 size_t client_i, | 534 QuicCryptoStream* server, |
| 543 PacketSavingConnection* server_conn, | 535 size_t server_i) { |
| 544 QuicCryptoStream* server, | |
| 545 size_t server_i) { | |
| 546 QUIC_LOG(INFO) << "Processing " | 536 QUIC_LOG(INFO) << "Processing " |
| 547 << client_conn->encrypted_packets_.size() - client_i | 537 << client_conn->encrypted_packets_.size() - client_i |
| 548 << " packets client->server"; | 538 << " packets client->server"; |
| 549 MovePackets(client_conn, &client_i, server, server_conn, | 539 MovePackets(client_conn, &client_i, server, server_conn, |
| 550 Perspective::IS_SERVER); | 540 Perspective::IS_SERVER); |
| 551 | 541 |
| 552 QUIC_LOG(INFO) << "Processing " | 542 QUIC_LOG(INFO) << "Processing " |
| 553 << server_conn->encrypted_packets_.size() - server_i | 543 << server_conn->encrypted_packets_.size() - server_i |
| 554 << " packets server->client"; | 544 << " packets server->client"; |
| 555 if (server_conn->encrypted_packets_.size() - server_i == 2) { | 545 if (server_conn->encrypted_packets_.size() - server_i == 2) { |
| 556 QUIC_LOG(INFO) << "here"; | 546 QUIC_LOG(INFO) << "here"; |
| 557 } | 547 } |
| 558 MovePackets(server_conn, &server_i, client, client_conn, | 548 MovePackets(server_conn, &server_i, client, client_conn, |
| 559 Perspective::IS_CLIENT); | 549 Perspective::IS_CLIENT); |
| 560 | 550 |
| 561 return std::make_pair(client_i, server_i); | 551 return std::make_pair(client_i, server_i); |
| 562 } | 552 } |
| 563 | 553 |
| 564 // static | 554 string GetValueForTag(const CryptoHandshakeMessage& message, QuicTag tag) { |
| 565 string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message, | |
| 566 QuicTag tag) { | |
| 567 QuicTagValueMap::const_iterator it = message.tag_value_map().find(tag); | 555 QuicTagValueMap::const_iterator it = message.tag_value_map().find(tag); |
| 568 if (it == message.tag_value_map().end()) { | 556 if (it == message.tag_value_map().end()) { |
| 569 return string(); | 557 return string(); |
| 570 } | 558 } |
| 571 return it->second; | 559 return it->second; |
| 572 } | 560 } |
| 573 | 561 |
| 574 uint64_t CryptoTestUtils::LeafCertHashForTesting() { | 562 uint64_t LeafCertHashForTesting() { |
| 575 QuicReferenceCountedPointer<ProofSource::Chain> chain; | 563 QuicReferenceCountedPointer<ProofSource::Chain> chain; |
| 576 QuicSocketAddress server_address; | 564 QuicSocketAddress server_address; |
| 577 QuicCryptoProof proof; | 565 QuicCryptoProof proof; |
| 578 std::unique_ptr<ProofSource> proof_source( | 566 std::unique_ptr<ProofSource> proof_source(ProofSourceForTesting()); |
| 579 CryptoTestUtils::ProofSourceForTesting()); | 567 |
| 580 if (!proof_source->GetProof(server_address, "", "", | 568 class Callback : public ProofSource::Callback { |
| 581 AllSupportedVersions().front(), "", | 569 public: |
| 582 QuicTagVector(), &chain, &proof) || | 570 Callback(bool* ok, QuicReferenceCountedPointer<ProofSource::Chain>* chain) |
| 583 chain->certs.empty()) { | 571 : ok_(ok), chain_(chain) {} |
| 572 |
| 573 void Run(bool ok, |
| 574 const QuicReferenceCountedPointer<ProofSource::Chain>& chain, |
| 575 const QuicCryptoProof& /* proof */, |
| 576 std::unique_ptr<ProofSource::Details> /* details */) override { |
| 577 *ok_ = ok; |
| 578 *chain_ = chain; |
| 579 } |
| 580 |
| 581 private: |
| 582 bool* ok_; |
| 583 QuicReferenceCountedPointer<ProofSource::Chain>* chain_; |
| 584 }; |
| 585 |
| 586 // Note: relies on the callback being invoked synchronously |
| 587 bool ok = false; |
| 588 proof_source->GetProof( |
| 589 server_address, "", "", AllSupportedVersions().front(), "", |
| 590 QuicTagVector(), |
| 591 std::unique_ptr<ProofSource::Callback>(new Callback(&ok, &chain))); |
| 592 if (!ok || chain->certs.empty()) { |
| 584 DCHECK(false) << "Proof generation failed"; | 593 DCHECK(false) << "Proof generation failed"; |
| 585 return 0; | 594 return 0; |
| 586 } | 595 } |
| 587 | 596 |
| 588 return QuicUtils::FNV1a_64_Hash(chain->certs.at(0)); | 597 return QuicUtils::FNV1a_64_Hash(chain->certs.at(0)); |
| 589 } | 598 } |
| 590 | 599 |
| 591 class MockCommonCertSets : public CommonCertSets { | 600 class MockCommonCertSets : public CommonCertSets { |
| 592 public: | 601 public: |
| 593 MockCommonCertSets(StringPiece cert, uint64_t hash, uint32_t index) | 602 MockCommonCertSets(StringPiece cert, uint64_t hash, uint32_t index) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 *out_index = index_; | 643 *out_index = index_; |
| 635 return true; | 644 return true; |
| 636 } | 645 } |
| 637 | 646 |
| 638 private: | 647 private: |
| 639 const string cert_; | 648 const string cert_; |
| 640 const uint64_t hash_; | 649 const uint64_t hash_; |
| 641 const uint32_t index_; | 650 const uint32_t index_; |
| 642 }; | 651 }; |
| 643 | 652 |
| 644 CommonCertSets* CryptoTestUtils::MockCommonCertSets(StringPiece cert, | 653 CommonCertSets* MockCommonCertSets(StringPiece cert, |
| 645 uint64_t hash, | 654 uint64_t hash, |
| 646 uint32_t index) { | 655 uint32_t index) { |
| 647 return new class MockCommonCertSets(cert, hash, index); | 656 return new class MockCommonCertSets(cert, hash, index); |
| 648 } | 657 } |
| 649 | 658 |
| 650 // static | 659 void FillInDummyReject(CryptoHandshakeMessage* rej, bool reject_is_stateless) { |
| 651 void CryptoTestUtils::FillInDummyReject(CryptoHandshakeMessage* rej, | |
| 652 bool reject_is_stateless) { | |
| 653 if (reject_is_stateless) { | 660 if (reject_is_stateless) { |
| 654 rej->set_tag(kSREJ); | 661 rej->set_tag(kSREJ); |
| 655 } else { | 662 } else { |
| 656 rej->set_tag(kREJ); | 663 rej->set_tag(kREJ); |
| 657 } | 664 } |
| 658 | 665 |
| 659 // Minimum SCFG that passes config validation checks. | 666 // Minimum SCFG that passes config validation checks. |
| 660 // clang-format off | 667 // clang-format off |
| 661 unsigned char scfg[] = { | 668 unsigned char scfg[] = { |
| 662 // SCFG | 669 // SCFG |
| (...skipping 13 matching lines...) Expand all Loading... |
| 676 // clang-format on | 683 // clang-format on |
| 677 rej->SetValue(kSCFG, scfg); | 684 rej->SetValue(kSCFG, scfg); |
| 678 rej->SetStringPiece(kServerNonceTag, "SERVER_NONCE"); | 685 rej->SetStringPiece(kServerNonceTag, "SERVER_NONCE"); |
| 679 int64_t ttl = 2 * 24 * 60 * 60; | 686 int64_t ttl = 2 * 24 * 60 * 60; |
| 680 rej->SetValue(kSTTL, ttl); | 687 rej->SetValue(kSTTL, ttl); |
| 681 std::vector<QuicTag> reject_reasons; | 688 std::vector<QuicTag> reject_reasons; |
| 682 reject_reasons.push_back(CLIENT_NONCE_INVALID_FAILURE); | 689 reject_reasons.push_back(CLIENT_NONCE_INVALID_FAILURE); |
| 683 rej->SetVector(kRREJ, reject_reasons); | 690 rej->SetVector(kRREJ, reject_reasons); |
| 684 } | 691 } |
| 685 | 692 |
| 686 void CryptoTestUtils::CompareClientAndServerKeys( | 693 void CompareClientAndServerKeys(QuicCryptoClientStream* client, |
| 687 QuicCryptoClientStream* client, | 694 QuicCryptoServerStream* server) { |
| 688 QuicCryptoServerStream* server) { | 695 QuicFramer* client_framer = QuicConnectionPeer::GetFramer( |
| 689 QuicFramer* client_framer = | 696 QuicStreamPeer::session(client)->connection()); |
| 690 QuicConnectionPeer::GetFramer(client->session()->connection()); | 697 QuicFramer* server_framer = QuicConnectionPeer::GetFramer( |
| 691 QuicFramer* server_framer = | 698 QuicStreamPeer::session(server)->connection()); |
| 692 QuicConnectionPeer::GetFramer(server->session()->connection()); | |
| 693 const QuicEncrypter* client_encrypter( | 699 const QuicEncrypter* client_encrypter( |
| 694 QuicFramerPeer::GetEncrypter(client_framer, ENCRYPTION_INITIAL)); | 700 QuicFramerPeer::GetEncrypter(client_framer, ENCRYPTION_INITIAL)); |
| 695 const QuicDecrypter* client_decrypter( | 701 const QuicDecrypter* client_decrypter( |
| 696 client->session()->connection()->decrypter()); | 702 QuicStreamPeer::session(client)->connection()->decrypter()); |
| 697 const QuicEncrypter* client_forward_secure_encrypter( | 703 const QuicEncrypter* client_forward_secure_encrypter( |
| 698 QuicFramerPeer::GetEncrypter(client_framer, ENCRYPTION_FORWARD_SECURE)); | 704 QuicFramerPeer::GetEncrypter(client_framer, ENCRYPTION_FORWARD_SECURE)); |
| 699 const QuicDecrypter* client_forward_secure_decrypter( | 705 const QuicDecrypter* client_forward_secure_decrypter( |
| 700 client->session()->connection()->alternative_decrypter()); | 706 QuicStreamPeer::session(client)->connection()->alternative_decrypter()); |
| 701 const QuicEncrypter* server_encrypter( | 707 const QuicEncrypter* server_encrypter( |
| 702 QuicFramerPeer::GetEncrypter(server_framer, ENCRYPTION_INITIAL)); | 708 QuicFramerPeer::GetEncrypter(server_framer, ENCRYPTION_INITIAL)); |
| 703 const QuicDecrypter* server_decrypter( | 709 const QuicDecrypter* server_decrypter( |
| 704 server->session()->connection()->decrypter()); | 710 QuicStreamPeer::session(server)->connection()->decrypter()); |
| 705 const QuicEncrypter* server_forward_secure_encrypter( | 711 const QuicEncrypter* server_forward_secure_encrypter( |
| 706 QuicFramerPeer::GetEncrypter(server_framer, ENCRYPTION_FORWARD_SECURE)); | 712 QuicFramerPeer::GetEncrypter(server_framer, ENCRYPTION_FORWARD_SECURE)); |
| 707 const QuicDecrypter* server_forward_secure_decrypter( | 713 const QuicDecrypter* server_forward_secure_decrypter( |
| 708 server->session()->connection()->alternative_decrypter()); | 714 QuicStreamPeer::session(server)->connection()->alternative_decrypter()); |
| 709 | 715 |
| 710 StringPiece client_encrypter_key = client_encrypter->GetKey(); | 716 StringPiece client_encrypter_key = client_encrypter->GetKey(); |
| 711 StringPiece client_encrypter_iv = client_encrypter->GetNoncePrefix(); | 717 StringPiece client_encrypter_iv = client_encrypter->GetNoncePrefix(); |
| 712 StringPiece client_decrypter_key = client_decrypter->GetKey(); | 718 StringPiece client_decrypter_key = client_decrypter->GetKey(); |
| 713 StringPiece client_decrypter_iv = client_decrypter->GetNoncePrefix(); | 719 StringPiece client_decrypter_iv = client_decrypter->GetNoncePrefix(); |
| 714 StringPiece client_forward_secure_encrypter_key = | 720 StringPiece client_forward_secure_encrypter_key = |
| 715 client_forward_secure_encrypter->GetKey(); | 721 client_forward_secure_encrypter->GetKey(); |
| 716 StringPiece client_forward_secure_encrypter_iv = | 722 StringPiece client_forward_secure_encrypter_iv = |
| 717 client_forward_secure_encrypter->GetNoncePrefix(); | 723 client_forward_secure_encrypter->GetNoncePrefix(); |
| 718 StringPiece client_forward_secure_decrypter_key = | 724 StringPiece client_forward_secure_decrypter_key = |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 CompareCharArraysWithHexError( | 802 CompareCharArraysWithHexError( |
| 797 "sample key extraction", client_key_extraction.data(), | 803 "sample key extraction", client_key_extraction.data(), |
| 798 client_key_extraction.length(), server_key_extraction.data(), | 804 client_key_extraction.length(), server_key_extraction.data(), |
| 799 server_key_extraction.length()); | 805 server_key_extraction.length()); |
| 800 | 806 |
| 801 CompareCharArraysWithHexError("token binding key extraction", | 807 CompareCharArraysWithHexError("token binding key extraction", |
| 802 client_tb_ekm.data(), client_tb_ekm.length(), | 808 client_tb_ekm.data(), client_tb_ekm.length(), |
| 803 server_tb_ekm.data(), server_tb_ekm.length()); | 809 server_tb_ekm.data(), server_tb_ekm.length()); |
| 804 } | 810 } |
| 805 | 811 |
| 806 // static | 812 QuicTag ParseTag(const char* tagstr) { |
| 807 QuicTag CryptoTestUtils::ParseTag(const char* tagstr) { | |
| 808 const size_t len = strlen(tagstr); | 813 const size_t len = strlen(tagstr); |
| 809 CHECK_NE(0u, len); | 814 CHECK_NE(0u, len); |
| 810 | 815 |
| 811 QuicTag tag = 0; | 816 QuicTag tag = 0; |
| 812 | 817 |
| 813 if (tagstr[0] == '#') { | 818 if (tagstr[0] == '#') { |
| 814 CHECK_EQ(static_cast<size_t>(1 + 2 * 4), len); | 819 CHECK_EQ(static_cast<size_t>(1 + 2 * 4), len); |
| 815 tagstr++; | 820 tagstr++; |
| 816 | 821 |
| 817 for (size_t i = 0; i < 8; i++) { | 822 for (size_t i = 0; i < 8; i++) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 829 for (size_t i = 0; i < 4; i++) { | 834 for (size_t i = 0; i < 4; i++) { |
| 830 tag >>= 8; | 835 tag >>= 8; |
| 831 if (i < len) { | 836 if (i < len) { |
| 832 tag |= static_cast<uint32_t>(tagstr[i]) << 24; | 837 tag |= static_cast<uint32_t>(tagstr[i]) << 24; |
| 833 } | 838 } |
| 834 } | 839 } |
| 835 | 840 |
| 836 return tag; | 841 return tag; |
| 837 } | 842 } |
| 838 | 843 |
| 839 // static | 844 CryptoHandshakeMessage CreateCHLO( |
| 840 CryptoHandshakeMessage CryptoTestUtils::Message(const char* message_tag, ...) { | 845 std::vector<std::pair<string, string>> tags_and_values) { |
| 841 va_list ap; | 846 return CreateCHLO(tags_and_values, -1); |
| 842 va_start(ap, message_tag); | 847 } |
| 843 | 848 |
| 849 CryptoHandshakeMessage CreateCHLO( |
| 850 std::vector<std::pair<string, string>> tags_and_values, |
| 851 int minimum_size_bytes) { |
| 844 CryptoHandshakeMessage msg; | 852 CryptoHandshakeMessage msg; |
| 845 msg.set_tag(ParseTag(message_tag)); | 853 msg.set_tag(MakeQuicTag('C', 'H', 'L', 'O')); |
| 846 | 854 |
| 847 for (;;) { | 855 if (minimum_size_bytes > 0) { |
| 848 const char* tagstr = va_arg(ap, const char*); | 856 msg.set_minimum_size(minimum_size_bytes); |
| 849 if (tagstr == nullptr) { | 857 } |
| 850 break; | |
| 851 } | |
| 852 | 858 |
| 853 if (tagstr[0] == '$') { | 859 for (const auto& tag_and_value : tags_and_values) { |
| 854 // Special value. | 860 const string& tag = tag_and_value.first; |
| 855 const char* const special = tagstr + 1; | 861 const string& value = tag_and_value.second; |
| 856 if (strcmp(special, "padding") == 0) { | |
| 857 const int min_bytes = va_arg(ap, int); | |
| 858 msg.set_minimum_size(min_bytes); | |
| 859 } else { | |
| 860 CHECK(false) << "Unknown special value: " << special; | |
| 861 } | |
| 862 | 862 |
| 863 const QuicTag quic_tag = ParseTag(tag.c_str()); |
| 864 |
| 865 size_t value_len = value.length(); |
| 866 if (value_len > 0 && value[0] == '#') { |
| 867 // This is ascii encoded hex. |
| 868 string hex_value = QuicTextUtils::HexDecode(StringPiece(&value[1])); |
| 869 msg.SetStringPiece(quic_tag, hex_value); |
| 863 continue; | 870 continue; |
| 864 } | 871 } |
| 865 | 872 msg.SetStringPiece(quic_tag, value); |
| 866 const QuicTag tag = ParseTag(tagstr); | |
| 867 const char* valuestr = va_arg(ap, const char*); | |
| 868 | |
| 869 size_t len = strlen(valuestr); | |
| 870 if (len > 0 && valuestr[0] == '#') { | |
| 871 valuestr++; | |
| 872 len--; | |
| 873 | |
| 874 CHECK_EQ(0u, len % 2); | |
| 875 std::unique_ptr<uint8_t[]> buf(new uint8_t[len / 2]); | |
| 876 | |
| 877 for (size_t i = 0; i < len / 2; i++) { | |
| 878 uint8_t v = 0; | |
| 879 CHECK(HexChar(valuestr[i * 2], &v)); | |
| 880 buf[i] = v << 4; | |
| 881 CHECK(HexChar(valuestr[i * 2 + 1], &v)); | |
| 882 buf[i] |= v; | |
| 883 } | |
| 884 | |
| 885 msg.SetStringPiece( | |
| 886 tag, StringPiece(reinterpret_cast<char*>(buf.get()), len / 2)); | |
| 887 continue; | |
| 888 } | |
| 889 | |
| 890 msg.SetStringPiece(tag, valuestr); | |
| 891 } | 873 } |
| 892 | 874 |
| 893 // The CryptoHandshakeMessage needs to be serialized and parsed to ensure | 875 // The CryptoHandshakeMessage needs to be serialized and parsed to ensure |
| 894 // that any padding is included. | 876 // that any padding is included. |
| 895 std::unique_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); | 877 std::unique_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); |
| 896 std::unique_ptr<CryptoHandshakeMessage> parsed( | 878 std::unique_ptr<CryptoHandshakeMessage> parsed( |
| 897 CryptoFramer::ParseMessage(bytes->AsStringPiece())); | 879 CryptoFramer::ParseMessage(bytes->AsStringPiece())); |
| 898 CHECK(parsed.get()); | 880 CHECK(parsed.get()); |
| 899 | 881 |
| 900 va_end(ap); | |
| 901 return *parsed; | 882 return *parsed; |
| 902 } | 883 } |
| 903 | 884 |
| 904 // static | 885 ChannelIDSource* ChannelIDSourceForTesting() { |
| 905 ChannelIDSource* CryptoTestUtils::ChannelIDSourceForTesting() { | |
| 906 return new TestChannelIDSource(); | 886 return new TestChannelIDSource(); |
| 907 } | 887 } |
| 908 | 888 |
| 909 // static | 889 void MovePackets(PacketSavingConnection* source_conn, |
| 910 void CryptoTestUtils::MovePackets(PacketSavingConnection* source_conn, | 890 size_t* inout_packet_index, |
| 911 size_t* inout_packet_index, | 891 QuicCryptoStream* dest_stream, |
| 912 QuicCryptoStream* dest_stream, | 892 PacketSavingConnection* dest_conn, |
| 913 PacketSavingConnection* dest_conn, | 893 Perspective dest_perspective) { |
| 914 Perspective dest_perspective) { | |
| 915 SimpleQuicFramer framer(source_conn->supported_versions(), dest_perspective); | 894 SimpleQuicFramer framer(source_conn->supported_versions(), dest_perspective); |
| 916 CryptoFramer crypto_framer; | 895 CryptoFramer crypto_framer; |
| 917 CryptoFramerVisitor crypto_visitor; | 896 CryptoFramerVisitor crypto_visitor; |
| 918 | 897 |
| 919 // In order to properly test the code we need to perform encryption and | 898 // In order to properly test the code we need to perform encryption and |
| 920 // decryption so that the crypters latch when expected. The crypters are in | 899 // decryption so that the crypters latch when expected. The crypters are in |
| 921 // |dest_conn|, but we don't want to try and use them there. Instead we swap | 900 // |dest_conn|, but we don't want to try and use them there. Instead we swap |
| 922 // them into |framer|, perform the decryption with them, and then swap ther | 901 // them into |framer|, perform the decryption with them, and then swap ther |
| 923 // back. | 902 // back. |
| 924 QuicConnectionPeer::SwapCrypters(dest_conn, framer.framer()); | 903 QuicConnectionPeer::SwapCrypters(dest_conn, framer.framer()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 946 QuicConnectionPeer::SwapCrypters(dest_conn, framer.framer()); | 925 QuicConnectionPeer::SwapCrypters(dest_conn, framer.framer()); |
| 947 | 926 |
| 948 ASSERT_EQ(0u, crypto_framer.InputBytesRemaining()); | 927 ASSERT_EQ(0u, crypto_framer.InputBytesRemaining()); |
| 949 | 928 |
| 950 for (const CryptoHandshakeMessage& message : crypto_visitor.messages()) { | 929 for (const CryptoHandshakeMessage& message : crypto_visitor.messages()) { |
| 951 dest_stream->OnHandshakeMessage(message); | 930 dest_stream->OnHandshakeMessage(message); |
| 952 } | 931 } |
| 953 QuicConnectionPeer::SetCurrentPacket(dest_conn, StringPiece(nullptr, 0)); | 932 QuicConnectionPeer::SetCurrentPacket(dest_conn, StringPiece(nullptr, 0)); |
| 954 } | 933 } |
| 955 | 934 |
| 956 CryptoHandshakeMessage CryptoTestUtils::GenerateDefaultInchoateCHLO( | 935 CryptoHandshakeMessage GenerateDefaultInchoateCHLO( |
| 957 const QuicClock* clock, | 936 const QuicClock* clock, |
| 958 QuicVersion version, | 937 QuicVersion version, |
| 959 QuicCryptoServerConfig* crypto_config) { | 938 QuicCryptoServerConfig* crypto_config) { |
| 960 // clang-format off | 939 // clang-format off |
| 961 return CryptoTestUtils::Message( | 940 return CreateCHLO( |
| 962 "CHLO", | 941 {{"PDMD", "X509"}, |
| 963 "PDMD", "X509", | 942 {"AEAD", "AESG"}, |
| 964 "AEAD", "AESG", | 943 {"KEXS", "C255"}, |
| 965 "KEXS", "C255", | 944 {"PUBS", GenerateClientPublicValuesHex().c_str()}, |
| 966 "PUBS", CryptoTestUtils::GenerateClientPublicValuesHex().c_str(), | 945 {"NONC", GenerateClientNonceHex(clock, crypto_config).c_str()}, |
| 967 "NONC", CryptoTestUtils::GenerateClientNonceHex(clock, | 946 {"VER\0", QuicTagToString(QuicVersionToQuicTag(version)).c_str()}}, |
| 968 crypto_config).c_str(), | 947 kClientHelloMinimumSize); |
| 969 "VER\0", QuicTagToString( | |
| 970 QuicVersionToQuicTag(version)).c_str(), | |
| 971 "$padding", static_cast<int>(kClientHelloMinimumSize), | |
| 972 nullptr); | |
| 973 // clang-format on | 948 // clang-format on |
| 974 } | 949 } |
| 975 | 950 |
| 976 string CryptoTestUtils::GenerateClientNonceHex( | 951 string GenerateClientNonceHex(const QuicClock* clock, |
| 977 const QuicClock* clock, | 952 QuicCryptoServerConfig* crypto_config) { |
| 978 QuicCryptoServerConfig* crypto_config) { | |
| 979 net::QuicCryptoServerConfig::ConfigOptions old_config_options; | 953 net::QuicCryptoServerConfig::ConfigOptions old_config_options; |
| 980 net::QuicCryptoServerConfig::ConfigOptions new_config_options; | 954 net::QuicCryptoServerConfig::ConfigOptions new_config_options; |
| 981 old_config_options.id = "old-config-id"; | 955 old_config_options.id = "old-config-id"; |
| 982 delete crypto_config->AddDefaultConfig(net::QuicRandom::GetInstance(), clock, | 956 delete crypto_config->AddDefaultConfig(net::QuicRandom::GetInstance(), clock, |
| 983 old_config_options); | 957 old_config_options); |
| 984 std::unique_ptr<QuicServerConfigProtobuf> primary_config( | 958 std::unique_ptr<QuicServerConfigProtobuf> primary_config( |
| 985 crypto_config->GenerateConfig(net::QuicRandom::GetInstance(), clock, | 959 crypto_config->GenerateConfig(net::QuicRandom::GetInstance(), clock, |
| 986 new_config_options)); | 960 new_config_options)); |
| 987 primary_config->set_primary_time(clock->WallNow().ToUNIXSeconds()); | 961 primary_config->set_primary_time(clock->WallNow().ToUNIXSeconds()); |
| 988 std::unique_ptr<net::CryptoHandshakeMessage> msg( | 962 std::unique_ptr<net::CryptoHandshakeMessage> msg( |
| 989 crypto_config->AddConfig(std::move(primary_config), clock->WallNow())); | 963 crypto_config->AddConfig(std::move(primary_config), clock->WallNow())); |
| 990 StringPiece orbit; | 964 StringPiece orbit; |
| 991 CHECK(msg->GetStringPiece(net::kORBT, &orbit)); | 965 CHECK(msg->GetStringPiece(net::kORBT, &orbit)); |
| 992 string nonce; | 966 string nonce; |
| 993 net::CryptoUtils::GenerateNonce( | 967 net::CryptoUtils::GenerateNonce( |
| 994 clock->WallNow(), net::QuicRandom::GetInstance(), | 968 clock->WallNow(), net::QuicRandom::GetInstance(), |
| 995 StringPiece(reinterpret_cast<const char*>(orbit.data()), | 969 StringPiece(reinterpret_cast<const char*>(orbit.data()), |
| 996 sizeof(orbit.size())), | 970 sizeof(orbit.size())), |
| 997 &nonce); | 971 &nonce); |
| 998 return ("#" + QuicTextUtils::HexEncode(nonce)); | 972 return ("#" + QuicTextUtils::HexEncode(nonce)); |
| 999 } | 973 } |
| 1000 | 974 |
| 1001 string CryptoTestUtils::GenerateClientPublicValuesHex() { | 975 string GenerateClientPublicValuesHex() { |
| 1002 char public_value[32]; | 976 char public_value[32]; |
| 1003 memset(public_value, 42, sizeof(public_value)); | 977 memset(public_value, 42, sizeof(public_value)); |
| 1004 return ("#" + QuicTextUtils::HexEncode(public_value, sizeof(public_value))); | 978 return ("#" + QuicTextUtils::HexEncode(public_value, sizeof(public_value))); |
| 1005 } | 979 } |
| 1006 | 980 |
| 1007 // static | 981 void GenerateFullCHLO(const CryptoHandshakeMessage& inchoate_chlo, |
| 1008 void CryptoTestUtils::GenerateFullCHLO( | 982 QuicCryptoServerConfig* crypto_config, |
| 1009 const CryptoHandshakeMessage& inchoate_chlo, | 983 QuicSocketAddress server_addr, |
| 1010 QuicCryptoServerConfig* crypto_config, | 984 QuicSocketAddress client_addr, |
| 1011 QuicSocketAddress server_addr, | 985 QuicVersion version, |
| 1012 QuicSocketAddress client_addr, | 986 const QuicClock* clock, |
| 1013 QuicVersion version, | 987 QuicReferenceCountedPointer<QuicSignedServerConfig> proof, |
| 1014 const QuicClock* clock, | 988 QuicCompressedCertsCache* compressed_certs_cache, |
| 1015 QuicReferenceCountedPointer<QuicSignedServerConfig> proof, | 989 CryptoHandshakeMessage* out) { |
| 1016 QuicCompressedCertsCache* compressed_certs_cache, | |
| 1017 CryptoHandshakeMessage* out) { | |
| 1018 // Pass a inchoate CHLO. | 990 // Pass a inchoate CHLO. |
| 1019 FullChloGenerator generator(crypto_config, server_addr, client_addr, clock, | 991 FullChloGenerator generator(crypto_config, server_addr, client_addr, clock, |
| 1020 proof, compressed_certs_cache, out); | 992 proof, compressed_certs_cache, out); |
| 1021 crypto_config->ValidateClientHello( | 993 crypto_config->ValidateClientHello( |
| 1022 inchoate_chlo, client_addr.host(), server_addr, version, clock, proof, | 994 inchoate_chlo, client_addr.host(), server_addr, version, clock, proof, |
| 1023 generator.GetValidateClientHelloCallback()); | 995 generator.GetValidateClientHelloCallback()); |
| 1024 } | 996 } |
| 1025 | 997 |
| 998 } // namespace crypto_test_utils |
| 1026 } // namespace test | 999 } // namespace test |
| 1027 } // namespace net | 1000 } // namespace net |
| OLD | NEW |