Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1333)

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h

Issue 333113002: Move data reduction proxy to Chrome-Proxy header for authentication (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@flywheel-refactor-net-fake-a-redirect-response-headers-chrome-proxy-auth
Patch Set: Added auth support to Android Webview Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/strings/string16.h" 10 #include "base/strings/string16.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" 12 #include "url/gurl.h"
12
13 13
14 namespace net { 14 namespace net {
15 class AuthChallengeInfo; 15 class HttpRequestHeaders;
16 class HttpResponseHeaders;
17 class ProxyServer;
18 class URLRequest;
16 } 19 }
17 20
18 namespace data_reduction_proxy { 21 namespace data_reduction_proxy {
19 22
20 class DataReductionProxySettings; 23 extern const char kProtocolVersion[];
24
25 extern const char kClientAndroidWebview[];
26 extern const char kClientChromeAndroid[];
27 extern const char kClientChromeIOS[];
28
29 class DataReductionProxyParams;
21 30
22 class DataReductionProxyAuthRequestHandler { 31 class DataReductionProxyAuthRequestHandler {
23 public: 32 public:
24 enum TryHandleResult { 33 static bool IsKeySetOnCommandLine();
25 TRY_HANDLE_RESULT_IGNORE,
26 TRY_HANDLE_RESULT_PROCEED,
27 TRY_HANDLE_RESULT_CANCEL
28 };
29 34
30 // Constructs an authentication request handler and takes a pointer to a 35 // Constructs an authentication request handler.
31 // |settings| object, which must outlive the handler.
32 explicit DataReductionProxyAuthRequestHandler( 36 explicit DataReductionProxyAuthRequestHandler(
33 DataReductionProxySettings* settings); 37 DataReductionProxyParams* params);
34 virtual ~DataReductionProxyAuthRequestHandler(); 38 virtual ~DataReductionProxyAuthRequestHandler();
35 39
36 // Returns |PROCEED| if the authentication challenge provided is one that the 40 void MaybeAddRequestHeader(net::URLRequest* request,
marq (ping after 24h) 2014/06/25 16:39:27 All methods in public header files must have comme
bengr 2014/06/25 17:15:19 Done.
37 // data reduction proxy should handle and |IGNORE| if not. Returns |CANCEL| if 41 const net::ProxyServer& proxy_server,
38 // there are a string of |MAX_BACK_TO_BACK_FAILURES| successive retries. 42 net::HttpRequestHeaders* request_headers);
39 TryHandleResult TryHandleAuthentication(net::AuthChallengeInfo* auth_info, 43
40 base::string16* user, 44 void SetKey(const std::string& key,
41 base::string16* password); 45 const std::string& client,
46 const std::string& version);
42 47
43 protected: 48 protected:
49 void Init();
50 void InitAuthentication(const std::string& key);
51
52 void AddAuthorizationHeader(net::HttpRequestHeaders* headers);
53
54 // Returns a UTF16 string that's the hash of the configured authentication
55 // |key| and |salt|. Returns an empty UTF16 string if no key is configured or
56 // the data reduction proxy feature isn't available.
57 static base::string16 AuthHashForSalt(int64 salt,
58 const std::string& key);
44 // Visible for testing. 59 // Visible for testing.
45 virtual bool IsAcceptableAuthChallenge(net::AuthChallengeInfo* auth_info); 60 virtual base::Time Now() const;
61 virtual void RandBytes(void* output, size_t length);
46 62
47 // Visible for testing. 63 // Visible for testing.
48 virtual base::string16 GetTokenForAuthChallenge( 64 virtual std::string GetDefaultKey() const;
49 net::AuthChallengeInfo* auth_info);
50
51 // Visible for testing.
52 virtual base::TimeTicks Now();
53 65
54 private: 66 private:
55 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, 67 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest,
56 CancelAfterSuccessiveAuthAttempts); 68 Authorization);
69 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest,
70 AuthHashForSalt);
57 71
72 // Authentication state.
73 std::string key_;
74 std::string session_;
75 std::string credentials_;
76 std::string client_;
marq (ping after 24h) 2014/06/25 16:39:27 From reading the .cc, client_ is a string identify
bengr 2014/06/25 17:15:19 Done. Client can be things other than an OS, e.g.
77 std::string version_;
58 78
59 79 DataReductionProxyParams* data_reduction_proxy_params_;
60 // System timestamp of the last data reduction proxy authentication request.
61 // This is used to cancel data reduction proxy auth requests that are denied
62 // rather than loop forever trying a rejected token.
63 static int64 auth_request_timestamp_;
64
65 // The number of back to back data reduction proxy authentication failures
66 // that occurred with no more than |MIN_AUTH_REQUEST_INTERVAL_MS| between each
67 // adjacent pair of them.
68 static int back_to_back_failure_count_;
69
70 // System timestamp of the last data reduction proxy auth token invalidation.
71 // This is used to expire old tokens on back-to-back failures, and distinguish
72 // invalidation from repeat failures due to the client not being authorized.
73 static int64 auth_token_invalidation_timestamp_;
74
75 // Settings object for the data reduction proxy. Must outlive the handler.
76 DataReductionProxySettings* settings_;
77 80
78 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler); 81 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler);
79 }; 82 };
80 83
81 } // namespace data_reduction_proxy 84 } // namespace data_reduction_proxy
82 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ UEST_HANDLER_H_ 85 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ UEST_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698