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

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: Fixing 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 // Enum indicating whether an SCT can be checked for inclusion and if not,
19 // the reason it cannot.
20 //
21 // Note: The numeric values are used within a histogram and should not change
22 // or be re-assigned.
23 enum SCTCanBeCheckedForInclusion {
24 // If the SingleTreeTracker does not have a valid STH, then a valid STH is
25 // first required to evaluate whether the SCT can be checked for inclusion
26 // or not.
27 VALID_STH_REQUIRED = 0,
28 // If the STH does not cover the SCT (the timestamp in the SCT is greater than
29 // MMD + timestamp in the STH), then a newer STH is needed.
30 NEWER_STH_REQUIRED = 1,
31 // When an SCT is observed, if the SingleTreeTracker instance has a valid STH
32 // and the STH covers the SCT (the timestamp in the SCT is less than MMD +
33 // timestamp in the STH), then it can be checked for inclusion.
34 CAN_BE_CHECKED = 2,
35 SCT_CAN_BE_CHECKED_MAX
36 };
37
38 // Measure how often clients encounter very new SCTs, by measuring whether an
39 // SCT can be checked for inclusion upon first observation.
40 void LogCanBeCheckedForInclusionToUMA(
41 SCTCanBeCheckedForInclusion can_be_checked) {
42 UMA_HISTOGRAM_ENUMERATION("Net.CertificateTransparency.CanInclusionCheckSCT",
43 can_be_checked, SCT_CAN_BE_CHECKED_MAX);
44 }
45
46 } // namespace
47
15 namespace certificate_transparency { 48 namespace certificate_transparency {
16 49
17 SingleTreeTracker::SingleTreeTracker( 50 SingleTreeTracker::SingleTreeTracker(
18 scoped_refptr<const net::CTLogVerifier> ct_log) 51 scoped_refptr<const net::CTLogVerifier> ct_log)
19 : ct_log_(std::move(ct_log)) {} 52 : ct_log_(std::move(ct_log)) {}
20 53
21 SingleTreeTracker::~SingleTreeTracker() {} 54 SingleTreeTracker::~SingleTreeTracker() {}
22 55
23 void SingleTreeTracker::OnSCTVerified( 56 void SingleTreeTracker::OnSCTVerified(
24 net::X509Certificate* cert, 57 net::X509Certificate* cert,
25 const net::ct::SignedCertificateTimestamp* sct) { 58 const net::ct::SignedCertificateTimestamp* sct) {
26 DCHECK_EQ(ct_log_->key_id(), sct->log_id); 59 DCHECK_EQ(ct_log_->key_id(), sct->log_id);
27 60
28 // SCT was previously observed, so its status should not be changed. 61 // SCT was previously observed, so its status should not be changed.
29 if (entries_status_.find(sct->timestamp) != entries_status_.end()) 62 if (entries_status_.find(sct->timestamp) != entries_status_.end())
30 return; 63 return;
31 64
32 // If there isn't a valid STH or the STH is not fresh enough to check 65 // 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. 66 // inclusion against, store the SCT for future checking and return.
34 if (verified_sth_.timestamp.is_null() || 67 if (verified_sth_.timestamp.is_null() ||
35 (verified_sth_.timestamp < 68 (verified_sth_.timestamp <
36 (sct->timestamp + base::TimeDelta::FromHours(24)))) { 69 (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( 70 entries_status_.insert(
40 std::make_pair(sct->timestamp, SCT_PENDING_NEWER_STH)); 71 std::make_pair(sct->timestamp, SCT_PENDING_NEWER_STH));
72
73 if (!verified_sth_.timestamp.is_null()) {
74 LogCanBeCheckedForInclusionToUMA(NEWER_STH_REQUIRED);
75 } else {
76 LogCanBeCheckedForInclusionToUMA(VALID_STH_REQUIRED);
77 }
78
41 return; 79 return;
42 } 80 }
43 81
82 LogCanBeCheckedForInclusionToUMA(CAN_BE_CHECKED);
44 // TODO(eranm): Check inclusion here. 83 // TODO(eranm): Check inclusion here.
45 // TODO(eranm): UMA - how often inclusion can be checked immediately.
46 entries_status_.insert( 84 entries_status_.insert(
47 std::make_pair(sct->timestamp, SCT_PENDING_INCLUSION_CHECK)); 85 std::make_pair(sct->timestamp, SCT_PENDING_INCLUSION_CHECK));
48 } 86 }
49 87
50 void SingleTreeTracker::NewSTHObserved(const SignedTreeHead& sth) { 88 void SingleTreeTracker::NewSTHObserved(const SignedTreeHead& sth) {
51 DCHECK_EQ(ct_log_->key_id(), sth.log_id); 89 DCHECK_EQ(ct_log_->key_id(), sth.log_id);
52 90
53 if (!ct_log_->VerifySignedTreeHead(sth)) { 91 if (!ct_log_->VerifySignedTreeHead(sth)) {
54 // Sanity check the STH; the caller should have done this 92 // Sanity check the STH; the caller should have done this
55 // already, but being paranoid here. 93 // already, but being paranoid here.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 SingleTreeTracker::SCTInclusionStatus 129 SingleTreeTracker::SCTInclusionStatus
92 SingleTreeTracker::GetLogEntryInclusionStatus( 130 SingleTreeTracker::GetLogEntryInclusionStatus(
93 net::X509Certificate* cert, 131 net::X509Certificate* cert,
94 const net::ct::SignedCertificateTimestamp* sct) { 132 const net::ct::SignedCertificateTimestamp* sct) {
95 auto it = entries_status_.find(sct->timestamp); 133 auto it = entries_status_.find(sct->timestamp);
96 134
97 return it == entries_status_.end() ? SCT_NOT_OBSERVED : it->second; 135 return it == entries_status_.end() ? SCT_NOT_OBSERVED : it->second;
98 } 136 }
99 137
100 } // namespace certificate_transparency 138 } // 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