OLD | NEW |
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 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 using SignedTreeHeadFetchedCallback = | 46 using SignedTreeHeadFetchedCallback = |
47 base::Callback<void(const std::string& log_id, | 47 base::Callback<void(const std::string& log_id, |
48 const net::ct::SignedTreeHead& signed_tree_head)>; | 48 const net::ct::SignedTreeHead& signed_tree_head)>; |
49 | 49 |
50 // Callback for failure of Signed Tree Head retrieval. Called with the log_id | 50 // 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 | 51 // that the log fetching was requested for and a net error code of the |
52 // failure. | 52 // failure. |
53 using FetchFailedCallback = base::Callback< | 53 using FetchFailedCallback = base::Callback< |
54 void(const std::string& log_id, int net_error, int http_response_code)>; | 54 void(const std::string& log_id, int net_error, int http_response_code)>; |
55 | 55 |
| 56 // Callback for successful retrieval of consistency proofs between two |
| 57 // STHs. Called with the log_id of the log the consistency belongs to (as |
| 58 // supplied by the caller to FetchConsistencyProof) and the vector of |
| 59 // proof nodes. |
| 60 using ConsistencyProofFetchedCallback = |
| 61 base::Callback<void(const std::string& log_id, |
| 62 const std::vector<std::string>& consistency_proof)>; |
| 63 |
56 explicit LogProofFetcher(net::URLRequestContext* request_context); | 64 explicit LogProofFetcher(net::URLRequestContext* request_context); |
57 ~LogProofFetcher() override; | 65 ~LogProofFetcher() override; |
58 | 66 |
59 // Fetch the latest Signed Tree Head from the log identified by |log_id| | 67 // 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 | 68 // 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. | 69 // identify the log the retrieved Signed Tree Head belongs to. |
62 // The callbacks won't be invoked if the request is destroyed before | 70 // The callbacks won't be invoked if the request is destroyed before |
63 // fetching is completed. | 71 // fetching is completed. |
64 // It is possible, but does not make a lot of sense, to have multiple | 72 // 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 | 73 // Signed Tree Head fetching requests going out to the same log, since |
66 // they are likely to return the same result. | 74 // they are likely to return the same result. |
67 // TODO(eranm): Think further about whether multiple requests to the same | 75 // TODO(eranm): Think further about whether multiple requests to the same |
68 // log imply cancellation of previous requests, should be coalesced or handled | 76 // log imply cancellation of previous requests, should be coalesced or handled |
69 // independently. | 77 // independently. |
70 void FetchSignedTreeHead( | 78 void FetchSignedTreeHead( |
71 const GURL& base_log_url, | 79 const GURL& base_log_url, |
72 const std::string& log_id, | 80 const std::string& log_id, |
73 const SignedTreeHeadFetchedCallback& fetched_callback, | 81 const SignedTreeHeadFetchedCallback& fetched_callback, |
74 const FetchFailedCallback& failed_callback); | 82 const FetchFailedCallback& failed_callback); |
75 | 83 |
| 84 // Fetch a consistency proof between the Merkle trees identified by |
| 85 // |old_tree_size| and |new_tree_size| of the log identified by |log_id| |
| 86 // from |base_log_url|. |
| 87 // |
| 88 // See the documentation of FetchSignedTreeHead regarding request destruction |
| 89 // and multiple requests to the same log. |
| 90 void FetchConsistencyProof( |
| 91 const GURL& base_log_url, |
| 92 const std::string& log_id, |
| 93 size_t old_tree_size, |
| 94 size_t new_tree_size, |
| 95 const ConsistencyProofFetchedCallback& fetched_callback, |
| 96 const FetchFailedCallback& failed_callback); |
| 97 |
76 // net::URLRequest::Delegate | 98 // net::URLRequest::Delegate |
77 void OnResponseStarted(net::URLRequest* request) override; | 99 void OnResponseStarted(net::URLRequest* request) override; |
78 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | 100 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
79 | 101 |
80 private: | 102 private: |
81 struct FetchState; | 103 struct FetchState; |
82 // Handles the final result of a URLRequest::Read call on |request|. | 104 // Handles the final result of a URLRequest::Read call on |request|. |
83 // Returns true if another read should be started, false if the read | 105 // Returns true if another read should be started, false if the read |
84 // failed completely or we have to wait for OnResponseStarted to | 106 // failed completely or we have to wait for OnResponseStarted to |
85 // be called. | 107 // be called. |
(...skipping 14 matching lines...) Expand all Loading... |
100 // the request. | 122 // the request. |
101 void InvokeFailureCallback(net::URLRequest* request, | 123 void InvokeFailureCallback(net::URLRequest* request, |
102 int net_error, | 124 int net_error, |
103 int http_response_code); | 125 int http_response_code); |
104 | 126 |
105 // Callbacks for parsing the STH's JSON by the SafeJsonParser | 127 // Callbacks for parsing the STH's JSON by the SafeJsonParser |
106 void OnSTHJsonParseSuccess(net::URLRequest* request, | 128 void OnSTHJsonParseSuccess(net::URLRequest* request, |
107 scoped_ptr<base::Value> parsed_json); | 129 scoped_ptr<base::Value> parsed_json); |
108 void OnSTHJsonParseError(net::URLRequest* request, const std::string& error); | 130 void OnSTHJsonParseError(net::URLRequest* request, const std::string& error); |
109 | 131 |
| 132 // Callbacks for parsing the consistency proof's JSON by the SafeJsonParser |
| 133 void OnConsistencyProofJsonParseSuccess(net::URLRequest* request, |
| 134 scoped_ptr<base::Value> parsed_json); |
| 135 void OnConsistencyProofJsonParseError(net::URLRequest* request, |
| 136 const std::string& error); |
| 137 |
| 138 // Creates a new URLRequest with the right flags for log requests. |
| 139 net::URLRequest* CreateRequest(const GURL& url); |
| 140 |
110 net::URLRequestContext* const request_context_; | 141 net::URLRequestContext* const request_context_; |
111 | 142 |
112 // Owns the contained requests, as well as FetchState. | 143 // Owns the contained requests, as well as FetchState. |
113 std::map<net::URLRequest*, FetchState*> inflight_requests_; | 144 std::map<net::URLRequest*, FetchState*> inflight_requests_; |
114 | 145 |
115 base::WeakPtrFactory<LogProofFetcher> weak_factory_; | 146 base::WeakPtrFactory<LogProofFetcher> weak_factory_; |
116 | 147 |
117 DISALLOW_COPY_AND_ASSIGN(LogProofFetcher); | 148 DISALLOW_COPY_AND_ASSIGN(LogProofFetcher); |
118 }; | 149 }; |
119 | 150 |
120 } // namespace certificate_transparency | 151 } // namespace certificate_transparency |
121 | 152 |
122 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ | 153 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_PROOF_FETCHER_H_ |
OLD | NEW |