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

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: errata 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);
38
34 virtual ~DataReductionProxyAuthRequestHandler(); 39 virtual ~DataReductionProxyAuthRequestHandler();
35 40
36 // Returns |PROCEED| if the authentication challenge provided is one that the 41 // Adds a 'Chrome-Proxy' header to |request_headers| with the data reduction
37 // data reduction proxy should handle and |IGNORE| if not. Returns |CANCEL| if 42 // proxy authentication credentials. Only adds this header if the provided
38 // there are a string of |MAX_BACK_TO_BACK_FAILURES| successive retries. 43 // |proxy_server| is a data reduction proxy.
39 TryHandleResult TryHandleAuthentication(net::AuthChallengeInfo* auth_info, 44 void MaybeAddRequestHeader(net::URLRequest* request,
40 base::string16* user, 45 const net::ProxyServer& proxy_server,
41 base::string16* password); 46 net::HttpRequestHeaders* request_headers);
47
48 // Sets a new authentication key. This must be called for platforms that do
49 // not have a default key defined. See the constructor implementation for
50 // those platforms. Client is the canonical name for the client. Client names
51 // should be defined in this file as one of |kClient...|. Version is the
52 // authentication protocol version that the client uses, which should be
53 // |kProtocolVersion| unless the client expects to be handled differently from
54 // the standard behavior.
55 void SetKey(const std::string& key,
56 const std::string& client,
57 const std::string& version);
42 58
43 protected: 59 protected:
60 void Init();
61 void InitAuthentication(const std::string& key);
62
63 void AddAuthorizationHeader(net::HttpRequestHeaders* headers);
64
65 // Returns a UTF16 string that's the hash of the configured authentication
66 // |key| and |salt|. Returns an empty UTF16 string if no key is configured or
67 // the data reduction proxy feature isn't available.
68 static base::string16 AuthHashForSalt(int64 salt,
69 const std::string& key);
44 // Visible for testing. 70 // Visible for testing.
45 virtual bool IsAcceptableAuthChallenge(net::AuthChallengeInfo* auth_info); 71 virtual base::Time Now() const;
72 virtual void RandBytes(void* output, size_t length);
46 73
47 // Visible for testing. 74 // Visible for testing.
48 virtual base::string16 GetTokenForAuthChallenge( 75 virtual std::string GetDefaultKey() const;
49 net::AuthChallengeInfo* auth_info);
50
51 // Visible for testing.
52 virtual base::TimeTicks Now();
53 76
54 private: 77 private:
55 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest, 78 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest,
56 CancelAfterSuccessiveAuthAttempts); 79 Authorization);
80 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyAuthRequestHandlerTest,
81 AuthHashForSalt);
57 82
83 // Authentication state.
84 std::string key_;
85 std::string session_;
86 std::string credentials_;
58 87
88 // Name of the client and version of the data reduction proxy protocol to use.
89 std::string client_;
90 std::string version_;
59 91
60 // System timestamp of the last data reduction proxy authentication request. 92 DataReductionProxyParams* data_reduction_proxy_params_;
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 93
78 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler); 94 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler);
79 }; 95 };
80 96
81 } // namespace data_reduction_proxy 97 } // namespace data_reduction_proxy
82 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ UEST_HANDLER_H_ 98 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ UEST_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698