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/component_updater/ev_whitelist_component_installer.h" | 5 #include "chrome/browser/component_updater/ev_whitelist_component_installer.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.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 "base/numerics/safe_conversions.h" |
15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
16 #include "chrome/browser/net/packed_ct_ev_whitelist.h" | 17 #include "chrome/browser/net/packed_ct_ev_whitelist.h" |
17 #include "components/component_updater/component_updater_paths.h" | 18 #include "components/component_updater/component_updater_paths.h" |
18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
19 #include "net/ssl/ssl_config_service.h" | 20 #include "net/ssl/ssl_config_service.h" |
20 | 21 |
21 using component_updater::ComponentUpdateService; | 22 using component_updater::ComponentUpdateService; |
22 | 23 |
23 namespace { | 24 namespace { |
24 const base::FilePath::CharType kCompressedEVWhitelistFileName[] = | 25 const base::FilePath::CharType kCompressedEVWhitelistFileName[] = |
25 FILE_PATH_LITERAL("ev_hashes_whitelist.bin"); | 26 FILE_PATH_LITERAL("ev_hashes_whitelist.bin"); |
| 27 |
| 28 base::FilePath GetEVWhitelistFilePath(const base::FilePath& base_path) { |
| 29 return base_path.Append(kCompressedEVWhitelistFileName); |
| 30 } |
| 31 |
| 32 void UpdateNewWhitelistData(const base::FilePath& new_whitelist_file, |
| 33 const base::FilePath& stored_whitelist_path) { |
| 34 VLOG(1) << "Reading new EV whitelist from file: " |
| 35 << new_whitelist_file.value(); |
| 36 std::string compressed_list; |
| 37 if (!base::ReadFileToString(new_whitelist_file, &compressed_list)) { |
| 38 VLOG(1) << "Failed reading from " << new_whitelist_file.value(); |
| 39 return; |
| 40 } |
| 41 |
| 42 scoped_refptr<net::ct::EVCertsWhitelist> new_whitelist( |
| 43 new PackedEVCertsWhitelist(compressed_list)); |
| 44 if (!new_whitelist->IsValid()) { |
| 45 VLOG(1) << "Failed uncompressing EV certs whitelist."; |
| 46 return; |
| 47 } |
| 48 |
| 49 if (base::IsValueInRangeForNumericType<int>(compressed_list.size())) { |
| 50 const int list_size = base::checked_cast<int>(compressed_list.size()); |
| 51 if (base::WriteFile(stored_whitelist_path, compressed_list.data(), |
| 52 list_size) != list_size) { |
| 53 LOG(WARNING) << "Failed to save new EV whitelist to file."; |
| 54 } |
| 55 } |
| 56 |
| 57 SetEVCertsWhitelist(new_whitelist); |
| 58 } |
| 59 |
| 60 void DoInitialLoadFromDisk(const base::FilePath& stored_whitelist_path) { |
| 61 if (stored_whitelist_path.empty()) { |
| 62 return; |
| 63 } |
| 64 |
| 65 VLOG(1) << "Initial load: reading EV whitelist from file: " |
| 66 << stored_whitelist_path.value(); |
| 67 std::string compressed_list; |
| 68 if (!base::ReadFileToString(stored_whitelist_path, &compressed_list)) { |
| 69 VLOG(1) << "Failed reading from " << stored_whitelist_path.value(); |
| 70 return; |
| 71 } |
| 72 |
| 73 scoped_refptr<net::ct::EVCertsWhitelist> new_whitelist( |
| 74 new PackedEVCertsWhitelist(compressed_list)); |
| 75 if (!new_whitelist->IsValid()) { |
| 76 VLOG(1) << "Failed uncompressing EV certs whitelist."; |
| 77 return; |
| 78 } |
| 79 |
| 80 VLOG(1) << "EV whitelist: Sucessfully loaded initial data."; |
| 81 SetEVCertsWhitelist(new_whitelist); |
| 82 } |
| 83 |
26 } // namespace | 84 } // namespace |
27 | 85 |
28 namespace component_updater { | 86 namespace component_updater { |
29 | 87 |
30 // The SHA256 of the SubjectPublicKeyInfo used to sign the extension. | 88 // The SHA256 of the SubjectPublicKeyInfo used to sign the extension. |
31 // The extension id is: oafdbfcohdcjandcenmccfopbeklnicp | 89 // The extension id is: oafdbfcohdcjandcenmccfopbeklnicp |
32 const uint8_t kPublicKeySHA256[32] = { | 90 const uint8_t kPublicKeySHA256[32] = { |
33 0xe0, 0x53, 0x15, 0x2e, 0x73, 0x29, 0x0d, 0x32, 0x4d, 0xc2, 0x25, | 91 0xe0, 0x53, 0x15, 0x2e, 0x73, 0x29, 0x0d, 0x32, 0x4d, 0xc2, 0x25, |
34 0xef, 0x14, 0xab, 0xd8, 0x2f, 0x84, 0xf5, 0x85, 0x9e, 0xc0, 0xfa, | 92 0xef, 0x14, 0xab, 0xd8, 0x2f, 0x84, 0xf5, 0x85, 0x9e, 0xc0, 0xfa, |
35 0x94, 0xbc, 0x99, 0xc9, 0x5a, 0x27, 0x55, 0x19, 0x83, 0xef}; | 93 0x94, 0xbc, 0x99, 0xc9, 0x5a, 0x27, 0x55, 0x19, 0x83, 0xef}; |
36 | 94 |
37 const char kEVWhitelistManifestName[] = "EV Certs CT whitelist"; | 95 const char kEVWhitelistManifestName[] = "EV Certs CT whitelist"; |
38 | 96 |
39 EVWhitelistComponentInstallerTraits::EVWhitelistComponentInstallerTraits() { | 97 EVWhitelistComponentInstallerTraits::EVWhitelistComponentInstallerTraits( |
| 98 const base::FilePath& base_path) |
| 99 : ev_whitelist_path_(GetEVWhitelistFilePath(base_path)) { |
40 } | 100 } |
41 | 101 |
42 bool EVWhitelistComponentInstallerTraits::CanAutoUpdate() const { | 102 bool EVWhitelistComponentInstallerTraits::CanAutoUpdate() const { |
43 return true; | 103 return true; |
44 } | 104 } |
45 | 105 |
46 bool EVWhitelistComponentInstallerTraits::OnCustomInstall( | 106 bool EVWhitelistComponentInstallerTraits::OnCustomInstall( |
47 const base::DictionaryValue& manifest, | 107 const base::DictionaryValue& manifest, |
48 const base::FilePath& install_dir) { | 108 const base::FilePath& install_dir) { |
49 VLOG(1) << "Entering EVWhitelistComponentInstallerTraits::OnCustomInstall."; | 109 VLOG(1) << "Entering EVWhitelistComponentInstallerTraits::OnCustomInstall."; |
(...skipping 11 matching lines...) Expand all Loading... |
61 | 121 |
62 void EVWhitelistComponentInstallerTraits::ComponentReady( | 122 void EVWhitelistComponentInstallerTraits::ComponentReady( |
63 const base::Version& version, | 123 const base::Version& version, |
64 const base::FilePath& path, | 124 const base::FilePath& path, |
65 scoped_ptr<base::DictionaryValue> manifest) { | 125 scoped_ptr<base::DictionaryValue> manifest) { |
66 VLOG(1) << "Component ready, version " << version.GetString() << " in " | 126 VLOG(1) << "Component ready, version " << version.GetString() << " in " |
67 << path.value(); | 127 << path.value(); |
68 | 128 |
69 const base::FilePath whitelist_file = GetInstalledPath(path); | 129 const base::FilePath whitelist_file = GetInstalledPath(path); |
70 content::BrowserThread::PostBlockingPoolTask( | 130 content::BrowserThread::PostBlockingPoolTask( |
71 FROM_HERE, base::Bind(&SetEVWhitelistFromFile, whitelist_file)); | 131 FROM_HERE, |
| 132 base::Bind(&UpdateNewWhitelistData, whitelist_file, ev_whitelist_path_)); |
72 } | 133 } |
73 | 134 |
74 bool EVWhitelistComponentInstallerTraits::VerifyInstallation( | 135 bool EVWhitelistComponentInstallerTraits::VerifyInstallation( |
75 const base::DictionaryValue& manifest, | 136 const base::DictionaryValue& manifest, |
76 const base::FilePath& install_dir) const { | 137 const base::FilePath& install_dir) const { |
77 const base::FilePath expected_file = GetInstalledPath(install_dir); | 138 const base::FilePath expected_file = GetInstalledPath(install_dir); |
78 VLOG(1) << "Verifying install: " << expected_file.value(); | 139 VLOG(1) << "Verifying install: " << expected_file.value(); |
79 if (!base::PathExists(expected_file)) { | 140 if (!base::PathExists(expected_file)) { |
80 VLOG(1) << "File missing."; | 141 VLOG(1) << "File missing."; |
81 return false; | 142 return false; |
(...skipping 19 matching lines...) Expand all Loading... |
101 void EVWhitelistComponentInstallerTraits::GetHash( | 162 void EVWhitelistComponentInstallerTraits::GetHash( |
102 std::vector<uint8_t>* hash) const { | 163 std::vector<uint8_t>* hash) const { |
103 hash->assign(kPublicKeySHA256, | 164 hash->assign(kPublicKeySHA256, |
104 kPublicKeySHA256 + arraysize(kPublicKeySHA256)); | 165 kPublicKeySHA256 + arraysize(kPublicKeySHA256)); |
105 } | 166 } |
106 | 167 |
107 std::string EVWhitelistComponentInstallerTraits::GetName() const { | 168 std::string EVWhitelistComponentInstallerTraits::GetName() const { |
108 return kEVWhitelistManifestName; | 169 return kEVWhitelistManifestName; |
109 } | 170 } |
110 | 171 |
111 void RegisterEVWhitelistComponent(ComponentUpdateService* cus) { | 172 void RegisterEVWhitelistComponent(ComponentUpdateService* cus, |
| 173 const base::FilePath& path) { |
112 VLOG(1) << "Registering EV whitelist component."; | 174 VLOG(1) << "Registering EV whitelist component."; |
113 | 175 |
114 scoped_ptr<ComponentInstallerTraits> traits( | 176 scoped_ptr<ComponentInstallerTraits> traits( |
115 new EVWhitelistComponentInstallerTraits()); | 177 new EVWhitelistComponentInstallerTraits(path)); |
116 // |cus| will take ownership of |installer| during installer->Register(cus). | 178 // |cus| will take ownership of |installer| during installer->Register(cus). |
117 DefaultComponentInstaller* installer = | 179 DefaultComponentInstaller* installer = |
118 new DefaultComponentInstaller(traits.Pass()); | 180 new DefaultComponentInstaller(traits.Pass()); |
119 installer->Register(cus); | 181 installer->Register(cus); |
| 182 |
| 183 if (!content::BrowserThread::PostBlockingPoolTask( |
| 184 FROM_HERE, |
| 185 base::Bind(&DoInitialLoadFromDisk, GetEVWhitelistFilePath(path)))) { |
| 186 NOTREACHED(); |
| 187 } |
120 } | 188 } |
121 | 189 |
122 } // namespace component_updater | 190 } // namespace component_updater |
OLD | NEW |