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

Side by Side Diff: components/update_client/request_sender.h

Issue 1685323002: Implement CUP signing in UpdateClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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_UPDATE_CLIENT_REQUEST_SENDER_H_ 5 #ifndef COMPONENTS_UPDATE_CLIENT_REQUEST_SENDER_H_
6 #define COMPONENTS_UPDATE_CLIENT_REQUEST_SENDER_H_ 6 #define COMPONENTS_UPDATE_CLIENT_REQUEST_SENDER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "net/url_request/url_fetcher_delegate.h" 16 #include "net/url_request/url_fetcher_delegate.h"
17 #include "url/gurl.h" 17 #include "url/gurl.h"
18 18
19 namespace net { 19 namespace net {
20 class URLFetcher; 20 class URLFetcher;
21 } 21 }
22 22
23 namespace update_client { 23 namespace update_client {
24 24
25 class ClientUpdateProtocolEcdsa;
25 class Configurator; 26 class Configurator;
26 27
27 // Sends a request to one of the urls provided. The class implements a chain 28 // Sends a request to one of the urls provided. The class implements a chain
28 // of responsibility design pattern, where the urls are tried in the order they 29 // of responsibility design pattern, where the urls are tried in the order they
29 // are specified, until the request to one of them succeeds or all have failed. 30 // are specified, until the request to one of them succeeds or all have failed.
31 // CUP signing is optional.
30 class RequestSender : public net::URLFetcherDelegate { 32 class RequestSender : public net::URLFetcherDelegate {
31 public: 33 public:
32 // The |source| refers to the fetcher object used to make the request. This 34 // If |error| is 0, then the response is provided in the |response| parameter.
33 // parameter can be NULL in some error cases. 35 using RequestSenderCallback =
34 typedef base::Callback<void(const net::URLFetcher* source)> 36 base::Callback<void(int error, const std::string& response)>;
35 RequestSenderCallback; 37
38 // This value is chosen not to conflict with network errors defined by
39 // net/base/net_error_list.h. The callers don't have to handle this error in
40 // any meaningful way, but this value may be reported in UMA stats, therefore
41 // avoiding collisions with known network errors is desirable.
42 static int kErrorResponseNotTrusted;
36 43
37 explicit RequestSender(const scoped_refptr<Configurator>& config); 44 explicit RequestSender(const scoped_refptr<Configurator>& config);
38 ~RequestSender() override; 45 ~RequestSender() override;
39 46
40 void Send(const std::string& request_string, 47 // |use_signing| enables CUP signing of protocol messages exchanged using
48 // this class.
49 void Send(bool use_signing,
50 const std::string& request_body,
41 const std::vector<GURL>& urls, 51 const std::vector<GURL>& urls,
42 const RequestSenderCallback& request_sender_callback); 52 const RequestSenderCallback& request_sender_callback);
43 53
44 private: 54 private:
45 void SendInternal(); 55 // Combines the |url| and |query_params| parameters.
56 static GURL BuildUpdateUrl(const GURL& url, const std::string& query_params);
57
58 // Decodes and returns the public key used by CUP.
59 static std::string GetKey(const char* key_bytes_base64);
60
61 // Returns the Etag of the server response or an empty string if the
62 // Etag is not available.
63 static std::string GetServerETag(const net::URLFetcher* source);
46 64
47 // Overrides for URLFetcherDelegate. 65 // Overrides for URLFetcherDelegate.
48 void OnURLFetchComplete(const net::URLFetcher* source) override; 66 void OnURLFetchComplete(const net::URLFetcher* source) override;
49 67
50 const scoped_refptr<Configurator> config_; 68 // Implements the error handling and url fallback mechanism.
51 std::vector<GURL> urls_; 69 void SendInternal();
52 std::vector<GURL>::const_iterator cur_url_; 70
53 scoped_ptr<net::URLFetcher> url_fetcher_; 71 // Called when SendInternal complets. |response_body|and |response_etag|
54 std::string request_string_; 72 // contain the body and the etag associated with the HTTP response.
55 RequestSenderCallback request_sender_callback_; 73 void SendInternalComplete(int error,
74 const std::string& response_body,
75 const std::string& response_etag);
76
77 // Helper function to handle a non-continuable error in Send.
78 void HandleSendError(int error);
56 79
57 base::ThreadChecker thread_checker_; 80 base::ThreadChecker thread_checker_;
58 81
82 const scoped_refptr<Configurator> config_;
83 bool use_signing_;
84 std::vector<GURL> urls_;
85 std::string request_body_;
86 RequestSenderCallback request_sender_callback_;
87
88 std::string public_key_;
89 std::vector<GURL>::const_iterator cur_url_;
90 scoped_ptr<net::URLFetcher> url_fetcher_;
91 scoped_ptr<ClientUpdateProtocolEcdsa> signer_;
92
59 DISALLOW_COPY_AND_ASSIGN(RequestSender); 93 DISALLOW_COPY_AND_ASSIGN(RequestSender);
60 }; 94 };
61 95
62 } // namespace update_client 96 } // namespace update_client
63 97
64 #endif // COMPONENTS_UPDATE_CLIENT_REQUEST_SENDER_H_ 98 #endif // COMPONENTS_UPDATE_CLIENT_REQUEST_SENDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698