Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_CERTIFICATE_TRANSPARENCY_SINGLE_TREE_TRACKER_H_ | |
| 6 #define COMPONENTS_CERTIFICATE_TRANSPARENCY_SINGLE_TREE_TRACKER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/time/time.h" | |
| 14 #include "net/cert/ct_observer.h" | |
| 15 #include "net/cert/signed_tree_head.h" | |
| 16 | |
| 17 namespace net { | |
| 18 class CTLogVerifier; | |
| 19 class X509Certificate; | |
| 20 | |
| 21 namespace ct { | |
| 22 struct SignedCertificateTimestamp; | |
| 23 } // namespace ct | |
| 24 | |
| 25 } // namespace net | |
| 26 | |
| 27 namespace certificate_transparency { | |
| 28 | |
| 29 // Tracks the state of an individual CT log's Merkle Tree. By keeping the | |
| 30 // latest Signed Tree Head for a log, this class can check inclusion for | |
| 31 // observed SCTs. | |
| 32 class SingleTreeTracker : public net::ct::CTObserver { | |
| 33 public: | |
| 34 // TODO(eranm): This enum will expand to include check success/failure, | |
| 35 // see crbug.com/506227 | |
| 36 enum SCTInclusionStatus { | |
| 37 // SCT was not observed by this class. | |
| 38 SCT_NOT_OBSERVED, | |
| 39 | |
| 40 // SCT was observed but the STH known to this class is not old | |
| 41 // enough to check for inclusion. | |
| 42 SCT_PENDING_NEWER_STH, | |
| 43 | |
| 44 // SCT is known and there's a new-enough STH to check inclusion against. | |
| 45 // Actual inclusion check has to be performed. | |
| 46 SCT_PENDING_INCLUSION_CHECK | |
| 47 }; | |
| 48 | |
| 49 explicit SingleTreeTracker(scoped_refptr<const net::CTLogVerifier> ct_log); | |
| 50 ~SingleTreeTracker() override; | |
| 51 | |
| 52 // net::ct::CTVerifier::Observer implementation. | |
| 53 // Performs an inclusion check for the given certificate if the latest | |
| 54 // STH known for this log is older than sct.timestamp + MMD, enqueues | |
| 55 // the SCT for future checking later on. | |
| 56 // TODO(eranm): Make sure not to perform any synchronous, blocking operation | |
| 57 // here as this callback is invoked during certificate validation. | |
| 58 void OnSCTVerified(net::X509Certificate* cert, | |
|
Ryan Sleevi
2016/04/21 14:05:16
Note: If you ever expect |cert| to be retained, yo
Eran Messeri
2016/04/25 14:50:59
Acknowledged - I don't yet know if the |cert| will
Ryan Sleevi
2016/04/27 23:05:58
I'm not sure I know what you're asking. They're re
| |
| 59 const net::ct::SignedCertificateTimestamp* sct) override; | |
| 60 | |
| 61 // net::ct::STHObserver implementation. | |
| 62 // After verification of the signature over the |sth|, uses this | |
| 63 // STH for future inclusion checks. | |
| 64 void NewSTHObserved(const net::ct::SignedTreeHead& sth) override; | |
| 65 | |
| 66 // Returns the status of a given log entry (that is assembled from | |
| 67 // |cert| and |sct|). | |
| 68 SCTInclusionStatus GetLogEntryInclusionStatus( | |
| 69 net::X509Certificate* cert, | |
| 70 const net::ct::SignedCertificateTimestamp* sct); | |
| 71 | |
| 72 private: | |
| 73 // Logs an error and aborts if the provided log_id is not the same as the | |
| 74 // log id this instance knows of. | |
| 75 void CheckLogId(const std::string& log_id); | |
| 76 | |
| 77 // Holds the latest STH fetched and verified for each log. | |
| 78 net::ct::SignedTreeHead verified_sth_; | |
| 79 // The log tracked. | |
| 80 scoped_refptr<const net::CTLogVerifier> ct_log_; | |
| 81 // List of log entries pending inclusion check. | |
| 82 // TODO(eranm): Rather than rely on the timestamp, extend to to use the | |
| 83 // whole MerkleTreeLeaf (RFC6962, section 3.4.) as a key. See crbug.com/506227 | |
| 84 std::map<base::Time, SCTInclusionStatus> entries_status_; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(SingleTreeTracker); | |
| 87 }; | |
| 88 | |
| 89 } // namespace certificate_transparency | |
| 90 | |
| 91 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_SINGLE_TREE_TRACKER_H_ | |
| OLD | NEW |