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 "net/cert/ct_log_verifier.h" | |
| 10 #include "net/cert/signed_certificate_timestamp.h" | |
| 11 #include "net/cert/x509_certificate.h" | |
| 12 | |
| 13 using net::ct::SignedTreeHead; | |
| 14 | |
| 15 namespace certificate_transparency { | |
| 16 | |
| 17 SingleTreeTracker::SingleTreeTracker( | |
| 18 scoped_refptr<const net::CTLogVerifier> ct_log) | |
| 19 : ct_log_(std::move(ct_log)) {} | |
| 20 | |
| 21 SingleTreeTracker::~SingleTreeTracker() {} | |
| 22 | |
| 23 void SingleTreeTracker::OnSCTVerified( | |
| 24 net::X509Certificate* cert, | |
| 25 const net::ct::SignedCertificateTimestamp* sct) { | |
| 26 DCHECK_EQ(ct_log_->key_id(), sct->log_id) | |
| 27 << "Got called for a different log."; | |
|
Ryan Sleevi
2016/05/18 16:58:18
Drop the << - the DCHECK message will have plenty
Eran Messeri
2016/05/19 12:34:59
Done.
| |
| 28 | |
| 29 // SCT was previously observed so its status should not be changed. | |
|
Ryan Sleevi
2016/05/18 16:58:18
observed, so
Eran Messeri
2016/05/19 12:35:00
Done.
| |
| 30 if (entries_status_.find(sct->timestamp) != entries_status_.end()) | |
| 31 return; | |
| 32 | |
| 33 // Check if there's a valid, fresh-enough STH to check inclusion against. | |
| 34 if (verified_sth_.timestamp.is_null() || | |
|
Ryan Sleevi
2016/05/18 16:58:18
Why is timestamp.is_null() valid, out of curiousit
Eran Messeri
2016/05/19 12:35:00
My bad, documentation was bad - what we're checkin
| |
| 35 (verified_sth_.timestamp < | |
| 36 (sct->timestamp + base::TimeDelta::FromHours(24)))) { | |
| 37 // TODO(eranm): UMA - how often SCTs have to wait for a newer STH for | |
| 38 // inclusion check. | |
| 39 entries_status_.insert( | |
| 40 std::make_pair(sct->timestamp, SCT_PENDING_NEWER_STH)); | |
| 41 return; | |
| 42 } | |
| 43 | |
| 44 // TODO(eranm): Check inclusion here. | |
| 45 // TODO(eranm): UMA - how often inclusion can be checked immediately. | |
| 46 entries_status_.insert( | |
| 47 std::make_pair(sct->timestamp, SCT_PENDING_INCLUSION_CHECK)); | |
| 48 } | |
| 49 | |
| 50 void SingleTreeTracker::NewSTHObserved(const SignedTreeHead& sth) { | |
| 51 DCHECK_EQ(ct_log_->key_id(), sth.log_id) << "Got called for a different log."; | |
|
Ryan Sleevi
2016/05/18 16:58:18
Drop the <<
Eran Messeri
2016/05/19 12:35:00
Done.
| |
| 52 | |
| 53 if (!ct_log_->VerifySignedTreeHead(sth)) { | |
| 54 // This may be caused due to an operational error - STHs supposed to be | |
| 55 // validated prior to being pushed via the component updater, so an | |
| 56 // invalid STH should never be observed by Chrome clients. | |
|
Ryan Sleevi
2016/05/18 16:58:18
Again, layering - Chrome, component updater - shou
Eran Messeri
2016/05/19 12:35:00
Done - switched to your suggested documentation an
| |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 // In order to avoid updating |verified_sth_| to an older STH in case | |
| 61 // an older STH is observed, check that either the observed STH is for | |
| 62 // a larger tree size or that it is for the same tree size but has | |
| 63 // a newer timestamp. | |
| 64 const bool sths_for_same_tree = verified_sth_.tree_size == sth.tree_size; | |
| 65 const bool received_sth_is_for_larger_tree = | |
| 66 (verified_sth_.tree_size > sth.tree_size); | |
| 67 const bool received_sth_is_newer = (sth.timestamp > verified_sth_.timestamp); | |
| 68 | |
| 69 if (verified_sth_.timestamp.is_null() || received_sth_is_for_larger_tree || | |
| 70 (sths_for_same_tree && received_sth_is_newer)) { | |
| 71 verified_sth_ = sth; | |
| 72 } | |
| 73 | |
| 74 // Find out which SCTs can now be checked for inclusion. | |
| 75 // TODO(eranm): Keep two maps of MerkleTreeLeaf instances, one for leaves | |
| 76 // pending inclusion checks and one for leaves pending a new STH. | |
| 77 // The comparison function between MerkleTreeLeaf instances should use the | |
| 78 // timestamp to determine sorting order, so that bulk moving from one | |
| 79 // map to the other can happen. | |
| 80 auto entry = entries_status_.begin(); | |
| 81 while (entry != entries_status_.end() && | |
| 82 entry->first < verified_sth_.timestamp) { | |
| 83 entry->second = SCT_PENDING_INCLUSION_CHECK; | |
| 84 ++entry; | |
| 85 // TODO(eranm): Check inclusion here. | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 SingleTreeTracker::SCTInclusionStatus | |
| 90 SingleTreeTracker::GetLogEntryInclusionStatus( | |
| 91 net::X509Certificate* cert, | |
| 92 const net::ct::SignedCertificateTimestamp* sct) { | |
| 93 auto it = entries_status_.find(sct->timestamp); | |
| 94 | |
| 95 return it == entries_status_.end() ? SCT_NOT_OBSERVED : it->second; | |
| 96 } | |
| 97 | |
| 98 } // namespace certificate_transparency | |
| OLD | NEW |