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_server_config.h" | 5 #include "net/quic/crypto/quic_crypto_server_config.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 private: | 140 private: |
141 ValidateClientHelloResultCallback::Result* result_; | 141 ValidateClientHelloResultCallback::Result* result_; |
142 ValidateClientHelloResultCallback* done_cb_; | 142 ValidateClientHelloResultCallback* done_cb_; |
143 | 143 |
144 DISALLOW_COPY_AND_ASSIGN(VerifyNonceIsValidAndUniqueCallback); | 144 DISALLOW_COPY_AND_ASSIGN(VerifyNonceIsValidAndUniqueCallback); |
145 }; | 145 }; |
146 | 146 |
147 // static | 147 // static |
148 const char QuicCryptoServerConfig::TESTING[] = "secret string for testing"; | 148 const char QuicCryptoServerConfig::TESTING[] = "secret string for testing"; |
149 | 149 |
| 150 PrimaryConfigChangedCallback::PrimaryConfigChangedCallback() { |
| 151 } |
| 152 |
| 153 PrimaryConfigChangedCallback::~PrimaryConfigChangedCallback() { |
| 154 } |
150 | 155 |
151 ValidateClientHelloResultCallback::ValidateClientHelloResultCallback() { | 156 ValidateClientHelloResultCallback::ValidateClientHelloResultCallback() { |
152 } | 157 } |
153 | 158 |
154 ValidateClientHelloResultCallback::~ValidateClientHelloResultCallback() { | 159 ValidateClientHelloResultCallback::~ValidateClientHelloResultCallback() { |
155 } | 160 } |
156 | 161 |
157 void ValidateClientHelloResultCallback::Run(const Result* result) { | 162 void ValidateClientHelloResultCallback::Run(const Result* result) { |
158 RunImpl(result->client_hello, *result); | 163 RunImpl(result->client_hello, *result); |
159 delete result; | 164 delete result; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 414 |
410 configs_.swap(new_configs); | 415 configs_.swap(new_configs); |
411 SelectNewPrimaryConfig(now); | 416 SelectNewPrimaryConfig(now); |
412 DCHECK(primary_config_); | 417 DCHECK(primary_config_); |
413 DCHECK_EQ(configs_.find(primary_config_->id)->second, primary_config_); | 418 DCHECK_EQ(configs_.find(primary_config_->id)->second, primary_config_); |
414 } | 419 } |
415 | 420 |
416 return ok; | 421 return ok; |
417 } | 422 } |
418 | 423 |
| 424 void QuicCryptoServerConfig::GetConfigIds(vector<string>* scids) const { |
| 425 base::AutoLock locked(configs_lock_); |
| 426 for (ConfigMap::const_iterator it = configs_.begin(); |
| 427 it != configs_.end(); ++it) { |
| 428 scids->push_back(it->first); |
| 429 } |
| 430 } |
| 431 |
419 void QuicCryptoServerConfig::ValidateClientHello( | 432 void QuicCryptoServerConfig::ValidateClientHello( |
420 const CryptoHandshakeMessage& client_hello, | 433 const CryptoHandshakeMessage& client_hello, |
421 IPEndPoint client_ip, | 434 IPEndPoint client_ip, |
422 const QuicClock* clock, | 435 const QuicClock* clock, |
423 ValidateClientHelloResultCallback* done_cb) const { | 436 ValidateClientHelloResultCallback* done_cb) const { |
424 const QuicWallTime now(clock->WallNow()); | 437 const QuicWallTime now(clock->WallNow()); |
425 | 438 |
426 ValidateClientHelloResultCallback::Result* result = | 439 ValidateClientHelloResultCallback::Result* result = |
427 new ValidateClientHelloResultCallback::Result( | 440 new ValidateClientHelloResultCallback::Result( |
428 client_hello, client_ip, now); | 441 client_hello, client_ip, now); |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 | 790 |
778 if (primary_config_.get()) { | 791 if (primary_config_.get()) { |
779 primary_config_->is_primary = false; | 792 primary_config_->is_primary = false; |
780 } | 793 } |
781 primary_config_ = new_primary; | 794 primary_config_ = new_primary; |
782 new_primary->is_primary = true; | 795 new_primary->is_primary = true; |
783 DVLOG(1) << "New primary config. orbit: " | 796 DVLOG(1) << "New primary config. orbit: " |
784 << base::HexEncode( | 797 << base::HexEncode( |
785 reinterpret_cast<const char*>(primary_config_->orbit), | 798 reinterpret_cast<const char*>(primary_config_->orbit), |
786 kOrbitSize); | 799 kOrbitSize); |
| 800 if (primary_config_changed_cb_.get() != NULL) { |
| 801 primary_config_changed_cb_->Run(primary_config_->id); |
| 802 } |
787 | 803 |
788 return; | 804 return; |
789 } | 805 } |
790 | 806 |
791 // All config's primary times are in the past. We should make the most recent | 807 // All config's primary times are in the past. We should make the most recent |
792 // most recent and highest priority candidate primary. | 808 // most recent and highest priority candidate primary. |
793 scoped_refptr<Config> new_primary(best_candidate); | 809 scoped_refptr<Config> new_primary(best_candidate); |
794 if (primary_config_.get()) { | 810 if (primary_config_.get()) { |
795 primary_config_->is_primary = false; | 811 primary_config_->is_primary = false; |
796 } | 812 } |
797 primary_config_ = new_primary; | 813 primary_config_ = new_primary; |
798 new_primary->is_primary = true; | 814 new_primary->is_primary = true; |
799 DVLOG(1) << "New primary config. orbit: " | 815 DVLOG(1) << "New primary config. orbit: " |
800 << base::HexEncode( | 816 << base::HexEncode( |
801 reinterpret_cast<const char*>(primary_config_->orbit), | 817 reinterpret_cast<const char*>(primary_config_->orbit), |
802 kOrbitSize); | 818 kOrbitSize); |
803 next_config_promotion_time_ = QuicWallTime::Zero(); | 819 next_config_promotion_time_ = QuicWallTime::Zero(); |
| 820 if (primary_config_changed_cb_.get() != NULL) { |
| 821 primary_config_changed_cb_->Run(primary_config_->id); |
| 822 } |
804 } | 823 } |
805 | 824 |
806 void QuicCryptoServerConfig::EvaluateClientHello( | 825 void QuicCryptoServerConfig::EvaluateClientHello( |
807 const uint8* primary_orbit, | 826 const uint8* primary_orbit, |
808 ValidateClientHelloResultCallback::Result* client_hello_state, | 827 ValidateClientHelloResultCallback::Result* client_hello_state, |
809 ValidateClientHelloResultCallback* done_cb) const { | 828 ValidateClientHelloResultCallback* done_cb) const { |
810 ValidateClientHelloHelper helper(client_hello_state, done_cb); | 829 ValidateClientHelloHelper helper(client_hello_state, done_cb); |
811 | 830 |
812 const CryptoHandshakeMessage& client_hello = | 831 const CryptoHandshakeMessage& client_hello = |
813 client_hello_state->client_hello; | 832 client_hello_state->client_hello; |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 DCHECK(!server_nonce_strike_register_.get()); | 1196 DCHECK(!server_nonce_strike_register_.get()); |
1178 server_nonce_strike_register_max_entries_ = max_entries; | 1197 server_nonce_strike_register_max_entries_ = max_entries; |
1179 } | 1198 } |
1180 | 1199 |
1181 void QuicCryptoServerConfig::set_server_nonce_strike_register_window_secs( | 1200 void QuicCryptoServerConfig::set_server_nonce_strike_register_window_secs( |
1182 uint32 window_secs) { | 1201 uint32 window_secs) { |
1183 DCHECK(!server_nonce_strike_register_.get()); | 1202 DCHECK(!server_nonce_strike_register_.get()); |
1184 server_nonce_strike_register_window_secs_ = window_secs; | 1203 server_nonce_strike_register_window_secs_ = window_secs; |
1185 } | 1204 } |
1186 | 1205 |
| 1206 void QuicCryptoServerConfig::AcquirePrimaryConfigChangedCb( |
| 1207 PrimaryConfigChangedCallback* cb) { |
| 1208 base::AutoLock locked(configs_lock_); |
| 1209 primary_config_changed_cb_.reset(cb); |
| 1210 } |
| 1211 |
1187 string QuicCryptoServerConfig::NewSourceAddressToken( | 1212 string QuicCryptoServerConfig::NewSourceAddressToken( |
1188 const IPEndPoint& ip, | 1213 const IPEndPoint& ip, |
1189 QuicRandom* rand, | 1214 QuicRandom* rand, |
1190 QuicWallTime now) const { | 1215 QuicWallTime now) const { |
1191 SourceAddressToken source_address_token; | 1216 SourceAddressToken source_address_token; |
1192 source_address_token.set_ip(IPAddressToPackedString(ip.address())); | 1217 source_address_token.set_ip(IPAddressToPackedString(ip.address())); |
1193 source_address_token.set_timestamp(now.ToUNIXSeconds()); | 1218 source_address_token.set_timestamp(now.ToUNIXSeconds()); |
1194 | 1219 |
1195 return source_address_token_boxer_.Box( | 1220 return source_address_token_boxer_.Box( |
1196 rand, source_address_token.SerializeAsString()); | 1221 rand, source_address_token.SerializeAsString()); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 | 1327 |
1303 QuicCryptoServerConfig::Config::Config() | 1328 QuicCryptoServerConfig::Config::Config() |
1304 : channel_id_enabled(false), | 1329 : channel_id_enabled(false), |
1305 is_primary(false), | 1330 is_primary(false), |
1306 primary_time(QuicWallTime::Zero()), | 1331 primary_time(QuicWallTime::Zero()), |
1307 priority(0) {} | 1332 priority(0) {} |
1308 | 1333 |
1309 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } | 1334 QuicCryptoServerConfig::Config::~Config() { STLDeleteElements(&key_exchanges); } |
1310 | 1335 |
1311 } // namespace net | 1336 } // namespace net |
OLD | NEW |