Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: components/certificate_transparency/single_tree_tracker.cc

Issue 2153123002: Certificate Transparency: Collect metrics on age of SCT vs STH (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing Ryan's comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/certificate_transparency/single_tree_tracker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
16 namespace {
17
18 // Measure how often clients encounter very new SCTs, by measuring whether an
19 // SCT can be checked for inclusion upon first observation.
20 //
21 // When an SCT is observed, if the SingleTreeTracker instance has a valid STH
22 // and the STH covers the SCT (the timestamp in the SCT is less than MMD +
23 // timestamp in the STH), this function should be called with |can_be_checked|
24 // set to true.
25 // If the STH does not cover the SCT (the timestamp in the SCT is greater than
26 // MMD + timestamp in the STH), this function should be called with false.
27 //
28 // If the SingleTreeTracker does not have a valid STH, then this function
29 // should not be called as it would not yield meaningful data on how frequently
30 // clients encounter very fresh SCTs, as otherwise all observed SCTs would be
31 // logged as if they cannot be checked for inclusion, skewing the data.
Ryan Sleevi 2016/07/21 18:15:01 I don't understand this last comment, from a desig
Eran Messeri 2016/07/21 20:01:33 If I understand correctly, the question is why I d
Ryan Sleevi 2016/07/21 20:14:18 No, because we can filter out that population of u
Eran Messeri 2016/07/22 10:40:28 Acknowledged.
32 void LogCanBeCheckedForInclusionToUMA(bool can_be_checked) {
33 UMA_HISTOGRAM_BOOLEAN("Net.CertificateTransparency.CanInclusionCheckSCT",
34 can_be_checked);
35 }
36
37 } // namespace
38
15 namespace certificate_transparency { 39 namespace certificate_transparency {
16 40
17 SingleTreeTracker::SingleTreeTracker( 41 SingleTreeTracker::SingleTreeTracker(
18 scoped_refptr<const net::CTLogVerifier> ct_log) 42 scoped_refptr<const net::CTLogVerifier> ct_log)
19 : ct_log_(std::move(ct_log)) {} 43 : ct_log_(std::move(ct_log)) {}
20 44
21 SingleTreeTracker::~SingleTreeTracker() {} 45 SingleTreeTracker::~SingleTreeTracker() {}
22 46
23 void SingleTreeTracker::OnSCTVerified( 47 void SingleTreeTracker::OnSCTVerified(
24 net::X509Certificate* cert, 48 net::X509Certificate* cert,
25 const net::ct::SignedCertificateTimestamp* sct) { 49 const net::ct::SignedCertificateTimestamp* sct) {
26 DCHECK_EQ(ct_log_->key_id(), sct->log_id); 50 DCHECK_EQ(ct_log_->key_id(), sct->log_id);
27 51
28 // SCT was previously observed, so its status should not be changed. 52 // SCT was previously observed, so its status should not be changed.
29 if (entries_status_.find(sct->timestamp) != entries_status_.end()) 53 if (entries_status_.find(sct->timestamp) != entries_status_.end())
30 return; 54 return;
31 55
32 // If there isn't a valid STH or the STH is not fresh enough to check 56 // 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. 57 // inclusion against, store the SCT for future checking and return.
34 if (verified_sth_.timestamp.is_null() || 58 if (verified_sth_.timestamp.is_null() ||
35 (verified_sth_.timestamp < 59 (verified_sth_.timestamp <
36 (sct->timestamp + base::TimeDelta::FromHours(24)))) { 60 (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( 61 entries_status_.insert(
40 std::make_pair(sct->timestamp, SCT_PENDING_NEWER_STH)); 62 std::make_pair(sct->timestamp, SCT_PENDING_NEWER_STH));
63
64 // Do not log histogram if there's no STH for this log yet, as it does
65 // not provide any meaningful data on how fresh SCTs usually are.
66 if (!verified_sth_.timestamp.is_null())
67 LogCanBeCheckedForInclusionToUMA(false);
41 return; 68 return;
42 } 69 }
43 70
71 LogCanBeCheckedForInclusionToUMA(true);
44 // TODO(eranm): Check inclusion here. 72 // TODO(eranm): Check inclusion here.
45 // TODO(eranm): UMA - how often inclusion can be checked immediately.
46 entries_status_.insert( 73 entries_status_.insert(
47 std::make_pair(sct->timestamp, SCT_PENDING_INCLUSION_CHECK)); 74 std::make_pair(sct->timestamp, SCT_PENDING_INCLUSION_CHECK));
48 } 75 }
49 76
50 void SingleTreeTracker::NewSTHObserved(const SignedTreeHead& sth) { 77 void SingleTreeTracker::NewSTHObserved(const SignedTreeHead& sth) {
51 DCHECK_EQ(ct_log_->key_id(), sth.log_id); 78 DCHECK_EQ(ct_log_->key_id(), sth.log_id);
52 79
53 if (!ct_log_->VerifySignedTreeHead(sth)) { 80 if (!ct_log_->VerifySignedTreeHead(sth)) {
54 // Sanity check the STH; the caller should have done this 81 // Sanity check the STH; the caller should have done this
55 // already, but being paranoid here. 82 // already, but being paranoid here.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 SingleTreeTracker::SCTInclusionStatus 118 SingleTreeTracker::SCTInclusionStatus
92 SingleTreeTracker::GetLogEntryInclusionStatus( 119 SingleTreeTracker::GetLogEntryInclusionStatus(
93 net::X509Certificate* cert, 120 net::X509Certificate* cert,
94 const net::ct::SignedCertificateTimestamp* sct) { 121 const net::ct::SignedCertificateTimestamp* sct) {
95 auto it = entries_status_.find(sct->timestamp); 122 auto it = entries_status_.find(sct->timestamp);
96 123
97 return it == entries_status_.end() ? SCT_NOT_OBSERVED : it->second; 124 return it == entries_status_.end() ? SCT_NOT_OBSERVED : it->second;
98 } 125 }
99 126
100 } // namespace certificate_transparency 127 } // namespace certificate_transparency
OLDNEW
« no previous file with comments | « no previous file | components/certificate_transparency/single_tree_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698