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_client_config.h" | 5 #include "net/quic/crypto/quic_crypto_client_config.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/metrics/sparse_histogram.h" | 8 #include "base/metrics/sparse_histogram.h" |
9 #include "base/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "net/quic/crypto/cert_compressor.h" | 12 #include "net/quic/crypto/cert_compressor.h" |
13 #include "net/quic/crypto/chacha20_poly1305_encrypter.h" | 13 #include "net/quic/crypto/chacha20_poly1305_encrypter.h" |
14 #include "net/quic/crypto/channel_id.h" | 14 #include "net/quic/crypto/channel_id.h" |
15 #include "net/quic/crypto/common_cert_set.h" | 15 #include "net/quic/crypto/common_cert_set.h" |
16 #include "net/quic/crypto/crypto_framer.h" | 16 #include "net/quic/crypto/crypto_framer.h" |
17 #include "net/quic/crypto/crypto_utils.h" | 17 #include "net/quic/crypto/crypto_utils.h" |
18 #include "net/quic/crypto/curve25519_key_exchange.h" | 18 #include "net/quic/crypto/curve25519_key_exchange.h" |
19 #include "net/quic/crypto/key_exchange.h" | 19 #include "net/quic/crypto/key_exchange.h" |
20 #include "net/quic/crypto/p256_key_exchange.h" | 20 #include "net/quic/crypto/p256_key_exchange.h" |
21 #include "net/quic/crypto/proof_verifier.h" | 21 #include "net/quic/crypto/proof_verifier.h" |
22 #include "net/quic/crypto/quic_encrypter.h" | 22 #include "net/quic/crypto/quic_encrypter.h" |
23 #include "net/quic/quic_utils.h" | 23 #include "net/quic/quic_utils.h" |
24 | 24 |
25 using base::StringPiece; | 25 using base::StringPiece; |
26 using std::find; | |
27 using std::make_pair; | |
28 using std::map; | 26 using std::map; |
29 using std::string; | 27 using std::string; |
30 using std::vector; | 28 using std::vector; |
31 | 29 |
32 namespace net { | 30 namespace net { |
33 | 31 |
34 namespace { | 32 namespace { |
35 | 33 |
36 // Tracks the reason (the state of the server config) for sending inchoate | 34 // Tracks the reason (the state of the server config) for sending inchoate |
37 // ClientHello to the server. | 35 // ClientHello to the server. |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 315 } |
318 | 316 |
319 QuicCryptoClientConfig::CachedState* QuicCryptoClientConfig::LookupOrCreate( | 317 QuicCryptoClientConfig::CachedState* QuicCryptoClientConfig::LookupOrCreate( |
320 const QuicServerId& server_id) { | 318 const QuicServerId& server_id) { |
321 CachedStateMap::const_iterator it = cached_states_.find(server_id); | 319 CachedStateMap::const_iterator it = cached_states_.find(server_id); |
322 if (it != cached_states_.end()) { | 320 if (it != cached_states_.end()) { |
323 return it->second; | 321 return it->second; |
324 } | 322 } |
325 | 323 |
326 CachedState* cached = new CachedState; | 324 CachedState* cached = new CachedState; |
327 cached_states_.insert(make_pair(server_id, cached)); | 325 cached_states_.insert(std::make_pair(server_id, cached)); |
328 bool cache_populated = PopulateFromCanonicalConfig(server_id, cached); | 326 bool cache_populated = PopulateFromCanonicalConfig(server_id, cached); |
329 UMA_HISTOGRAM_BOOLEAN( | 327 UMA_HISTOGRAM_BOOLEAN( |
330 "Net.QuicCryptoClientConfig.PopulatedFromCanonicalConfig", | 328 "Net.QuicCryptoClientConfig.PopulatedFromCanonicalConfig", |
331 cache_populated); | 329 cache_populated); |
332 return cached; | 330 return cached; |
333 } | 331 } |
334 | 332 |
335 void QuicCryptoClientConfig::ClearCachedStates() { | 333 void QuicCryptoClientConfig::ClearCachedStates() { |
336 for (CachedStateMap::const_iterator it = cached_states_.begin(); | 334 for (CachedStateMap::const_iterator it = cached_states_.begin(); |
337 it != cached_states_.end(); ++it) { | 335 it != cached_states_.end(); ++it) { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 if (!CryptoUtils::DeriveKeys(out_params->initial_premaster_secret, | 536 if (!CryptoUtils::DeriveKeys(out_params->initial_premaster_secret, |
539 out_params->aead, out_params->client_nonce, | 537 out_params->aead, out_params->client_nonce, |
540 out_params->server_nonce, hkdf_input, | 538 out_params->server_nonce, hkdf_input, |
541 CryptoUtils::CLIENT, &crypters, | 539 CryptoUtils::CLIENT, &crypters, |
542 nullptr /* subkey secret */)) { | 540 nullptr /* subkey secret */)) { |
543 *error_details = "Symmetric key setup failed"; | 541 *error_details = "Symmetric key setup failed"; |
544 return QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED; | 542 return QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED; |
545 } | 543 } |
546 | 544 |
547 const QuicData& cetv_plaintext = cetv.GetSerialized(); | 545 const QuicData& cetv_plaintext = cetv.GetSerialized(); |
548 scoped_ptr<QuicData> cetv_ciphertext(crypters.encrypter->EncryptPacket( | 546 const size_t encrypted_len = |
549 0 /* sequence number */, | 547 crypters.encrypter->GetCiphertextSize(cetv_plaintext.length()); |
550 StringPiece() /* associated data */, | 548 scoped_ptr<char[]> output(new char[encrypted_len]); |
551 cetv_plaintext.AsStringPiece())); | 549 size_t output_size = 0; |
552 if (!cetv_ciphertext.get()) { | 550 if (!crypters.encrypter->EncryptPacket( |
| 551 0 /* sequence number */, StringPiece() /* associated data */, |
| 552 cetv_plaintext.AsStringPiece(), output.get(), &output_size, |
| 553 encrypted_len)) { |
553 *error_details = "Packet encryption failed"; | 554 *error_details = "Packet encryption failed"; |
554 return QUIC_ENCRYPTION_FAILURE; | 555 return QUIC_ENCRYPTION_FAILURE; |
555 } | 556 } |
556 | 557 |
557 out->SetStringPiece(kCETV, cetv_ciphertext->AsStringPiece()); | 558 out->SetStringPiece(kCETV, StringPiece(output.get(), output_size)); |
558 out->MarkDirty(); | 559 out->MarkDirty(); |
559 | 560 |
560 out->set_minimum_size(orig_min_size); | 561 out->set_minimum_size(orig_min_size); |
561 } | 562 } |
562 | 563 |
563 // Derive the symmetric keys and set up the encrypters and decrypters. | 564 // Derive the symmetric keys and set up the encrypters and decrypters. |
564 // Set the following members of out_params: | 565 // Set the following members of out_params: |
565 // out_params->hkdf_input_suffix | 566 // out_params->hkdf_input_suffix |
566 // out_params->initial_crypters | 567 // out_params->initial_crypters |
567 out_params->hkdf_input_suffix.clear(); | 568 out_params->hkdf_input_suffix.clear(); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 | 831 |
831 void QuicCryptoClientConfig::AddCanonicalSuffix(const string& suffix) { | 832 void QuicCryptoClientConfig::AddCanonicalSuffix(const string& suffix) { |
832 canonical_suffixes_.push_back(suffix); | 833 canonical_suffixes_.push_back(suffix); |
833 } | 834 } |
834 | 835 |
835 void QuicCryptoClientConfig::PreferAesGcm() { | 836 void QuicCryptoClientConfig::PreferAesGcm() { |
836 DCHECK(!aead.empty()); | 837 DCHECK(!aead.empty()); |
837 if (aead.size() <= 1) { | 838 if (aead.size() <= 1) { |
838 return; | 839 return; |
839 } | 840 } |
840 QuicTagVector::iterator pos = find(aead.begin(), aead.end(), kAESG); | 841 QuicTagVector::iterator pos = std::find(aead.begin(), aead.end(), kAESG); |
841 if (pos != aead.end()) { | 842 if (pos != aead.end()) { |
842 aead.erase(pos); | 843 aead.erase(pos); |
843 aead.insert(aead.begin(), kAESG); | 844 aead.insert(aead.begin(), kAESG); |
844 } | 845 } |
845 } | 846 } |
846 | 847 |
847 void QuicCryptoClientConfig::DisableEcdsa() { | 848 void QuicCryptoClientConfig::DisableEcdsa() { |
848 disable_ecdsa_ = true; | 849 disable_ecdsa_ = true; |
849 } | 850 } |
850 | 851 |
(...skipping 29 matching lines...) Expand all Loading... |
880 } | 881 } |
881 | 882 |
882 // Update canonical version to point at the "most recent" entry. | 883 // Update canonical version to point at the "most recent" entry. |
883 canonical_server_map_[suffix_server_id] = server_id; | 884 canonical_server_map_[suffix_server_id] = server_id; |
884 | 885 |
885 server_state->InitializeFrom(*canonical_state); | 886 server_state->InitializeFrom(*canonical_state); |
886 return true; | 887 return true; |
887 } | 888 } |
888 | 889 |
889 } // namespace net | 890 } // namespace net |
OLD | NEW |