Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/certificate_transparency/single_tree_tracker.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/strings/string_number_conversions.h" | |
| 10 #include "net/cert/ct_log_verifier.h" | |
| 11 #include "net/cert/signed_certificate_timestamp.h" | |
| 12 #include "net/cert/x509_certificate.h" | |
| 13 | |
| 14 using net::ct::SignedTreeHead; | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 bool STHIsTooOld(const SignedTreeHead& sth, const base::Time& sct_timestamp) { | |
|
Ryan Sleevi
2016/04/14 16:56:15
Doesn't seem like this needs to be a utility funct
Eran Messeri
2016/04/18 22:02:12
Done, removed.
| |
| 19 return sth.timestamp < (sct_timestamp + base::TimeDelta::FromHours(24)); | |
| 20 } | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 namespace certificate_transparency { | |
| 25 | |
| 26 SingleTreeTracker::SingleTreeTracker( | |
| 27 scoped_refptr<const net::CTLogVerifier>& ct_log) | |
| 28 : ct_log_(ct_log) {} | |
|
Ryan Sleevi
2016/04/14 16:56:15
When you update to be by-value, move
Eran Messeri
2016/04/18 22:02:12
Done.
| |
| 29 | |
| 30 SingleTreeTracker::~SingleTreeTracker() {} | |
| 31 | |
| 32 void SingleTreeTracker::OnSCTVerified( | |
| 33 net::X509Certificate* cert, | |
| 34 const net::ct::SignedCertificateTimestamp* sct) { | |
| 35 CheckLogId(sct->log_id); | |
| 36 | |
| 37 if (entries_status_.find(sct->timestamp) != entries_status_.end()) | |
| 38 return; | |
| 39 | |
| 40 if (verified_sth_.timestamp.is_null() || | |
| 41 STHIsTooOld(verified_sth_, sct->timestamp)) { | |
| 42 // TODO(eranm): UMA - how often SCTs have to wait for a newer STH for | |
| 43 // inclusion check. | |
| 44 entries_status_.insert( | |
| 45 std::make_pair(sct->timestamp, SCT_PENDING_NEWER_STH)); | |
| 46 return; | |
| 47 } | |
| 48 | |
| 49 // TODO(eranm): Check inclusion here. | |
| 50 // TODO(eranm): UMA - how often inclusion can be checked immediately. | |
| 51 entries_status_.insert( | |
| 52 std::make_pair(sct->timestamp, SCT_PENDING_INCLUSION_CHECK)); | |
| 53 } | |
| 54 | |
| 55 void SingleTreeTracker::NewSTHObserved(const SignedTreeHead& sth) { | |
| 56 CheckLogId(sth.log_id); | |
| 57 | |
| 58 if (!ct_log_->VerifySignedTreeHead(sth)) { | |
| 59 // This is an error - STHs are validated prior to being pushed via the | |
| 60 // component updater. | |
|
Ryan Sleevi
2016/04/14 16:56:15
What sort of error is this? Developer error? In wh
Eran Messeri
2016/04/18 22:02:12
Operational error? This would only happen if we (G
| |
| 61 LOG(WARNING) << "STH is for " << ct_log_->url() | |
| 62 << " could not be verified."; | |
| 63 // TODO(eranm): UMA | |
| 64 return; | |
| 65 } | |
| 66 | |
| 67 bool sths_for_same_tree = (verified_sth_.tree_size == sth.tree_size); | |
| 68 bool received_sth_is_for_larger_tree = | |
| 69 (verified_sth_.tree_size > sth.tree_size); | |
| 70 bool received_sth_is_newer = (sth.timestamp > verified_sth_.timestamp); | |
| 71 | |
| 72 if (verified_sth_.timestamp.is_null() || received_sth_is_for_larger_tree || | |
| 73 (sths_for_same_tree && received_sth_is_newer)) { | |
| 74 verified_sth_ = sth; | |
| 75 } | |
| 76 | |
| 77 // Find out which SCTs can now be checked for inclusion. | |
| 78 for (auto it = entries_status_.begin(); it != entries_status_.end(); ++it) { | |
| 79 const base::Time& timestamp(it->first); | |
|
Ryan Sleevi
2016/04/14 16:56:15
Seems unnecessary
Eran Messeri
2016/04/18 22:02:12
Done - removed.
| |
| 80 if (timestamp < verified_sth_.timestamp) { | |
| 81 it->second = SCT_PENDING_INCLUSION_CHECK; | |
| 82 // TODO(eranm): Check inclusion here. | |
| 83 } | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 SingleTreeTracker::SCTInclusionStatus | |
| 88 SingleTreeTracker::GetLogEntryInclusionStatus( | |
| 89 net::X509Certificate* cert, | |
| 90 const net::ct::SignedCertificateTimestamp* sct) { | |
| 91 auto it = entries_status_.find(sct->timestamp); | |
| 92 if (it == entries_status_.end()) | |
| 93 return SCT_NOT_OBSERVED; | |
| 94 | |
| 95 return it->second; | |
| 96 } | |
| 97 | |
| 98 void SingleTreeTracker::CheckLogId(const std::string& log_id) { | |
| 99 if (log_id != ct_log_->key_id()) { | |
|
Ryan Sleevi
2016/04/14 16:56:16
Explain why or when this happens.
As far as I can
Eran Messeri
2016/04/18 22:02:12
You're right - it's a developer error, so changed
| |
| 100 LOG(ERROR) << "Got called for a different log: " | |
| 101 << base::HexEncode(log_id.data(), log_id.size()) | |
| 102 << " this log: " << base::HexEncode(ct_log_->key_id().data(), | |
| 103 ct_log_->key_id().size()); | |
| 104 NOTREACHED(); | |
| 105 return; | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 } // namespace certificate_transparency | |
| OLD | NEW |