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/json/json_reader.h" | |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 #include "base/version.h" | 18 #include "base/version.h" |
18 #include "chrome/browser/net/sth_distributor_provider.h" | 19 #include "chrome/browser/net/sth_distributor_provider.h" |
20 #include "chrome/common/chrome_features.h" | |
19 #include "components/component_updater/component_updater_paths.h" | 21 #include "components/component_updater/component_updater_paths.h" |
20 #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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 const std::string log_id(reinterpret_cast<const char*>(&decoding_output[0]), | 147 const std::string log_id(reinterpret_cast<const char*>(&decoding_output[0]), |
139 decoding_output.size()); | 148 decoding_output.size()); |
140 | 149 |
141 std::string json_sth; | 150 std::string json_sth; |
142 if (!base::ReadFileToString(sth_file_path, &json_sth)) { | 151 if (!base::ReadFileToString(sth_file_path, &json_sth)) { |
143 DVLOG(1) << "Failed reading from " << sth_file_path.value(); | 152 DVLOG(1) << "Failed reading from " << sth_file_path.value(); |
144 continue; | 153 continue; |
145 } | 154 } |
146 | 155 |
147 DVLOG(1) << "STH: Successfully read: " << json_sth; | 156 DVLOG(1) << "STH: Successfully read: " << json_sth; |
148 safe_json::SafeJsonParser::Parse( | 157 |
149 json_sth, | 158 int error_code = 0; |
Alexei Svitkine (slow)
2016/07/13 19:25:01
Can you keep the old behavior based on variation p
Eran Messeri
2016/07/14 10:01:03
Done.
| |
150 base::Bind(&STHSetComponentInstallerTraits::OnJsonParseSuccess, | 159 std::string error_message; |
151 base::Unretained(this), log_id), | 160 std::unique_ptr<base::Value> parsed_json = |
152 base::Bind(&STHSetComponentInstallerTraits::OnJsonParseError, | 161 base::JSONReader::ReadAndReturnError(json_sth, base::JSON_PARSE_RFC, |
153 base::Unretained(this), log_id)); | 162 &error_code, &error_message); |
163 | |
164 if (error_code == base::JSONReader::JSON_NO_ERROR) { | |
165 OnJsonParseSuccess(log_id, std::move(parsed_json)); | |
166 } else { | |
167 OnJsonParseError(log_id, error_message); | |
168 } | |
154 } | 169 } |
155 } | 170 } |
156 | 171 |
157 void STHSetComponentInstallerTraits::OnJsonParseSuccess( | 172 void STHSetComponentInstallerTraits::OnJsonParseSuccess( |
158 const std::string& log_id, | 173 const std::string& log_id, |
159 std::unique_ptr<base::Value> parsed_json) { | 174 std::unique_ptr<base::Value> parsed_json) { |
160 net::ct::SignedTreeHead signed_tree_head; | 175 net::ct::SignedTreeHead signed_tree_head; |
161 DVLOG(1) << "STH parsing success for log: " | 176 DVLOG(1) << "STH parsing success for log: " |
162 << base::HexEncode(log_id.data(), log_id.length()); | 177 << base::HexEncode(log_id.data(), log_id.length()); |
163 if (!net::ct::FillSignedTreeHead(*(parsed_json.get()), &signed_tree_head)) { | 178 if (!net::ct::FillSignedTreeHead(*(parsed_json.get()), &signed_tree_head)) { |
(...skipping 27 matching lines...) Expand all Loading... | |
191 | 206 |
192 std::unique_ptr<ComponentInstallerTraits> traits( | 207 std::unique_ptr<ComponentInstallerTraits> traits( |
193 new STHSetComponentInstallerTraits(distributor)); | 208 new STHSetComponentInstallerTraits(distributor)); |
194 // |cus| will take ownership of |installer| during installer->Register(cus). | 209 // |cus| will take ownership of |installer| during installer->Register(cus). |
195 DefaultComponentInstaller* installer = | 210 DefaultComponentInstaller* installer = |
196 new DefaultComponentInstaller(std::move(traits)); | 211 new DefaultComponentInstaller(std::move(traits)); |
197 installer->Register(cus, base::Closure()); | 212 installer->Register(cus, base::Closure()); |
198 } | 213 } |
199 | 214 |
200 } // namespace component_updater | 215 } // namespace component_updater |
OLD | NEW |