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 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUES
T_HANDLER_H_ | 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUES
T_HANDLER_H_ |
6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUES
T_HANDLER_H_ | 6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUES
T_HANDLER_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 extern const char kClientAndroidWebview[]; | 31 extern const char kClientAndroidWebview[]; |
32 extern const char kClientChromeAndroid[]; | 32 extern const char kClientChromeAndroid[]; |
33 extern const char kClientChromeIOS[]; | 33 extern const char kClientChromeIOS[]; |
34 | 34 |
35 class DataReductionProxyParams; | 35 class DataReductionProxyParams; |
36 | 36 |
37 class DataReductionProxyAuthRequestHandler { | 37 class DataReductionProxyAuthRequestHandler { |
38 public: | 38 public: |
39 static bool IsKeySetOnCommandLine(); | 39 static bool IsKeySetOnCommandLine(); |
40 | 40 |
| 41 // Constructs a DataReductionProxyAuthRequestHandler object with the given |
| 42 // client, version, params, and network task runner. The Chromium |version| is |
| 43 // expected to be of the form "xx.xx.xx.xx". If it isn't of this form, |
| 44 // |build_number_| and |patch_number_| are set to empty strings and not |
| 45 // included in the header. http://crbug.com/410127 will change this so that |
| 46 // the version is retrieved inside this constructor. |
41 DataReductionProxyAuthRequestHandler( | 47 DataReductionProxyAuthRequestHandler( |
42 const std::string& client, | 48 const std::string& client, |
43 const std::string& version, | 49 const std::string& version, |
44 DataReductionProxyParams* params, | 50 DataReductionProxyParams* params, |
45 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner); | 51 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner); |
46 | 52 |
47 virtual ~DataReductionProxyAuthRequestHandler(); | 53 virtual ~DataReductionProxyAuthRequestHandler(); |
48 | 54 |
49 // Adds a 'Chrome-Proxy' header to |request_headers| with the data reduction | 55 // Adds a 'Chrome-Proxy' header to |request_headers| with the data reduction |
50 // proxy authentication credentials. Only adds this header if the provided | 56 // proxy authentication credentials. Only adds this header if the provided |
(...skipping 22 matching lines...) Expand all Loading... |
73 virtual base::Time Now() const; | 79 virtual base::Time Now() const; |
74 virtual void RandBytes(void* output, size_t length); | 80 virtual void RandBytes(void* output, size_t length); |
75 | 81 |
76 // Visible for testing. | 82 // Visible for testing. |
77 virtual std::string GetDefaultKey() const; | 83 virtual std::string GetDefaultKey() const; |
78 | 84 |
79 private: | 85 private: |
80 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, | 86 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, |
81 Authorization); | 87 Authorization); |
82 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, | 88 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, |
| 89 AuthorizationBogusVersion); |
| 90 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, |
83 AuthHashForSalt); | 91 AuthHashForSalt); |
84 | 92 |
| 93 // Returns the number at |index| of |version|. If |version| isn't of the form |
| 94 // xx.xx.xx.xx returns an empty string. |
| 95 std::string GetChromiumVersionComponent(std::string version, int index); |
| 96 |
85 // Stores the supplied key and sets up credentials suitable for authenticating | 97 // Stores the supplied key and sets up credentials suitable for authenticating |
86 // with the data reduction proxy. | 98 // with the data reduction proxy. |
87 void InitAuthentication(const std::string& key); | 99 void InitAuthentication(const std::string& key); |
88 | 100 |
89 // Generates a session ID and credentials suitable for authenticating with | 101 // Generates a session ID and credentials suitable for authenticating with |
90 // the data reduction proxy. | 102 // the data reduction proxy. |
91 void ComputeCredentials(const base::Time& now, | 103 void ComputeCredentials(const base::Time& now, |
92 std::string* session, | 104 std::string* session, |
93 std::string* credentials); | 105 std::string* credentials); |
94 | 106 |
95 // Authentication state. | 107 // Authentication state. |
96 std::string key_; | 108 std::string key_; |
97 | 109 |
98 // Lives on the IO thread. | 110 // Lives on the IO thread. |
99 std::string session_; | 111 std::string session_; |
100 std::string credentials_; | 112 std::string credentials_; |
101 | 113 |
102 // Name of the client and version of the data reduction proxy protocol to use. | 114 // Name of the client and version of the data reduction proxy protocol to use. |
103 // Both live on the IO thread. | 115 // Both live on the IO thread. |
104 std::string client_; | 116 std::string client_; |
105 std::string version_; | 117 std::string build_number_; |
| 118 std::string patch_number_; |
106 | 119 |
107 // The last time the session was updated. Used to ensure that a session is | 120 // The last time the session was updated. Used to ensure that a session is |
108 // never used for more than twenty-four hours. | 121 // never used for more than twenty-four hours. |
109 base::Time last_update_time_; | 122 base::Time last_update_time_; |
110 | 123 |
111 DataReductionProxyParams* data_reduction_proxy_params_; | 124 DataReductionProxyParams* data_reduction_proxy_params_; |
112 | 125 |
113 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 126 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
114 | 127 |
115 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler); | 128 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler); |
116 }; | 129 }; |
117 | 130 |
118 } // namespace data_reduction_proxy | 131 } // namespace data_reduction_proxy |
119 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ
UEST_HANDLER_H_ | 132 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ
UEST_HANDLER_H_ |
OLD | NEW |