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

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: Deleted unused data_loaded_ member 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 *error_details = "SCFG missing EXPY"; 110 *error_details = "SCFG missing EXPY";
109 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER; 111 return QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER;
110 } 112 }
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();
wtc 2014/02/11 01:01:45 It seems that should set need_to_persist_ to true
ramant (doing other things) 2014/02/11 07:57:55 Done.
119 SetProofInvalid(); 121 SetProofInvalid();
120 scfg_.reset(new_scfg_storage.release()); 122 scfg_.reset(new_scfg_storage.release());
121 } 123 }
122 return QUIC_NO_ERROR; 124 return QUIC_NO_ERROR;
123 } 125 }
124 126
125 void QuicCryptoClientConfig::CachedState::InvalidateServerConfig() { 127 void QuicCryptoClientConfig::CachedState::InvalidateServerConfig() {
126 server_config_.clear(); 128 server_config_.clear();
127 scfg_.reset(); 129 scfg_.reset();
128 SetProofInvalid(); 130 SetProofInvalid();
(...skipping 14 matching lines...) Expand all
143 } 145 }
144 146
145 if (!has_changed) { 147 if (!has_changed) {
146 return; 148 return;
147 } 149 }
148 150
149 // If the proof has changed then it needs to be revalidated. 151 // If the proof has changed then it needs to be revalidated.
150 SetProofInvalid(); 152 SetProofInvalid();
151 certs_ = certs; 153 certs_ = certs;
152 server_config_sig_ = signature.as_string(); 154 server_config_sig_ = signature.as_string();
155 need_to_persist_ = true;
wtc 2014/02/11 01:01:45 This doesn't seem like the right place to set need
ramant (doing other things) 2014/02/11 07:57:55 Done.
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;
(...skipping 27 matching lines...) Expand all
190 193
191 uint64 QuicCryptoClientConfig::CachedState::generation_counter() const { 194 uint64 QuicCryptoClientConfig::CachedState::generation_counter() const {
192 return generation_counter_; 195 return generation_counter_;
193 } 196 }
194 197
195 const ProofVerifyDetails* 198 const ProofVerifyDetails*
196 QuicCryptoClientConfig::CachedState::proof_verify_details() const { 199 QuicCryptoClientConfig::CachedState::proof_verify_details() const {
197 return proof_verify_details_.get(); 200 return proof_verify_details_.get();
198 } 201 }
199 202
203 QuicServerInfo* QuicCryptoClientConfig::CachedState::quic_server_info() const {
204 return quic_server_info_.get();
205 }
206
200 void QuicCryptoClientConfig::CachedState::set_source_address_token( 207 void QuicCryptoClientConfig::CachedState::set_source_address_token(
201 StringPiece token) { 208 StringPiece token) {
202 source_address_token_ = token.as_string(); 209 source_address_token_ = token.as_string();
203 } 210 }
204 211
205 void QuicCryptoClientConfig::CachedState::SetProofVerifyDetails( 212 void QuicCryptoClientConfig::CachedState::SetProofVerifyDetails(
206 ProofVerifyDetails* details) { 213 ProofVerifyDetails* details) {
207 proof_verify_details_.reset(details); 214 proof_verify_details_.reset(details);
208 } 215 }
209 216
210 void QuicCryptoClientConfig::CachedState::InitializeFrom( 217 void QuicCryptoClientConfig::CachedState::InitializeFrom(
211 const QuicCryptoClientConfig::CachedState& other) { 218 const QuicCryptoClientConfig::CachedState& other) {
212 DCHECK(server_config_.empty()); 219 DCHECK(server_config_.empty());
213 DCHECK(!server_config_valid_); 220 DCHECK(!server_config_valid_);
214 server_config_ = other.server_config_; 221 server_config_ = other.server_config_;
215 source_address_token_ = other.source_address_token_; 222 source_address_token_ = other.source_address_token_;
216 certs_ = other.certs_; 223 certs_ = other.certs_;
217 server_config_sig_ = other.server_config_sig_; 224 server_config_sig_ = other.server_config_sig_;
218 server_config_valid_ = other.server_config_valid_; 225 server_config_valid_ = other.server_config_valid_;
219 } 226 }
220 227
228 // TODO(rtenneti): LoadQuicServerInfo and SaveQuicServerInfo have duplication of
229 // data in CachedState and QuicServerInfo. We should eliminate the duplication
230 // of data.
231 // An issue to be solved: while we are loading the data from disk cache, it is
232 // possible for another request for the same hostname update the CachedState
233 // because that request has sent FillInchoateClientHello and got REJ message.
234 // Loading of data from disk cache shouldn't blindly overwrite what is in
235 // CachedState.
236 void QuicCryptoClientConfig::CachedState::LoadQuicServerInfo() {
237 if (server_config_valid_ || !server_config_sig_.empty()) {
wtc 2014/02/11 01:01:45 It seems that we should not test server_config_val
ramant (doing other things) 2014/02/11 07:57:55 Done.
238 return;
239 }
240 DCHECK(quic_server_info_.get());
241
242 const QuicServerInfo::State& state(quic_server_info_->state());
243 if (state.certs_.empty()) {
wtc 2014/02/11 01:01:45 It is better to test state.server_config_.empty()
ramant (doing other things) 2014/02/11 07:57:55 Done.
244 return;
245 }
246
247 server_config_ = state.server_config_;
248 source_address_token_ = state.source_address_token_;
249 server_config_sig_ = state.server_config_sig_;
250 certs_ = state.certs_;
251 need_to_persist_ = false;
252 }
253
254 void QuicCryptoClientConfig::CachedState::SaveQuicServerInfo() {
255 if (!quic_server_info_.get() || !need_to_persist_) {
256 return;
257 }
258 DCHECK(server_config_valid_);
259
260 // If the QuicServerInfo hasn't managed to load from disk yet then we can't
261 // save anything.
262 if (!quic_server_info_->IsDataReady()) {
263 return;
264 }
265
266 QuicServerInfo::State* state = quic_server_info_->mutable_state();
267
268 state->Clear();
wtc 2014/02/11 01:01:45 This state->Clear() call is not necessary because
ramant (doing other things) 2014/02/11 07:57:55 Done.
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();
wtc 2014/02/11 01:01:45 We should set need_to_persist_ to false after the
ramant (doing other things) 2014/02/11 07:57:55 Done.
275 }
276
221 void QuicCryptoClientConfig::SetDefaults() { 277 void QuicCryptoClientConfig::SetDefaults() {
222 // Key exchange methods. 278 // Key exchange methods.
223 kexs.resize(2); 279 kexs.resize(2);
224 kexs[0] = kC255; 280 kexs[0] = kC255;
225 kexs[1] = kP256; 281 kexs[1] = kP256;
226 282
227 // Authenticated encryption algorithms. 283 // Authenticated encryption algorithms.
228 aead.resize(1); 284 aead.resize(1);
229 aead[0] = kAESG; 285 aead[0] = kAESG;
230 } 286 }
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 CachedState* canonical_cached = 723 CachedState* canonical_cached =
668 canonical_crypto_config->LookupOrCreate(canonical_server_hostname); 724 canonical_crypto_config->LookupOrCreate(canonical_server_hostname);
669 if (!canonical_cached->proof_valid()) { 725 if (!canonical_cached->proof_valid()) {
670 return; 726 return;
671 } 727 }
672 CachedState* cached = LookupOrCreate(server_hostname); 728 CachedState* cached = LookupOrCreate(server_hostname);
673 cached->InitializeFrom(*canonical_cached); 729 cached->InitializeFrom(*canonical_cached);
674 } 730 }
675 731
676 } // namespace net 732 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698