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

Side by Side Diff: net/cert/sth_distributor.cc

Issue 1968053002: Certificate Transparency: Notify STH Observers of known STHs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final operator, test changes Created 4 years, 7 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 | « net/cert/sth_distributor.h ('k') | net/cert/sth_distributor_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 "net/cert/sth_distributor.h" 5 #include "net/cert/sth_distributor.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "net/cert/signed_tree_head.h" 9 #include "net/cert/signed_tree_head.h"
10 10
11 namespace { 11 namespace {
12 const uint8_t kPilotLogID[] = {0xa4, 0xb9, 0x09, 0x90, 0xb4, 0x18, 0x58, 0x14, 12 const uint8_t kPilotLogID[] = {0xa4, 0xb9, 0x09, 0x90, 0xb4, 0x18, 0x58, 0x14,
13 0x87, 0xbb, 0x13, 0xa2, 0xcc, 0x67, 0x70, 0x0a, 13 0x87, 0xbb, 0x13, 0xa2, 0xcc, 0x67, 0x70, 0x0a,
14 0x3c, 0x35, 0x98, 0x04, 0xf9, 0x1b, 0xdf, 0xb8, 14 0x3c, 0x35, 0x98, 0x04, 0xf9, 0x1b, 0xdf, 0xb8,
15 0xe3, 0x77, 0xcd, 0x0e, 0xc8, 0x0d, 0xdc, 0x10}; 15 0xe3, 0x77, 0xcd, 0x0e, 0xc8, 0x0d, 0xdc, 0x10};
16 } 16 }
17 17
18 namespace net { 18 namespace net {
19 19
20 namespace ct { 20 namespace ct {
21 21
22 STHDistributor::STHDistributor() 22 STHDistributor::STHDistributor()
23 : observer_list_(base::ObserverList<STHObserver>::NOTIFY_EXISTING_ONLY) {} 23 : observer_list_(base::ObserverList<STHObserver>::NOTIFY_EXISTING_ONLY) {}
24 24
25 STHDistributor::~STHDistributor() {} 25 STHDistributor::~STHDistributor() {}
26 26
27 void STHDistributor::NewSTHObserved(const SignedTreeHead& sth) { 27 void STHDistributor::NewSTHObserved(const SignedTreeHead& sth) {
28 auto it = std::find_if(observed_sths_.begin(), observed_sths_.end(),
29 [&sth](const SignedTreeHead& other) {
30 return sth.log_id == other.log_id;
31 });
32
33 if (it == observed_sths_.end())
34 observed_sths_.push_back(sth);
35 else
36 *it = sth;
37
28 FOR_EACH_OBSERVER(STHObserver, observer_list_, NewSTHObserved(sth)); 38 FOR_EACH_OBSERVER(STHObserver, observer_list_, NewSTHObserved(sth));
29 39
30 if (sth.log_id.compare(0, sth.log_id.size(), 40 if (sth.log_id.compare(0, sth.log_id.size(),
31 reinterpret_cast<const char*>(kPilotLogID), 41 reinterpret_cast<const char*>(kPilotLogID),
32 sizeof(kPilotLogID)) != 0) 42 sizeof(kPilotLogID)) != 0)
33 return; 43 return;
34 44
35 const base::TimeDelta sth_age = base::Time::Now() - sth.timestamp; 45 const base::TimeDelta sth_age = base::Time::Now() - sth.timestamp;
36 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertificateTransparency.PilotSTHAge", sth_age, 46 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertificateTransparency.PilotSTHAge", sth_age,
37 base::TimeDelta::FromHours(1), 47 base::TimeDelta::FromHours(1),
38 base::TimeDelta::FromDays(4), 100); 48 base::TimeDelta::FromDays(4), 100);
39 } 49 }
40 50
41 void STHDistributor::RegisterObserver(STHObserver* observer) { 51 void STHDistributor::RegisterObserver(STHObserver* observer) {
42 observer_list_.AddObserver(observer); 52 observer_list_.AddObserver(observer);
53 // Make a local copy, because notifying the |observer| of a
54 // new STH may result in this class being notified of a
55 // (different) new STH, thus invalidating the iterator.
56 std::vector<SignedTreeHead> local_sths(observed_sths_);
57
58 for (const auto& sth : local_sths)
59 observer->NewSTHObserved(sth);
43 } 60 }
44 61
45 void STHDistributor::UnregisterObserver(STHObserver* observer) { 62 void STHDistributor::UnregisterObserver(STHObserver* observer) {
46 observer_list_.RemoveObserver(observer); 63 observer_list_.RemoveObserver(observer);
47 } 64 }
48 65
49 } // namespace ct 66 } // namespace ct
50 67
51 } // namespace net 68 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/sth_distributor.h ('k') | net/cert/sth_distributor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698