| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/sth_set_component_installer.h" | 5 #include "chrome/browser/component_updater/sth_set_component_installer.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.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/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "base/version.h" | 17 #include "base/version.h" |
| 18 #include "chrome/browser/net/sth_distributor_provider.h" | 18 #include "chrome/browser/net/sth_distributor_provider.h" |
| 19 #include "chrome/common/chrome_features.h" |
| 19 #include "components/component_updater/component_updater_paths.h" | 20 #include "components/component_updater/component_updater_paths.h" |
| 20 #include "components/safe_json/safe_json_parser.h" | 21 #include "components/safe_json/safe_json_parser.h" |
| 22 #include "components/variations/variations_associated_data.h" |
| 21 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 22 #include "crypto/sha2.h" | 24 #include "crypto/sha2.h" |
| 23 #include "net/cert/ct_log_response_parser.h" | 25 #include "net/cert/ct_log_response_parser.h" |
| 24 #include "net/cert/signed_tree_head.h" | 26 #include "net/cert/signed_tree_head.h" |
| 25 #include "net/cert/sth_distributor.h" | 27 #include "net/cert/sth_distributor.h" |
| 26 #include "net/cert/sth_observer.h" | 28 #include "net/cert/sth_observer.h" |
| 27 | 29 |
| 28 using component_updater::ComponentUpdateService; | 30 using component_updater::ComponentUpdateService; |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 // The extension id is: ojjgnpkioondelmggbekfhllhdaimnho | 46 // The extension id is: ojjgnpkioondelmggbekfhllhdaimnho |
| 45 const uint8_t kPublicKeySHA256[32] = { | 47 const uint8_t kPublicKeySHA256[32] = { |
| 46 0xe9, 0x96, 0xdf, 0xa8, 0xee, 0xd3, 0x4b, 0xc6, 0x61, 0x4a, 0x57, | 48 0xe9, 0x96, 0xdf, 0xa8, 0xee, 0xd3, 0x4b, 0xc6, 0x61, 0x4a, 0x57, |
| 47 0xbb, 0x73, 0x08, 0xcd, 0x7e, 0x51, 0x9b, 0xcc, 0x69, 0x08, 0x41, | 49 0xbb, 0x73, 0x08, 0xcd, 0x7e, 0x51, 0x9b, 0xcc, 0x69, 0x08, 0x41, |
| 48 0xe1, 0x96, 0x9f, 0x7c, 0xb1, 0x73, 0xef, 0x16, 0x80, 0x0a}; | 50 0xe1, 0x96, 0x9f, 0x7c, 0xb1, 0x73, 0xef, 0x16, 0x80, 0x0a}; |
| 49 | 51 |
| 50 const char kSTHSetFetcherManifestName[] = "Signed Tree Heads"; | 52 const char kSTHSetFetcherManifestName[] = "Signed Tree Heads"; |
| 51 | 53 |
| 52 STHSetComponentInstallerTraits::STHSetComponentInstallerTraits( | 54 STHSetComponentInstallerTraits::STHSetComponentInstallerTraits( |
| 53 net::ct::STHObserver* sth_observer) | 55 net::ct::STHObserver* sth_observer) |
| 54 : sth_observer_(sth_observer) {} | 56 : sth_observer_(sth_observer), weak_ptr_factory_(this) {} |
| 55 | 57 |
| 56 STHSetComponentInstallerTraits::~STHSetComponentInstallerTraits() {} | 58 STHSetComponentInstallerTraits::~STHSetComponentInstallerTraits() {} |
| 57 | 59 |
| 58 bool STHSetComponentInstallerTraits::CanAutoUpdate() const { | 60 bool STHSetComponentInstallerTraits::CanAutoUpdate() const { |
| 59 return true; | 61 return true; |
| 60 } | 62 } |
| 61 | 63 |
| 62 // Public data is delivered via this component, no need for encryption. | 64 // Public data is delivered via this component, no need for encryption. |
| 63 bool STHSetComponentInstallerTraits::RequiresNetworkEncryption() const { | 65 bool STHSetComponentInstallerTraits::RequiresNetworkEncryption() const { |
| 64 return false; | 66 return false; |
| 65 } | 67 } |
| 66 | 68 |
| 67 bool STHSetComponentInstallerTraits::OnCustomInstall( | 69 bool STHSetComponentInstallerTraits::OnCustomInstall( |
| 68 const base::DictionaryValue& manifest, | 70 const base::DictionaryValue& manifest, |
| 69 const base::FilePath& install_dir) { | 71 const base::FilePath& install_dir) { |
| 70 return true; // Nothing custom here. | 72 return true; // Nothing custom here. |
| 71 } | 73 } |
| 72 | 74 |
| 73 void STHSetComponentInstallerTraits::ComponentReady( | 75 void STHSetComponentInstallerTraits::ComponentReady( |
| 74 const base::Version& version, | 76 const base::Version& version, |
| 75 const base::FilePath& install_dir, | 77 const base::FilePath& install_dir, |
| 76 std::unique_ptr<base::DictionaryValue> manifest) { | 78 std::unique_ptr<base::DictionaryValue> manifest) { |
| 77 if (!content::BrowserThread::PostBlockingPoolTask( | 79 const base::Closure load_sths_closure = base::Bind( |
| 78 FROM_HERE, | 80 &STHSetComponentInstallerTraits::LoadSTHsFromDisk, |
| 79 base::Bind(&STHSetComponentInstallerTraits::LoadSTHsFromDisk, | 81 weak_ptr_factory_.GetWeakPtr(), GetInstalledPath(install_dir), version); |
| 80 base::Unretained(this), GetInstalledPath(install_dir), | 82 |
| 81 version))) { | 83 if (variations::GetVariationParamValueByFeature(features::kSTHSetComponent, |
| 82 NOTREACHED(); | 84 "delayed_load") != "no") { |
| 85 DVLOG(1) << "Delaying STHSet load until after start-up."; |
| 86 content::BrowserThread::PostAfterStartupTask( |
| 87 FROM_HERE, content::BrowserThread::GetBlockingPool(), |
| 88 load_sths_closure); |
| 89 } else { |
| 90 DVLOG(1) << "Loading STHSet during start-up."; |
| 91 content::BrowserThread::PostBlockingPoolTask(FROM_HERE, load_sths_closure); |
| 83 } | 92 } |
| 84 } | 93 } |
| 85 | 94 |
| 86 // Called during startup and installation before ComponentReady(). | 95 // Called during startup and installation before ComponentReady(). |
| 87 bool STHSetComponentInstallerTraits::VerifyInstallation( | 96 bool STHSetComponentInstallerTraits::VerifyInstallation( |
| 88 const base::DictionaryValue& manifest, | 97 const base::DictionaryValue& manifest, |
| 89 const base::FilePath& install_dir) const { | 98 const base::FilePath& install_dir) const { |
| 90 return base::PathExists(GetInstalledPath(install_dir)); | 99 return base::PathExists(GetInstalledPath(install_dir)); |
| 91 } | 100 } |
| 92 | 101 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 200 |
| 192 std::unique_ptr<ComponentInstallerTraits> traits( | 201 std::unique_ptr<ComponentInstallerTraits> traits( |
| 193 new STHSetComponentInstallerTraits(distributor)); | 202 new STHSetComponentInstallerTraits(distributor)); |
| 194 // |cus| will take ownership of |installer| during installer->Register(cus). | 203 // |cus| will take ownership of |installer| during installer->Register(cus). |
| 195 DefaultComponentInstaller* installer = | 204 DefaultComponentInstaller* installer = |
| 196 new DefaultComponentInstaller(std::move(traits)); | 205 new DefaultComponentInstaller(std::move(traits)); |
| 197 installer->Register(cus, base::Closure()); | 206 installer->Register(cus, base::Closure()); |
| 198 } | 207 } |
| 199 | 208 |
| 200 } // namespace component_updater | 209 } // namespace component_updater |
| OLD | NEW |