| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 CHROME_BROWSER_NET_PACKED_CT_EV_WHITELIST_H_ | |
| 6 #define CHROME_BROWSER_NET_PACKED_CT_EV_WHITELIST_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/gtest_prod_util.h" | |
| 14 #include "base/version.h" | |
| 15 #include "net/cert/ct_ev_whitelist.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class FilePath; | |
| 19 } | |
| 20 | |
| 21 // An implementation of the EVCertsWhitelist that gets its data packed using | |
| 22 // Golomb coding to encode the difference between subsequent hash values. | |
| 23 // Format of the packed list: | |
| 24 // * First 8 bytes: First hash | |
| 25 // * Repeating Golomb-coded number which is the numeric difference of the | |
| 26 // previous hash value from this one | |
| 27 // | |
| 28 // The resulting, unpacked list is a sorted list of hash values that can be | |
| 29 // efficiently searched. | |
| 30 class PackedEVCertsWhitelist : public net::ct::EVCertsWhitelist { | |
| 31 public: | |
| 32 // Unpacks the given |compressed_whitelist|. See the class documentation | |
| 33 // for description of the |compressed_whitelist| format. | |
| 34 PackedEVCertsWhitelist(const std::string& compressed_whitelist, | |
| 35 const base::Version& version); | |
| 36 | |
| 37 // Returns true if the |certificate_hash| appears in the EV certificate hashes | |
| 38 // whitelist. Must not be called if IsValid for this instance returned false. | |
| 39 bool ContainsCertificateHash( | |
| 40 const std::string& certificate_hash) const override; | |
| 41 | |
| 42 // Returns true if the EV certificate hashes whitelist provided in the c'tor | |
| 43 // was valid, false otherwise. | |
| 44 bool IsValid() const override; | |
| 45 | |
| 46 // Returns the version of the whitelist in use, if available. | |
| 47 base::Version Version() const override; | |
| 48 | |
| 49 protected: | |
| 50 ~PackedEVCertsWhitelist() override; | |
| 51 | |
| 52 private: | |
| 53 FRIEND_TEST_ALL_PREFIXES(PackedEVCertsWhitelistTest, | |
| 54 UncompressFailsForTooShortList); | |
| 55 FRIEND_TEST_ALL_PREFIXES(PackedEVCertsWhitelistTest, | |
| 56 UncompressFailsForTruncatedList); | |
| 57 FRIEND_TEST_ALL_PREFIXES(PackedEVCertsWhitelistTest, | |
| 58 UncompressFailsForInvalidValuesInList); | |
| 59 FRIEND_TEST_ALL_PREFIXES(PackedEVCertsWhitelistTest, | |
| 60 UncompressesWhitelistCorrectly); | |
| 61 | |
| 62 // Given a Golomb-coded list of hashes in |compressed_whitelist|, unpack into | |
| 63 // |uncompressed_list|. Returns true if the format of the compressed whitelist | |
| 64 // is valid, false otherwise. | |
| 65 static bool UncompressEVWhitelist(const std::string& compressed_whitelist, | |
| 66 std::vector<uint64_t>* uncompressed_list); | |
| 67 | |
| 68 // The whitelist is an array containing certificate hashes (truncated | |
| 69 // to a fixed size of 8 bytes), sorted. | |
| 70 // Binary search is used to locate hashes in the the array. | |
| 71 // Benchmarking bsearch vs std::set (with 120K entries, doing 1.2M lookups) | |
| 72 // shows that bsearch is about twice as fast as std::set lookups (and std::set | |
| 73 // has additional memory overhead). | |
| 74 std::vector<uint64_t> whitelist_; | |
| 75 base::Version version_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(PackedEVCertsWhitelist); | |
| 78 }; | |
| 79 | |
| 80 // Sets the EV certificate hashes whitelist in the SSLConfigService | |
| 81 // to the provided |whitelist|, if valid. Otherwise, does nothing. | |
| 82 // To set the new whitelist, this function dispatches a task to the IO thread. | |
| 83 void SetEVCertsWhitelist(scoped_refptr<net::ct::EVCertsWhitelist> whitelist); | |
| 84 | |
| 85 #endif // CHROME_BROWSER_NET_PACKED_CT_EV_WHITELIST_H_ | |
| OLD | NEW |