Chromium Code Reviews| 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/base/completion_callback.h" | |
| 9 #include "net/base/net_errors.h" | |
| 8 #include "net/quic/crypto/cert_compressor.h" | 10 #include "net/quic/crypto/cert_compressor.h" |
| 9 #include "net/quic/crypto/channel_id.h" | 11 #include "net/quic/crypto/channel_id.h" |
| 10 #include "net/quic/crypto/common_cert_set.h" | 12 #include "net/quic/crypto/common_cert_set.h" |
| 11 #include "net/quic/crypto/crypto_framer.h" | 13 #include "net/quic/crypto/crypto_framer.h" |
| 12 #include "net/quic/crypto/crypto_utils.h" | 14 #include "net/quic/crypto/crypto_utils.h" |
| 13 #include "net/quic/crypto/curve25519_key_exchange.h" | 15 #include "net/quic/crypto/curve25519_key_exchange.h" |
| 14 #include "net/quic/crypto/key_exchange.h" | 16 #include "net/quic/crypto/key_exchange.h" |
| 15 #include "net/quic/crypto/p256_key_exchange.h" | 17 #include "net/quic/crypto/p256_key_exchange.h" |
| 16 #include "net/quic/crypto/proof_verifier.h" | 18 #include "net/quic/crypto/proof_verifier.h" |
| 17 #include "net/quic/crypto/quic_encrypter.h" | 19 #include "net/quic/crypto/quic_encrypter.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 31 | 33 |
| 32 QuicCryptoClientConfig::QuicCryptoClientConfig() { | 34 QuicCryptoClientConfig::QuicCryptoClientConfig() { |
| 33 } | 35 } |
| 34 | 36 |
| 35 QuicCryptoClientConfig::~QuicCryptoClientConfig() { | 37 QuicCryptoClientConfig::~QuicCryptoClientConfig() { |
| 36 STLDeleteValues(&cached_states_); | 38 STLDeleteValues(&cached_states_); |
| 37 } | 39 } |
| 38 | 40 |
| 39 QuicCryptoClientConfig::CachedState::CachedState() | 41 QuicCryptoClientConfig::CachedState::CachedState() |
| 40 : server_config_valid_(false), | 42 : server_config_valid_(false), |
| 43 need_to_persist_(false), | |
| 41 generation_counter_(0) {} | 44 generation_counter_(0) {} |
| 42 | 45 |
| 43 QuicCryptoClientConfig::CachedState::CachedState( | 46 QuicCryptoClientConfig::CachedState::CachedState( |
| 44 scoped_ptr<QuicServerInfo> quic_server_info) | 47 scoped_ptr<QuicServerInfo> quic_server_info) |
| 45 : server_config_valid_(false), | 48 : server_config_valid_(false), |
| 49 need_to_persist_(false), | |
| 46 generation_counter_(0), | 50 generation_counter_(0), |
| 47 quic_server_info_(quic_server_info.Pass()) {} | 51 quic_server_info_(quic_server_info.Pass()) {} |
| 48 | 52 |
| 49 QuicCryptoClientConfig::CachedState::~CachedState() {} | 53 QuicCryptoClientConfig::CachedState::~CachedState() {} |
| 50 | 54 |
| 51 bool QuicCryptoClientConfig::CachedState::IsComplete(QuicWallTime now) const { | 55 bool QuicCryptoClientConfig::CachedState::IsComplete(QuicWallTime now) const { |
| 52 if (server_config_.empty() || !server_config_valid_) { | 56 if (server_config_.empty() || !server_config_valid_) { |
| 53 return false; | 57 return false; |
| 54 } | 58 } |
| 55 | 59 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 certs_.clear(); | 161 certs_.clear(); |
| 158 server_config_sig_.clear(); | 162 server_config_sig_.clear(); |
| 159 } | 163 } |
| 160 | 164 |
| 161 void QuicCryptoClientConfig::CachedState::SetProofValid() { | 165 void QuicCryptoClientConfig::CachedState::SetProofValid() { |
| 162 server_config_valid_ = true; | 166 server_config_valid_ = true; |
| 163 } | 167 } |
| 164 | 168 |
| 165 void QuicCryptoClientConfig::CachedState::SetProofInvalid() { | 169 void QuicCryptoClientConfig::CachedState::SetProofInvalid() { |
| 166 server_config_valid_ = false; | 170 server_config_valid_ = false; |
| 171 need_to_persist_ = true; | |
|
wtc
2014/02/07 00:54:11
IMPORTANT: is this a bug? It seems that we should
ramant (doing other things)
2014/02/07 20:30:51
Added need_to_persist_ = true in SetProof and only
| |
| 167 ++generation_counter_; | 172 ++generation_counter_; |
| 168 } | 173 } |
| 169 | 174 |
| 170 const string& QuicCryptoClientConfig::CachedState::server_config() const { | 175 const string& QuicCryptoClientConfig::CachedState::server_config() const { |
| 171 return server_config_; | 176 return server_config_; |
| 172 } | 177 } |
| 173 | 178 |
| 174 const string& | 179 const string& |
| 175 QuicCryptoClientConfig::CachedState::source_address_token() const { | 180 QuicCryptoClientConfig::CachedState::source_address_token() const { |
| 176 return source_address_token_; | 181 return source_address_token_; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 190 | 195 |
| 191 uint64 QuicCryptoClientConfig::CachedState::generation_counter() const { | 196 uint64 QuicCryptoClientConfig::CachedState::generation_counter() const { |
| 192 return generation_counter_; | 197 return generation_counter_; |
| 193 } | 198 } |
| 194 | 199 |
| 195 const ProofVerifyDetails* | 200 const ProofVerifyDetails* |
| 196 QuicCryptoClientConfig::CachedState::proof_verify_details() const { | 201 QuicCryptoClientConfig::CachedState::proof_verify_details() const { |
| 197 return proof_verify_details_.get(); | 202 return proof_verify_details_.get(); |
| 198 } | 203 } |
| 199 | 204 |
| 205 QuicServerInfo* QuicCryptoClientConfig::CachedState::quic_server_info() const { | |
| 206 return quic_server_info_.get(); | |
| 207 } | |
| 208 | |
| 200 void QuicCryptoClientConfig::CachedState::set_source_address_token( | 209 void QuicCryptoClientConfig::CachedState::set_source_address_token( |
| 201 StringPiece token) { | 210 StringPiece token) { |
| 202 source_address_token_ = token.as_string(); | 211 source_address_token_ = token.as_string(); |
| 203 } | 212 } |
| 204 | 213 |
| 205 void QuicCryptoClientConfig::CachedState::SetProofVerifyDetails( | 214 void QuicCryptoClientConfig::CachedState::SetProofVerifyDetails( |
| 206 ProofVerifyDetails* details) { | 215 ProofVerifyDetails* details) { |
| 207 proof_verify_details_.reset(details); | 216 proof_verify_details_.reset(details); |
| 208 } | 217 } |
| 209 | 218 |
| 210 void QuicCryptoClientConfig::CachedState::InitializeFrom( | 219 void QuicCryptoClientConfig::CachedState::InitializeFrom( |
| 211 const QuicCryptoClientConfig::CachedState& other) { | 220 const QuicCryptoClientConfig::CachedState& other) { |
| 212 DCHECK(server_config_.empty()); | 221 DCHECK(server_config_.empty()); |
| 213 DCHECK(!server_config_valid_); | 222 DCHECK(!server_config_valid_); |
| 214 server_config_ = other.server_config_; | 223 server_config_ = other.server_config_; |
| 215 source_address_token_ = other.source_address_token_; | 224 source_address_token_ = other.source_address_token_; |
| 216 certs_ = other.certs_; | 225 certs_ = other.certs_; |
| 217 server_config_sig_ = other.server_config_sig_; | 226 server_config_sig_ = other.server_config_sig_; |
| 218 server_config_valid_ = other.server_config_valid_; | 227 server_config_valid_ = other.server_config_valid_; |
| 219 } | 228 } |
| 220 | 229 |
| 230 void QuicCryptoClientConfig::CachedState::LoadQuicServerInfo() { | |
| 231 if (proof_valid() || !signature().empty()) { | |
|
wtc
2014/02/07 00:54:11
1. Why do you test !signature().empty()?
2. Since
ramant (doing other things)
2014/02/07 20:30:51
Made the changes to access members directly.
| |
| 232 return; | |
| 233 } | |
| 234 DCHECK(quic_server_info()); | |
| 235 | |
| 236 const QuicServerInfo::State& state(quic_server_info_->state()); | |
| 237 if (state.certs_.empty()) { | |
| 238 return; | |
| 239 } | |
| 240 | |
| 241 server_config_ = state.server_config_; | |
| 242 source_address_token_ = state.source_address_token_; | |
| 243 server_config_sig_ = state.server_config_sig_; | |
| 244 for (size_t i = 0; i < state.certs_.size(); i++) { | |
| 245 certs_.push_back(state.certs_[i]); | |
| 246 } | |
|
wtc
2014/02/07 00:54:11
I think we should be able to assign a std::vector
ramant (doing other things)
2014/02/07 20:30:51
Done.
| |
| 247 need_to_persist_ = false; | |
| 248 } | |
| 249 | |
| 250 void QuicCryptoClientConfig::CachedState::SaveQuicServerInfo() { | |
|
wtc
2014/02/07 00:54:11
IMPORTANT: these two methods show a duplication of
ramant (doing other things)
2014/02/07 20:30:51
Added a TODO for the above. Possible race conditio
| |
| 251 if (!quic_server_info() || !proof_valid() || signature().empty() || | |
| 252 !need_to_persist_) { | |
|
wtc
2014/02/07 00:54:11
It seems that if we set need_to_persist_ appropria
ramant (doing other things)
2014/02/07 20:30:51
Done.
| |
| 253 return; | |
| 254 } | |
| 255 | |
| 256 // If the QuicServerInfo hasn't managed to load from disk yet then we can't | |
| 257 // save anything. | |
| 258 if (quic_server_info_->WaitForDataReady(CompletionCallback()) != OK) { | |
| 259 return; | |
| 260 } | |
| 261 | |
| 262 QuicServerInfo::State* state = quic_server_info_->mutable_state(); | |
| 263 | |
| 264 state->Clear(); | |
| 265 state->server_config_ = server_config_; | |
| 266 state->source_address_token_ = source_address_token_; | |
| 267 state->server_config_sig_ = server_config_sig_; | |
| 268 for (size_t i = 0; i < certs_.size(); i++) { | |
| 269 state->certs_.push_back(certs_[i]); | |
| 270 } | |
|
wtc
2014/02/07 00:54:11
An assignment should work:
state->certs_ = cert
ramant (doing other things)
2014/02/07 20:30:51
Done.
| |
| 271 | |
| 272 quic_server_info_->Persist(); | |
| 273 } | |
| 274 | |
| 221 void QuicCryptoClientConfig::SetDefaults() { | 275 void QuicCryptoClientConfig::SetDefaults() { |
| 222 // Key exchange methods. | 276 // Key exchange methods. |
| 223 kexs.resize(2); | 277 kexs.resize(2); |
| 224 kexs[0] = kC255; | 278 kexs[0] = kC255; |
| 225 kexs[1] = kP256; | 279 kexs[1] = kP256; |
| 226 | 280 |
| 227 // Authenticated encryption algorithms. | 281 // Authenticated encryption algorithms. |
| 228 aead.resize(1); | 282 aead.resize(1); |
| 229 aead[0] = kAESG; | 283 aead[0] = kAESG; |
| 230 } | 284 } |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 CachedState* canonical_cached = | 721 CachedState* canonical_cached = |
| 668 canonical_crypto_config->LookupOrCreate(canonical_server_hostname); | 722 canonical_crypto_config->LookupOrCreate(canonical_server_hostname); |
| 669 if (!canonical_cached->proof_valid()) { | 723 if (!canonical_cached->proof_valid()) { |
| 670 return; | 724 return; |
| 671 } | 725 } |
| 672 CachedState* cached = LookupOrCreate(server_hostname); | 726 CachedState* cached = LookupOrCreate(server_hostname); |
| 673 cached->InitializeFrom(*canonical_cached); | 727 cached->InitializeFrom(*canonical_cached); |
| 674 } | 728 } |
| 675 | 729 |
| 676 } // namespace net | 730 } // namespace net |
| OLD | NEW |