Chromium Code Reviews| 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 VLOG(1) << "Reading SSL error assistant config from file: " | |
|
waffles
2017/02/09 22:33:56
Can we use DVLOG? This will happen in the performa
meacer
2017/02/09 23:06:40
Done, here and elsewhere.
| |
| 35 << pb_path.value(); | |
| 36 std::string binary_pb; | |
| 37 if (!base::ReadFileToString(pb_path, &binary_pb)) { | |
| 38 // The file won't exist on new installations, so this is not always an | |
| 39 // error. | |
| 40 VLOG(1) << "Failed reading from " << pb_path.value(); | |
| 41 return; | |
| 42 } | |
| 43 auto proto = base::MakeUnique<chrome_browser_ssl::SSLErrorAssistantConfig>(); | |
| 44 if (!proto->ParseFromString(binary_pb)) { | |
| 45 VLOG(1) << "Failed parsing proto " << pb_path.value(); | |
| 46 return; | |
| 47 } | |
| 48 content::BrowserThread::PostTask( | |
| 49 content::BrowserThread::UI, FROM_HERE, | |
| 50 base::Bind(&SSLErrorHandler::SetErrorAssistantProto, | |
| 51 base::Passed(std::move(proto)))); | |
| 52 } | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 56 namespace component_updater { | |
| 57 | |
| 58 bool SSLErrorAssistantComponentInstallerTraits:: | |
| 59 SupportsGroupPolicyEnabledComponentUpdates() const { | |
| 60 return false; | |
| 61 } | |
| 62 | |
| 63 bool SSLErrorAssistantComponentInstallerTraits::RequiresNetworkEncryption() | |
| 64 const { | |
| 65 return false; | |
| 66 } | |
| 67 | |
| 68 update_client::CrxInstaller::Result | |
| 69 SSLErrorAssistantComponentInstallerTraits::OnCustomInstall( | |
| 70 const base::DictionaryValue& manifest, | |
| 71 const base::FilePath& install_dir) { | |
| 72 return update_client::CrxInstaller::Result(0); // Nothing custom here. | |
| 73 } | |
| 74 | |
| 75 base::FilePath SSLErrorAssistantComponentInstallerTraits::GetInstalledPath( | |
| 76 const base::FilePath& base) { | |
| 77 LOG(ERROR) << ">> GetInstalledPath"; | |
|
waffles
2017/02/09 22:33:56
Remove this line.
meacer
2017/02/09 23:06:40
Done.
| |
| 78 return base.Append(kConfigBinaryPbFileName); | |
| 79 } | |
| 80 | |
| 81 void SSLErrorAssistantComponentInstallerTraits::ComponentReady( | |
| 82 const base::Version& version, | |
| 83 const base::FilePath& install_dir, | |
| 84 std::unique_ptr<base::DictionaryValue> manifest) { | |
| 85 VLOG(1) << "Component ready, version " << version.GetString() << " in " | |
| 86 << install_dir.value(); | |
| 87 | |
| 88 if (!content::BrowserThread::PostBlockingPoolTask( | |
| 89 FROM_HERE, | |
| 90 base::Bind(&LoadProtoFromDisk, GetInstalledPath(install_dir)))) { | |
| 91 NOTREACHED(); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 // Called during startup and installation before ComponentReady(). | |
| 96 bool SSLErrorAssistantComponentInstallerTraits::VerifyInstallation( | |
| 97 const base::DictionaryValue& manifest, | |
| 98 const base::FilePath& install_dir) const { | |
| 99 // No need to actually validate the proto here, since we'll do the checking | |
| 100 // in PopulateFromDynamicUpdate(). | |
| 101 LOG(ERROR) << ">> VerifyInstallation"; | |
|
waffles
2017/02/09 22:33:56
Remove this line.
meacer
2017/02/09 23:06:40
Done.
| |
| 102 return base::PathExists(GetInstalledPath(install_dir)); | |
| 103 } | |
| 104 | |
| 105 base::FilePath | |
| 106 SSLErrorAssistantComponentInstallerTraits::GetRelativeInstallDir() const { | |
| 107 return base::FilePath(FILE_PATH_LITERAL("SSLErrorAssistant")); | |
| 108 } | |
| 109 | |
| 110 void SSLErrorAssistantComponentInstallerTraits::GetHash( | |
| 111 std::vector<uint8_t>* hash) const { | |
| 112 hash->assign(kPublicKeySHA256, | |
| 113 kPublicKeySHA256 + arraysize(kPublicKeySHA256)); | |
| 114 } | |
| 115 | |
| 116 std::string SSLErrorAssistantComponentInstallerTraits::GetName() const { | |
| 117 return "TLS Error Assistant"; | |
| 118 } | |
| 119 | |
| 120 update_client::InstallerAttributes | |
| 121 SSLErrorAssistantComponentInstallerTraits::GetInstallerAttributes() const { | |
| 122 return update_client::InstallerAttributes(); | |
| 123 } | |
| 124 | |
| 125 std::vector<std::string> | |
| 126 SSLErrorAssistantComponentInstallerTraits::GetMimeTypes() const { | |
| 127 return std::vector<std::string>(); | |
| 128 } | |
| 129 | |
| 130 void RegisterSSLErrorAssistantComponent(ComponentUpdateService* cus, | |
| 131 const base::FilePath& user_data_dir) { | |
| 132 VLOG(1) << "Registering SSLS Error Assistant component."; | |
|
waffles
2017/02/09 22:33:56
Can we use DVLOG?
meacer
2017/02/09 23:06:40
Done.
| |
| 133 | |
| 134 std::unique_ptr<ComponentInstallerTraits> traits( | |
| 135 new SSLErrorAssistantComponentInstallerTraits()); | |
| 136 // |cus| takes ownership of |installer|. | |
| 137 DefaultComponentInstaller* installer = | |
| 138 new DefaultComponentInstaller(std::move(traits)); | |
| 139 installer->Register(cus, base::Closure()); | |
| 140 } | |
| 141 | |
| 142 } // namespace component_updater | |
| OLD | NEW |