Chromium Code Reviews| 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/single_tree_tracker.h" | 5 #include "components/certificate_transparency/single_tree_tracker.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/metrics/histogram_macros.h" | |
| 9 #include "net/cert/ct_log_verifier.h" | 10 #include "net/cert/ct_log_verifier.h" |
| 10 #include "net/cert/signed_certificate_timestamp.h" | 11 #include "net/cert/signed_certificate_timestamp.h" |
| 11 #include "net/cert/x509_certificate.h" | 12 #include "net/cert/x509_certificate.h" |
| 12 | 13 |
| 13 using net::ct::SignedTreeHead; | 14 using net::ct::SignedTreeHead; |
| 14 | 15 |
| 15 namespace certificate_transparency { | 16 namespace certificate_transparency { |
| 16 | 17 |
| 18 namespace internal { | |
| 19 | |
| 20 const char kCanCheckForInclusionHistogramName[] = | |
| 21 "Net.CertificateTransparency.CanInclusionCheckSCT"; | |
| 22 | |
| 23 } // namespace internal | |
| 24 | |
| 25 namespace { | |
| 26 | |
| 27 void LogCanBeCheckedForInclusionToUMA(bool can_be_checked) { | |
|
Eran Messeri
2016/07/21 17:53:43
FYI I've documented, in this function, what we're
| |
| 28 UMA_HISTOGRAM_BOOLEAN(internal::kCanCheckForInclusionHistogramName, | |
| 29 can_be_checked); | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
|
Ryan Sleevi
2016/07/20 20:34:00
Generally we try to have the unnamed namespace at
Eran Messeri
2016/07/21 17:53:43
Moved the unnamed namespace to the top, will keep
| |
| 33 | |
| 17 SingleTreeTracker::SingleTreeTracker( | 34 SingleTreeTracker::SingleTreeTracker( |
| 18 scoped_refptr<const net::CTLogVerifier> ct_log) | 35 scoped_refptr<const net::CTLogVerifier> ct_log) |
| 19 : ct_log_(std::move(ct_log)) {} | 36 : ct_log_(std::move(ct_log)) {} |
| 20 | 37 |
| 21 SingleTreeTracker::~SingleTreeTracker() {} | 38 SingleTreeTracker::~SingleTreeTracker() {} |
| 22 | 39 |
| 23 void SingleTreeTracker::OnSCTVerified( | 40 void SingleTreeTracker::OnSCTVerified( |
| 24 net::X509Certificate* cert, | 41 net::X509Certificate* cert, |
| 25 const net::ct::SignedCertificateTimestamp* sct) { | 42 const net::ct::SignedCertificateTimestamp* sct) { |
| 26 DCHECK_EQ(ct_log_->key_id(), sct->log_id); | 43 DCHECK_EQ(ct_log_->key_id(), sct->log_id); |
| 27 | 44 |
| 28 // SCT was previously observed, so its status should not be changed. | 45 // SCT was previously observed, so its status should not be changed. |
| 29 if (entries_status_.find(sct->timestamp) != entries_status_.end()) | 46 if (entries_status_.find(sct->timestamp) != entries_status_.end()) |
| 30 return; | 47 return; |
| 31 | 48 |
| 32 // If there isn't a valid STH or the STH is not fresh enough to check | 49 // If there isn't a valid STH or the STH is not fresh enough to check |
| 33 // inclusion against, store the SCT for future checking and return. | 50 // inclusion against, store the SCT for future checking and return. |
| 34 if (verified_sth_.timestamp.is_null() || | 51 if (verified_sth_.timestamp.is_null() || |
| 35 (verified_sth_.timestamp < | 52 (verified_sth_.timestamp < |
| 36 (sct->timestamp + base::TimeDelta::FromHours(24)))) { | 53 (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( | 54 entries_status_.insert( |
| 40 std::make_pair(sct->timestamp, SCT_PENDING_NEWER_STH)); | 55 std::make_pair(sct->timestamp, SCT_PENDING_NEWER_STH)); |
| 56 | |
| 57 // Do not log histogram if there's no STH for this log yet, as it does | |
| 58 // not provide any meaningful data on how fresh SCTs usually are. | |
| 59 if (!verified_sth_.timestamp.is_null()) | |
| 60 LogCanBeCheckedForInclusionToUMA(false); | |
| 41 return; | 61 return; |
| 42 } | 62 } |
| 43 | 63 |
| 64 LogCanBeCheckedForInclusionToUMA(true); | |
| 44 // TODO(eranm): Check inclusion here. | 65 // TODO(eranm): Check inclusion here. |
| 45 // TODO(eranm): UMA - how often inclusion can be checked immediately. | |
| 46 entries_status_.insert( | 66 entries_status_.insert( |
| 47 std::make_pair(sct->timestamp, SCT_PENDING_INCLUSION_CHECK)); | 67 std::make_pair(sct->timestamp, SCT_PENDING_INCLUSION_CHECK)); |
| 48 } | 68 } |
| 49 | 69 |
| 50 void SingleTreeTracker::NewSTHObserved(const SignedTreeHead& sth) { | 70 void SingleTreeTracker::NewSTHObserved(const SignedTreeHead& sth) { |
| 51 DCHECK_EQ(ct_log_->key_id(), sth.log_id); | 71 DCHECK_EQ(ct_log_->key_id(), sth.log_id); |
| 52 | 72 |
| 53 if (!ct_log_->VerifySignedTreeHead(sth)) { | 73 if (!ct_log_->VerifySignedTreeHead(sth)) { |
| 54 // Sanity check the STH; the caller should have done this | 74 // Sanity check the STH; the caller should have done this |
| 55 // already, but being paranoid here. | 75 // already, but being paranoid here. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 SingleTreeTracker::SCTInclusionStatus | 111 SingleTreeTracker::SCTInclusionStatus |
| 92 SingleTreeTracker::GetLogEntryInclusionStatus( | 112 SingleTreeTracker::GetLogEntryInclusionStatus( |
| 93 net::X509Certificate* cert, | 113 net::X509Certificate* cert, |
| 94 const net::ct::SignedCertificateTimestamp* sct) { | 114 const net::ct::SignedCertificateTimestamp* sct) { |
| 95 auto it = entries_status_.find(sct->timestamp); | 115 auto it = entries_status_.find(sct->timestamp); |
| 96 | 116 |
| 97 return it == entries_status_.end() ? SCT_NOT_OBSERVED : it->second; | 117 return it == entries_status_.end() ? SCT_NOT_OBSERVED : it->second; |
| 98 } | 118 } |
| 99 | 119 |
| 100 } // namespace certificate_transparency | 120 } // namespace certificate_transparency |
| OLD | NEW |