Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: net/quic/crypto/quic_crypto_client_config.cc

Issue 154933003: Persist server's crypto config data to disk cache for 0-RTT (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments for Patch Set 4 Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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()) {}
48 50
49 QuicCryptoClientConfig::CachedState::~CachedState() {} 51 QuicCryptoClientConfig::CachedState::~CachedState() {}
50 52
51 bool QuicCryptoClientConfig::CachedState::IsComplete(QuicWallTime now) const { 53 bool QuicCryptoClientConfig::CachedState::IsComplete(QuicWallTime now) const {
52 if (server_config_.empty() || !server_config_valid_) { 54 if (server_config_.empty() || !server_config_valid_) {
53 return false; 55 return false;
54 } 56 }
55 57
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 113
112 if (now.ToUNIXSeconds() >= expiry_seconds) { 114 if (now.ToUNIXSeconds() >= expiry_seconds) {
113 *error_details = "SCFG has expired"; 115 *error_details = "SCFG has expired";
114 return QUIC_CRYPTO_SERVER_CONFIG_EXPIRED; 116 return QUIC_CRYPTO_SERVER_CONFIG_EXPIRED;
115 } 117 }
116 118
117 if (!matches_existing) { 119 if (!matches_existing) {
118 server_config_ = server_config.as_string(); 120 server_config_ = server_config.as_string();
119 SetProofInvalid(); 121 SetProofInvalid();
120 scfg_.reset(new_scfg_storage.release()); 122 scfg_.reset(new_scfg_storage.release());
123 need_to_persist_ = true;
121 } 124 }
122 return QUIC_NO_ERROR; 125 return QUIC_NO_ERROR;
123 } 126 }
124 127
125 void QuicCryptoClientConfig::CachedState::InvalidateServerConfig() { 128 void QuicCryptoClientConfig::CachedState::InvalidateServerConfig() {
126 server_config_.clear(); 129 server_config_.clear();
127 scfg_.reset(); 130 scfg_.reset();
128 SetProofInvalid(); 131 SetProofInvalid();
129 } 132 }
130 133
(...skipping 22 matching lines...) Expand all
153 } 156 }
154 157
155 void QuicCryptoClientConfig::CachedState::ClearProof() { 158 void QuicCryptoClientConfig::CachedState::ClearProof() {
156 SetProofInvalid(); 159 SetProofInvalid();
157 certs_.clear(); 160 certs_.clear();
158 server_config_sig_.clear(); 161 server_config_sig_.clear();
159 } 162 }
160 163
161 void QuicCryptoClientConfig::CachedState::SetProofValid() { 164 void QuicCryptoClientConfig::CachedState::SetProofValid() {
162 server_config_valid_ = true; 165 server_config_valid_ = true;
166 SaveQuicServerInfo();
163 } 167 }
164 168
165 void QuicCryptoClientConfig::CachedState::SetProofInvalid() { 169 void QuicCryptoClientConfig::CachedState::SetProofInvalid() {
166 server_config_valid_ = false; 170 server_config_valid_ = false;
167 ++generation_counter_; 171 ++generation_counter_;
168 } 172 }
169 173
170 const string& QuicCryptoClientConfig::CachedState::server_config() const { 174 const string& QuicCryptoClientConfig::CachedState::server_config() const {
171 return server_config_; 175 return server_config_;
172 } 176 }
(...skipping 17 matching lines...) Expand all
190 194
191 uint64 QuicCryptoClientConfig::CachedState::generation_counter() const { 195 uint64 QuicCryptoClientConfig::CachedState::generation_counter() const {
192 return generation_counter_; 196 return generation_counter_;
193 } 197 }
194 198
195 const ProofVerifyDetails* 199 const ProofVerifyDetails*
196 QuicCryptoClientConfig::CachedState::proof_verify_details() const { 200 QuicCryptoClientConfig::CachedState::proof_verify_details() const {
197 return proof_verify_details_.get(); 201 return proof_verify_details_.get();
198 } 202 }
199 203
204 QuicServerInfo* QuicCryptoClientConfig::CachedState::quic_server_info() const {
205 return quic_server_info_.get();
206 }
207
200 void QuicCryptoClientConfig::CachedState::set_source_address_token( 208 void QuicCryptoClientConfig::CachedState::set_source_address_token(
201 StringPiece token) { 209 StringPiece token) {
202 source_address_token_ = token.as_string(); 210 source_address_token_ = token.as_string();
203 } 211 }
204 212
205 void QuicCryptoClientConfig::CachedState::SetProofVerifyDetails( 213 void QuicCryptoClientConfig::CachedState::SetProofVerifyDetails(
206 ProofVerifyDetails* details) { 214 ProofVerifyDetails* details) {
207 proof_verify_details_.reset(details); 215 proof_verify_details_.reset(details);
208 } 216 }
209 217
210 void QuicCryptoClientConfig::CachedState::InitializeFrom( 218 void QuicCryptoClientConfig::CachedState::InitializeFrom(
211 const QuicCryptoClientConfig::CachedState& other) { 219 const QuicCryptoClientConfig::CachedState& other) {
212 DCHECK(server_config_.empty()); 220 DCHECK(server_config_.empty());
213 DCHECK(!server_config_valid_); 221 DCHECK(!server_config_valid_);
214 server_config_ = other.server_config_; 222 server_config_ = other.server_config_;
215 source_address_token_ = other.source_address_token_; 223 source_address_token_ = other.source_address_token_;
216 certs_ = other.certs_; 224 certs_ = other.certs_;
217 server_config_sig_ = other.server_config_sig_; 225 server_config_sig_ = other.server_config_sig_;
218 server_config_valid_ = other.server_config_valid_; 226 server_config_valid_ = other.server_config_valid_;
219 } 227 }
220 228
229 // TODO(rtenneti): LoadQuicServerInfo and SaveQuicServerInfo have duplication of
230 // data in CachedState and QuicServerInfo. We should eliminate the duplication
231 // of data.
232 // An issue to be solved: while we are loading the data from disk cache, it is
233 // possible for another request for the same hostname update the CachedState
234 // because that request has sent FillInchoateClientHello and got REJ message.
235 // Loading of data from disk cache shouldn't blindly overwrite what is in
236 // CachedState.
237 void QuicCryptoClientConfig::CachedState::LoadQuicServerInfo() {
wtc 2014/02/14 01:46:13 This method needs to return a bool status.
ramant (doing other things) 2014/02/15 00:36:12 Done.
238 if (!server_config_.empty()) {
wtc 2014/02/14 01:46:13 This should become a DCHECK: DCHECK(server_confi
ramant (doing other things) 2014/02/15 00:36:12 Done.
239 return;
240 }
241 DCHECK(quic_server_info_.get());
242
243 const QuicServerInfo::State& state(quic_server_info_->state());
244 if (state.server_config.empty()) {
245 return;
wtc 2014/02/14 01:46:13 We should return false.
ramant (doing other things) 2014/02/15 00:36:12 Done.
246 }
247
248 server_config_ = state.server_config;
wtc 2014/02/13 23:48:43 I now think we should call SetServerConfig() to se
wtc 2014/02/14 01:46:13 If SetServerConfig() fails, we should return false
ramant (doing other things) 2014/02/15 00:36:12 Done.
ramant (doing other things) 2014/02/15 00:36:12 Done.
249 source_address_token_ = state.source_address_token;
250 server_config_sig_ = state.server_config_sig;
251 certs_ = state.certs;
252 need_to_persist_ = false;
253 }
254
255 void QuicCryptoClientConfig::CachedState::SaveQuicServerInfo() {
256 if (!quic_server_info_.get() || !need_to_persist_) {
257 return;
258 }
259 DCHECK(server_config_valid_);
260
261 // If the QuicServerInfo hasn't managed to load from disk yet then we can't
262 // save anything.
263 if (!quic_server_info_->IsDataReady()) {
264 return;
265 }
266
267 QuicServerInfo::State* state = quic_server_info_->mutable_state();
268
269 state->server_config = server_config_;
270 state->source_address_token = source_address_token_;
271 state->server_config_sig = server_config_sig_;
272 state->certs = certs_;
273
274 quic_server_info_->Persist();
275 need_to_persist_ = false;
276 }
277
221 void QuicCryptoClientConfig::SetDefaults() { 278 void QuicCryptoClientConfig::SetDefaults() {
222 // Key exchange methods. 279 // Key exchange methods.
223 kexs.resize(2); 280 kexs.resize(2);
224 kexs[0] = kC255; 281 kexs[0] = kC255;
225 kexs[1] = kP256; 282 kexs[1] = kP256;
226 283
227 // Authenticated encryption algorithms. 284 // Authenticated encryption algorithms.
228 aead.resize(1); 285 aead.resize(1);
229 aead[0] = kAESG; 286 aead[0] = kAESG;
230 } 287 }
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 CachedState* canonical_cached = 724 CachedState* canonical_cached =
668 canonical_crypto_config->LookupOrCreate(canonical_server_hostname); 725 canonical_crypto_config->LookupOrCreate(canonical_server_hostname);
669 if (!canonical_cached->proof_valid()) { 726 if (!canonical_cached->proof_valid()) {
670 return; 727 return;
671 } 728 }
672 CachedState* cached = LookupOrCreate(server_hostname); 729 CachedState* cached = LookupOrCreate(server_hostname);
673 cached->InitializeFrom(*canonical_cached); 730 cached->InitializeFrom(*canonical_cached);
674 } 731 }
675 732
676 } // namespace net 733 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698