Chromium Code Reviews| Index: components/certificate_transparency/single_tree_tracker.h |
| diff --git a/components/certificate_transparency/single_tree_tracker.h b/components/certificate_transparency/single_tree_tracker.h |
| index f7afe72c3b449ed80396f12f54744cce005f38cf..d771af8b7d9cf8bd573a1435f58ce7eb3a65fe83 100644 |
| --- a/components/certificate_transparency/single_tree_tracker.h |
| +++ b/components/certificate_transparency/single_tree_tracker.h |
| @@ -6,26 +6,36 @@ |
| #define COMPONENTS_CERTIFICATE_TRANSPARENCY_SINGLE_TREE_TRACKER_H_ |
| #include <map> |
| +#include <memory> |
| #include <string> |
| +#include "base/containers/mru_cache.h" |
| +#include "base/memory/memory_pressure_monitor.h" |
| #include "base/memory/ref_counted.h" |
| -#include "base/time/time.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "net/base/hash_value.h" |
| #include "net/cert/ct_verifier.h" |
| #include "net/cert/signed_tree_head.h" |
| #include "net/cert/sth_observer.h" |
| namespace net { |
| + |
| class CTLogVerifier; |
| class X509Certificate; |
| namespace ct { |
| + |
| +struct MerkleAuditProof; |
| struct SignedCertificateTimestamp; |
| + |
| } // namespace ct |
| } // namespace net |
| namespace certificate_transparency { |
| +class LogDnsClient; |
| + |
| // Tracks the state of an individual Certificate Transparency Log's Merkle Tree. |
| // A CT Log constantly issues Signed Tree Heads, for which every older STH must |
| // be incorporated into the current/newer STH. As new certificates are logged, |
| @@ -48,8 +58,6 @@ namespace certificate_transparency { |
| class SingleTreeTracker : public net::CTVerifier::Observer, |
| public net::ct::STHObserver { |
| public: |
| - // TODO(eranm): This enum will expand to include check success/failure, |
| - // see crbug.com/506227 |
| enum SCTInclusionStatus { |
| // SCT was not observed by this class and is not currently pending |
| // inclusion check. As there's no evidence the SCT this status relates |
| @@ -62,11 +70,15 @@ class SingleTreeTracker : public net::CTVerifier::Observer, |
| SCT_PENDING_NEWER_STH, |
| // SCT is known and there's a new-enough STH to check inclusion against. |
| - // Actual inclusion check has to be performed. |
| - SCT_PENDING_INCLUSION_CHECK |
| + // It's in the process of being checked for inclusion. |
| + SCT_PENDING_INCLUSION_CHECK, |
| + |
| + // Inclusion check succeeded. |
| + SCT_INCLUDED_IN_LOG, |
| }; |
| - explicit SingleTreeTracker(scoped_refptr<const net::CTLogVerifier> ct_log); |
| + SingleTreeTracker(scoped_refptr<const net::CTLogVerifier> ct_log, |
| + LogDnsClient* dns_client); |
| ~SingleTreeTracker() override; |
| // net::ct::CTVerifier::Observer implementation. |
| @@ -96,17 +108,61 @@ class SingleTreeTracker : public net::CTVerifier::Observer, |
| const net::ct::SignedCertificateTimestamp* sct); |
| private: |
| + struct EntryToAudit; |
| + struct EntryAuditState; |
| + struct EntryAuditResult; |
| + |
| + // Less-than comparator that orders entries from the oldest SCT timestamp to |
| + // the newest SCT timestamp |
|
Ryan Sleevi
2017/01/10 03:15:53
grammar nit: missing a full-stop here.
// Less-th
Eran Messeri
2017/01/17 11:37:57
Done.
|
| + struct OrderByTimestamp { |
| + bool operator()(const EntryToAudit& lhs, const EntryToAudit& rhs) const; |
| + }; |
| + |
| + // Requests an inclusion proof for each of the entries in |pending_entries_| |
| + // until throttled by the LogDnsClient. |
| + void ProcessPendingEntries(); |
| + |
| + // Identical to the public GetLogEntryInclusionStatus, except it |
| + // operates on an |entry| rather than cert, SCT combination. |
|
Ryan Sleevi
2017/01/10 03:15:53
Grammatically, there's an article missing here (un
Eran Messeri
2017/01/17 11:37:57
Done, PTAL - I've simply explained what it does an
|
| + SCTInclusionStatus GetAuditedEntryInclusionStatus(const EntryToAudit& entry); |
| + |
| + // Invoked by the LogDnsClient once an audit proof request was completed. |
|
Ryan Sleevi
2017/01/10 03:15:53
This line describes how it is used, not what it do
Eran Messeri
2017/01/17 11:37:57
Removed.
|
| + // Verifies the audit proof and updates the state of the entry accordingly: |
|
Ryan Sleevi
2017/01/10 03:15:53
the audit proof of what? ("of |entry|")
What is "
Eran Messeri
2017/01/17 11:37:57
Replaced my text with yours.
It's mostly correct -
|
| + // * If the audit proof was obtained successfully and validated, then |
| + // calls to GetLogEntryInclusionStatus with this entry will indicate |
| + // that the entry is included. |
| + // * If there was a failure to obtain the inclusion proof or it did not |
| + // validate, it is removed from the internal queue and considered to be |
| + // un-audited. |
| + void OnAuditProofObtained(const EntryToAudit& entry, int net_error); |
| + |
| + // Clear entries on low memory notifications callback. |
|
Ryan Sleevi
2017/01/10 03:15:53
// Clears entries to reduce memory overhead.
Expl
Eran Messeri
2017/01/17 11:37:57
Done.
|
| + void OnMemoryPressure( |
| + base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); |
| + |
| // Holds the latest STH fetched and verified for this log. |
| net::ct::SignedTreeHead verified_sth_; |
| // The log being tracked. |
| scoped_refptr<const net::CTLogVerifier> ct_log_; |
| - // List of log entries pending inclusion check. |
| - // TODO(eranm): Rather than rely on the timestamp, extend to to use the |
| - // whole MerkleTreeLeaf (RFC6962, section 3.4.) as a key. See |
| - // https://crbug.com/506227#c22 and https://crbug.com/613495 |
| - std::map<base::Time, SCTInclusionStatus> entries_status_; |
| + // Map of pending log entries to their state. |
|
Ryan Sleevi
2017/01/10 03:15:53
"Map of" is redundant here
From a header document
Eran Messeri
2017/01/17 11:37:57
Correct - all entries in this map are waiting to b
|
| + std::map<EntryToAudit, EntryAuditState, OrderByTimestamp> pending_entries_; |
| + |
| + // A cache of leaf hashes identifying entries which were checked for |
| + // inclusion (the key is the Leaf Hash of the log entry). |
| + // NOTE: The current implementation does not cache failures, the |
| + // EntryAuditResult struct is empty. |
|
Ryan Sleevi
2017/01/10 03:15:53
I'm not sure how to parse this comment.
Either
a)
Eran Messeri
2017/01/17 11:37:57
I've clarified that currently the presence of an e
|
| + base::MRUCache<net::SHA256HashValue, |
| + EntryAuditResult, |
| + net::SHA256HashValueLessThan> |
| + checked_entries_; |
| + |
| + LogDnsClient* dns_client_; |
| + |
| + std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
| + |
| + base::WeakPtrFactory<SingleTreeTracker> weak_factory_; |
| DISALLOW_COPY_AND_ASSIGN(SingleTreeTracker); |
| }; |