Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: chrome/browser/component_updater/ssl_error_assistant_component_installer.cc

Issue 2581903002: Add SSL error assistant component to dynamically update captive portal list (Closed)
Patch Set: waffles comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 DVLOG(1) << "Reading SSL error assistant config from file: "
Nathan Parker 2017/02/10 01:21:28 I'd argue much of this logging isn't useful to any
meacer 2017/02/10 01:29:55 Done :)
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 DVLOG(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 DVLOG(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 return base.Append(kConfigBinaryPbFileName);
78 }
79
80 void SSLErrorAssistantComponentInstallerTraits::ComponentReady(
81 const base::Version& version,
82 const base::FilePath& install_dir,
83 std::unique_ptr<base::DictionaryValue> manifest) {
84 DVLOG(1) << "Component ready, version " << version.GetString() << " in "
85 << install_dir.value();
86
87 if (!content::BrowserThread::PostBlockingPoolTask(
88 FROM_HERE,
89 base::Bind(&LoadProtoFromDisk, GetInstalledPath(install_dir)))) {
90 NOTREACHED();
91 }
92 }
93
94 // Called during startup and installation before ComponentReady().
95 bool SSLErrorAssistantComponentInstallerTraits::VerifyInstallation(
96 const base::DictionaryValue& manifest,
97 const base::FilePath& install_dir) const {
98 // No need to actually validate the proto here, since we'll do the checking
99 // in PopulateFromDynamicUpdate().
100 return base::PathExists(GetInstalledPath(install_dir));
101 }
102
103 base::FilePath
104 SSLErrorAssistantComponentInstallerTraits::GetRelativeInstallDir() const {
105 return base::FilePath(FILE_PATH_LITERAL("SSLErrorAssistant"));
106 }
107
108 void SSLErrorAssistantComponentInstallerTraits::GetHash(
109 std::vector<uint8_t>* hash) const {
110 hash->assign(kPublicKeySHA256,
111 kPublicKeySHA256 + arraysize(kPublicKeySHA256));
112 }
113
114 std::string SSLErrorAssistantComponentInstallerTraits::GetName() const {
115 return "SSL Error Assistant";
116 }
117
118 update_client::InstallerAttributes
119 SSLErrorAssistantComponentInstallerTraits::GetInstallerAttributes() const {
120 return update_client::InstallerAttributes();
121 }
122
123 std::vector<std::string>
124 SSLErrorAssistantComponentInstallerTraits::GetMimeTypes() const {
125 return std::vector<std::string>();
126 }
127
128 void RegisterSSLErrorAssistantComponent(ComponentUpdateService* cus,
129 const base::FilePath& user_data_dir) {
130 DVLOG(1) << "Registering SSLS Error Assistant component.";
Nathan Parker 2017/02/10 01:21:28 nit: "SSLS"
meacer 2017/02/10 01:29:55 Done.
131
132 std::unique_ptr<ComponentInstallerTraits> traits(
133 new SSLErrorAssistantComponentInstallerTraits());
134 // |cus| takes ownership of |installer|.
135 DefaultComponentInstaller* installer =
136 new DefaultComponentInstaller(std::move(traits));
137 installer->Register(cus, base::Closure());
138 }
139
140 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698