From e234b11aee841dcce3a9c48ed62883669a2259da Mon Sep 17 00:00:00 2001 From: "dilmah@chromium.org" Date: Tue, 13 Sep 2011 10:10:29 +0000 Subject: 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 --- chrome/browser/internal_auth.cc | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'chrome/browser/internal_auth.cc') 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 new_engine( - new crypto::HMAC(crypto::HMAC::SHA256)); + scoped_ptr 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 engine_; - base::RepeatingTimer timer_; int64 key_regeneration_tick_; std::deque used_ticks_; -- cgit v1.1