Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
chromium
GitHub Repository: chromium/chromium
Path: blob/main/chrome/browser/component_updater/crowd_deny_component_installer.cc
112514 views
1
// Copyright 2019 The Chromium Authors
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/crowd_deny_component_installer.h"
6
7
#include <memory>
8
#include <optional>
9
#include <string>
10
#include <utility>
11
#include <vector>
12
13
#include "base/files/file_path.h"
14
#include "base/files/file_util.h"
15
#include "base/functional/callback.h"
16
#include "base/logging.h"
17
#include "base/memory/ref_counted.h"
18
#include "base/values.h"
19
#include "chrome/browser/permissions/crowd_deny_preload_data.h"
20
#include "components/permissions/permission_uma_util.h"
21
22
namespace {
23
24
// The SHA-256 hash of the public key (in X.509 format, DER-encoded) used to
25
// sign the extension. The extension id is: ggkkehgbnfjpeggfpleeakpidbkibbmn.
26
constexpr uint8_t kCrowdDenyPublicKeySHA256[32] = {
27
0x66, 0xaa, 0x47, 0x61, 0xd5, 0x9f, 0x46, 0x65, 0xfb, 0x44, 0x0a,
28
0xf8, 0x31, 0xa8, 0x11, 0xcd, 0x5e, 0xea, 0x32, 0xe0, 0x29, 0x8b,
29
0x0c, 0x3a, 0xb4, 0xc9, 0x5e, 0x9c, 0xa4, 0x2a, 0x6d, 0x90};
30
31
constexpr char kCrowdDenyHumanReadableName[] = "Crowd Deny";
32
constexpr char kCrowdDenyManifestPreloadDataFormatKey[] = "preload_data_format";
33
constexpr int kCrowdDenyManifestPreloadDataCurrentFormat = 1;
34
35
constexpr base::FilePath::CharType kCrowdDenyPreloadDataFilename[] =
36
FILE_PATH_LITERAL("Preload Data");
37
38
base::FilePath GetPreloadDataFilePath(const base::FilePath& install_dir) {
39
return install_dir.Append(kCrowdDenyPreloadDataFilename);
40
}
41
42
} // namespace
43
44
namespace component_updater {
45
46
bool CrowdDenyComponentInstallerPolicy::
47
SupportsGroupPolicyEnabledComponentUpdates() const {
48
return true;
49
}
50
51
bool CrowdDenyComponentInstallerPolicy::VerifyInstallation(
52
const base::DictValue& manifest,
53
const base::FilePath& install_dir) const {
54
// Just check that the file is there, detailed verification of the contents is
55
// delegated to code in //chrome/browser/permissions.
56
return base::PathExists(GetPreloadDataFilePath(install_dir));
57
}
58
59
bool CrowdDenyComponentInstallerPolicy::RequiresNetworkEncryption() const {
60
return false;
61
}
62
63
update_client::CrxInstaller::Result
64
CrowdDenyComponentInstallerPolicy::OnCustomInstall(
65
const base::DictValue& manifest,
66
const base::FilePath& install_dir) {
67
// Nothing custom here.
68
return update_client::CrxInstaller::Result(0);
69
}
70
71
void CrowdDenyComponentInstallerPolicy::OnCustomUninstall() {
72
// Nothing custom here.
73
}
74
75
void CrowdDenyComponentInstallerPolicy::ComponentReady(
76
const base::Version& version,
77
const base::FilePath& install_dir,
78
base::DictValue manifest) {
79
DVLOG(1) << "Crowd Deny component ready, version " << version.GetString()
80
<< " in " << install_dir.value();
81
82
std::optional<int> format =
83
manifest.FindInt(kCrowdDenyManifestPreloadDataFormatKey);
84
if (!format || *format != kCrowdDenyManifestPreloadDataCurrentFormat) {
85
DVLOG(1) << "Crowd Deny component bailing out.";
86
DVLOG_IF(1, format) << "Future data version: " << *format;
87
return;
88
}
89
90
CrowdDenyPreloadData::GetInstance()->LoadFromDisk(
91
GetPreloadDataFilePath(install_dir), version);
92
}
93
94
base::FilePath CrowdDenyComponentInstallerPolicy::GetRelativeInstallDir()
95
const {
96
return base::FilePath(FILE_PATH_LITERAL("Crowd Deny"));
97
}
98
99
void CrowdDenyComponentInstallerPolicy::GetHash(
100
std::vector<uint8_t>* hash) const {
101
hash->assign(std::begin(kCrowdDenyPublicKeySHA256),
102
std::end(kCrowdDenyPublicKeySHA256));
103
}
104
105
std::string CrowdDenyComponentInstallerPolicy::GetName() const {
106
return kCrowdDenyHumanReadableName;
107
}
108
109
update_client::InstallerAttributes
110
CrowdDenyComponentInstallerPolicy::GetInstallerAttributes() const {
111
// No special update rules.
112
return update_client::InstallerAttributes();
113
}
114
115
void RegisterCrowdDenyComponent(ComponentUpdateService* cus) {
116
auto installer = base::MakeRefCounted<ComponentInstaller>(
117
std::make_unique<CrowdDenyComponentInstallerPolicy>());
118
installer->Register(cus, base::OnceClosure());
119
}
120
121
} // namespace component_updater
122
123