diff options
author | dilmah@chromium.org <dilmah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-13 10:10:29 +0000 |
---|---|---|
committer | dilmah@chromium.org <dilmah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-13 10:10:29 +0000 |
commit | e234b11aee841dcce3a9c48ed62883669a2259da (patch) | |
tree | b668f25ae3abf1b6f960cba3a579bbb383dd38e2 | |
parent | 10398a6053ffe9ce18deb17d186d107fbe729533 (diff) | |
download | chromium_src-e234b11aee841dcce3a9c48ed62883669a2259da.zip chromium_src-e234b11aee841dcce3a9c48ed62883669a2259da.tar.gz chromium_src-e234b11aee841dcce3a9c48ed62883669a2259da.tar.bz2 |
Fix behaviour of internal token generation in case of wakeup.
websocket-to-TCP proxy uses this token service for authorization purposes.
When device goes into sleep then timers stop to be invoked, thus key stops to be regenerated.
So after wakeup key appears to be outdated, leading to failure to generate token.
Fixed this.
BUG=chromium-os:20307
TEST=Manual
Review URL: http://codereview.chromium.org/7780027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100895 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/internal_auth.cc | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/chrome/browser/internal_auth.cc b/chrome/browser/internal_auth.cc index 76e32b4..faa44e1 100644 --- a/chrome/browser/internal_auth.cc +++ b/chrome/browser/internal_auth.cc @@ -16,7 +16,6 @@ #include "base/string_util.h" #include "base/threading/thread_checker.h" #include "base/time.h" -#include "base/timer.h" #include "base/values.h" #include "content/browser/browser_thread.h" #include "crypto/hmac.h" @@ -342,16 +341,7 @@ class InternalAuthGenerationService : public base::ThreadChecker { void GenerateNewKey() { DCHECK(CalledOnValidThread()); - if (!timer_.IsRunning()) { - timer_.Start(FROM_HERE, - base::TimeDelta::FromMicroseconds( - kKeyRegenerationSoftTicks * kTickUs), - this, - &InternalAuthGenerationService::GenerateNewKey); - } - - scoped_ptr<crypto::HMAC> new_engine( - new crypto::HMAC(crypto::HMAC::SHA256)); + scoped_ptr<crypto::HMAC> new_engine(new crypto::HMAC(crypto::HMAC::SHA256)); std::string key = base::RandBytesAsString(kKeySizeInBytes); if (!new_engine->Init(key)) return; @@ -374,8 +364,13 @@ class InternalAuthGenerationService : public base::ThreadChecker { int64 current_tick = GetCurrentTick(); if (!used_ticks_.empty() && used_ticks_.back() > current_tick) current_tick = used_ticks_.back(); - if (current_tick > key_regeneration_tick_ + kKeyRegenerationHardTicks) - return 0; + for (bool first_iteration = true;; first_iteration = false) { + if (current_tick < key_regeneration_tick_ + kKeyRegenerationHardTicks) + break; + if (!first_iteration) + return 0; + GenerateNewKey(); + } // Forget outdated ticks if any. used_ticks_.erase( @@ -426,7 +421,6 @@ class InternalAuthGenerationService : public base::ThreadChecker { } scoped_ptr<crypto::HMAC> engine_; - base::RepeatingTimer<InternalAuthGenerationService> timer_; int64 key_regeneration_tick_; std::deque<int64> used_ticks_; |