Index: components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc |
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc |
index 3683936cce8a3e252dbc531e5bcbabdfc7c27a17..ae9b1ff007c1c03e6fbeb6fe760dfd807e9f246e 100644 |
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc |
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_settings.cc |
@@ -67,7 +67,6 @@ int64 GetInt64PrefValue(const base::ListValue& list_value, size_t index) { |
namespace data_reduction_proxy { |
-std::string DataReductionProxySettings::key_; |
bool DataReductionProxySettings::allowed_; |
bool DataReductionProxySettings::promo_allowed_; |
@@ -93,11 +92,6 @@ bool DataReductionProxySettings::IsIncludedInFieldTrialOrFlags() { |
} |
// static |
-void DataReductionProxySettings::SetKey(const std::string& key) { |
- key_ = key; |
-} |
- |
-// static |
void DataReductionProxySettings::SetAllowed(bool allowed) { |
allowed_ = allowed; |
} |
@@ -108,7 +102,8 @@ void DataReductionProxySettings::SetPromoAllowed(bool promo_allowed) { |
} |
DataReductionProxySettings::DataReductionProxySettings() |
- : restricted_by_carrier_(false), |
+ : key_(), |
mmenke
2014/05/09 15:27:08
nit: Initializer not needed.
bengr
2014/05/09 15:47:28
Done.
|
+ restricted_by_carrier_(false), |
enabled_by_user_(false), |
prefs_(NULL), |
local_state_prefs_(NULL), |
@@ -121,6 +116,15 @@ DataReductionProxySettings::~DataReductionProxySettings() { |
spdy_proxy_auth_enabled_.Destroy(); |
} |
+void DataReductionProxySettings::set_key(const std::string& key) { |
+ key_ = key; |
+} |
+ |
+std::string DataReductionProxySettings::key() { |
+ return key_; |
+} |
+ |
+ |
mmenke
2014/05/09 15:27:08
nit: Remove extra blank line.
bengr
2014/05/09 15:47:28
I inlined.
|
void DataReductionProxySettings::InitPrefMembers() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
spdy_proxy_auth_enabled_.Init( |
@@ -174,7 +178,8 @@ void DataReductionProxySettings::SetProxyConfigurator( |
// static |
void DataReductionProxySettings::InitDataReductionProxySession( |
- net::HttpNetworkSession* session) { |
+ net::HttpNetworkSession* session, |
+ const std::string& key) { |
// This is a no-op unless the authentication parameters are compiled in. |
// (even though values for them may be specified on the command line). |
// Authentication will still work if the command line parameters are used, |
@@ -182,17 +187,18 @@ void DataReductionProxySettings::InitDataReductionProxySession( |
// (typically once per session). |
// TODO(bengr):Pass a configuration struct into DataReductionProxyConfigurator's |
// constructor. The struct would carry everything in the preprocessor flags. |
- if (key_.empty()) |
+ if (key.empty()) |
return; |
DCHECK(session); |
net::HttpAuthCache* auth_cache = session->http_auth_cache(); |
DCHECK(auth_cache); |
- InitDataReductionAuthentication(auth_cache); |
+ InitDataReductionAuthentication(auth_cache, key); |
} |
// static |
void DataReductionProxySettings::InitDataReductionAuthentication( |
- net::HttpAuthCache* auth_cache) { |
+ net::HttpAuthCache* auth_cache, |
+ const std::string& key) { |
DCHECK(auth_cache); |
int64 timestamp = |
(base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds() / 1000; |
@@ -215,7 +221,7 @@ void DataReductionProxySettings::InitDataReductionAuthentication( |
rand[0], |
rand[1], |
rand[2]); |
- base::string16 password = AuthHashForSalt(timestamp); |
+ base::string16 password = AuthHashForSalt(timestamp, key); |
DVLOG(1) << "origin: [" << auth_origin << "] realm: [" << realm |
<< "] challenge: [" << challenge << "] password: [" << password << "]"; |
@@ -310,7 +316,6 @@ bool DataReductionProxySettings::IsAcceptableAuthChallenge( |
return false; |
} |
-// static |
base::string16 DataReductionProxySettings::GetTokenForAuthChallenge( |
net::AuthChallengeInfo* auth_info) { |
if (auth_info->realm.length() > strlen(kAuthenticationRealmName)) { |
@@ -318,7 +323,7 @@ base::string16 DataReductionProxySettings::GetTokenForAuthChallenge( |
std::string realm_suffix = |
auth_info->realm.substr(strlen(kAuthenticationRealmName)); |
if (base::StringToInt64(realm_suffix, &salt)) { |
- return AuthHashForSalt(salt); |
+ return AuthHashForSalt(salt, key_); |
} else { |
DVLOG(1) << "Unable to parse realm name " << auth_info->realm |
<< "into an int for salting."; |
@@ -652,11 +657,10 @@ std::string DataReductionProxySettings::GetProxyCheckURL() { |
} |
// static |
-base::string16 DataReductionProxySettings::AuthHashForSalt(int64 salt) { |
- if (!IsDataReductionProxyAllowed()) |
- return base::string16(); |
- |
- std::string key; |
+base::string16 DataReductionProxySettings::AuthHashForSalt( |
+ int64 salt, |
+ const std::string& key) { |
+ std::string active_key; |
const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
if (command_line.HasSwitch(switches::kDataReductionProxy)) { |
@@ -665,17 +669,17 @@ base::string16 DataReductionProxySettings::AuthHashForSalt(int64 salt) { |
// Don't expose |key_| to a proxy passed in via the command line. |
if (!command_line.HasSwitch(switches::kDataReductionProxyKey)) |
return base::string16(); |
- key = command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey); |
+ active_key = command_line.GetSwitchValueASCII( |
+ switches::kDataReductionProxyKey); |
} else { |
- key = key_; |
+ active_key = key; |
} |
- |
- DCHECK(!key.empty()); |
+ DCHECK(!active_key.empty()); |
std::string salted_key = |
base::StringPrintf("%lld%s%lld", |
static_cast<long long>(salt), |
- key.c_str(), |
+ active_key.c_str(), |
static_cast<long long>(salt)); |
return base::UTF8ToUTF16(base::MD5String(salted_key)); |
} |