OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ est_handler.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ est_handler.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. h" | 12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. h" |
13 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" | 13 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" |
14 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | 14 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
15 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " | 15 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " |
16 #include "crypto/random.h" | 16 #include "crypto/random.h" |
17 #include "net/proxy/proxy_server.h" | 17 #include "net/proxy/proxy_server.h" |
18 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
20 | 20 |
21 namespace data_reduction_proxy { | 21 namespace data_reduction_proxy { |
22 | 22 |
23 // The version of the authentication protocol. | 23 // The empty version for the authentication protocol. Currently used by |
24 // android webview. | |
bengr
2014/08/01 16:05:18
Android
megjablon
2014/08/01 17:30:36
Done.
| |
24 const char kProtocolVersion[] = "0"; | 25 const char kProtocolVersion[] = "0"; |
25 | 26 |
26 // The clients supported by the data reduction proxy. | 27 // The clients supported by the data reduction proxy. |
27 const char kClientAndroidWebview[] = "webview"; | 28 const char kClientAndroidWebview[] = "webview"; |
28 const char kClientChromeAndroid[] = "android"; | 29 const char kClientChromeAndroid[] = "android"; |
29 const char kClientChromeIOS[] = "ios"; | 30 const char kClientChromeIOS[] = "ios"; |
30 | 31 |
31 // static | 32 // static |
32 bool DataReductionProxyAuthRequestHandler::IsKeySetOnCommandLine() { | 33 bool DataReductionProxyAuthRequestHandler::IsKeySetOnCommandLine() { |
33 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 34 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
34 return command_line.HasSwitch( | 35 return command_line.HasSwitch( |
35 data_reduction_proxy::switches::kDataReductionProxyKey); | 36 data_reduction_proxy::switches::kDataReductionProxyKey); |
36 } | 37 } |
37 | 38 |
38 DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler( | 39 DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler( |
40 const std::string& client, | |
41 const std::string& version, | |
39 DataReductionProxyParams* params) | 42 DataReductionProxyParams* params) |
40 : data_reduction_proxy_params_(params) { | 43 : data_reduction_proxy_params_(params) { |
41 version_ = kProtocolVersion; | 44 client_ = client; |
42 #if defined(OS_ANDROID) | 45 version_ = version; |
43 client_ = kClientChromeAndroid; | |
44 #elif defined(OS_IOS) | |
45 client_ = kClientChromeIOS; | |
46 #endif | |
47 Init(); | 46 Init(); |
48 } | 47 } |
49 | 48 |
50 void DataReductionProxyAuthRequestHandler::Init() { | 49 void DataReductionProxyAuthRequestHandler::Init() { |
51 InitAuthentication(GetDefaultKey()); | 50 InitAuthentication(GetDefaultKey()); |
52 } | 51 } |
53 | 52 |
54 | 53 |
55 DataReductionProxyAuthRequestHandler::~DataReductionProxyAuthRequestHandler() { | 54 DataReductionProxyAuthRequestHandler::~DataReductionProxyAuthRequestHandler() { |
56 } | 55 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 static_cast<long long>(timestamp), | 118 static_cast<long long>(timestamp), |
120 rand[0], | 119 rand[0], |
121 rand[1], | 120 rand[1], |
122 rand[2]); | 121 rand[2]); |
123 credentials_ = base::UTF16ToUTF8(AuthHashForSalt(timestamp, key_)); | 122 credentials_ = base::UTF16ToUTF8(AuthHashForSalt(timestamp, key_)); |
124 | 123 |
125 DVLOG(1) << "session: [" << session_ << "] " | 124 DVLOG(1) << "session: [" << session_ << "] " |
126 << "password: [" << credentials_ << "]"; | 125 << "password: [" << credentials_ << "]"; |
127 } | 126 } |
128 | 127 |
129 void DataReductionProxyAuthRequestHandler::SetKey(const std::string& key, | 128 void DataReductionProxyAuthRequestHandler::SetKey(const std::string& key) { |
130 const std::string& client, | |
131 const std::string& version) { | |
132 client_ = client; | |
133 version_ = version; | |
134 if (!key.empty()) | 129 if (!key.empty()) |
135 InitAuthentication(key); | 130 InitAuthentication(key); |
136 } | 131 } |
137 | 132 |
138 | 133 |
139 std::string DataReductionProxyAuthRequestHandler::GetDefaultKey() const { | 134 std::string DataReductionProxyAuthRequestHandler::GetDefaultKey() const { |
140 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 135 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
141 std::string key = | 136 std::string key = |
142 command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey); | 137 command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey); |
143 #if defined(SPDY_PROXY_AUTH_VALUE) | 138 #if defined(SPDY_PROXY_AUTH_VALUE) |
144 if (key.empty()) | 139 if (key.empty()) |
145 key = SPDY_PROXY_AUTH_VALUE; | 140 key = SPDY_PROXY_AUTH_VALUE; |
146 #endif | 141 #endif |
147 return key; | 142 return key; |
148 } | 143 } |
149 | 144 |
150 } // namespace data_reduction_proxy | 145 } // namespace data_reduction_proxy |
OLD | NEW |