Path: blob/main/chrome/browser/component_updater/crowd_deny_component_installer.cc
112514 views
// Copyright 2019 The Chromium Authors1// Use of this source code is governed by a BSD-style license that can be2// found in the LICENSE file.34#include "chrome/browser/component_updater/crowd_deny_component_installer.h"56#include <memory>7#include <optional>8#include <string>9#include <utility>10#include <vector>1112#include "base/files/file_path.h"13#include "base/files/file_util.h"14#include "base/functional/callback.h"15#include "base/logging.h"16#include "base/memory/ref_counted.h"17#include "base/values.h"18#include "chrome/browser/permissions/crowd_deny_preload_data.h"19#include "components/permissions/permission_uma_util.h"2021namespace {2223// The SHA-256 hash of the public key (in X.509 format, DER-encoded) used to24// sign the extension. The extension id is: ggkkehgbnfjpeggfpleeakpidbkibbmn.25constexpr uint8_t kCrowdDenyPublicKeySHA256[32] = {260x66, 0xaa, 0x47, 0x61, 0xd5, 0x9f, 0x46, 0x65, 0xfb, 0x44, 0x0a,270xf8, 0x31, 0xa8, 0x11, 0xcd, 0x5e, 0xea, 0x32, 0xe0, 0x29, 0x8b,280x0c, 0x3a, 0xb4, 0xc9, 0x5e, 0x9c, 0xa4, 0x2a, 0x6d, 0x90};2930constexpr char kCrowdDenyHumanReadableName[] = "Crowd Deny";31constexpr char kCrowdDenyManifestPreloadDataFormatKey[] = "preload_data_format";32constexpr int kCrowdDenyManifestPreloadDataCurrentFormat = 1;3334constexpr base::FilePath::CharType kCrowdDenyPreloadDataFilename[] =35FILE_PATH_LITERAL("Preload Data");3637base::FilePath GetPreloadDataFilePath(const base::FilePath& install_dir) {38return install_dir.Append(kCrowdDenyPreloadDataFilename);39}4041} // namespace4243namespace component_updater {4445bool CrowdDenyComponentInstallerPolicy::46SupportsGroupPolicyEnabledComponentUpdates() const {47return true;48}4950bool CrowdDenyComponentInstallerPolicy::VerifyInstallation(51const base::DictValue& manifest,52const base::FilePath& install_dir) const {53// Just check that the file is there, detailed verification of the contents is54// delegated to code in //chrome/browser/permissions.55return base::PathExists(GetPreloadDataFilePath(install_dir));56}5758bool CrowdDenyComponentInstallerPolicy::RequiresNetworkEncryption() const {59return false;60}6162update_client::CrxInstaller::Result63CrowdDenyComponentInstallerPolicy::OnCustomInstall(64const base::DictValue& manifest,65const base::FilePath& install_dir) {66// Nothing custom here.67return update_client::CrxInstaller::Result(0);68}6970void CrowdDenyComponentInstallerPolicy::OnCustomUninstall() {71// Nothing custom here.72}7374void CrowdDenyComponentInstallerPolicy::ComponentReady(75const base::Version& version,76const base::FilePath& install_dir,77base::DictValue manifest) {78DVLOG(1) << "Crowd Deny component ready, version " << version.GetString()79<< " in " << install_dir.value();8081std::optional<int> format =82manifest.FindInt(kCrowdDenyManifestPreloadDataFormatKey);83if (!format || *format != kCrowdDenyManifestPreloadDataCurrentFormat) {84DVLOG(1) << "Crowd Deny component bailing out.";85DVLOG_IF(1, format) << "Future data version: " << *format;86return;87}8889CrowdDenyPreloadData::GetInstance()->LoadFromDisk(90GetPreloadDataFilePath(install_dir), version);91}9293base::FilePath CrowdDenyComponentInstallerPolicy::GetRelativeInstallDir()94const {95return base::FilePath(FILE_PATH_LITERAL("Crowd Deny"));96}9798void CrowdDenyComponentInstallerPolicy::GetHash(99std::vector<uint8_t>* hash) const {100hash->assign(std::begin(kCrowdDenyPublicKeySHA256),101std::end(kCrowdDenyPublicKeySHA256));102}103104std::string CrowdDenyComponentInstallerPolicy::GetName() const {105return kCrowdDenyHumanReadableName;106}107108update_client::InstallerAttributes109CrowdDenyComponentInstallerPolicy::GetInstallerAttributes() const {110// No special update rules.111return update_client::InstallerAttributes();112}113114void RegisterCrowdDenyComponent(ComponentUpdateService* cus) {115auto installer = base::MakeRefCounted<ComponentInstaller>(116std::make_unique<CrowdDenyComponentInstallerPolicy>());117installer->Register(cus, base::OnceClosure());118}119120} // namespace component_updater121122123