Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_LOG_DNS_CLIENT_H_ | 5 #ifndef COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ |
| 6 #define COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ | 6 #define COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <string> | |
| 12 | 11 |
| 13 #include "base/callback.h" | 12 #include "base/callback.h" |
| 14 #include "base/macros.h" | 13 #include "base/macros.h" |
| 15 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
| 15 #include "net/base/net_errors.h" | |
| 16 #include "net/base/network_change_notifier.h" | 16 #include "net/base/network_change_notifier.h" |
| 17 #include "net/log/net_log.h" | 17 #include "net/log/net_log.h" |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 class DnsClient; | 20 class DnsClient; |
| 21 class DnsResponse; | |
| 22 class DnsTransaction; | |
| 23 namespace ct { | 21 namespace ct { |
| 24 struct MerkleAuditProof; | 22 struct MerkleAuditProof; |
| 25 } // namespace ct | 23 } // namespace ct |
| 26 } // namespace net | 24 } // namespace net |
| 27 | 25 |
| 28 namespace certificate_transparency { | 26 namespace certificate_transparency { |
| 29 | 27 |
| 30 // Queries Certificate Transparency (CT) log servers via DNS. | 28 // Queries Certificate Transparency (CT) log servers via DNS. |
| 31 // All queries are performed asynchronously. | 29 // All queries are performed asynchronously. |
| 32 // For more information, see | 30 // For more information, see |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 59 | 57 |
| 60 // Called by NetworkChangeNotifier when the DNS config changes. | 58 // Called by NetworkChangeNotifier when the DNS config changes. |
| 61 // The DnsClient's config will be updated in response. | 59 // The DnsClient's config will be updated in response. |
| 62 void OnDNSChanged() override; | 60 void OnDNSChanged() override; |
| 63 | 61 |
| 64 // Called by NetworkChangeNotifier when the DNS config is first read. | 62 // Called by NetworkChangeNotifier when the DNS config is first read. |
| 65 // The DnsClient's config will be updated in response. | 63 // The DnsClient's config will be updated in response. |
| 66 void OnInitialDNSConfigRead() override; | 64 void OnInitialDNSConfigRead() override; |
| 67 | 65 |
| 68 // Queries a CT log to retrieve an audit proof for the leaf with |leaf_hash|. | 66 // Queries a CT log to retrieve an audit proof for the leaf with |leaf_hash|. |
| 69 // The |leaf_hash| is the SHA-256 Merkle leaf hash (see RFC6962, section 2.1). | |
| 70 // The size of the CT log tree must be provided in |tree_size|. | |
| 71 // The log is identified by |domain_for_log|, which is the DNS name used as a | 67 // The log is identified by |domain_for_log|, which is the DNS name used as a |
| 72 // suffix for all queries. | 68 // suffix for all queries. |
| 73 // The |callback| is invoked when the query is complete, or an error occurs. | 69 // The |leaf_hash| is the SHA-256 Merkle leaf hash (see RFC6962, section 2.1). |
| 74 void QueryAuditProof(const std::string& domain_for_log, | 70 // The size of the CT log tree, for which the proof is requested, must be |
| 75 base::StringPiece leaf_hash, | 71 // provided in |tree_size|. |
| 76 uint64_t tree_size, | 72 // The |callback| is invoked when the query is complete, or an asynchronous |
|
Eran Messeri
2016/09/30 09:26:51
Nit: Mention that the |callback| is invoked only i
Rob Percival
2016/09/30 12:03:21
Done.
| |
| 77 const AuditProofCallback& callback); | 73 // error occurs. |
| 74 // Returns: | |
| 75 // - net::ERR_IO_PENDING if the query was successfully started and is | |
| 76 // continuing asynchronously. | |
| 77 // - net::ERR_TEMPORARILY_THROTTLED if the maximum number of concurrent | |
|
Eran Messeri
2016/09/30 09:26:51
nit: Add a TODO to refer to the mechanism for gett
Rob Percival
2016/09/30 12:03:21
Done.
| |
| 78 // queries are already in progress. Try again later. | |
| 79 // - net::ERR_NAME_RESOLUTION_FAILED if DNS queries are not possible. | |
| 80 // Check that the DnsConfig returned by NetworkChangeNotifier is valid. | |
| 81 // - net::ERR_INVALID_ARGUMENT if an argument is invalid, e.g. |leaf_hash| is | |
| 82 // not a SHA-256 hash. | |
| 83 net::Error QueryAuditProof(base::StringPiece domain_for_log, | |
| 84 base::StringPiece leaf_hash, | |
| 85 uint64_t tree_size, | |
| 86 const AuditProofCallback& callback); | |
| 78 | 87 |
| 79 private: | 88 private: |
| 80 // An audit proof query that is in progress. | 89 // An audit proof query that is in progress. |
| 81 class AuditProofQuery; | 90 class AuditProofQuery; |
| 82 | 91 |
| 83 // Invoked when an audit proof query completes. | 92 // Invoked when an audit proof query completes. |
| 84 // |callback| is the user-provided callback that should be notified. | 93 // |callback| is the user-provided callback that should be notified. |
| 85 // |result| is a net::Error indicating success or failure. | 94 // |result| is a net::Error indicating success or failure. |
| 86 // |query| is the query that has completed. | 95 // |query| is the query that has completed. |
| 87 // The query is removed from |audit_proof_queries_| by this method. | 96 // The query is removed from |audit_proof_queries_| by this method. |
| 88 void QueryAuditProofComplete(const AuditProofCallback& callback, | 97 void QueryAuditProofComplete(const AuditProofCallback& callback, |
| 89 int result, | 98 net::Error result, |
| 90 AuditProofQuery* query); | 99 AuditProofQuery* query); |
| 91 | 100 |
| 92 // Returns true if the maximum number of queries are currently in flight. | 101 // Returns true if the maximum number of queries are currently in flight. |
| 93 // If the maximum number of concurrency queries is set to 0, this will always | 102 // If the maximum number of concurrency queries is set to 0, this will always |
| 94 // return false. | 103 // return false. |
| 95 bool HasMaxConcurrentQueriesInProgress() const; | 104 bool HasMaxConcurrentQueriesInProgress() const; |
| 96 | 105 |
| 97 // Updates the |dns_client_| config using NetworkChangeNotifier. | 106 // Updates the |dns_client_| config using NetworkChangeNotifier. |
| 98 void UpdateDnsConfig(); | 107 void UpdateDnsConfig(); |
| 99 | 108 |
| 100 // Used to perform DNS queries. | 109 // Used to perform DNS queries. |
| 101 std::unique_ptr<net::DnsClient> dns_client_; | 110 std::unique_ptr<net::DnsClient> dns_client_; |
| 102 // Passed to the DNS client for logging. | 111 // Passed to the DNS client for logging. |
| 103 net::NetLogWithSource net_log_; | 112 net::NetLogWithSource net_log_; |
| 104 // Audit proof queries that haven't completed yet. | 113 // A FIFO queue of ongoing queries. Since entries will always be appended to |
| 114 // the end and lookups will typically yield entries at the beginning, | |
| 115 // std::list is an efficient choice. | |
| 105 std::list<std::unique_ptr<AuditProofQuery>> audit_proof_queries_; | 116 std::list<std::unique_ptr<AuditProofQuery>> audit_proof_queries_; |
| 106 // The maximum number of queries that can be in flight at one time. | 117 // The maximum number of queries that can be in flight at one time. |
| 107 size_t max_concurrent_queries_; | 118 size_t max_concurrent_queries_; |
| 108 // Creates weak_ptrs to this, for callback purposes. | 119 // Creates weak_ptrs to this, for callback purposes. |
| 109 base::WeakPtrFactory<LogDnsClient> weak_ptr_factory_; | 120 base::WeakPtrFactory<LogDnsClient> weak_ptr_factory_; |
| 110 | 121 |
| 111 DISALLOW_COPY_AND_ASSIGN(LogDnsClient); | 122 DISALLOW_COPY_AND_ASSIGN(LogDnsClient); |
| 112 }; | 123 }; |
| 113 | 124 |
| 114 } // namespace certificate_transparency | 125 } // namespace certificate_transparency |
| 115 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ | 126 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_LOG_DNS_CLIENT_H_ |
| OLD | NEW |