| 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 #include "components/certificate_transparency/tree_state_tracker.h" | 5 #include "components/certificate_transparency/tree_state_tracker.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "components/certificate_transparency/log_dns_client.h" |
| 7 #include "components/certificate_transparency/single_tree_tracker.h" | 9 #include "components/certificate_transparency/single_tree_tracker.h" |
| 10 #include "net/base/network_change_notifier.h" |
| 8 #include "net/cert/ct_log_verifier.h" | 11 #include "net/cert/ct_log_verifier.h" |
| 9 #include "net/cert/signed_certificate_timestamp.h" | 12 #include "net/cert/signed_certificate_timestamp.h" |
| 10 #include "net/cert/signed_tree_head.h" | 13 #include "net/cert/signed_tree_head.h" |
| 11 #include "net/cert/x509_certificate.h" | 14 #include "net/cert/x509_certificate.h" |
| 15 #include "net/dns/dns_client.h" |
| 16 #include "net/dns/dns_config_service.h" |
| 17 #include "net/log/net_log.h" |
| 12 | 18 |
| 13 using net::X509Certificate; | 19 using net::X509Certificate; |
| 14 using net::CTLogVerifier; | 20 using net::CTLogVerifier; |
| 15 using net::ct::SignedCertificateTimestamp; | 21 using net::ct::SignedCertificateTimestamp; |
| 16 using net::ct::SignedTreeHead; | 22 using net::ct::SignedTreeHead; |
| 17 | 23 |
| 18 namespace certificate_transparency { | 24 namespace certificate_transparency { |
| 19 | 25 |
| 20 TreeStateTracker::TreeStateTracker( | 26 TreeStateTracker::TreeStateTracker( |
| 21 std::vector<scoped_refptr<const CTLogVerifier>> ct_logs) { | 27 std::vector<scoped_refptr<const CTLogVerifier>> ct_logs) { |
| 22 for (const auto& log : ct_logs) | 28 net::BoundNetLog net_log; |
| 23 tree_trackers_[log->key_id()].reset(new SingleTreeTracker(log)); | 29 std::unique_ptr<net::DnsClient> dns_client = |
| 30 net::DnsClient::CreateClient(net_log.net_log()); |
| 31 dns_client_ = base::MakeUnique<LogDnsClient>(std::move(dns_client), net_log); |
| 32 |
| 33 for (const auto& log : ct_logs) { |
| 34 tree_trackers_[log->key_id()].reset( |
| 35 new SingleTreeTracker(log, dns_client_.get())); |
| 36 } |
| 24 } | 37 } |
| 25 | 38 |
| 26 TreeStateTracker::~TreeStateTracker() {} | 39 TreeStateTracker::~TreeStateTracker() {} |
| 27 | 40 |
| 28 void TreeStateTracker::OnSCTVerified(X509Certificate* cert, | 41 void TreeStateTracker::OnSCTVerified(X509Certificate* cert, |
| 29 const SignedCertificateTimestamp* sct) { | 42 const SignedCertificateTimestamp* sct) { |
| 30 auto it = tree_trackers_.find(sct->log_id); | 43 auto it = tree_trackers_.find(sct->log_id); |
| 31 // Ignore if the SCT is from an unknown log. | 44 // Ignore if the SCT is from an unknown log. |
| 32 if (it == tree_trackers_.end()) | 45 if (it == tree_trackers_.end()) |
| 33 return; | 46 return; |
| 34 | 47 |
| 35 it->second->OnSCTVerified(cert, sct); | 48 it->second->OnSCTVerified(cert, sct); |
| 36 } | 49 } |
| 37 | 50 |
| 38 void TreeStateTracker::NewSTHObserved(const SignedTreeHead& sth) { | 51 void TreeStateTracker::NewSTHObserved(const SignedTreeHead& sth) { |
| 39 auto it = tree_trackers_.find(sth.log_id); | 52 auto it = tree_trackers_.find(sth.log_id); |
| 40 // Is the STH from a known log? Since STHs can be provided from external | 53 // Is the STH from a known log? Since STHs can be provided from external |
| 41 // sources for logs not yet recognized by this client, return, rather than | 54 // sources for logs not yet recognized by this client, return, rather than |
| 42 // DCHECK. | 55 // DCHECK. |
| 43 if (it == tree_trackers_.end()) | 56 if (it == tree_trackers_.end()) |
| 44 return; | 57 return; |
| 45 | 58 |
| 46 it->second->NewSTHObserved(sth); | 59 it->second->NewSTHObserved(sth); |
| 47 } | 60 } |
| 48 | 61 |
| 49 } // namespace certificate_transparency | 62 } // namespace certificate_transparency |
| OLD | NEW |