OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "components/certificate_transparency/log_dns_client.h" | 5 #include "components/certificate_transparency/log_dns_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 public: | 88 public: |
89 using CompletionCallback = | 89 using CompletionCallback = |
90 base::Callback<void(int net_error, AuditProofQuery* query)>; | 90 base::Callback<void(int net_error, AuditProofQuery* query)>; |
91 | 91 |
92 // The LogDnsClient is guaranteed to outlive the AuditProofQuery, so it's safe | 92 // The LogDnsClient is guaranteed to outlive the AuditProofQuery, so it's safe |
93 // to leave ownership of |dns_client| with LogDnsClient. | 93 // to leave ownership of |dns_client| with LogDnsClient. |
94 AuditProofQuery(net::DnsClient* dns_client, | 94 AuditProofQuery(net::DnsClient* dns_client, |
95 const std::string& domain_for_log, | 95 const std::string& domain_for_log, |
96 uint64_t tree_size, | 96 uint64_t tree_size, |
97 const net::BoundNetLog& net_log) | 97 const net::BoundNetLog& net_log) |
98 : domain_for_log_(domain_for_log), | 98 : next_state_(State::NONE), |
99 domain_for_log_(domain_for_log), | |
99 tree_size_(tree_size), | 100 tree_size_(tree_size), |
100 dns_client_(dns_client), | 101 dns_client_(dns_client), |
101 net_log_(net_log), | 102 net_log_(net_log), |
102 weak_ptr_factory_(this) { | 103 weak_ptr_factory_(this) { |
103 DCHECK(dns_client_); | 104 DCHECK(dns_client_); |
104 DCHECK(!domain_for_log_.empty()); | 105 DCHECK(!domain_for_log_.empty()); |
105 } | 106 } |
106 | 107 |
107 // Start the query. | 108 // Start the query. |
108 void Start(base::StringPiece leaf_hash, CompletionCallback callback) { | 109 // If a query was already in progress, this will abort it first. |
Eran Messeri
2016/09/28 13:44:08
How often do you expect that case to happen?
If no
Rob Percival
2016/09/28 16:19:13
It's not the intended usage (there's little reason
| |
110 int Start(base::StringPiece leaf_hash, CompletionCallback callback) { | |
111 // Cancel any existing DNS transaction. | |
109 current_dns_transaction_.reset(); | 112 current_dns_transaction_.reset(); |
113 // Start a new audit proof. | |
110 proof_.reset(new net::ct::MerkleAuditProof); | 114 proof_.reset(new net::ct::MerkleAuditProof); |
115 // The leaf hash and callback will be used later. | |
116 leaf_hash.CopyToString(&leaf_hash_); | |
111 callback_ = callback; | 117 callback_ = callback; |
112 QueryLeafIndex(leaf_hash); | 118 // The first step in the query is to request the leaf index corresponding to |
113 } | 119 // |leaf_hash| from the CT log. |
114 | 120 next_state_ = State::REQUEST_LEAF_INDEX; |
121 // Begin the state machine. | |
122 return DoLoop(net::OK); | |
123 } | |
124 | |
125 // Take the audit proof obtained by the query. | |
126 // Should only be called once the CompletionCallback is invoked. | |
115 std::unique_ptr<net::ct::MerkleAuditProof> TakeProof() { | 127 std::unique_ptr<net::ct::MerkleAuditProof> TakeProof() { |
116 return std::move(proof_); | 128 return std::move(proof_); |
117 } | 129 } |
118 | 130 |
119 private: | 131 private: |
120 void QueryLeafIndex(base::StringPiece leaf_hash) { | 132 enum class State { |
133 NONE, | |
134 REQUEST_LEAF_INDEX, | |
135 REQUEST_LEAF_INDEX_COMPLETE, | |
136 REQUEST_AUDIT_PROOF_NODES, | |
137 REQUEST_AUDIT_PROOF_NODES_COMPLETE, | |
138 }; | |
139 | |
140 int DoLoop(int net_error) { | |
141 CHECK_NE(State::NONE, next_state_); | |
142 do { | |
143 State state = next_state_; | |
144 next_state_ = State::NONE; | |
145 switch (state) { | |
146 case State::REQUEST_LEAF_INDEX: | |
147 net_error = RequestLeafIndex(); | |
148 break; | |
149 case State::REQUEST_LEAF_INDEX_COMPLETE: | |
150 net_error = RequestLeafIndexComplete(net_error); | |
151 break; | |
152 case State::REQUEST_AUDIT_PROOF_NODES: | |
153 net_error = RequestAuditProofNodes(); | |
154 break; | |
155 case State::REQUEST_AUDIT_PROOF_NODES_COMPLETE: | |
156 net_error = RequestAuditProofNodesComplete(net_error); | |
157 break; | |
158 case State::NONE: | |
159 NOTREACHED(); | |
160 break; | |
161 } | |
162 } while (net_error != net::ERR_IO_PENDING && next_state_ != State::NONE); | |
163 | |
164 return net_error; | |
165 } | |
166 | |
167 // When a DnsTransaction completes, store the response and resume the state | |
168 // machine. It is safe to store a pointer to |response| because |transaction| | |
169 // is kept alive in |current_dns_transaction_|. | |
170 void OnDnsTransactionComplete(net::DnsTransaction* transaction, | |
171 int net_error, | |
172 const net::DnsResponse* response) { | |
173 last_dns_response_ = response; | |
174 net_error = DoLoop(net_error); | |
175 | |
176 if (net_error != net::ERR_IO_PENDING) { | |
Eran Messeri
2016/09/28 13:44:08
Nit: Document why not doing anything in case of ne
Rob Percival
2016/09/28 16:19:13
Done.
| |
177 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
178 FROM_HERE, base::Bind(callback_, net_error, base::Unretained(this))); | |
179 } | |
180 } | |
181 | |
182 // Requests the leaf index for the CT log entry with |leaf_hash_|. | |
183 int RequestLeafIndex() { | |
121 std::string encoded_leaf_hash = base32::Base32Encode( | 184 std::string encoded_leaf_hash = base32::Base32Encode( |
122 leaf_hash, base32::Base32EncodePolicy::OMIT_PADDING); | 185 leaf_hash_, base32::Base32EncodePolicy::OMIT_PADDING); |
123 DCHECK_EQ(encoded_leaf_hash.size(), 52u); | 186 DCHECK_EQ(encoded_leaf_hash.size(), 52u); |
124 | 187 |
125 std::string qname = base::StringPrintf( | |
126 "%s.hash.%s.", encoded_leaf_hash.c_str(), domain_for_log_.data()); | |
127 | |
128 net::DnsTransactionFactory* factory = dns_client_->GetTransactionFactory(); | 188 net::DnsTransactionFactory* factory = dns_client_->GetTransactionFactory(); |
129 if (factory == nullptr) { | 189 if (factory == nullptr) { |
130 base::ThreadTaskRunnerHandle::Get()->PostTask( | 190 return net::ERR_NAME_RESOLUTION_FAILED; |
131 FROM_HERE, | 191 } |
132 base::Bind(callback_, net::Error::ERR_NAME_RESOLUTION_FAILED, | 192 |
133 base::Unretained(this))); | 193 std::string qname = base::StringPrintf( |
134 return; | 194 "%s.hash.%s.", encoded_leaf_hash.c_str(), domain_for_log_.c_str()); |
135 } | |
136 | 195 |
137 net::DnsTransactionFactory::CallbackType transaction_callback = | 196 net::DnsTransactionFactory::CallbackType transaction_callback = |
Eran Messeri
2016/09/28 13:44:08
Inline transaction_callback creation & use into Cr
Rob Percival
2016/09/28 16:19:13
Done.
| |
138 base::Bind(&LogDnsClient::AuditProofQuery::QueryLeafIndexComplete, | 197 base::Bind(&LogDnsClient::AuditProofQuery::OnDnsTransactionComplete, |
139 weak_ptr_factory_.GetWeakPtr()); | 198 weak_ptr_factory_.GetWeakPtr()); |
140 | 199 |
141 current_dns_transaction_ = factory->CreateTransaction( | 200 current_dns_transaction_ = factory->CreateTransaction( |
142 qname, net::dns_protocol::kTypeTXT, transaction_callback, net_log_); | 201 qname, net::dns_protocol::kTypeTXT, transaction_callback, net_log_); |
143 | |
144 current_dns_transaction_->Start(); | 202 current_dns_transaction_->Start(); |
145 } | 203 |
146 | 204 next_state_ = State::REQUEST_LEAF_INDEX_COMPLETE; |
147 void QueryLeafIndexComplete(net::DnsTransaction* transaction, | 205 return net::ERR_IO_PENDING; |
148 int net_error, | 206 } |
149 const net::DnsResponse* response) { | 207 |
150 // If we've received no response but no net::error either (shouldn't | 208 // Stores the received leaf index in |proof_->leaf_index|. |
151 // happen), | 209 // If successful, the audit proof nodes will be requested next. |
210 int RequestLeafIndexComplete(int net_error) { | |
211 // If we receive no response but no net::error either (shouldn't happen), | |
Eran Messeri
2016/09/28 13:44:08
"shouldn't happen" implies this is a programming e
Rob Percival
2016/09/28 16:19:13
Done.
| |
152 // report the response as invalid. | 212 // report the response as invalid. |
153 if (response == nullptr && net_error == net::OK) { | 213 if (last_dns_response_ == nullptr && net_error == net::OK) { |
154 net_error = net::ERR_INVALID_RESPONSE; | 214 net_error = net::ERR_INVALID_RESPONSE; |
155 } | 215 } |
156 | 216 |
157 if (net_error != net::OK) { | 217 if (net_error != net::OK) { |
158 base::ThreadTaskRunnerHandle::Get()->PostTask( | 218 return net_error; |
159 FROM_HERE, base::Bind(callback_, net_error, base::Unretained(this))); | 219 } |
160 return; | 220 |
161 } | 221 if (!ParseLeafIndex(*last_dns_response_, &proof_->leaf_index)) { |
162 | 222 return net::ERR_DNS_MALFORMED_RESPONSE; |
163 if (!ParseLeafIndex(*response, &proof_->leaf_index)) { | |
164 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
165 FROM_HERE, base::Bind(callback_, net::ERR_DNS_MALFORMED_RESPONSE, | |
166 base::Unretained(this))); | |
167 return; | |
168 } | 223 } |
169 | 224 |
170 // Reject leaf index if it is out-of-range. | 225 // Reject leaf index if it is out-of-range. |
171 // This indicates either: | 226 // This indicates either: |
172 // a) the wrong tree_size was provided. | 227 // a) the wrong tree_size was provided. |
173 // b) the wrong leaf hash was provided. | 228 // b) the wrong leaf hash was provided. |
174 // c) there is a bug server-side. | 229 // c) there is a bug server-side. |
175 // The first two are more likely, so return ERR_INVALID_ARGUMENT. | 230 // The first two are more likely, so return ERR_INVALID_ARGUMENT. |
176 if (proof_->leaf_index >= tree_size_) { | 231 if (proof_->leaf_index >= tree_size_) { |
177 base::ThreadTaskRunnerHandle::Get()->PostTask( | 232 return net::ERR_INVALID_ARGUMENT; |
178 FROM_HERE, base::Bind(callback_, net::ERR_INVALID_ARGUMENT, | 233 } |
179 base::Unretained(this))); | 234 |
180 return; | 235 next_state_ = State::REQUEST_AUDIT_PROOF_NODES; |
181 } | 236 return net::OK; |
182 | 237 } |
183 // QueryAuditProof for the first batch of audit proof_ nodes (i.e. starting | 238 |
184 // from 0). | 239 // Requests the next batch of audit proof nodes from a CT log. |
185 QueryAuditProofNodes(0 /* start node index */); | 240 // The index of the first node required is determined by looking at how many |
186 } | 241 // nodes are already in |proof_->nodes|. |
187 | 242 // The CT log may return up to 7 nodes - this is the maximum allowed by the |
188 // Queries a CT log to retrieve part of an audit |proof|. The |node_index| | 243 // CT-over-DNS draft RFC, as a TXT RDATA string can have a maximum length of |
189 // indicates which node of the audit proof/ should be requested. The CT log | 244 // 255 bytes and each node is 32 bytes long (a SHA-256 hash). |
190 // may return up to 7 nodes, starting from |node_index| (this is the maximum | 245 // |
191 // that will fit in a DNS UDP packet). The nodes will be appended to | 246 // The performance of this could be improved by sending all of the expected |
192 // |proof->nodes|. | 247 // requests up front. Each response can contain a maximum of 7 audit path |
193 void QueryAuditProofNodes(uint64_t node_index) { | 248 // nodes, so for an audit proof of size 20, it could send 3 queries (for nodes |
249 // 0-6, 7-13 and 14-19) immediately. Currently, it sends only the first and | |
250 // then, based on the number of nodes received, sends the next query. | |
251 // The complexity of the code would increase though, as it would need to | |
252 // detect gaps in the audit proof caused by the server not responding with the | |
253 // anticipated number of nodes. It would also undermine LogDnsClient's ability | |
254 // to rate-limit DNS requests. | |
255 int RequestAuditProofNodes() { | |
194 DCHECK_LT(proof_->leaf_index, tree_size_); | 256 DCHECK_LT(proof_->leaf_index, tree_size_); |
195 DCHECK_LT(node_index, net::ct::CalculateAuditPathLength(proof_->leaf_index, | 257 DCHECK_LT(proof_->nodes.size(), net::ct::CalculateAuditPathLength( |
196 tree_size_)); | 258 proof_->leaf_index, tree_size_)); |
197 | |
198 std::string qname = base::StringPrintf( | |
199 "%" PRIu64 ".%" PRIu64 ".%" PRIu64 ".tree.%s.", node_index, | |
200 proof_->leaf_index, tree_size_, domain_for_log_.data()); | |
201 | 259 |
202 net::DnsTransactionFactory* factory = dns_client_->GetTransactionFactory(); | 260 net::DnsTransactionFactory* factory = dns_client_->GetTransactionFactory(); |
203 if (factory == nullptr) { | 261 if (factory == nullptr) { |
204 base::ThreadTaskRunnerHandle::Get()->PostTask( | 262 return net::ERR_NAME_RESOLUTION_FAILED; |
205 FROM_HERE, | 263 } |
206 base::Bind(callback_, net::Error::ERR_NAME_RESOLUTION_FAILED, | 264 |
207 base::Unretained(this))); | 265 std::string qname = base::StringPrintf( |
208 return; | 266 "%" PRIu64 ".%" PRIu64 ".%" PRIu64 ".tree.%s.", proof_->nodes.size(), |
209 } | 267 proof_->leaf_index, tree_size_, domain_for_log_.c_str()); |
210 | 268 |
211 net::DnsTransactionFactory::CallbackType transaction_callback = | 269 net::DnsTransactionFactory::CallbackType transaction_callback = |
Eran Messeri
2016/09/28 13:44:08
Ditto, inline callback creation.
Rob Percival
2016/09/28 16:19:13
Done.
| |
212 base::Bind(&LogDnsClient::AuditProofQuery::QueryAuditProofNodesComplete, | 270 base::Bind(&LogDnsClient::AuditProofQuery::OnDnsTransactionComplete, |
213 weak_ptr_factory_.GetWeakPtr()); | 271 weak_ptr_factory_.GetWeakPtr()); |
214 | 272 |
215 current_dns_transaction_ = factory->CreateTransaction( | 273 current_dns_transaction_ = factory->CreateTransaction( |
216 qname, net::dns_protocol::kTypeTXT, transaction_callback, net_log_); | 274 qname, net::dns_protocol::kTypeTXT, transaction_callback, net_log_); |
217 current_dns_transaction_->Start(); | 275 current_dns_transaction_->Start(); |
218 } | 276 |
219 | 277 next_state_ = State::REQUEST_AUDIT_PROOF_NODES_COMPLETE; |
220 void QueryAuditProofNodesComplete(net::DnsTransaction* transaction, | 278 return net::ERR_IO_PENDING; |
221 int net_error, | 279 } |
222 const net::DnsResponse* response) { | 280 |
223 // If we receive no response but no net::error either (shouldn't happen), | 281 // Appends the received audit proof nodes to |proof_->nodes|. |
282 // If any nodes are missing, another request will follow this one. | |
283 int RequestAuditProofNodesComplete(int net_error) { | |
284 // If we received no response but no net::error either (shouldn't happen), | |
224 // report the response as invalid. | 285 // report the response as invalid. |
225 if (response == nullptr && net_error == net::OK) { | 286 if (last_dns_response_ == nullptr && net_error == net::OK) { |
226 net_error = net::ERR_INVALID_RESPONSE; | 287 net_error = net::ERR_INVALID_RESPONSE; |
227 } | 288 } |
228 | 289 |
229 if (net_error != net::OK) { | 290 if (net_error != net::OK) { |
230 base::ThreadTaskRunnerHandle::Get()->PostTask( | 291 return net_error; |
231 FROM_HERE, base::Bind(callback_, net_error, base::Unretained(this))); | |
232 return; | |
233 } | 292 } |
234 | 293 |
235 const uint64_t audit_path_length = | 294 const uint64_t audit_path_length = |
236 net::ct::CalculateAuditPathLength(proof_->leaf_index, tree_size_); | 295 net::ct::CalculateAuditPathLength(proof_->leaf_index, tree_size_); |
296 | |
237 // The calculated |audit_path_length| can't ever be greater than 64, so | 297 // The calculated |audit_path_length| can't ever be greater than 64, so |
238 // deriving the amount of memory to reserve from the untrusted |leaf_index| | 298 // deriving the amount of memory to reserve from the untrusted |leaf_index| |
239 // is safe. | 299 // is safe. |
240 proof_->nodes.reserve(audit_path_length); | 300 proof_->nodes.reserve(audit_path_length); |
241 | 301 |
242 if (!ParseAuditPath(*response, proof_.get())) { | 302 if (!ParseAuditPath(*last_dns_response_, proof_.get())) { |
243 base::ThreadTaskRunnerHandle::Get()->PostTask( | 303 return net::ERR_DNS_MALFORMED_RESPONSE; |
244 FROM_HERE, base::Bind(callback_, net::ERR_DNS_MALFORMED_RESPONSE, | 304 } |
245 base::Unretained(this))); | 305 |
246 return; | 306 // If we don't have all of the proof nodes yet, request more. |
247 } | 307 if (proof_->nodes.size() < audit_path_length) { |
248 | 308 next_state_ = State::REQUEST_AUDIT_PROOF_NODES; |
249 const uint64_t audit_path_nodes_received = proof_->nodes.size(); | 309 } |
250 if (audit_path_nodes_received < audit_path_length) { | 310 |
251 QueryAuditProofNodes(audit_path_nodes_received); | 311 return net::OK; |
252 return; | 312 } |
253 } | 313 |
254 | 314 // The next state that this query will enter. |
255 base::ThreadTaskRunnerHandle::Get()->PostTask( | 315 State next_state_; |
256 FROM_HERE, base::Bind(callback_, net::OK, base::Unretained(this))); | 316 // The DNS domain of the CT log that is being queried. |
257 } | |
258 | |
259 std::string domain_for_log_; | 317 std::string domain_for_log_; |
318 // The Merkle leaf hash of the CT log entry an audit proof is required for. | |
319 std::string leaf_hash_; | |
320 // The size of the CT log's tree. | |
Eran Messeri
2016/09/28 13:44:08
Add: from which the proof is requested.
| |
260 // TODO(robpercival): Remove |tree_size| once |proof_| has a tree_size member. | 321 // TODO(robpercival): Remove |tree_size| once |proof_| has a tree_size member. |
261 uint64_t tree_size_; | 322 uint64_t tree_size_; |
323 // The audit proof. It will be null until the query is started and incomplete | |
324 // until the query is finished. | |
262 std::unique_ptr<net::ct::MerkleAuditProof> proof_; | 325 std::unique_ptr<net::ct::MerkleAuditProof> proof_; |
326 // The callback to invoke when the query is complete. | |
263 CompletionCallback callback_; | 327 CompletionCallback callback_; |
328 // The DnsClient to use for sending DNS requests to the CT log. | |
264 net::DnsClient* dns_client_; | 329 net::DnsClient* dns_client_; |
330 // The most recent DNS request. Null if no DNS requests have been made. | |
265 std::unique_ptr<net::DnsTransaction> current_dns_transaction_; | 331 std::unique_ptr<net::DnsTransaction> current_dns_transaction_; |
332 // The most recent DNS response. Only valid so long as the corresponding DNS | |
333 // request is stored in |current_dns_transaction_|. | |
334 const net::DnsResponse* last_dns_response_; | |
335 // The NetLog that DNS transactions will log to. | |
266 net::BoundNetLog net_log_; | 336 net::BoundNetLog net_log_; |
337 // Produces WeakPtrs to |this| for binding callbacks. | |
267 base::WeakPtrFactory<AuditProofQuery> weak_ptr_factory_; | 338 base::WeakPtrFactory<AuditProofQuery> weak_ptr_factory_; |
268 }; | 339 }; |
269 | 340 |
270 LogDnsClient::LogDnsClient(std::unique_ptr<net::DnsClient> dns_client, | 341 LogDnsClient::LogDnsClient(std::unique_ptr<net::DnsClient> dns_client, |
271 const net::BoundNetLog& net_log, | 342 const net::BoundNetLog& net_log, |
272 size_t max_concurrent_queries) | 343 size_t max_concurrent_queries) |
273 : dns_client_(std::move(dns_client)), | 344 : dns_client_(std::move(dns_client)), |
274 net_log_(net_log), | 345 net_log_(net_log), |
275 max_concurrent_queries_(max_concurrent_queries), | 346 max_concurrent_queries_(max_concurrent_queries), |
276 weak_ptr_factory_(this) { | 347 weak_ptr_factory_(this) { |
277 CHECK(dns_client_); | 348 CHECK(dns_client_); |
278 net::NetworkChangeNotifier::AddDNSObserver(this); | 349 net::NetworkChangeNotifier::AddDNSObserver(this); |
279 UpdateDnsConfig(); | 350 UpdateDnsConfig(); |
280 } | 351 } |
281 | 352 |
282 LogDnsClient::~LogDnsClient() { | 353 LogDnsClient::~LogDnsClient() { |
283 net::NetworkChangeNotifier::RemoveDNSObserver(this); | 354 net::NetworkChangeNotifier::RemoveDNSObserver(this); |
284 } | 355 } |
285 | 356 |
286 void LogDnsClient::OnDNSChanged() { | 357 void LogDnsClient::OnDNSChanged() { |
287 UpdateDnsConfig(); | 358 UpdateDnsConfig(); |
288 } | 359 } |
289 | 360 |
290 void LogDnsClient::OnInitialDNSConfigRead() { | 361 void LogDnsClient::OnInitialDNSConfigRead() { |
291 UpdateDnsConfig(); | 362 UpdateDnsConfig(); |
292 } | 363 } |
293 | 364 |
294 // The performance of this could be improved by sending all of the expected | 365 int LogDnsClient::QueryAuditProof(base::StringPiece domain_for_log, |
295 // queries up front. Each response can contain a maximum of 7 audit path nodes, | 366 base::StringPiece leaf_hash, |
296 // so for an audit proof of size 20, it could send 3 queries (for nodes 0-6, | 367 uint64_t tree_size, |
297 // 7-13 and 14-19) immediately. Currently, it sends only the first and then, | 368 const AuditProofCallback& callback) { |
298 // based on the number of nodes received, sends the next query-> The complexity | |
299 // of the code would increase though, as it would need to detect gaps in the | |
300 // audit proof caused by the server not responding with the anticipated number | |
301 // of nodes. Ownership of the proof would need to change, as it would be shared | |
302 // between simultaneous DNS transactions. Throttling of queries would also need | |
303 // to take into account this increase in parallelism. | |
304 void LogDnsClient::QueryAuditProof(const std::string& domain_for_log, | |
305 base::StringPiece leaf_hash, | |
306 uint64_t tree_size, | |
307 const AuditProofCallback& callback) { | |
308 if (domain_for_log.empty() || leaf_hash.size() != crypto::kSHA256Length) { | 369 if (domain_for_log.empty() || leaf_hash.size() != crypto::kSHA256Length) { |
309 base::ThreadTaskRunnerHandle::Get()->PostTask( | 370 return net::ERR_INVALID_ARGUMENT; |
310 FROM_HERE, | |
311 base::Bind(callback, net::Error::ERR_INVALID_ARGUMENT, nullptr)); | |
312 return; | |
313 } | 371 } |
314 | 372 |
315 if (HasMaxConcurrentQueriesInProgress()) { | 373 if (HasMaxConcurrentQueriesInProgress()) { |
316 base::ThreadTaskRunnerHandle::Get()->PostTask( | 374 return net::ERR_TEMPORARILY_THROTTLED; |
317 FROM_HERE, | |
318 base::Bind(callback, net::Error::ERR_TEMPORARILY_THROTTLED, nullptr)); | |
319 return; | |
320 } | 375 } |
321 | 376 |
322 audit_proof_queries_.emplace_back( | 377 AuditProofQuery* query = new AuditProofQuery( |
323 new AuditProofQuery(dns_client_.get(), domain_for_log, tree_size)); | 378 dns_client_.get(), domain_for_log.as_string(), tree_size, net_log_); |
379 // Transfers ownership of |query| to |audit_proof_queries_|. | |
380 audit_proof_queries_.emplace_back(query); | |
324 | 381 |
325 AuditProofQuery::CompletionCallback internal_callback = | 382 AuditProofQuery::CompletionCallback internal_callback = |
326 base::Bind(&LogDnsClient::QueryAuditProofComplete, | 383 base::Bind(&LogDnsClient::QueryAuditProofComplete, |
327 weak_ptr_factory_.GetWeakPtr(), callback); | 384 weak_ptr_factory_.GetWeakPtr(), callback); |
328 | 385 |
329 audit_proof_queries_.back()->Start(leaf_hash, internal_callback); | 386 return query->Start(leaf_hash, internal_callback); |
330 } | 387 } |
331 | 388 |
332 void LogDnsClient::QueryAuditProofComplete(const AuditProofCallback& callback, | 389 void LogDnsClient::QueryAuditProofComplete(const AuditProofCallback& callback, |
333 int result, | 390 int result, |
334 AuditProofQuery* query) { | 391 AuditProofQuery* query) { |
335 DCHECK(query); | 392 DCHECK(query); |
336 | 393 |
337 std::unique_ptr<net::ct::MerkleAuditProof> proof; | 394 std::unique_ptr<net::ct::MerkleAuditProof> proof; |
338 if (result == net::OK) { | 395 if (result == net::OK) { |
339 proof = query->TakeProof(); | 396 proof = query->TakeProof(); |
(...skipping 17 matching lines...) Expand all Loading... | |
357 } | 414 } |
358 | 415 |
359 void LogDnsClient::UpdateDnsConfig() { | 416 void LogDnsClient::UpdateDnsConfig() { |
360 net::DnsConfig config; | 417 net::DnsConfig config; |
361 net::NetworkChangeNotifier::GetDnsConfig(&config); | 418 net::NetworkChangeNotifier::GetDnsConfig(&config); |
362 if (config.IsValid()) | 419 if (config.IsValid()) |
363 dns_client_->SetConfig(config); | 420 dns_client_->SetConfig(config); |
364 } | 421 } |
365 | 422 |
366 } // namespace certificate_transparency | 423 } // namespace certificate_transparency |
OLD | NEW |