OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/net/packed_ct_ev_whitelist.h" | 5 #include "chrome/browser/net/packed_ct_ev_whitelist.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/big_endian.h" | 11 #include "base/big_endian.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "chrome/browser/net/bit_stream_reader.h" | 15 #include "chrome/browser/net/bit_stream_reader.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "net/ssl/ssl_config_service.h" | 17 #include "net/ssl/ssl_config_service.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 const uint8_t kCertHashLengthBits = 64; // 8 bytes | 20 const uint8_t kCertHashLengthBits = 64; // 8 bytes |
21 const uint8_t kCertHashLength = kCertHashLengthBits / 8; | 21 const uint8_t kCertHashLength = kCertHashLengthBits / 8; |
22 const uint64_t kGolombMParameterBits = 47; // 2^47 | 22 const uint64_t kGolombMParameterBits = 47; // 2^47 |
23 | 23 |
24 void SetNewEVWhitelistInSSLConfigService( | 24 void SetEVWhitelistInSSLConfigService( |
25 const scoped_refptr<net::ct::EVCertsWhitelist>& new_whitelist) { | 25 const scoped_refptr<net::ct::EVCertsWhitelist>& new_whitelist) { |
| 26 VLOG(1) << "Setting new EV Certs whitelist."; |
26 net::SSLConfigService::SetEVCertsWhitelist(new_whitelist); | 27 net::SSLConfigService::SetEVCertsWhitelist(new_whitelist); |
27 } | 28 } |
28 | 29 |
29 int TruncatedHashesComparator(const void* v1, const void* v2) { | 30 int TruncatedHashesComparator(const void* v1, const void* v2) { |
30 const uint64_t& h1(*(static_cast<const uint64_t*>(v1))); | 31 const uint64_t& h1(*(static_cast<const uint64_t*>(v1))); |
31 const uint64_t& h2(*(static_cast<const uint64_t*>(v2))); | 32 const uint64_t& h2(*(static_cast<const uint64_t*>(v2))); |
32 if (h1 < h2) | 33 if (h1 < h2) |
33 return -1; | 34 return -1; |
34 else if (h1 > h2) | 35 else if (h1 > h2) |
35 return 1; | 36 return 1; |
36 return 0; | 37 return 0; |
37 } | 38 } |
38 } // namespace | 39 } // namespace |
39 | 40 |
40 void SetEVWhitelistFromFile(const base::FilePath& compressed_whitelist_file) { | 41 void SetEVCertsWhitelist( |
41 VLOG(1) << "Setting EV whitelist from file: " | 42 scoped_refptr<net::ct::EVCertsWhitelist> new_whitelist) { |
42 << compressed_whitelist_file.value(); | |
43 std::string compressed_list; | |
44 if (!base::ReadFileToString(compressed_whitelist_file, &compressed_list)) { | |
45 VLOG(1) << "Failed reading from " << compressed_whitelist_file.value(); | |
46 return; | |
47 } | |
48 | |
49 scoped_refptr<net::ct::EVCertsWhitelist> new_whitelist( | |
50 new PackedEVCertsWhitelist(compressed_list)); | |
51 if (!new_whitelist->IsValid()) { | 43 if (!new_whitelist->IsValid()) { |
52 VLOG(1) << "Failed uncompressing EV certs whitelist."; | 44 VLOG(1) << "EV Certs whitelist is not valid, not setting."; |
53 return; | 45 return; |
54 } | 46 } |
55 | 47 |
56 base::Closure assign_cb = | 48 base::Closure assign_cb = |
57 base::Bind(SetNewEVWhitelistInSSLConfigService, new_whitelist); | 49 base::Bind(SetEVWhitelistInSSLConfigService, new_whitelist); |
58 content::BrowserThread::PostTask( | 50 content::BrowserThread::PostTask( |
59 content::BrowserThread::IO, FROM_HERE, assign_cb); | 51 content::BrowserThread::IO, FROM_HERE, assign_cb); |
60 } | 52 } |
61 | 53 |
62 bool PackedEVCertsWhitelist::UncompressEVWhitelist( | 54 bool PackedEVCertsWhitelist::UncompressEVWhitelist( |
63 const std::string& compressed_whitelist, | 55 const std::string& compressed_whitelist, |
64 std::vector<uint64_t>* uncompressed_list) { | 56 std::vector<uint64_t>* uncompressed_list) { |
65 internal::BitStreamReader reader(base::StringPiece( | 57 internal::BitStreamReader reader(base::StringPiece( |
66 compressed_whitelist.data(), compressed_whitelist.size())); | 58 compressed_whitelist.data(), compressed_whitelist.size())); |
67 std::vector<uint64_t> result; | 59 std::vector<uint64_t> result; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 return bsearch(&hash_to_lookup, | 121 return bsearch(&hash_to_lookup, |
130 &whitelist_[0], | 122 &whitelist_[0], |
131 whitelist_.size(), | 123 whitelist_.size(), |
132 kCertHashLength, | 124 kCertHashLength, |
133 TruncatedHashesComparator) != NULL; | 125 TruncatedHashesComparator) != NULL; |
134 } | 126 } |
135 | 127 |
136 bool PackedEVCertsWhitelist::IsValid() const { | 128 bool PackedEVCertsWhitelist::IsValid() const { |
137 return is_whitelist_valid_; | 129 return is_whitelist_valid_; |
138 } | 130 } |
OLD | NEW |