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

Side by Side Diff: components/certificate_transparency/log_proof_fetcher.h

Issue 1405293009: Certificate Transparency: Fetching consistency proofs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing forgotten review comment. Created 5 years 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ 5 #ifndef COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_
6 #define COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ 6 #define COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector>
10 11
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "net/url_request/url_request.h" 16 #include "net/url_request/url_request.h"
17 #include "url/gurl.h"
Ryan Sleevi 2015/12/08 01:13:52 You don't need this; Alternatively, delete line 3
Eran Messeri 2015/12/14 13:01:42 Done.
16 18
17 namespace base { 19 namespace base {
18 class Value; 20 class Value;
19 } // namespace base 21 } // namespace base
20 22
21 namespace net { 23 namespace net {
22 24
23 class URLRequestContext; 25 class URLRequestContext;
24 26
25 namespace ct { 27 namespace ct {
26 struct SignedTreeHead; 28 struct SignedTreeHead;
27 } // namespace ct 29 } // namespace ct
28 30
29 } // namespace net 31 } // namespace net
30 32
31 class GURL; 33 class GURL;
32 34
33 namespace certificate_transparency { 35 namespace certificate_transparency {
34 36
35 // Fetches Signed Tree Heads (STHs) and consistency proofs from Certificate 37 // Fetches Signed Tree Heads (STHs) and consistency proofs from Certificate
36 // Transparency logs using the URLRequestContext provided during the instance 38 // Transparency logs using the URLRequestContext provided during the instance
37 // construction. 39 // construction.
38 // Must outlive the provided URLRequestContext. 40 // Must outlive the provided URLRequestContext.
39 class LogProofFetcher : public net::URLRequest::Delegate { 41 class LogProofFetcher {
40 public: 42 public:
41 static const size_t kMaxLogResponseSizeInBytes = 600; 43 static const size_t kMaxLogResponseSizeInBytes = 600;
42 44
43 // Callback for successful retrieval of Signed Tree Heads. Called 45 // Callback for successful retrieval of Signed Tree Heads. Called
44 // with the log_id of the log the STH belogs to (as supplied by the caller 46 // with the log_id of the log the STH belogs to (as supplied by the caller
45 // to FetchSignedTreeHead) and the STH itself. 47 // to FetchSignedTreeHead) and the STH itself.
46 using SignedTreeHeadFetchedCallback = 48 using SignedTreeHeadFetchedCallback =
47 base::Callback<void(const std::string& log_id, 49 base::Callback<void(const std::string& log_id,
48 const net::ct::SignedTreeHead& signed_tree_head)>; 50 const net::ct::SignedTreeHead& signed_tree_head)>;
49 51
50 // Callback for failure of Signed Tree Head retrieval. Called with the log_id 52 // Callback for failure of Signed Tree Head retrieval. Called with the log_id
51 // that the log fetching was requested for and a net error code of the 53 // that the log fetching was requested for and a net error code of the
52 // failure. 54 // failure.
53 using FetchFailedCallback = base::Callback< 55 using FetchFailedCallback = base::Callback<
54 void(const std::string& log_id, int net_error, int http_response_code)>; 56 void(const std::string& log_id, int net_error, int http_response_code)>;
55 57
58 // Callback for successful retrieval of consistency proofs between two
59 // STHs. Called with the log_id of the log the consistency belongs to (as
60 // supplied by the caller to FetchConsistencyProof) and the vector of
61 // proof nodes.
62 using ConsistencyProofFetchedCallback =
63 base::Callback<void(const std::string& log_id,
64 const std::vector<std::string>& consistency_proof)>;
65
56 explicit LogProofFetcher(net::URLRequestContext* request_context); 66 explicit LogProofFetcher(net::URLRequestContext* request_context);
57 ~LogProofFetcher() override; 67 ~LogProofFetcher();
58 68
59 // Fetch the latest Signed Tree Head from the log identified by |log_id| 69 // Fetch the latest Signed Tree Head from the log identified by |log_id|
60 // from |base_log_url|. The |log_id| will be passed into the callbacks to 70 // from |base_log_url|. The |log_id| will be passed into the callbacks to
61 // identify the log the retrieved Signed Tree Head belongs to. 71 // identify the log the retrieved Signed Tree Head belongs to.
62 // The callbacks won't be invoked if the request is destroyed before 72 // The callbacks won't be invoked if the request is destroyed before
63 // fetching is completed. 73 // fetching is completed.
64 // It is possible, but does not make a lot of sense, to have multiple 74 // It is possible, but does not make a lot of sense, to have multiple
65 // Signed Tree Head fetching requests going out to the same log, since 75 // Signed Tree Head fetching requests going out to the same log, since
66 // they are likely to return the same result. 76 // they are likely to return the same result.
67 // TODO(eranm): Think further about whether multiple requests to the same 77 // TODO(eranm): Think further about whether multiple requests to the same
68 // log imply cancellation of previous requests, should be coalesced or handled 78 // log imply cancellation of previous requests, should be coalesced or handled
69 // independently. 79 // independently.
70 void FetchSignedTreeHead( 80 void FetchSignedTreeHead(
71 const GURL& base_log_url, 81 const GURL& base_log_url,
72 const std::string& log_id, 82 const std::string& log_id,
73 const SignedTreeHeadFetchedCallback& fetched_callback, 83 const SignedTreeHeadFetchedCallback& fetched_callback,
74 const FetchFailedCallback& failed_callback); 84 const FetchFailedCallback& failed_callback);
75 85
76 // net::URLRequest::Delegate 86 // Fetch a consistency proof between the Merkle trees identified by
77 void OnResponseStarted(net::URLRequest* request) override; 87 // |old_tree_size| and |new_tree_size| of the log identified by |log_id|
78 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; 88 // from |base_log_url|.
89 //
90 // See the documentation of FetchSignedTreeHead regarding request destruction
91 // and multiple requests to the same log.
92 void FetchConsistencyProof(
93 const GURL& base_log_url,
94 const std::string& log_id,
95 uint64_t old_tree_size,
96 uint64_t new_tree_size,
97 const ConsistencyProofFetchedCallback& fetched_callback,
98 const FetchFailedCallback& failed_callback);
79 99
80 private: 100 private:
81 struct FetchState; 101 class LogResponseHandler;
82 // Handles the final result of a URLRequest::Read call on |request|. 102 class GetSTHLogResponseHandler;
83 // Returns true if another read should be started, false if the read 103 class GetConsistencyProofLogResponseHandler;
84 // failed completely or we have to wait for OnResponseStarted to 104 class LogFetcher;
85 // be called.
86 bool HandleReadResult(net::URLRequest* request,
87 FetchState* params,
88 int bytes_read);
89 105
90 // Calls URLRequest::Read on |request| repeatedly, until HandleReadResult 106 // Creates and stores a LogFetcher, which takes care of fetching
91 // indicates it should no longer be called. Usually this would be when there 107 // and assembling the CT log's response to a single request.
92 // is pending IO that requires waiting for OnResponseStarted to be called. 108 // The created LogFetcher, as well as |log_handler| will be stored
93 void StartNextRead(net::URLRequest* request, FetchState* params); 109 // in the map for later cleanup.
110 void StartFetch(const GURL& request_url, LogResponseHandler* log_handler);
94 111
95 // Performs post-report cleanup. 112 // Callbacks for handling the fetch result. Invoked by the LogFetcher.
96 void RequestComplete(net::URLRequest* request); 113 void OnFetchCompleted(LogFetcher* fetcher);
97 // Deletes the request and associated FetchState from the internal map. 114 void OnFetchFailed(LogFetcher* fetcher,
98 void CleanupRequest(net::URLRequest* request); 115 int net_error,
99 // Invokes the failure callback with the supplied arguments, then cleans up 116 int http_response_code);
100 // the request.
101 void InvokeFailureCallback(net::URLRequest* request,
102 int net_error,
103 int http_response_code);
104 117
105 // Callbacks for parsing the STH's JSON by the SafeJsonParser 118 // Callbacks for parsing the response JSON by the SafeJsonParser
106 void OnSTHJsonParseSuccess(net::URLRequest* request, 119 void OnJsonParseSuccess(LogFetcher* fetcher,
107 scoped_ptr<base::Value> parsed_json); 120 scoped_ptr<base::Value> parsed_json);
108 void OnSTHJsonParseError(net::URLRequest* request, const std::string& error); 121 void OnJsonParseError(LogFetcher* fetcher, const std::string& error);
122
123 // Deletes, and removes, the |fetcher| and associated LogResponseHandler
124 // from the |inflight_fetches_| map.
125 void CleanupRequest(LogFetcher* fetcher);
109 126
110 net::URLRequestContext* const request_context_; 127 net::URLRequestContext* const request_context_;
111 128
112 // Owns the contained requests, as well as FetchState. 129 std::map<LogFetcher*, LogResponseHandler*> inflight_fetches_;
mmenke 2015/12/08 17:10:12 I still think you should have the handler own the
Eran Messeri 2015/12/14 13:01:42 Done - now the LogProofFetcher has a set of LogRes
113 std::map<net::URLRequest*, FetchState*> inflight_requests_;
114 130
115 base::WeakPtrFactory<LogProofFetcher> weak_factory_; 131 base::WeakPtrFactory<LogProofFetcher> weak_factory_;
116 132
117 DISALLOW_COPY_AND_ASSIGN(LogProofFetcher); 133 DISALLOW_COPY_AND_ASSIGN(LogProofFetcher);
118 }; 134 };
119 135
120 } // namespace certificate_transparency 136 } // namespace certificate_transparency
121 137
122 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ 138 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698