| 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 "net/quic/crypto/crypto_server_config.h" | 5 #include "net/quic/crypto/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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 const QuicData& client_hello_serialized = client_hello_copy.GetSerialized(); | 442 const QuicData& client_hello_serialized = client_hello_copy.GetSerialized(); |
| 443 string hkdf_input; | 443 string hkdf_input; |
| 444 hkdf_input.append(QuicCryptoConfig::kCETVLabel, | 444 hkdf_input.append(QuicCryptoConfig::kCETVLabel, |
| 445 strlen(QuicCryptoConfig::kCETVLabel) + 1); | 445 strlen(QuicCryptoConfig::kCETVLabel) + 1); |
| 446 hkdf_input.append(reinterpret_cast<char*>(&guid), sizeof(guid)); | 446 hkdf_input.append(reinterpret_cast<char*>(&guid), sizeof(guid)); |
| 447 hkdf_input.append(client_hello_serialized.data(), | 447 hkdf_input.append(client_hello_serialized.data(), |
| 448 client_hello_serialized.length()); | 448 client_hello_serialized.length()); |
| 449 hkdf_input.append(requested_config->serialized); | 449 hkdf_input.append(requested_config->serialized); |
| 450 | 450 |
| 451 CrypterPair crypters; | 451 CrypterPair crypters; |
| 452 CryptoUtils::DeriveKeys(params->initial_premaster_secret, params->aead, | 452 if (!CryptoUtils::DeriveKeys(params->initial_premaster_secret, params->aead, |
| 453 info.client_nonce, info.server_nonce, hkdf_input, | 453 info.client_nonce, info.server_nonce, |
| 454 CryptoUtils::SERVER, &crypters); | 454 hkdf_input, CryptoUtils::SERVER, &crypters)) { |
| 455 *error_details = "Symmetric key setup failed"; |
| 456 return QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED; |
| 457 } |
| 455 | 458 |
| 456 scoped_ptr<QuicData> cetv_plaintext(crypters.decrypter->DecryptPacket( | 459 scoped_ptr<QuicData> cetv_plaintext(crypters.decrypter->DecryptPacket( |
| 457 0 /* sequence number */, StringPiece() /* associated data */, | 460 0 /* sequence number */, StringPiece() /* associated data */, |
| 458 cetv_ciphertext)); | 461 cetv_ciphertext)); |
| 459 if (!cetv_plaintext.get()) { | 462 if (!cetv_plaintext.get()) { |
| 460 *error_details = "CETV decryption failure"; | 463 *error_details = "CETV decryption failure"; |
| 461 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; | 464 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; |
| 462 } | 465 } |
| 463 | 466 |
| 464 scoped_ptr<CryptoHandshakeMessage> cetv(CryptoFramer::ParseMessage( | 467 scoped_ptr<CryptoHandshakeMessage> cetv(CryptoFramer::ParseMessage( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 479 params->channel_id = key.as_string(); | 482 params->channel_id = key.as_string(); |
| 480 } | 483 } |
| 481 } | 484 } |
| 482 | 485 |
| 483 string hkdf_input; | 486 string hkdf_input; |
| 484 size_t label_len = strlen(QuicCryptoConfig::kInitialLabel) + 1; | 487 size_t label_len = strlen(QuicCryptoConfig::kInitialLabel) + 1; |
| 485 hkdf_input.reserve(label_len + hkdf_suffix.size()); | 488 hkdf_input.reserve(label_len + hkdf_suffix.size()); |
| 486 hkdf_input.append(QuicCryptoConfig::kInitialLabel, label_len); | 489 hkdf_input.append(QuicCryptoConfig::kInitialLabel, label_len); |
| 487 hkdf_input.append(hkdf_suffix); | 490 hkdf_input.append(hkdf_suffix); |
| 488 | 491 |
| 489 CryptoUtils::DeriveKeys(params->initial_premaster_secret, params->aead, | 492 if (!CryptoUtils::DeriveKeys(params->initial_premaster_secret, params->aead, |
| 490 info.client_nonce, info.server_nonce, hkdf_input, | 493 info.client_nonce, info.server_nonce, hkdf_input, |
| 491 CryptoUtils::SERVER, ¶ms->initial_crypters); | 494 CryptoUtils::SERVER, |
| 495 ¶ms->initial_crypters)) { |
| 496 *error_details = "Symmetric key setup failed"; |
| 497 return QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED; |
| 498 } |
| 492 | 499 |
| 493 string forward_secure_public_value; | 500 string forward_secure_public_value; |
| 494 if (ephemeral_key_source_.get()) { | 501 if (ephemeral_key_source_.get()) { |
| 495 params->forward_secure_premaster_secret = | 502 params->forward_secure_premaster_secret = |
| 496 ephemeral_key_source_->CalculateForwardSecureKey( | 503 ephemeral_key_source_->CalculateForwardSecureKey( |
| 497 key_exchange, rand, clock->ApproximateNow(), public_value, | 504 key_exchange, rand, clock->ApproximateNow(), public_value, |
| 498 &forward_secure_public_value); | 505 &forward_secure_public_value); |
| 499 } else { | 506 } else { |
| 500 scoped_ptr<KeyExchange> forward_secure_key_exchange( | 507 scoped_ptr<KeyExchange> forward_secure_key_exchange( |
| 501 key_exchange->NewKeyPair(rand)); | 508 key_exchange->NewKeyPair(rand)); |
| 502 forward_secure_public_value = | 509 forward_secure_public_value = |
| 503 forward_secure_key_exchange->public_value().as_string(); | 510 forward_secure_key_exchange->public_value().as_string(); |
| 504 if (!forward_secure_key_exchange->CalculateSharedKey( | 511 if (!forward_secure_key_exchange->CalculateSharedKey( |
| 505 public_value, ¶ms->forward_secure_premaster_secret)) { | 512 public_value, ¶ms->forward_secure_premaster_secret)) { |
| 506 *error_details = "Invalid public value"; | 513 *error_details = "Invalid public value"; |
| 507 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; | 514 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; |
| 508 } | 515 } |
| 509 } | 516 } |
| 510 | 517 |
| 511 string forward_secure_hkdf_input; | 518 string forward_secure_hkdf_input; |
| 512 label_len = strlen(QuicCryptoConfig::kForwardSecureLabel) + 1; | 519 label_len = strlen(QuicCryptoConfig::kForwardSecureLabel) + 1; |
| 513 forward_secure_hkdf_input.reserve(label_len + hkdf_suffix.size()); | 520 forward_secure_hkdf_input.reserve(label_len + hkdf_suffix.size()); |
| 514 forward_secure_hkdf_input.append(QuicCryptoConfig::kForwardSecureLabel, | 521 forward_secure_hkdf_input.append(QuicCryptoConfig::kForwardSecureLabel, |
| 515 label_len); | 522 label_len); |
| 516 forward_secure_hkdf_input.append(hkdf_suffix); | 523 forward_secure_hkdf_input.append(hkdf_suffix); |
| 517 | 524 |
| 518 CryptoUtils::DeriveKeys(params->forward_secure_premaster_secret, params->aead, | 525 if (!CryptoUtils::DeriveKeys( |
| 519 info.client_nonce, info.server_nonce, | 526 params->forward_secure_premaster_secret, params->aead, |
| 520 forward_secure_hkdf_input, CryptoUtils::SERVER, | 527 info.client_nonce, info.server_nonce, forward_secure_hkdf_input, |
| 521 ¶ms->forward_secure_crypters); | 528 CryptoUtils::SERVER, ¶ms->forward_secure_crypters)) { |
| 529 *error_details = "Symmetric key setup failed"; |
| 530 return QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED; |
| 531 } |
| 522 | 532 |
| 523 out->set_tag(kSHLO); | 533 out->set_tag(kSHLO); |
| 524 out->SetStringPiece(kSourceAddressTokenTag, | 534 out->SetStringPiece(kSourceAddressTokenTag, |
| 525 NewSourceAddressToken(client_ip, rand, info.now)); | 535 NewSourceAddressToken(client_ip, rand, info.now)); |
| 526 out->SetStringPiece(kPUBS, forward_secure_public_value); | 536 out->SetStringPiece(kPUBS, forward_secure_public_value); |
| 527 return QUIC_NO_ERROR; | 537 return QUIC_NO_ERROR; |
| 528 } | 538 } |
| 529 | 539 |
| 530 // ConfigPrimaryTimeLessThan is a comparator that implements "less than" for | 540 // ConfigPrimaryTimeLessThan is a comparator that implements "less than" for |
| 531 // Config's based on their primary_time. | 541 // Config's based on their primary_time. |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 } | 1090 } |
| 1081 | 1091 |
| 1082 QuicCryptoServerConfig::Config::Config() | 1092 QuicCryptoServerConfig::Config::Config() |
| 1083 : channel_id_enabled(false), | 1093 : channel_id_enabled(false), |
| 1084 is_primary(false), | 1094 is_primary(false), |
| 1085 primary_time(QuicWallTime::Zero()) {} | 1095 primary_time(QuicWallTime::Zero()) {} |
| 1086 | 1096 |
| 1087 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } | 1097 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } |
| 1088 | 1098 |
| 1089 } // namespace net | 1099 } // namespace net |
| OLD | NEW |