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

Unified Diff: chrome/browser/component_updater/sth_set_component_installer.cc

Issue 1845113003: Certificate Transparency: Start tracking logs' state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/component_updater/sth_set_component_installer.h ('k') | chrome/browser/io_thread.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/component_updater/sth_set_component_installer.cc
diff --git a/chrome/browser/component_updater/sth_set_component_installer.cc b/chrome/browser/component_updater/sth_set_component_installer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..de0d57dedefe5cf81579560206a926c1cdb65f27
--- /dev/null
+++ b/chrome/browser/component_updater/sth_set_component_installer.cc
@@ -0,0 +1,179 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/component_updater/sth_set_component_installer.h"
+
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "base/bind.h"
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/logging.h"
+#include "base/macros.h"
+#include "base/path_service.h"
+#include "base/values.h"
+#include "base/version.h"
+#include "components/component_updater/component_updater_paths.h"
+#include "components/safe_json/safe_json_parser.h"
+#include "content/public/browser/browser_thread.h"
+#include "crypto/sha2.h"
+#include "net/cert/ct_known_logs_static.h"
+#include "net/cert/ct_log_response_parser.h"
+#include "net/cert/signed_tree_head.h"
+
+using component_updater::ComponentUpdateService;
+
+namespace {
+const base::FilePath::CharType kSTHsDirName[] = FILE_PATH_LITERAL("sths");
+
+// TODO(eranm): Make it work for all logs.
+const base::FilePath::CharType kPilotSTHsFileName[] =
+ FILE_PATH_LITERAL("pilot.sth");
+
+} // namespace
+
+namespace component_updater {
+
+// The SHA256 of the SubjectPublicKeyInfo used to sign the extension.
+// The extension id is: aplidfpohcjpojgnkjpkibbkcghkogef
+const uint8_t kPublicKeySHA256[32] = {
+ 0x0f, 0xb8, 0x35, 0xfe, 0x72, 0x9f, 0xe9, 0x6d, 0xa9, 0xfa, 0x81,
+ 0x1a, 0x26, 0x7a, 0xe6, 0x45, 0x22, 0x50, 0xc4, 0xd4, 0x01, 0xcc,
+ 0x33, 0x90, 0x1c, 0xe9, 0x44, 0x37, 0xc4, 0xa0, 0x2e, 0x02};
+
+const char kSTHSetFetcherManifestName[] = "Signed Tree Heads";
+
+STHSetComponentInstallerTraits::STHSetComponentInstallerTraits(
+ scoped_ptr<net::ct::STHDistributor> sth_distributor)
+ : sth_distributor_(std::move(sth_distributor)) {
+ VLOG(1) << "XXX: STHSetComponentInstallerTraits::c'tor";
+}
+
+STHSetComponentInstallerTraits::~STHSetComponentInstallerTraits() {
+ VLOG(1) << "XXX: STHSetComponentInstallerTraits::d'tor";
+}
+
+bool STHSetComponentInstallerTraits::CanAutoUpdate() const {
+ return true;
+}
+
+bool STHSetComponentInstallerTraits::OnCustomInstall(
+ const base::DictionaryValue& manifest,
+ const base::FilePath& install_dir) {
+ VLOG(1) << "Entering STHSetComponentInstallerTraits::OnCustomInstall.";
+
+ return true; // Nothing custom here.
+}
+
+base::FilePath STHSetComponentInstallerTraits::GetInstalledPath(
+ const base::FilePath& base) {
+ return base.Append(FILE_PATH_LITERAL("_platform_specific"))
+ .Append(FILE_PATH_LITERAL("all"))
+ .Append(kSTHsDirName)
+ .Append(kPilotSTHsFileName);
+}
+
+void STHSetComponentInstallerTraits::ComponentReady(
+ const base::Version& version,
+ const base::FilePath& install_dir,
+ scoped_ptr<base::DictionaryValue> manifest) {
+ VLOG(1) << "Component ready, version " << version.GetString() << " in "
+ << install_dir.value();
+
+ if (!content::BrowserThread::PostBlockingPoolTask(
+ FROM_HERE,
+ base::Bind(&STHSetComponentInstallerTraits::LoadSTHsFromDisk,
+ base::Unretained(this), GetInstalledPath(install_dir),
+ version))) {
+ NOTREACHED();
+ }
+}
+
+// Called during startup and installation before ComponentReady().
+bool STHSetComponentInstallerTraits::VerifyInstallation(
+ const base::DictionaryValue& manifest,
+ const base::FilePath& install_dir) const {
+ return base::PathExists(GetInstalledPath(install_dir));
+}
+
+base::FilePath STHSetComponentInstallerTraits::GetBaseDirectory() const {
+ base::FilePath result;
+ PathService::Get(DIR_CERT_TRANS_TREE_STATES, &result);
+ return result;
+}
+
+void STHSetComponentInstallerTraits::GetHash(std::vector<uint8_t>* hash) const {
+ hash->assign(kPublicKeySHA256,
+ kPublicKeySHA256 + arraysize(kPublicKeySHA256));
+}
+
+std::string STHSetComponentInstallerTraits::GetName() const {
+ return kSTHSetFetcherManifestName;
+}
+
+void STHSetComponentInstallerTraits::LoadSTHsFromDisk(
+ const base::FilePath& sths_file_path,
+ const base::Version& version) {
+ if (sths_file_path.empty())
+ return;
+
+ VLOG(1) << "Reading STH from file: " << sths_file_path.value();
+ std::string json_sth;
+ if (!base::ReadFileToString(sths_file_path, &json_sth)) {
+ VLOG(1) << "Failed reading from " << sths_file_path.value();
+ return;
+ }
+
+ VLOG(1) << "STH: Successfully read: " << json_sth;
+ safe_json::SafeJsonParser::Parse(
+ json_sth, base::Bind(&STHSetComponentInstallerTraits::OnJsonParseSuccess,
+ base::Unretained(this)),
+ base::Bind(&STHSetComponentInstallerTraits::OnJsonParseError,
+ base::Unretained(this)));
+}
+
+void STHSetComponentInstallerTraits::OnJsonParseSuccess(
+ scoped_ptr<base::Value> parsed_json) {
+ net::ct::SignedTreeHead signed_tree_head;
+ if (!net::ct::FillSignedTreeHead(*(parsed_json.get()), &signed_tree_head)) {
+ LOG(WARNING) << "Failed to fill in signed tree head.";
+ return;
+ }
+
+ // TODO(eranm): Remove this hack
+ // Pilot is the first log in the list.
+ base::StringPiece pilot_key(kCTLogList[0].log_key,
+ kCTLogList[0].log_key_length);
+ std::string pilot_key_id = crypto::SHA256HashString(pilot_key);
+
+ // The log id is not a part of the response, fill in manually.
+ signed_tree_head.log_id = pilot_key_id;
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&net::ct::STHDistributor::NewSTHObserved,
+ base::Unretained(sth_distributor_.get()), signed_tree_head));
+}
+
+void STHSetComponentInstallerTraits::OnJsonParseError(
+ const std::string& error) {
+ VLOG(0) << "STH loading failed: " << error;
+}
+
+void RegisterSTHSetComponent(
+ ComponentUpdateService* cus,
+ const base::FilePath& user_data_dir,
+ scoped_ptr<net::ct::STHDistributor> sth_distributor) {
+ VLOG(1) << "Registering STH Set fetcher component.";
+
+ scoped_ptr<ComponentInstallerTraits> traits(
+ new STHSetComponentInstallerTraits(std::move(sth_distributor)));
+ // |cus| will take ownership of |installer| during installer->Register(cus).
+ DefaultComponentInstaller* installer =
+ new DefaultComponentInstaller(std::move(traits));
+ installer->Register(cus, base::Closure());
+}
+
+} // namespace component_updater
« no previous file with comments | « chrome/browser/component_updater/sth_set_component_installer.h ('k') | chrome/browser/io_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698