| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/internal_auth.h" | 5 #include "chrome/browser/internal_auth.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 244 } |
| 245 | 245 |
| 246 void ChangeKey(const std::string& key) { | 246 void ChangeKey(const std::string& key) { |
| 247 old_key_.swap(key_); | 247 old_key_.swap(key_); |
| 248 key_.clear(); | 248 key_.clear(); |
| 249 old_engine_.swap(engine_); | 249 old_engine_.swap(engine_); |
| 250 engine_.reset(NULL); | 250 engine_.reset(NULL); |
| 251 | 251 |
| 252 if (key.size() != kKeySizeInBytes) | 252 if (key.size() != kKeySizeInBytes) |
| 253 return; | 253 return; |
| 254 engine_.reset(new crypto::HMAC(crypto::HMAC::SHA256)); | 254 scoped_ptr<crypto::HMAC> new_engine( |
| 255 engine_->Init(key); | 255 new crypto::HMAC(crypto::HMAC::SHA256)); |
| 256 if (!new_engine->Init(key)) |
| 257 return; |
| 258 engine_.swap(new_engine); |
| 256 key_ = key; | 259 key_ = key; |
| 257 key_change_tick_ = GetCurrentTick(); | 260 key_change_tick_ = GetCurrentTick(); |
| 258 } | 261 } |
| 259 | 262 |
| 260 private: | 263 private: |
| 261 static int get_verification_window_ticks() { | 264 static int get_verification_window_ticks() { |
| 262 return InternalAuthVerification::get_verification_window_ticks(); | 265 return InternalAuthVerification::get_verification_window_ticks(); |
| 263 } | 266 } |
| 264 | 267 |
| 265 // Returns tick bound to given passport on success or zero on failure. | 268 // Returns tick bound to given passport on success or zero on failure. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 void GenerateNewKey() { | 343 void GenerateNewKey() { |
| 341 DCHECK(CalledOnValidThread()); | 344 DCHECK(CalledOnValidThread()); |
| 342 if (!timer_.IsRunning()) { | 345 if (!timer_.IsRunning()) { |
| 343 timer_.Start( | 346 timer_.Start( |
| 344 base::TimeDelta::FromMicroseconds( | 347 base::TimeDelta::FromMicroseconds( |
| 345 kKeyRegenerationSoftTicks * kTickUs), | 348 kKeyRegenerationSoftTicks * kTickUs), |
| 346 this, | 349 this, |
| 347 &InternalAuthGenerationService::GenerateNewKey); | 350 &InternalAuthGenerationService::GenerateNewKey); |
| 348 } | 351 } |
| 349 | 352 |
| 350 engine_.reset(new crypto::HMAC(crypto::HMAC::SHA256)); | 353 scoped_ptr<crypto::HMAC> new_engine( |
| 354 new crypto::HMAC(crypto::HMAC::SHA256)); |
| 351 std::string key = base::RandBytesAsString(kKeySizeInBytes); | 355 std::string key = base::RandBytesAsString(kKeySizeInBytes); |
| 352 engine_->Init(key); | 356 if (!new_engine->Init(key)) |
| 357 return; |
| 358 engine_.swap(new_engine); |
| 353 key_regeneration_tick_ = GetCurrentTick(); | 359 key_regeneration_tick_ = GetCurrentTick(); |
| 354 g_verification_service.Get().ChangeKey(key); | 360 g_verification_service.Get().ChangeKey(key); |
| 355 std::fill(key.begin(), key.end(), 0); | 361 std::fill(key.begin(), key.end(), 0); |
| 356 } | 362 } |
| 357 | 363 |
| 358 // Returns zero on failure. | 364 // Returns zero on failure. |
| 359 int64 GetUnusedTick(const std::string& domain) { | 365 int64 GetUnusedTick(const std::string& domain) { |
| 360 DCHECK(CalledOnValidThread()); | 366 DCHECK(CalledOnValidThread()); |
| 361 if (engine_ == NULL) { | 367 if (engine_ == NULL) { |
| 362 NOTREACHED(); | 368 NOTREACHED(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 return g_generation_service.Get().GeneratePassport(domain, var_value_map, 0); | 477 return g_generation_service.Get().GeneratePassport(domain, var_value_map, 0); |
| 472 } | 478 } |
| 473 | 479 |
| 474 // static | 480 // static |
| 475 void InternalAuthGeneration::GenerateNewKey() { | 481 void InternalAuthGeneration::GenerateNewKey() { |
| 476 g_generation_service.Get().GenerateNewKey(); | 482 g_generation_service.Get().GenerateNewKey(); |
| 477 } | 483 } |
| 478 | 484 |
| 479 } // namespace browser | 485 } // namespace browser |
| 480 | 486 |
| OLD | NEW |