| 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/crypto/quic_crypto_server_config.h" | 5 #include "net/quic/crypto/quic_crypto_server_config.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 198 |
| 199 void ValidateClientHelloResultCallback::Run(const Result* result) { | 199 void ValidateClientHelloResultCallback::Run(const Result* result) { |
| 200 RunImpl(result->client_hello, *result); | 200 RunImpl(result->client_hello, *result); |
| 201 delete result; | 201 delete result; |
| 202 delete this; | 202 delete this; |
| 203 } | 203 } |
| 204 | 204 |
| 205 QuicCryptoServerConfig::ConfigOptions::ConfigOptions() | 205 QuicCryptoServerConfig::ConfigOptions::ConfigOptions() |
| 206 : expiry_time(QuicWallTime::Zero()), | 206 : expiry_time(QuicWallTime::Zero()), |
| 207 channel_id_enabled(false), | 207 channel_id_enabled(false), |
| 208 token_binding_enabled(false), |
| 208 p256(false) {} | 209 p256(false) {} |
| 209 | 210 |
| 210 QuicCryptoServerConfig::QuicCryptoServerConfig( | 211 QuicCryptoServerConfig::QuicCryptoServerConfig( |
| 211 StringPiece source_address_token_secret, | 212 StringPiece source_address_token_secret, |
| 212 QuicRandom* server_nonce_entropy, | 213 QuicRandom* server_nonce_entropy, |
| 213 ProofSource* proof_source) | 214 ProofSource* proof_source) |
| 214 : replay_protection_(true), | 215 : replay_protection_(true), |
| 215 configs_lock_(), | 216 configs_lock_(), |
| 216 primary_config_(nullptr), | 217 primary_config_(nullptr), |
| 217 next_config_promotion_time_(QuicWallTime::Zero()), | 218 next_config_promotion_time_(QuicWallTime::Zero()), |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } else { | 316 } else { |
| 316 DCHECK(options.orbit.empty()); | 317 DCHECK(options.orbit.empty()); |
| 317 rand->RandBytes(orbit_bytes, sizeof(orbit_bytes)); | 318 rand->RandBytes(orbit_bytes, sizeof(orbit_bytes)); |
| 318 } | 319 } |
| 319 msg.SetStringPiece(kORBT, StringPiece(orbit_bytes, sizeof(orbit_bytes))); | 320 msg.SetStringPiece(kORBT, StringPiece(orbit_bytes, sizeof(orbit_bytes))); |
| 320 | 321 |
| 321 if (options.channel_id_enabled) { | 322 if (options.channel_id_enabled) { |
| 322 msg.SetTaglist(kPDMD, kCHID, 0); | 323 msg.SetTaglist(kPDMD, kCHID, 0); |
| 323 } | 324 } |
| 324 | 325 |
| 326 if (options.token_binding_enabled) { |
| 327 msg.SetTaglist(kTBKP, kP256, 0); |
| 328 } |
| 329 |
| 325 if (options.id.empty()) { | 330 if (options.id.empty()) { |
| 326 // We need to ensure that the SCID changes whenever the server config does | 331 // We need to ensure that the SCID changes whenever the server config does |
| 327 // thus we make it a hash of the rest of the server config. | 332 // thus we make it a hash of the rest of the server config. |
| 328 scoped_ptr<QuicData> serialized( | 333 scoped_ptr<QuicData> serialized( |
| 329 CryptoFramer::ConstructHandshakeMessage(msg)); | 334 CryptoFramer::ConstructHandshakeMessage(msg)); |
| 330 scoped_ptr<SecureHash> hash(SecureHash::Create(SecureHash::SHA256)); | 335 scoped_ptr<SecureHash> hash(SecureHash::Create(SecureHash::SHA256)); |
| 331 hash->Update(serialized->data(), serialized->length()); | 336 hash->Update(serialized->data(), serialized->length()); |
| 332 | 337 |
| 333 char scid_bytes[16]; | 338 char scid_bytes[16]; |
| 334 hash->Finish(scid_bytes, sizeof(scid_bytes)); | 339 hash->Finish(scid_bytes, sizeof(scid_bytes)); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 QuicCryptoNegotiatedParameters* params, | 545 QuicCryptoNegotiatedParameters* params, |
| 541 QuicCryptoProof* crypto_proof, | 546 QuicCryptoProof* crypto_proof, |
| 542 CryptoHandshakeMessage* out, | 547 CryptoHandshakeMessage* out, |
| 543 string* error_details) const { | 548 string* error_details) const { |
| 544 DCHECK(error_details); | 549 DCHECK(error_details); |
| 545 | 550 |
| 546 const CryptoHandshakeMessage& client_hello = | 551 const CryptoHandshakeMessage& client_hello = |
| 547 validate_chlo_result.client_hello; | 552 validate_chlo_result.client_hello; |
| 548 const ClientHelloInfo& info = validate_chlo_result.info; | 553 const ClientHelloInfo& info = validate_chlo_result.info; |
| 549 | 554 |
| 550 // If the client's preferred version is not the version we are currently | 555 QuicErrorCode valid = CryptoUtils::ValidateClientHello( |
| 551 // speaking, then the client went through a version negotiation. In this | 556 client_hello, version, supported_versions, error_details); |
| 552 // case, we need to make sure that we actually do not support this version | 557 if (valid != QUIC_NO_ERROR) |
| 553 // and that it wasn't a downgrade attack. | 558 return valid; |
| 554 QuicTag client_version_tag; | |
| 555 if (client_hello.GetUint32(kVER, &client_version_tag) != QUIC_NO_ERROR) { | |
| 556 *error_details = "client hello missing version list"; | |
| 557 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; | |
| 558 } | |
| 559 QuicVersion client_version = QuicTagToQuicVersion(client_version_tag); | |
| 560 if (client_version != version) { | |
| 561 // Just because client_version is a valid version enum doesn't mean that | |
| 562 // this server actually supports that version, so we check to see if | |
| 563 // it's actually in the supported versions list. | |
| 564 for (size_t i = 0; i < supported_versions.size(); ++i) { | |
| 565 if (client_version == supported_versions[i]) { | |
| 566 *error_details = "Downgrade attack detected"; | |
| 567 return QUIC_VERSION_NEGOTIATION_MISMATCH; | |
| 568 } | |
| 569 } | |
| 570 } | |
| 571 | 559 |
| 572 StringPiece requested_scid; | 560 StringPiece requested_scid; |
| 573 client_hello.GetStringPiece(kSCID, &requested_scid); | 561 client_hello.GetStringPiece(kSCID, &requested_scid); |
| 574 const QuicWallTime now(clock->WallNow()); | 562 const QuicWallTime now(clock->WallNow()); |
| 575 | 563 |
| 576 scoped_refptr<Config> requested_config; | 564 scoped_refptr<Config> requested_config; |
| 577 scoped_refptr<Config> primary_config; | 565 scoped_refptr<Config> primary_config; |
| 578 { | 566 { |
| 579 base::AutoLock locked(configs_lock_); | 567 base::AutoLock locked(configs_lock_); |
| 580 | 568 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 num_their_aeads, QuicUtils::LOCAL_PRIORITY, | 639 num_their_aeads, QuicUtils::LOCAL_PRIORITY, |
| 652 ¶ms->aead, nullptr) || | 640 ¶ms->aead, nullptr) || |
| 653 !QuicUtils::FindMutualTag( | 641 !QuicUtils::FindMutualTag( |
| 654 requested_config->kexs, their_key_exchanges, num_their_key_exchanges, | 642 requested_config->kexs, their_key_exchanges, num_their_key_exchanges, |
| 655 QuicUtils::LOCAL_PRIORITY, ¶ms->key_exchange, | 643 QuicUtils::LOCAL_PRIORITY, ¶ms->key_exchange, |
| 656 &key_exchange_index)) { | 644 &key_exchange_index)) { |
| 657 *error_details = "Unsupported AEAD or KEXS"; | 645 *error_details = "Unsupported AEAD or KEXS"; |
| 658 return QUIC_CRYPTO_NO_SUPPORT; | 646 return QUIC_CRYPTO_NO_SUPPORT; |
| 659 } | 647 } |
| 660 | 648 |
| 649 if (!requested_config->tb_key_params.empty()) { |
| 650 const QuicTag* their_tbkps; |
| 651 size_t num_their_tbkps; |
| 652 switch (client_hello.GetTaglist(kTBKP, &their_tbkps, &num_their_tbkps)) { |
| 653 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: |
| 654 break; |
| 655 case QUIC_NO_ERROR: |
| 656 if (QuicUtils::FindMutualTag( |
| 657 requested_config->tb_key_params, their_tbkps, num_their_tbkps, |
| 658 QuicUtils::LOCAL_PRIORITY, ¶ms->token_binding_key_param, |
| 659 nullptr)) { |
| 660 break; |
| 661 } |
| 662 default: |
| 663 *error_details = "Invalid Token Binding key parameter"; |
| 664 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; |
| 665 } |
| 666 } |
| 667 |
| 661 StringPiece public_value; | 668 StringPiece public_value; |
| 662 if (!client_hello.GetStringPiece(kPUBS, &public_value)) { | 669 if (!client_hello.GetStringPiece(kPUBS, &public_value)) { |
| 663 *error_details = "Missing public value"; | 670 *error_details = "Missing public value"; |
| 664 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; | 671 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; |
| 665 } | 672 } |
| 666 | 673 |
| 667 const KeyExchange* key_exchange = | 674 const KeyExchange* key_exchange = |
| 668 requested_config->key_exchanges[key_exchange_index]; | 675 requested_config->key_exchanges[key_exchange_index]; |
| 669 if (!key_exchange->CalculateSharedKey(public_value, | 676 if (!key_exchange->CalculateSharedKey(public_value, |
| 670 ¶ms->initial_premaster_secret)) { | 677 ¶ms->initial_premaster_secret)) { |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 } | 1318 } |
| 1312 config->aead = vector<QuicTag>(aead_tags, aead_tags + aead_len); | 1319 config->aead = vector<QuicTag>(aead_tags, aead_tags + aead_len); |
| 1313 | 1320 |
| 1314 const QuicTag* kexs_tags; | 1321 const QuicTag* kexs_tags; |
| 1315 size_t kexs_len; | 1322 size_t kexs_len; |
| 1316 if (msg->GetTaglist(kKEXS, &kexs_tags, &kexs_len) != QUIC_NO_ERROR) { | 1323 if (msg->GetTaglist(kKEXS, &kexs_tags, &kexs_len) != QUIC_NO_ERROR) { |
| 1317 LOG(WARNING) << "Server config message is missing KEXS"; | 1324 LOG(WARNING) << "Server config message is missing KEXS"; |
| 1318 return nullptr; | 1325 return nullptr; |
| 1319 } | 1326 } |
| 1320 | 1327 |
| 1328 const QuicTag* tbkp_tags; |
| 1329 size_t tbkp_len; |
| 1330 QuicErrorCode err; |
| 1331 if ((err = msg->GetTaglist(kTBKP, &tbkp_tags, &tbkp_len)) != |
| 1332 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND && |
| 1333 err != QUIC_NO_ERROR) { |
| 1334 LOG(WARNING) << "Server config message is missing or has invalid TBKP"; |
| 1335 return nullptr; |
| 1336 } |
| 1337 config->tb_key_params = vector<QuicTag>(tbkp_tags, tbkp_tags + tbkp_len); |
| 1338 |
| 1321 StringPiece orbit; | 1339 StringPiece orbit; |
| 1322 if (!msg->GetStringPiece(kORBT, &orbit)) { | 1340 if (!msg->GetStringPiece(kORBT, &orbit)) { |
| 1323 LOG(WARNING) << "Server config message is missing ORBT"; | 1341 LOG(WARNING) << "Server config message is missing ORBT"; |
| 1324 return nullptr; | 1342 return nullptr; |
| 1325 } | 1343 } |
| 1326 | 1344 |
| 1327 if (orbit.size() != kOrbitSize) { | 1345 if (orbit.size() != kOrbitSize) { |
| 1328 LOG(WARNING) << "Orbit value in server config is the wrong length." | 1346 LOG(WARNING) << "Orbit value in server config is the wrong length." |
| 1329 " Got " << orbit.size() << " want " << kOrbitSize; | 1347 " Got " << orbit.size() << " want " << kOrbitSize; |
| 1330 return nullptr; | 1348 return nullptr; |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1741 QuicCryptoServerConfig::Config::Config() | 1759 QuicCryptoServerConfig::Config::Config() |
| 1742 : channel_id_enabled(false), | 1760 : channel_id_enabled(false), |
| 1743 is_primary(false), | 1761 is_primary(false), |
| 1744 primary_time(QuicWallTime::Zero()), | 1762 primary_time(QuicWallTime::Zero()), |
| 1745 priority(0), | 1763 priority(0), |
| 1746 source_address_token_boxer(nullptr) {} | 1764 source_address_token_boxer(nullptr) {} |
| 1747 | 1765 |
| 1748 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } | 1766 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } |
| 1749 | 1767 |
| 1750 } // namespace net | 1768 } // namespace net |
| OLD | NEW |