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

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 review comments 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"
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 {
(...skipping 20 matching lines...) Expand all
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() override;
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
86 // Fetch a consistency proof between the Merkle trees identified by
87 // |old_tree_size| and |new_tree_size| of the log identified by |log_id|
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 size_t old_tree_size,
96 size_t new_tree_size,
97 const ConsistencyProofFetchedCallback& fetched_callback,
98 const FetchFailedCallback& failed_callback);
99
76 // net::URLRequest::Delegate 100 // net::URLRequest::Delegate
77 void OnResponseStarted(net::URLRequest* request) override; 101 void OnResponseStarted(net::URLRequest* request) override;
78 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; 102 void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
79 103
80 private: 104 private:
81 struct FetchState; 105 struct FetchState;
82 // Handles the final result of a URLRequest::Read call on |request|. 106 // Handles the final result of a URLRequest::Read call on |request|.
83 // Returns true if another read should be started, false if the read 107 // Returns true if another read should be started, false if the read
84 // failed completely or we have to wait for OnResponseStarted to 108 // failed completely or we have to wait for OnResponseStarted to
85 // be called. 109 // be called.
(...skipping 14 matching lines...) Expand all
100 // the request. 124 // the request.
101 void InvokeFailureCallback(net::URLRequest* request, 125 void InvokeFailureCallback(net::URLRequest* request,
102 int net_error, 126 int net_error,
103 int http_response_code); 127 int http_response_code);
104 128
105 // Callbacks for parsing the STH's JSON by the SafeJsonParser 129 // Callbacks for parsing the STH's JSON by the SafeJsonParser
106 void OnSTHJsonParseSuccess(net::URLRequest* request, 130 void OnSTHJsonParseSuccess(net::URLRequest* request,
107 scoped_ptr<base::Value> parsed_json); 131 scoped_ptr<base::Value> parsed_json);
108 void OnSTHJsonParseError(net::URLRequest* request, const std::string& error); 132 void OnSTHJsonParseError(net::URLRequest* request, const std::string& error);
109 133
134 // Callbacks for parsing the consistency proof's JSON by the SafeJsonParser
135 void OnConsistencyProofJsonParseSuccess(net::URLRequest* request,
136 scoped_ptr<base::Value> parsed_json);
137 void OnConsistencyProofJsonParseError(net::URLRequest* request,
138 const std::string& error);
139
140 // Creates a new request with the right flags for log requests.
Ryan Sleevi 2015/11/26 00:50:09 "with the right flags" is not very clear/helpful.
Eran Messeri 2015/11/26 22:07:13 Done - completely changed the documentation as thi
141 void FetchFromLog(
142 const GURL& request_url,
143 const std::string& log_id,
144 const SignedTreeHeadFetchedCallback& sth_fetched_callback,
145 const ConsistencyProofFetchedCallback& proof_fetched_callback,
146 const FetchFailedCallback& failed_callback);
147
110 net::URLRequestContext* const request_context_; 148 net::URLRequestContext* const request_context_;
111 149
112 // Owns the contained requests, as well as FetchState. 150 // Owns the contained requests, as well as FetchState.
113 std::map<net::URLRequest*, FetchState*> inflight_requests_; 151 std::map<net::URLRequest*, FetchState*> inflight_requests_;
114 152
115 base::WeakPtrFactory<LogProofFetcher> weak_factory_; 153 base::WeakPtrFactory<LogProofFetcher> weak_factory_;
116 154
117 DISALLOW_COPY_AND_ASSIGN(LogProofFetcher); 155 DISALLOW_COPY_AND_ASSIGN(LogProofFetcher);
118 }; 156 };
119 157
120 } // namespace certificate_transparency 158 } // namespace certificate_transparency
121 159
122 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ 160 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698