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_(ct_log) {} | |
| 20 | |
| 21 SingleTreeTracker::~SingleTreeTracker() {} | |
| 22 | |
| 23 void SingleTreeTracker::OnSCTVerified( | |
| 24 net::X509Certificate* cert, | |
| 25 const net::ct::SignedCertificateTimestamp* sct) { | |
| 26 CheckLogId(sct->log_id); | |
| 27 | |
| 28 if (entries_status_.find(sct->timestamp) != entries_status_.end()) | |
|
Ryan Sleevi
2016/05/09 17:03:49
Document why the short-circuit
Eran Messeri
2016/05/10 20:01:10
Done.
| |
| 29 return; | |
| 30 | |
| 31 if (verified_sth_.timestamp.is_null() || | |
|
Ryan Sleevi
2016/05/09 17:03:48
Document what this conditional is measuring
Eran Messeri
2016/05/10 20:01:10
Done.
| |
| 32 (verified_sth_.timestamp < | |
| 33 (sct->timestamp + base::TimeDelta::FromHours(24)))) { | |
| 34 // TODO(eranm): UMA - how often SCTs have to wait for a newer STH for | |
| 35 // inclusion check. | |
| 36 entries_status_.insert( | |
| 37 std::make_pair(sct->timestamp, SCT_PENDING_NEWER_STH)); | |
| 38 return; | |
| 39 } | |
| 40 | |
| 41 // TODO(eranm): Check inclusion here. | |
| 42 // TODO(eranm): UMA - how often inclusion can be checked immediately. | |
| 43 entries_status_.insert( | |
| 44 std::make_pair(sct->timestamp, SCT_PENDING_INCLUSION_CHECK)); | |
| 45 } | |
| 46 | |
| 47 void SingleTreeTracker::NewSTHObserved(const SignedTreeHead& sth) { | |
| 48 CheckLogId(sth.log_id); | |
| 49 | |
| 50 if (!ct_log_->VerifySignedTreeHead(sth)) { | |
| 51 // This may be caused due to an operational error - STHs supposed to be | |
| 52 // validated prior to being pushed via the component updater, so an | |
| 53 // invalid STH should never be observed by Chrome clients. | |
|
Ryan Sleevi
2016/05/09 17:03:48
So why are we re-checking it here? Why shouldn't t
Eran Messeri
2016/05/10 20:01:09
This is the first time we're verifying the STH on
| |
| 54 return; | |
| 55 } | |
| 56 | |
| 57 bool sths_for_same_tree = (verified_sth_.tree_size == sth.tree_size); | |
| 58 bool received_sth_is_for_larger_tree = | |
| 59 (verified_sth_.tree_size > sth.tree_size); | |
| 60 bool received_sth_is_newer = (sth.timestamp > verified_sth_.timestamp); | |
|
Ryan Sleevi
2016/05/09 17:03:49
Documentation explaining why this matters (either
Eran Messeri
2016/05/10 20:01:10
Done.
| |
| 61 | |
| 62 if (verified_sth_.timestamp.is_null() || received_sth_is_for_larger_tree || | |
| 63 (sths_for_same_tree && received_sth_is_newer)) { | |
| 64 verified_sth_ = sth; | |
| 65 } | |
| 66 | |
| 67 // Find out which SCTs can now be checked for inclusion. | |
| 68 for (auto& entry : entries_status_) { | |
| 69 if (entry.first < verified_sth_.timestamp) { | |
| 70 entry.second = SCT_PENDING_INCLUSION_CHECK; | |
| 71 // TODO(eranm): Check inclusion here. | |
| 72 } | |
| 73 } | |
|
Ryan Sleevi
2016/05/09 17:03:49
These are sorted by timestamp, right? So once you
Eran Messeri
2016/05/10 20:01:10
Correct - I've changed the code to stop iterating
| |
| 74 } | |
| 75 | |
| 76 SingleTreeTracker::SCTInclusionStatus | |
| 77 SingleTreeTracker::GetLogEntryInclusionStatus( | |
| 78 net::X509Certificate* cert, | |
| 79 const net::ct::SignedCertificateTimestamp* sct) { | |
| 80 auto it = entries_status_.find(sct->timestamp); | |
| 81 if (it == entries_status_.end()) | |
| 82 return SCT_NOT_OBSERVED; | |
| 83 | |
| 84 return it->second; | |
| 85 } | |
| 86 | |
| 87 void SingleTreeTracker::CheckLogId(const std::string& log_id) { | |
| 88 DCHECK_EQ(ct_log_->key_id(), log_id) << "Got called for a different log."; | |
|
Ryan Sleevi
2016/05/09 17:03:49
See previous remarks about folding this Check into
Eran Messeri
2016/05/10 20:01:10
Done.
| |
| 89 } | |
| 90 | |
| 91 } // namespace certificate_transparency | |
| OLD | NEW |