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 "components/packed_ct_ev_whitelist/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 "components/packed_ct_ev_whitelist/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 SetEVWhitelistInSSLConfigService( | 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 VLOG(1) << "Setting new EV Certs whitelist."; |
27 net::SSLConfigService::SetEVCertsWhitelist(new_whitelist); | 27 net::SSLConfigService::SetEVCertsWhitelist(new_whitelist); |
28 } | 28 } |
29 | 29 |
30 int TruncatedHashesComparator(const void* v1, const void* v2) { | 30 int TruncatedHashesComparator(const void* v1, const void* v2) { |
31 const uint64_t& h1(*(static_cast<const uint64_t*>(v1))); | 31 const uint64_t& h1(*(static_cast<const uint64_t*>(v1))); |
32 const uint64_t& h2(*(static_cast<const uint64_t*>(v2))); | 32 const uint64_t& h2(*(static_cast<const uint64_t*>(v2))); |
33 if (h1 < h2) | 33 if (h1 < h2) |
34 return -1; | 34 return -1; |
35 else if (h1 > h2) | 35 else if (h1 > h2) |
36 return 1; | 36 return 1; |
37 return 0; | 37 return 0; |
38 } | 38 } |
39 } // namespace | 39 } // namespace |
40 | 40 |
| 41 namespace packed_ct_ev_whitelist { |
| 42 |
41 void SetEVCertsWhitelist(scoped_refptr<net::ct::EVCertsWhitelist> whitelist) { | 43 void SetEVCertsWhitelist(scoped_refptr<net::ct::EVCertsWhitelist> whitelist) { |
42 if (!whitelist->IsValid()) { | 44 if (!whitelist->IsValid()) { |
43 VLOG(1) << "EV Certs whitelist is not valid, not setting."; | 45 VLOG(1) << "EV Certs whitelist is not valid, not setting."; |
44 return; | 46 return; |
45 } | 47 } |
46 | 48 |
47 base::Closure assign_cb = | 49 base::Closure assign_cb = |
48 base::Bind(SetEVWhitelistInSSLConfigService, whitelist); | 50 base::Bind(SetEVWhitelistInSSLConfigService, whitelist); |
49 content::BrowserThread::PostTask( | 51 content::BrowserThread::PostTask( |
50 content::BrowserThread::IO, FROM_HERE, assign_cb); | 52 content::BrowserThread::IO, FROM_HERE, assign_cb); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 return bsearch(&hash_to_lookup, | 119 return bsearch(&hash_to_lookup, |
118 &whitelist_[0], | 120 &whitelist_[0], |
119 whitelist_.size(), | 121 whitelist_.size(), |
120 kCertHashLength, | 122 kCertHashLength, |
121 TruncatedHashesComparator) != NULL; | 123 TruncatedHashesComparator) != NULL; |
122 } | 124 } |
123 | 125 |
124 bool PackedEVCertsWhitelist::IsValid() const { | 126 bool PackedEVCertsWhitelist::IsValid() const { |
125 return whitelist_.size() > 0; | 127 return whitelist_.size() > 0; |
126 } | 128 } |
| 129 |
| 130 } // namespace packed_ct_ev_whitelist |
OLD | NEW |