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 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 QuicCryptoClientConfig::QuicCryptoClientConfig() { | 32 QuicCryptoClientConfig::QuicCryptoClientConfig() { |
33 } | 33 } |
34 | 34 |
35 QuicCryptoClientConfig::~QuicCryptoClientConfig() { | 35 QuicCryptoClientConfig::~QuicCryptoClientConfig() { |
36 STLDeleteValues(&cached_states_); | 36 STLDeleteValues(&cached_states_); |
37 } | 37 } |
38 | 38 |
39 QuicCryptoClientConfig::CachedState::CachedState() | 39 QuicCryptoClientConfig::CachedState::CachedState() |
40 : server_config_valid_(false), | 40 : server_config_valid_(false), |
41 need_to_persist_(false), | |
41 generation_counter_(0) {} | 42 generation_counter_(0) {} |
42 | 43 |
43 QuicCryptoClientConfig::CachedState::CachedState( | 44 QuicCryptoClientConfig::CachedState::CachedState( |
44 scoped_ptr<QuicServerInfo> quic_server_info) | 45 scoped_ptr<QuicServerInfo> quic_server_info) |
45 : server_config_valid_(false), | 46 : server_config_valid_(false), |
47 need_to_persist_(false), | |
46 generation_counter_(0), | 48 generation_counter_(0), |
47 quic_server_info_(quic_server_info.Pass()) {} | 49 quic_server_info_(quic_server_info.Pass()) { |
50 if (quic_server_info_.get()) { | |
51 QuicServerInfo::State* state = quic_server_info_->mutable_state(); | |
52 state->SetConfigData(&server_config_, | |
wtc
2014/02/19 02:24:11
It is a little dangerous for quic_server_info_ to
ramant (doing other things)
2014/02/19 02:57:53
This change shouldn't have been uploaded. I was ha
| |
53 &source_address_token_, | |
54 &certs_, | |
55 &server_config_sig_); | |
56 } | |
57 } | |
48 | 58 |
49 QuicCryptoClientConfig::CachedState::~CachedState() {} | 59 QuicCryptoClientConfig::CachedState::~CachedState() {} |
50 | 60 |
51 bool QuicCryptoClientConfig::CachedState::IsComplete(QuicWallTime now) const { | 61 bool QuicCryptoClientConfig::CachedState::IsComplete(QuicWallTime now) const { |
52 if (server_config_.empty() || !server_config_valid_) { | 62 if (server_config_.empty() || !server_config_valid_) { |
53 return false; | 63 return false; |
54 } | 64 } |
55 | 65 |
56 const CryptoHandshakeMessage* scfg = GetServerConfig(); | 66 const CryptoHandshakeMessage* scfg = GetServerConfig(); |
57 if (!scfg) { | 67 if (!scfg) { |
58 // Should be impossible short of cache corruption. | 68 // Should be impossible short of cache corruption. |
59 DCHECK(false); | 69 DCHECK(false); |
60 return false; | 70 return false; |
61 } | 71 } |
62 | 72 |
63 uint64 expiry_seconds; | 73 uint64 expiry_seconds; |
64 if (scfg->GetUint64(kEXPY, &expiry_seconds) != QUIC_NO_ERROR || | 74 if (scfg->GetUint64(kEXPY, &expiry_seconds) != QUIC_NO_ERROR || |
65 now.ToUNIXSeconds() >= expiry_seconds) { | 75 now.ToUNIXSeconds() >= expiry_seconds) { |
66 return false; | 76 return false; |
67 } | 77 } |
68 | 78 |
69 return true; | 79 return true; |
70 } | 80 } |
71 | 81 |
82 bool QuicCryptoClientConfig::CachedState::IsEmpty() const { | |
83 return server_config_.empty(); | |
84 } | |
85 | |
72 const CryptoHandshakeMessage* | 86 const CryptoHandshakeMessage* |
73 QuicCryptoClientConfig::CachedState::GetServerConfig() const { | 87 QuicCryptoClientConfig::CachedState::GetServerConfig() const { |
74 if (server_config_.empty()) { | 88 if (server_config_.empty()) { |
75 return NULL; | 89 return NULL; |
76 } | 90 } |
77 | 91 |
78 if (!scfg_.get()) { | 92 if (!scfg_.get()) { |
79 scfg_.reset(CryptoFramer::ParseMessage(server_config_)); | 93 scfg_.reset(CryptoFramer::ParseMessage(server_config_)); |
80 DCHECK(scfg_.get()); | 94 DCHECK(scfg_.get()); |
81 } | 95 } |
(...skipping 29 matching lines...) Expand all Loading... | |
111 | 125 |
112 if (now.ToUNIXSeconds() >= expiry_seconds) { | 126 if (now.ToUNIXSeconds() >= expiry_seconds) { |
113 *error_details = "SCFG has expired"; | 127 *error_details = "SCFG has expired"; |
114 return QUIC_CRYPTO_SERVER_CONFIG_EXPIRED; | 128 return QUIC_CRYPTO_SERVER_CONFIG_EXPIRED; |
115 } | 129 } |
116 | 130 |
117 if (!matches_existing) { | 131 if (!matches_existing) { |
118 server_config_ = server_config.as_string(); | 132 server_config_ = server_config.as_string(); |
119 SetProofInvalid(); | 133 SetProofInvalid(); |
120 scfg_.reset(new_scfg_storage.release()); | 134 scfg_.reset(new_scfg_storage.release()); |
135 need_to_persist_ = true; | |
121 } | 136 } |
122 return QUIC_NO_ERROR; | 137 return QUIC_NO_ERROR; |
123 } | 138 } |
124 | 139 |
125 void QuicCryptoClientConfig::CachedState::InvalidateServerConfig() { | 140 void QuicCryptoClientConfig::CachedState::InvalidateServerConfig() { |
126 server_config_.clear(); | 141 server_config_.clear(); |
127 scfg_.reset(); | 142 scfg_.reset(); |
128 SetProofInvalid(); | 143 SetProofInvalid(); |
129 } | 144 } |
130 | 145 |
(...skipping 22 matching lines...) Expand all Loading... | |
153 } | 168 } |
154 | 169 |
155 void QuicCryptoClientConfig::CachedState::ClearProof() { | 170 void QuicCryptoClientConfig::CachedState::ClearProof() { |
156 SetProofInvalid(); | 171 SetProofInvalid(); |
157 certs_.clear(); | 172 certs_.clear(); |
158 server_config_sig_.clear(); | 173 server_config_sig_.clear(); |
159 } | 174 } |
160 | 175 |
161 void QuicCryptoClientConfig::CachedState::SetProofValid() { | 176 void QuicCryptoClientConfig::CachedState::SetProofValid() { |
162 server_config_valid_ = true; | 177 server_config_valid_ = true; |
178 SaveQuicServerInfo(); | |
163 } | 179 } |
164 | 180 |
165 void QuicCryptoClientConfig::CachedState::SetProofInvalid() { | 181 void QuicCryptoClientConfig::CachedState::SetProofInvalid() { |
166 server_config_valid_ = false; | 182 server_config_valid_ = false; |
167 ++generation_counter_; | 183 ++generation_counter_; |
168 } | 184 } |
169 | 185 |
170 const string& QuicCryptoClientConfig::CachedState::server_config() const { | 186 const string& QuicCryptoClientConfig::CachedState::server_config() const { |
171 return server_config_; | 187 return server_config_; |
172 } | 188 } |
(...skipping 17 matching lines...) Expand all Loading... | |
190 | 206 |
191 uint64 QuicCryptoClientConfig::CachedState::generation_counter() const { | 207 uint64 QuicCryptoClientConfig::CachedState::generation_counter() const { |
192 return generation_counter_; | 208 return generation_counter_; |
193 } | 209 } |
194 | 210 |
195 const ProofVerifyDetails* | 211 const ProofVerifyDetails* |
196 QuicCryptoClientConfig::CachedState::proof_verify_details() const { | 212 QuicCryptoClientConfig::CachedState::proof_verify_details() const { |
197 return proof_verify_details_.get(); | 213 return proof_verify_details_.get(); |
198 } | 214 } |
199 | 215 |
216 QuicServerInfo* QuicCryptoClientConfig::CachedState::quic_server_info() const { | |
217 return quic_server_info_.get(); | |
218 } | |
219 | |
200 void QuicCryptoClientConfig::CachedState::set_source_address_token( | 220 void QuicCryptoClientConfig::CachedState::set_source_address_token( |
201 StringPiece token) { | 221 StringPiece token) { |
202 source_address_token_ = token.as_string(); | 222 source_address_token_ = token.as_string(); |
203 } | 223 } |
204 | 224 |
205 void QuicCryptoClientConfig::CachedState::SetProofVerifyDetails( | 225 void QuicCryptoClientConfig::CachedState::SetProofVerifyDetails( |
206 ProofVerifyDetails* details) { | 226 ProofVerifyDetails* details) { |
207 proof_verify_details_.reset(details); | 227 proof_verify_details_.reset(details); |
208 } | 228 } |
209 | 229 |
210 void QuicCryptoClientConfig::CachedState::InitializeFrom( | 230 void QuicCryptoClientConfig::CachedState::InitializeFrom( |
211 const QuicCryptoClientConfig::CachedState& other) { | 231 const QuicCryptoClientConfig::CachedState& other) { |
212 DCHECK(server_config_.empty()); | 232 DCHECK(server_config_.empty()); |
213 DCHECK(!server_config_valid_); | 233 DCHECK(!server_config_valid_); |
214 server_config_ = other.server_config_; | 234 server_config_ = other.server_config_; |
215 source_address_token_ = other.source_address_token_; | 235 source_address_token_ = other.source_address_token_; |
216 certs_ = other.certs_; | 236 certs_ = other.certs_; |
217 server_config_sig_ = other.server_config_sig_; | 237 server_config_sig_ = other.server_config_sig_; |
218 server_config_valid_ = other.server_config_valid_; | 238 server_config_valid_ = other.server_config_valid_; |
219 } | 239 } |
220 | 240 |
241 // TODO(rtenneti): LoadQuicServerInfo and SaveQuicServerInfo have duplication of | |
242 // data in CachedState and QuicServerInfo. We should eliminate the duplication | |
243 // of data. | |
wtc
2014/02/19 02:24:11
I think you should remove this TODO comment now.
| |
244 // An issue to be solved: while we are loading the data from disk cache, it is | |
245 // possible for another request for the same hostname update the CachedState | |
246 // because that request has sent FillInchoateClientHello and got REJ message. | |
247 // Loading of data from disk cache shouldn't blindly overwrite what is in | |
248 // CachedState. | |
249 bool QuicCryptoClientConfig::CachedState::LoadQuicServerInfo(QuicWallTime now) { | |
250 DCHECK(server_config_.empty()); | |
251 DCHECK(quic_server_info_.get()); | |
252 DCHECK(quic_server_info_->IsDataReady()); | |
253 | |
254 // TODO (rtenneti): Implement check for expiration. | |
255 return true; | |
256 } | |
257 | |
258 void QuicCryptoClientConfig::CachedState::SaveQuicServerInfo() { | |
259 if (!quic_server_info_.get() || !need_to_persist_) { | |
260 return; | |
261 } | |
262 DCHECK(server_config_valid_); | |
263 | |
264 // If the QuicServerInfo hasn't managed to load from disk yet then we can't | |
265 // save anything. | |
266 if (!quic_server_info_->IsDataReady()) { | |
267 return; | |
268 } | |
269 | |
270 quic_server_info_->Persist(); | |
271 need_to_persist_ = false; | |
272 } | |
273 | |
221 void QuicCryptoClientConfig::SetDefaults() { | 274 void QuicCryptoClientConfig::SetDefaults() { |
222 // Key exchange methods. | 275 // Key exchange methods. |
223 kexs.resize(2); | 276 kexs.resize(2); |
224 kexs[0] = kC255; | 277 kexs[0] = kC255; |
225 kexs[1] = kP256; | 278 kexs[1] = kP256; |
226 | 279 |
227 // Authenticated encryption algorithms. | 280 // Authenticated encryption algorithms. |
228 aead.resize(1); | 281 aead.resize(1); |
229 aead[0] = kAESG; | 282 aead[0] = kAESG; |
230 } | 283 } |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
662 CachedState* canonical_cached = | 715 CachedState* canonical_cached = |
663 canonical_crypto_config->LookupOrCreate(canonical_server_hostname); | 716 canonical_crypto_config->LookupOrCreate(canonical_server_hostname); |
664 if (!canonical_cached->proof_valid()) { | 717 if (!canonical_cached->proof_valid()) { |
665 return; | 718 return; |
666 } | 719 } |
667 CachedState* cached = LookupOrCreate(server_hostname); | 720 CachedState* cached = LookupOrCreate(server_hostname); |
668 cached->InitializeFrom(*canonical_cached); | 721 cached->InitializeFrom(*canonical_cached); |
669 } | 722 } |
670 | 723 |
671 } // namespace net | 724 } // namespace net |
OLD | NEW |