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

Side by Side Diff: chrome/browser/net/packed_ct_ev_whitelist.h

Issue 547603002: Certificate Transparency: Code for unpacking EV cert hashes whitelist (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Attempting to address ambiguity in c'tor selection Created 6 years, 2 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
OLDNEW
(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/memory/ref_counted.h"
Ryan Sleevi 2014/10/21 22:50:26 Unusued?
Eran Messeri 2014/10/22 10:53:26 Done.
15 #include "base/strings/string_piece.h"
Ryan Sleevi 2014/10/21 22:50:25 Unused?
Eran Messeri 2014/10/22 10:53:27 Done.
16 #include "net/cert/ct_ev_whitelist.h"
17
18 namespace base {
19 class FilePath;
20 }
21
22 // An implementation of the EVCertsWhitelist that gets its data packed using
23 // Golomb coding to encode the difference between subsequent hash values.
24 // Format of the packed list:
25 // * First 8 bytes: First hash
26 // * Repeating Golomb-coded number which is the numberic difference of the
Ryan Sleevi 2014/10/21 22:50:25 s/numeric/
Eran Messeri 2014/10/22 10:53:26 Done.
27 // previous hash value from this one
28 //
29 // The resulting, unpacked list is a sorted list of hash values that can be
30 // efficiently searched.
31 class PackedEVCertsWhitelist : public net::ct::EVCertsWhitelist {
32 public:
33 // Unpacks the given |compressed_whitelist|. See the class documentation
34 // for description of the |compressed_whitelist| format.
35 explicit PackedEVCertsWhitelist(const std::string& compressed_whitelist);
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 virtual 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 virtual bool IsValid() const override;
Ryan Sleevi 2014/10/21 22:50:25 latest Chromium style is you can drop the "virtual
Eran Messeri 2014/10/22 10:53:26 Done.
45
46 protected:
47 virtual ~PackedEVCertsWhitelist();
Ryan Sleevi 2014/10/21 22:50:25 latest Chromium style is ~PackedEVCertsWhitelist(
Eran Messeri 2014/10/22 10:53:26 Done.
48 FRIEND_TEST_ALL_PREFIXES(PackedEVCertsWhitelistTest,
49 UncompressFailsForTooShortList);
50 FRIEND_TEST_ALL_PREFIXES(PackedEVCertsWhitelistTest,
51 UncompressFailsForTruncatedList);
52 FRIEND_TEST_ALL_PREFIXES(PackedEVCertsWhitelistTest,
53 UncompressFailsForInvalidValuesInList);
54 FRIEND_TEST_ALL_PREFIXES(PackedEVCertsWhitelistTest,
55 UncompressesWhitelistCorrectly);
Ryan Sleevi 2014/10/21 22:50:25 These can / should all be private friends, not pro
Eran Messeri 2014/10/22 10:53:27 Done.
56
57 private:
58 // Given a Golomb-coded list of hashes in |compressed_whitelist|, unpack into
59 // |uncompressed_list|. Returns true if the format of the compressed whitelist
60 // is valid, false otherwise.
61 static bool UncompressEVWhitelist(
62 const std::string& compressed_whitelist,
63 std::vector<std::string>* uncompressed_list);
64
65 bool is_whitelist_valid_;
66 // The whitelist is an array containing certificate hashes (truncated
67 // to a fixed size of 8 bytes), sorted.
68 // Binary search is used to locate hashes in the the array.
69 // Benchmarking bsearch vs std::set (with 120K entries, doing 1.2M lookups)
70 // shows that bsearch is about twice as fast as std::set lookups (and std::set
71 // has additional memory overhead).
72 char* whitelist_;
73 uint32_t whitelist_size_;
Ryan Sleevi 2014/10/21 22:50:25 DISALLOW_COPY_AND_ASSIGN
Eran Messeri 2014/10/22 10:53:27 Done.
74 };
75
76 // Sets the EV certificate hashes whitelist from |compressed_whitelist_file|
77 // in |ssl_config_service|, after uncompressing it.
78 // If the data in |compressed_whitelist_file| is not a valid compressed
79 // whitelist, does nothing.
80 // As this function performs file operations, it should be called from a
81 // blocking pool worker or a file worker.
82 // To set the new whitelist, this function dispatches a task to the IO thread.
83 void SetEVWhitelistFromFile(const base::FilePath& compressed_whitelist_file);
84
85 #endif // CHROME_BROWSER_NET_PACKED_CT_EV_WHITELIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698