| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 #include "chrome/browser/component_updater/ssl_error_assistant_component_install
er.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" |
| 13 #include "chrome/browser/ssl/ssl_error_handler.h" |
| 14 #include "content/public/browser/browser_thread.h" |
| 15 |
| 16 using component_updater::ComponentUpdateService; |
| 17 |
| 18 namespace { |
| 19 |
| 20 const base::FilePath::CharType kConfigBinaryPbFileName[] = |
| 21 FILE_PATH_LITERAL("ssl_error_assistant.pb"); |
| 22 |
| 23 // The SHA256 of the SubjectPublicKeyInfo used to sign the extension. |
| 24 // The extension id is: giekcmmlnklenlaomppkphknjmnnpneh |
| 25 const uint8_t kPublicKeySHA256[32] = { |
| 26 0x68, 0x4a, 0x2c, 0xcb, 0xda, 0xb4, 0xdb, 0x0e, 0xcf, 0xfa, 0xf7, |
| 27 0xad, 0x9c, 0xdd, 0xfd, 0x47, 0x97, 0xe4, 0x73, 0x24, 0x67, 0x93, |
| 28 0x9c, 0xb1, 0x14, 0xcd, 0x3f, 0x54, 0x66, 0x25, 0x99, 0x3f}; |
| 29 |
| 30 void LoadProtoFromDisk(const base::FilePath& pb_path) { |
| 31 if (pb_path.empty()) |
| 32 return; |
| 33 |
| 34 std::string binary_pb; |
| 35 if (!base::ReadFileToString(pb_path, &binary_pb)) { |
| 36 // The file won't exist on new installations, so this is not always an |
| 37 // error. |
| 38 DVLOG(1) << "Failed reading from " << pb_path.value(); |
| 39 return; |
| 40 } |
| 41 auto proto = base::MakeUnique<chrome_browser_ssl::SSLErrorAssistantConfig>(); |
| 42 if (!proto->ParseFromString(binary_pb)) { |
| 43 DVLOG(1) << "Failed parsing proto " << pb_path.value(); |
| 44 return; |
| 45 } |
| 46 content::BrowserThread::PostTask( |
| 47 content::BrowserThread::UI, FROM_HERE, |
| 48 base::Bind(&SSLErrorHandler::SetErrorAssistantProto, |
| 49 base::Passed(std::move(proto)))); |
| 50 } |
| 51 |
| 52 } // namespace |
| 53 |
| 54 namespace component_updater { |
| 55 |
| 56 bool SSLErrorAssistantComponentInstallerTraits:: |
| 57 SupportsGroupPolicyEnabledComponentUpdates() const { |
| 58 return false; |
| 59 } |
| 60 |
| 61 bool SSLErrorAssistantComponentInstallerTraits::RequiresNetworkEncryption() |
| 62 const { |
| 63 return false; |
| 64 } |
| 65 |
| 66 update_client::CrxInstaller::Result |
| 67 SSLErrorAssistantComponentInstallerTraits::OnCustomInstall( |
| 68 const base::DictionaryValue& manifest, |
| 69 const base::FilePath& install_dir) { |
| 70 return update_client::CrxInstaller::Result(0); // Nothing custom here. |
| 71 } |
| 72 |
| 73 base::FilePath SSLErrorAssistantComponentInstallerTraits::GetInstalledPath( |
| 74 const base::FilePath& base) { |
| 75 return base.Append(kConfigBinaryPbFileName); |
| 76 } |
| 77 |
| 78 void SSLErrorAssistantComponentInstallerTraits::ComponentReady( |
| 79 const base::Version& version, |
| 80 const base::FilePath& install_dir, |
| 81 std::unique_ptr<base::DictionaryValue> manifest) { |
| 82 DVLOG(1) << "Component ready, version " << version.GetString() << " in " |
| 83 << install_dir.value(); |
| 84 |
| 85 if (!content::BrowserThread::PostBlockingPoolTask( |
| 86 FROM_HERE, |
| 87 base::Bind(&LoadProtoFromDisk, GetInstalledPath(install_dir)))) { |
| 88 NOTREACHED(); |
| 89 } |
| 90 } |
| 91 |
| 92 // Called during startup and installation before ComponentReady(). |
| 93 bool SSLErrorAssistantComponentInstallerTraits::VerifyInstallation( |
| 94 const base::DictionaryValue& manifest, |
| 95 const base::FilePath& install_dir) const { |
| 96 // No need to actually validate the proto here, since we'll do the checking |
| 97 // in PopulateFromDynamicUpdate(). |
| 98 return base::PathExists(GetInstalledPath(install_dir)); |
| 99 } |
| 100 |
| 101 base::FilePath |
| 102 SSLErrorAssistantComponentInstallerTraits::GetRelativeInstallDir() const { |
| 103 return base::FilePath(FILE_PATH_LITERAL("SSLErrorAssistant")); |
| 104 } |
| 105 |
| 106 void SSLErrorAssistantComponentInstallerTraits::GetHash( |
| 107 std::vector<uint8_t>* hash) const { |
| 108 hash->assign(kPublicKeySHA256, |
| 109 kPublicKeySHA256 + arraysize(kPublicKeySHA256)); |
| 110 } |
| 111 |
| 112 std::string SSLErrorAssistantComponentInstallerTraits::GetName() const { |
| 113 return "SSL Error Assistant"; |
| 114 } |
| 115 |
| 116 update_client::InstallerAttributes |
| 117 SSLErrorAssistantComponentInstallerTraits::GetInstallerAttributes() const { |
| 118 return update_client::InstallerAttributes(); |
| 119 } |
| 120 |
| 121 std::vector<std::string> |
| 122 SSLErrorAssistantComponentInstallerTraits::GetMimeTypes() const { |
| 123 return std::vector<std::string>(); |
| 124 } |
| 125 |
| 126 void RegisterSSLErrorAssistantComponent(ComponentUpdateService* cus, |
| 127 const base::FilePath& user_data_dir) { |
| 128 DVLOG(1) << "Registering SSL Error Assistant component."; |
| 129 |
| 130 std::unique_ptr<ComponentInstallerTraits> traits( |
| 131 new SSLErrorAssistantComponentInstallerTraits()); |
| 132 // |cus| takes ownership of |installer|. |
| 133 DefaultComponentInstaller* installer = |
| 134 new DefaultComponentInstaller(std::move(traits)); |
| 135 installer->Register(cus, base::Closure()); |
| 136 } |
| 137 |
| 138 } // namespace component_updater |
| OLD | NEW |