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

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

Issue 2017563002: Add Certificate Transparency logs auditing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Marking comparator const 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.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 #ifndef COMPONENTS_CERTIFICATE_TRANSPARENCY_SINGLE_TREE_TRACKER_H_ 5 #ifndef COMPONENTS_CERTIFICATE_TRANSPARENCY_SINGLE_TREE_TRACKER_H_
6 #define COMPONENTS_CERTIFICATE_TRANSPARENCY_SINGLE_TREE_TRACKER_H_ 6 #define COMPONENTS_CERTIFICATE_TRANSPARENCY_SINGLE_TREE_TRACKER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/optional.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "net/cert/ct_verifier.h" 14 #include "net/cert/ct_verifier.h"
15 #include "net/cert/merkle_tree_leaf.h"
14 #include "net/cert/signed_tree_head.h" 16 #include "net/cert/signed_tree_head.h"
15 #include "net/cert/sth_observer.h" 17 #include "net/cert/sth_observer.h"
16 18
17 namespace net { 19 namespace net {
18 class CTLogVerifier; 20 class CTLogVerifier;
19 class X509Certificate; 21 class X509Certificate;
20 22
21 namespace ct { 23 namespace ct {
22 struct SignedCertificateTimestamp; 24 struct SignedCertificateTimestamp;
23 } // namespace ct 25 } // namespace ct
24 26
25 } // namespace net 27 } // namespace net
26 28
27 namespace certificate_transparency { 29 namespace certificate_transparency {
28
29 // Tracks the state of an individual Certificate Transparency Log's Merkle Tree. 30 // Tracks the state of an individual Certificate Transparency Log's Merkle Tree.
30 // A CT Log constantly issues Signed Tree Heads, for which every older STH must 31 // A CT Log constantly issues Signed Tree Heads, for which every older STH must
31 // be incorporated into the current/newer STH. As new certificates are logged, 32 // be incorporated into the current/newer STH. As new certificates are logged,
32 // new SCTs are produced, and eventually, those SCTs are incorporated into the 33 // new SCTs are produced, and eventually, those SCTs are incorporated into the
33 // log and a new STH is produced, with there being an inclusion proof between 34 // log and a new STH is produced, with there being an inclusion proof between
34 // the SCTs and the new STH, and a consistency proof between the old STH and the 35 // the SCTs and the new STH, and a consistency proof between the old STH and the
35 // new STH. 36 // new STH.
36 // This class receives STHs provided by/observed by the embedder, with the 37 // This class receives STHs provided by/observed by the embedder, with the
37 // assumption that STHs have been checked for consistency already. As SCTs are 38 // assumption that STHs have been checked for consistency already. As SCTs are
38 // observed, their status is checked against the latest STH to ensure they were 39 // observed, their status is checked against the latest STH to ensure they were
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 90
90 // Returns the status of a given log entry that is assembled from 91 // Returns the status of a given log entry that is assembled from
91 // |cert| and |sct|. If |cert| and |sct| were not previously observed, 92 // |cert| and |sct|. If |cert| and |sct| were not previously observed,
92 // |sct| is not an SCT for |cert| or |sct| is not for this log, 93 // |sct| is not an SCT for |cert| or |sct| is not for this log,
93 // SCT_NOT_OBSERVED will be returned. 94 // SCT_NOT_OBSERVED will be returned.
94 SCTInclusionStatus GetLogEntryInclusionStatus( 95 SCTInclusionStatus GetLogEntryInclusionStatus(
95 net::X509Certificate* cert, 96 net::X509Certificate* cert,
96 const net::ct::SignedCertificateTimestamp* sct); 97 const net::ct::SignedCertificateTimestamp* sct);
97 98
98 private: 99 private:
100 // Contains metadata about a MerkleTreeLeaf: The time it was first observed
101 // by this client, the index of the MerkleTreeLeaf in the log, if known
102 // and its inclusion check status.
103 class LeafState {
Ryan Sleevi 2016/07/01 22:15:50 Declaring all of this in the .h defeats the very p
Eran Messeri 2016/07/13 14:42:56 Done.
104 public:
105 LeafState(SCTInclusionStatus status, const base::Time& observed_at);
106 LeafState(const LeafState& other);
107 LeafState(LeafState&&);
108 ~LeafState();
109
110 // Sets the index of the leaf in the tree. May be called only once per
111 // instance.
112 void SetLeafIndex(uint64_t index);
113
114 // Returns true if the leaf index was set for this instance.
115 bool HasLeafIndex() const;
116
117 // Returns the leaf index. May only be called on an instance where
118 // SetLeafIndex was called.
119 uint64_t GetLeafIndex() const;
120
121 // The time the leaf was observed.
122 const base::Time& ObservedAt() const;
123
124 // Returns the current inclusion status.
125 SCTInclusionStatus State() const;
126
127 // Sets the current inclusion status.
128 void SetState(SCTInclusionStatus status);
129
130 private:
131 // When the leaf for the particular certificate was first seen.
132 const base::Time observed_at_;
133
134 // The leaf's index in the tree. Only set if the index has been
135 // obtained from the log.
136 base::Optional<uint64_t> leaf_index_;
137
138 // Inclusion checking status of this leaf
139 SCTInclusionStatus state_;
140 };
141 // Orders LeafState instances by the timestamp of the MerkleTreeLeaf they
142 // contain, *not* the observation time.
143 struct OrderByTimestamp {
144 bool operator()(const net::ct::MerkleTreeLeaf& lhs,
145 const net::ct::MerkleTreeLeaf& rhs) const;
146 };
147
148 // Returns true if |leaf| has been observed in the past.
149 bool LeafAlreadyEncountered(const net::ct::MerkleTreeLeaf& leaf);
150
99 // Holds the latest STH fetched and verified for this log. 151 // Holds the latest STH fetched and verified for this log.
100 net::ct::SignedTreeHead verified_sth_; 152 net::ct::SignedTreeHead verified_sth_;
101 153
102 // The log being tracked. 154 // The log being tracked.
103 scoped_refptr<const net::CTLogVerifier> ct_log_; 155 scoped_refptr<const net::CTLogVerifier> ct_log_;
104 156
105 // List of log entries pending inclusion check. 157 // Map of log entries to their state.
106 // TODO(eranm): Rather than rely on the timestamp, extend to to use the 158 std::map<net::ct::MerkleTreeLeaf, LeafState, OrderByTimestamp>
107 // whole MerkleTreeLeaf (RFC6962, section 3.4.) as a key. See 159 observed_entries_;
108 // https://crbug.com/506227#c22 and https://crbug.com/613495
109 std::map<base::Time, SCTInclusionStatus> entries_status_;
110 160
111 DISALLOW_COPY_AND_ASSIGN(SingleTreeTracker); 161 DISALLOW_COPY_AND_ASSIGN(SingleTreeTracker);
112 }; 162 };
113 163
114 } // namespace certificate_transparency 164 } // namespace certificate_transparency
115 165
116 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_SINGLE_TREE_TRACKER_H_ 166 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_SINGLE_TREE_TRACKER_H_
OLDNEW
« no previous file with comments | « no previous file | components/certificate_transparency/single_tree_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698