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 <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "base/values.h" |
16 #include "components/base32/base32.h" | 17 #include "components/base32/base32.h" |
17 #include "crypto/sha2.h" | 18 #include "crypto/sha2.h" |
18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
19 #include "net/cert/merkle_audit_proof.h" | 20 #include "net/cert/merkle_audit_proof.h" |
20 #include "net/dns/dns_client.h" | 21 #include "net/dns/dns_client.h" |
| 22 #include "net/dns/dns_config_service.h" |
21 #include "net/dns/dns_protocol.h" | 23 #include "net/dns/dns_protocol.h" |
22 #include "net/dns/dns_response.h" | 24 #include "net/dns/dns_response.h" |
23 #include "net/dns/dns_transaction.h" | 25 #include "net/dns/dns_transaction.h" |
24 #include "net/dns/record_parsed.h" | 26 #include "net/dns/record_parsed.h" |
25 #include "net/dns/record_rdata.h" | 27 #include "net/dns/record_rdata.h" |
26 | 28 |
27 namespace certificate_transparency { | 29 namespace certificate_transparency { |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 } | 81 } |
80 | 82 |
81 } // namespace | 83 } // namespace |
82 | 84 |
83 LogDnsClient::LogDnsClient(std::unique_ptr<net::DnsClient> dns_client, | 85 LogDnsClient::LogDnsClient(std::unique_ptr<net::DnsClient> dns_client, |
84 const net::BoundNetLog& net_log) | 86 const net::BoundNetLog& net_log) |
85 : dns_client_(std::move(dns_client)), | 87 : dns_client_(std::move(dns_client)), |
86 net_log_(net_log), | 88 net_log_(net_log), |
87 weak_ptr_factory_(this) { | 89 weak_ptr_factory_(this) { |
88 CHECK(dns_client_); | 90 CHECK(dns_client_); |
| 91 net::NetworkChangeNotifier::AddDNSObserver(this); |
| 92 UpdateDnsConfig(); |
89 } | 93 } |
90 | 94 |
91 LogDnsClient::~LogDnsClient() {} | 95 LogDnsClient::~LogDnsClient() { |
| 96 net::NetworkChangeNotifier::RemoveDNSObserver(this); |
| 97 } |
| 98 |
| 99 void LogDnsClient::OnDNSChanged() { |
| 100 UpdateDnsConfig(); |
| 101 } |
| 102 |
| 103 void LogDnsClient::OnInitialDNSConfigRead() { |
| 104 UpdateDnsConfig(); |
| 105 } |
92 | 106 |
93 void LogDnsClient::QueryLeafIndex(base::StringPiece domain_for_log, | 107 void LogDnsClient::QueryLeafIndex(base::StringPiece domain_for_log, |
94 base::StringPiece leaf_hash, | 108 base::StringPiece leaf_hash, |
95 const LeafIndexCallback& callback) { | 109 const LeafIndexCallback& callback) { |
96 if (domain_for_log.empty() || leaf_hash.size() != crypto::kSHA256Length) { | 110 if (domain_for_log.empty() || leaf_hash.size() != crypto::kSHA256Length) { |
97 base::ThreadTaskRunnerHandle::Get()->PostTask( | 111 base::ThreadTaskRunnerHandle::Get()->PostTask( |
98 FROM_HERE, base::Bind(callback, net::Error::ERR_INVALID_ARGUMENT, 0)); | 112 FROM_HERE, base::Bind(callback, net::Error::ERR_INVALID_ARGUMENT, 0)); |
99 return; | 113 return; |
100 } | 114 } |
101 | 115 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 QueryAuditProofNodes(std::move(proof), domain_for_log, tree_size, | 298 QueryAuditProofNodes(std::move(proof), domain_for_log, tree_size, |
285 audit_path_nodes_received, query.callback); | 299 audit_path_nodes_received, query.callback); |
286 return; | 300 return; |
287 } | 301 } |
288 | 302 |
289 base::ThreadTaskRunnerHandle::Get()->PostTask( | 303 base::ThreadTaskRunnerHandle::Get()->PostTask( |
290 FROM_HERE, | 304 FROM_HERE, |
291 base::Bind(query.callback, net::OK, base::Passed(std::move(proof)))); | 305 base::Bind(query.callback, net::OK, base::Passed(std::move(proof)))); |
292 } | 306 } |
293 | 307 |
| 308 void LogDnsClient::UpdateDnsConfig() { |
| 309 net::DnsConfig config; |
| 310 net::NetworkChangeNotifier::GetDnsConfig(&config); |
| 311 if (config.IsValid()) |
| 312 dns_client_->SetConfig(config); |
| 313 } |
| 314 |
294 } // namespace certificate_transparency | 315 } // namespace certificate_transparency |
OLD | NEW |