OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "net/quic/core/crypto/quic_crypto_client_config.h" | 5 #include "net/quic/core/crypto/quic_crypto_client_config.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 i != certs.end(); ++i) { | 478 i != certs.end(); ++i) { |
479 hashes.push_back(QuicUtils::FNV1a_64_Hash(i->data(), i->size())); | 479 hashes.push_back(QuicUtils::FNV1a_64_Hash(i->data(), i->size())); |
480 } | 480 } |
481 out->SetVector(kCCRT, hashes); | 481 out->SetVector(kCCRT, hashes); |
482 } | 482 } |
483 } | 483 } |
484 | 484 |
485 QuicErrorCode QuicCryptoClientConfig::FillClientHello( | 485 QuicErrorCode QuicCryptoClientConfig::FillClientHello( |
486 const QuicServerId& server_id, | 486 const QuicServerId& server_id, |
487 QuicConnectionId connection_id, | 487 QuicConnectionId connection_id, |
488 const QuicVersion actual_version, | |
489 const QuicVersion preferred_version, | 488 const QuicVersion preferred_version, |
490 const CachedState* cached, | 489 const CachedState* cached, |
491 QuicWallTime now, | 490 QuicWallTime now, |
492 QuicRandom* rand, | 491 QuicRandom* rand, |
493 const ChannelIDKey* channel_id_key, | 492 const ChannelIDKey* channel_id_key, |
494 scoped_refptr<QuicCryptoNegotiatedParameters> out_params, | 493 scoped_refptr<QuicCryptoNegotiatedParameters> out_params, |
495 CryptoHandshakeMessage* out, | 494 CryptoHandshakeMessage* out, |
496 string* error_details) const { | 495 string* error_details) const { |
497 DCHECK(error_details != nullptr); | 496 DCHECK(error_details != nullptr); |
498 | 497 |
(...skipping 27 matching lines...) Expand all Loading... |
526 *error_details = "Missing AEAD or KEXS"; | 525 *error_details = "Missing AEAD or KEXS"; |
527 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; | 526 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; |
528 } | 527 } |
529 | 528 |
530 // AEAD: the work loads on the client and server are symmetric. Since the | 529 // AEAD: the work loads on the client and server are symmetric. Since the |
531 // client is more likely to be CPU-constrained, break the tie by favoring | 530 // client is more likely to be CPU-constrained, break the tie by favoring |
532 // the client's preference. | 531 // the client's preference. |
533 // Key exchange: the client does more work than the server, so favor the | 532 // Key exchange: the client does more work than the server, so favor the |
534 // client's preference. | 533 // client's preference. |
535 size_t key_exchange_index; | 534 size_t key_exchange_index; |
536 if (!QuicUtils::FindMutualTag(aead, their_aeads, num_their_aeads, | 535 if (!FindMutualQuicTag(aead, their_aeads, num_their_aeads, &out_params->aead, |
537 QuicUtils::LOCAL_PRIORITY, &out_params->aead, | 536 nullptr) || |
538 nullptr) || | 537 !FindMutualQuicTag(kexs, their_key_exchanges, num_their_key_exchanges, |
539 !QuicUtils::FindMutualTag( | 538 &out_params->key_exchange, &key_exchange_index)) { |
540 kexs, their_key_exchanges, num_their_key_exchanges, | |
541 QuicUtils::LOCAL_PRIORITY, &out_params->key_exchange, | |
542 &key_exchange_index)) { | |
543 *error_details = "Unsupported AEAD or KEXS"; | 539 *error_details = "Unsupported AEAD or KEXS"; |
544 return QUIC_CRYPTO_NO_SUPPORT; | 540 return QUIC_CRYPTO_NO_SUPPORT; |
545 } | 541 } |
546 out->SetVector(kAEAD, QuicTagVector{out_params->aead}); | 542 out->SetVector(kAEAD, QuicTagVector{out_params->aead}); |
547 out->SetVector(kKEXS, QuicTagVector{out_params->key_exchange}); | 543 out->SetVector(kKEXS, QuicTagVector{out_params->key_exchange}); |
548 | 544 |
549 if (!tb_key_params.empty() && | 545 if (!tb_key_params.empty() && |
550 server_id.privacy_mode() == PRIVACY_MODE_DISABLED) { | 546 server_id.privacy_mode() == PRIVACY_MODE_DISABLED) { |
551 const QuicTag* their_tbkps; | 547 const QuicTag* their_tbkps; |
552 size_t num_their_tbkps; | 548 size_t num_their_tbkps; |
553 switch (scfg->GetTaglist(kTBKP, &their_tbkps, &num_their_tbkps)) { | 549 switch (scfg->GetTaglist(kTBKP, &their_tbkps, &num_their_tbkps)) { |
554 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: | 550 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: |
555 break; | 551 break; |
556 case QUIC_NO_ERROR: | 552 case QUIC_NO_ERROR: |
557 if (QuicUtils::FindMutualTag(tb_key_params, their_tbkps, | 553 if (FindMutualQuicTag(tb_key_params, their_tbkps, num_their_tbkps, |
558 num_their_tbkps, QuicUtils::LOCAL_PRIORITY, | 554 &out_params->token_binding_key_param, nullptr)) { |
559 &out_params->token_binding_key_param, | |
560 nullptr)) { | |
561 out->SetVector(kTBKP, | 555 out->SetVector(kTBKP, |
562 QuicTagVector{out_params->token_binding_key_param}); | 556 QuicTagVector{out_params->token_binding_key_param}); |
563 } | 557 } |
564 break; | 558 break; |
565 default: | 559 default: |
566 *error_details = "Invalid TBKP"; | 560 *error_details = "Invalid TBKP"; |
567 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; | 561 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; |
568 } | 562 } |
569 } | 563 } |
570 | 564 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 out_params->hkdf_input_suffix.append(certs[0]); | 687 out_params->hkdf_input_suffix.append(certs[0]); |
694 | 688 |
695 string hkdf_input; | 689 string hkdf_input; |
696 const size_t label_len = strlen(QuicCryptoConfig::kInitialLabel) + 1; | 690 const size_t label_len = strlen(QuicCryptoConfig::kInitialLabel) + 1; |
697 hkdf_input.reserve(label_len + out_params->hkdf_input_suffix.size()); | 691 hkdf_input.reserve(label_len + out_params->hkdf_input_suffix.size()); |
698 hkdf_input.append(QuicCryptoConfig::kInitialLabel, label_len); | 692 hkdf_input.append(QuicCryptoConfig::kInitialLabel, label_len); |
699 hkdf_input.append(out_params->hkdf_input_suffix); | 693 hkdf_input.append(out_params->hkdf_input_suffix); |
700 | 694 |
701 string* subkey_secret = &out_params->initial_subkey_secret; | 695 string* subkey_secret = &out_params->initial_subkey_secret; |
702 | 696 |
703 // Only perform key diversification for QUIC versions 33 and later. | 697 if (!CryptoUtils::DeriveKeys( |
704 // TODO(rch): remove the |actual_version| argument to this method when | 698 out_params->initial_premaster_secret, out_params->aead, |
705 // QUIC_VERSION_32 is removed. | 699 out_params->client_nonce, out_params->server_nonce, hkdf_input, |
706 CryptoUtils::Diversification diversification = | 700 Perspective::IS_CLIENT, CryptoUtils::Diversification::Pending(), |
707 actual_version > QUIC_VERSION_32 ? CryptoUtils::Diversification::Pending() | 701 &out_params->initial_crypters, subkey_secret)) { |
708 : CryptoUtils::Diversification::Never(); | |
709 if (!CryptoUtils::DeriveKeys(out_params->initial_premaster_secret, | |
710 out_params->aead, out_params->client_nonce, | |
711 out_params->server_nonce, hkdf_input, | |
712 Perspective::IS_CLIENT, diversification, | |
713 &out_params->initial_crypters, subkey_secret)) { | |
714 *error_details = "Symmetric key setup failed"; | 702 *error_details = "Symmetric key setup failed"; |
715 return QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED; | 703 return QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED; |
716 } | 704 } |
717 | 705 |
718 return QUIC_NO_ERROR; | 706 return QUIC_NO_ERROR; |
719 } | 707 } |
720 | 708 |
721 QuicErrorCode QuicCryptoClientConfig::CacheNewServerConfig( | 709 QuicErrorCode QuicCryptoClientConfig::CacheNewServerConfig( |
722 const CryptoHandshakeMessage& message, | 710 const CryptoHandshakeMessage& message, |
723 QuicWallTime now, | 711 QuicWallTime now, |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 } | 973 } |
986 | 974 |
987 // Update canonical version to point at the "most recent" entry. | 975 // Update canonical version to point at the "most recent" entry. |
988 canonical_server_map_[suffix_server_id] = server_id; | 976 canonical_server_map_[suffix_server_id] = server_id; |
989 | 977 |
990 server_state->InitializeFrom(*canonical_state); | 978 server_state->InitializeFrom(*canonical_state); |
991 return true; | 979 return true; |
992 } | 980 } |
993 | 981 |
994 } // namespace net | 982 } // namespace net |
OLD | NEW |