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

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: 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
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 const char kPendingSTHHistogramName[] =
18 "Net.CertificateTransparency.SCTNeedsFreshSTH";
19 }
20
15 namespace certificate_transparency { 21 namespace certificate_transparency {
16 22
17 SingleTreeTracker::SingleTreeTracker( 23 SingleTreeTracker::SingleTreeTracker(
18 scoped_refptr<const net::CTLogVerifier> ct_log) 24 scoped_refptr<const net::CTLogVerifier> ct_log)
19 : ct_log_(std::move(ct_log)) {} 25 : ct_log_(std::move(ct_log)) {}
20 26
21 SingleTreeTracker::~SingleTreeTracker() {} 27 SingleTreeTracker::~SingleTreeTracker() {}
22 28
23 void SingleTreeTracker::OnSCTVerified( 29 void SingleTreeTracker::OnSCTVerified(
24 net::X509Certificate* cert, 30 net::X509Certificate* cert,
25 const net::ct::SignedCertificateTimestamp* sct) { 31 const net::ct::SignedCertificateTimestamp* sct) {
26 DCHECK_EQ(ct_log_->key_id(), sct->log_id); 32 DCHECK_EQ(ct_log_->key_id(), sct->log_id);
27 33
28 // SCT was previously observed, so its status should not be changed. 34 // SCT was previously observed, so its status should not be changed.
29 if (entries_status_.find(sct->timestamp) != entries_status_.end()) 35 if (entries_status_.find(sct->timestamp) != entries_status_.end())
30 return; 36 return;
31 37
32 // If there isn't a valid STH or the STH is not fresh enough to check 38 // 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. 39 // inclusion against, store the SCT for future checking and return.
34 if (verified_sth_.timestamp.is_null() || 40 if (verified_sth_.timestamp.is_null() ||
35 (verified_sth_.timestamp < 41 (verified_sth_.timestamp <
36 (sct->timestamp + base::TimeDelta::FromHours(24)))) { 42 (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( 43 entries_status_.insert(
40 std::make_pair(sct->timestamp, SCT_PENDING_NEWER_STH)); 44 std::make_pair(sct->timestamp, SCT_PENDING_NEWER_STH));
45
46 // Do not log histogram if there's no STH for this log yet, as it does
47 // not provide any meaningful data on how fresh SCTs usually are.
48 if (!verified_sth_.timestamp.is_null())
49 UMA_HISTOGRAM_BOOLEAN(kPendingSTHHistogramName, true);
41 return; 50 return;
42 } 51 }
43 52
53 UMA_HISTOGRAM_BOOLEAN(kPendingSTHHistogramName, false);
44 // TODO(eranm): Check inclusion here. 54 // TODO(eranm): Check inclusion here.
45 // TODO(eranm): UMA - how often inclusion can be checked immediately.
46 entries_status_.insert( 55 entries_status_.insert(
47 std::make_pair(sct->timestamp, SCT_PENDING_INCLUSION_CHECK)); 56 std::make_pair(sct->timestamp, SCT_PENDING_INCLUSION_CHECK));
48 } 57 }
49 58
50 void SingleTreeTracker::NewSTHObserved(const SignedTreeHead& sth) { 59 void SingleTreeTracker::NewSTHObserved(const SignedTreeHead& sth) {
51 DCHECK_EQ(ct_log_->key_id(), sth.log_id); 60 DCHECK_EQ(ct_log_->key_id(), sth.log_id);
52 61
53 if (!ct_log_->VerifySignedTreeHead(sth)) { 62 if (!ct_log_->VerifySignedTreeHead(sth)) {
54 // Sanity check the STH; the caller should have done this 63 // Sanity check the STH; the caller should have done this
55 // already, but being paranoid here. 64 // already, but being paranoid here.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 SingleTreeTracker::SCTInclusionStatus 100 SingleTreeTracker::SCTInclusionStatus
92 SingleTreeTracker::GetLogEntryInclusionStatus( 101 SingleTreeTracker::GetLogEntryInclusionStatus(
93 net::X509Certificate* cert, 102 net::X509Certificate* cert,
94 const net::ct::SignedCertificateTimestamp* sct) { 103 const net::ct::SignedCertificateTimestamp* sct) {
95 auto it = entries_status_.find(sct->timestamp); 104 auto it = entries_status_.find(sct->timestamp);
96 105
97 return it == entries_status_.end() ? SCT_NOT_OBSERVED : it->second; 106 return it == entries_status_.end() ? SCT_NOT_OBSERVED : it->second;
98 } 107 }
99 108
100 } // namespace certificate_transparency 109 } // namespace certificate_transparency
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698