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/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "net/quic/crypto/cert_compressor.h" | 8 #include "net/quic/crypto/cert_compressor.h" |
9 #include "net/quic/crypto/channel_id.h" | 9 #include "net/quic/crypto/channel_id.h" |
10 #include "net/quic/crypto/common_cert_set.h" | 10 #include "net/quic/crypto/common_cert_set.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "base/win/windows_version.h" | 22 #include "base/win/windows_version.h" |
23 #endif | 23 #endif |
24 | 24 |
25 using base::StringPiece; | 25 using base::StringPiece; |
26 using std::map; | 26 using std::map; |
27 using std::string; | 27 using std::string; |
28 using std::vector; | 28 using std::vector; |
29 | 29 |
30 namespace net { | 30 namespace net { |
31 | 31 |
32 QuicCryptoClientConfig::QuicCryptoClientConfig() | 32 QuicCryptoClientConfig::QuicCryptoClientConfig() { |
33 : quic_server_info_factory_(NULL) { | |
34 } | |
35 | |
36 QuicCryptoClientConfig::QuicCryptoClientConfig( | |
37 QuicServerInfoFactory* quic_server_info_factory) | |
38 : quic_server_info_factory_(quic_server_info_factory) { | |
39 } | 33 } |
40 | 34 |
41 QuicCryptoClientConfig::~QuicCryptoClientConfig() { | 35 QuicCryptoClientConfig::~QuicCryptoClientConfig() { |
42 STLDeleteValues(&cached_states_); | 36 STLDeleteValues(&cached_states_); |
43 } | 37 } |
44 | 38 |
45 QuicCryptoClientConfig::CachedState::CachedState() | 39 QuicCryptoClientConfig::CachedState::CachedState() |
46 : server_config_valid_(false), | 40 : server_config_valid_(false), |
47 generation_counter_(0) {} | 41 generation_counter_(0) {} |
48 | 42 |
43 QuicCryptoClientConfig::CachedState::CachedState( | |
44 scoped_ptr<QuicServerInfo> quic_server_info) | |
45 : server_config_valid_(false), | |
46 generation_counter_(0), | |
47 quic_server_info_(quic_server_info.Pass()) {} | |
48 | |
49 QuicCryptoClientConfig::CachedState::~CachedState() {} | 49 QuicCryptoClientConfig::CachedState::~CachedState() {} |
50 | 50 |
51 void QuicCryptoClientConfig::CachedState::LoadFromDiskCache( | |
52 QuicServerInfoFactory* quic_server_info_factory, | |
53 const string& server_hostname) { | |
54 DCHECK(quic_server_info_factory); | |
55 quic_server_info_.reset( | |
56 quic_server_info_factory->GetForHost(server_hostname)); | |
57 | |
58 // TODO(rtenneti): Need to flesh out reading data from disk cache. | |
59 } | |
60 | |
61 bool QuicCryptoClientConfig::CachedState::IsComplete(QuicWallTime now) const { | 51 bool QuicCryptoClientConfig::CachedState::IsComplete(QuicWallTime now) const { |
62 if (server_config_.empty() || !server_config_valid_) { | 52 if (server_config_.empty() || !server_config_valid_) { |
63 return false; | 53 return false; |
64 } | 54 } |
65 | 55 |
66 const CryptoHandshakeMessage* scfg = GetServerConfig(); | 56 const CryptoHandshakeMessage* scfg = GetServerConfig(); |
67 if (!scfg) { | 57 if (!scfg) { |
68 // Should be impossible short of cache corruption. | 58 // Should be impossible short of cache corruption. |
69 DCHECK(false); | 59 DCHECK(false); |
70 return false; | 60 return false; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 // Key exchange methods. | 222 // Key exchange methods. |
233 kexs.resize(2); | 223 kexs.resize(2); |
234 kexs[0] = kC255; | 224 kexs[0] = kC255; |
235 kexs[1] = kP256; | 225 kexs[1] = kP256; |
236 | 226 |
237 // Authenticated encryption algorithms. | 227 // Authenticated encryption algorithms. |
238 aead.resize(1); | 228 aead.resize(1); |
239 aead[0] = kAESG; | 229 aead[0] = kAESG; |
240 } | 230 } |
241 | 231 |
232 QuicCryptoClientConfig::CachedState* QuicCryptoClientConfig::CreateCachedState( | |
233 const string& server_hostname, | |
234 QuicServerInfoFactory* quic_server_info_factory) { | |
235 DCHECK(quic_server_info_factory); | |
236 | |
237 map<string, CachedState*>::const_iterator it = | |
238 cached_states_.find(server_hostname); | |
239 DCHECK(it == cached_states_.end()); | |
wtc
2014/02/04 01:37:02
Nit: this should be
DCHECK_EQ(cached_states_.fi
ramant (doing other things)
2014/02/04 19:23:53
Done.
| |
240 | |
241 scoped_ptr<QuicServerInfo> quic_server_info( | |
242 quic_server_info_factory->GetForHost(server_hostname)); | |
243 quic_server_info->Start(); | |
244 | |
245 CachedState* cached = new CachedState(quic_server_info.Pass()); | |
246 cached_states_.insert(make_pair(server_hostname, cached)); | |
247 return cached; | |
248 } | |
249 | |
242 QuicCryptoClientConfig::CachedState* QuicCryptoClientConfig::LookupOrCreate( | 250 QuicCryptoClientConfig::CachedState* QuicCryptoClientConfig::LookupOrCreate( |
243 const string& server_hostname) { | 251 const string& server_hostname) { |
244 map<string, CachedState*>::const_iterator it = | 252 map<string, CachedState*>::const_iterator it = |
245 cached_states_.find(server_hostname); | 253 cached_states_.find(server_hostname); |
246 if (it != cached_states_.end()) { | 254 if (it != cached_states_.end()) { |
247 return it->second; | 255 return it->second; |
248 } | 256 } |
249 | 257 |
250 CachedState* cached = new CachedState; | 258 CachedState* cached = new CachedState; |
251 if (quic_server_info_factory_) { | |
252 cached->LoadFromDiskCache(quic_server_info_factory_, server_hostname); | |
253 } | |
254 cached_states_.insert(make_pair(server_hostname, cached)); | 259 cached_states_.insert(make_pair(server_hostname, cached)); |
wtc
2014/02/04 01:37:02
It seems that you should use the new CreateCachedS
ramant (doing other things)
2014/02/04 19:23:53
In chrome, we call LookupOrCreate() after we call
| |
255 return cached; | 260 return cached; |
256 } | 261 } |
257 | 262 |
258 void QuicCryptoClientConfig::FillInchoateClientHello( | 263 void QuicCryptoClientConfig::FillInchoateClientHello( |
259 const string& server_hostname, | 264 const string& server_hostname, |
260 const QuicVersion preferred_version, | 265 const QuicVersion preferred_version, |
261 const CachedState* cached, | 266 const CachedState* cached, |
262 QuicCryptoNegotiatedParameters* out_params, | 267 QuicCryptoNegotiatedParameters* out_params, |
263 CryptoHandshakeMessage* out) const { | 268 CryptoHandshakeMessage* out) const { |
264 out->set_tag(kCHLO); | 269 out->set_tag(kCHLO); |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
667 CachedState* canonical_cached = | 672 CachedState* canonical_cached = |
668 canonical_crypto_config->LookupOrCreate(canonical_server_hostname); | 673 canonical_crypto_config->LookupOrCreate(canonical_server_hostname); |
669 if (!canonical_cached->proof_valid()) { | 674 if (!canonical_cached->proof_valid()) { |
670 return; | 675 return; |
671 } | 676 } |
672 CachedState* cached = LookupOrCreate(server_hostname); | 677 CachedState* cached = LookupOrCreate(server_hostname); |
673 cached->InitializeFrom(*canonical_cached); | 678 cached->InitializeFrom(*canonical_cached); |
674 } | 679 } |
675 | 680 |
676 } // namespace net | 681 } // namespace net |
OLD | NEW |