forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow the component updater framework to control Origin Trials.
This patch adds support for updating the public key for verifying origin trial token signatures through the component updater. Future patches are planned to add support for disabling individual experimental APIs and for revoking individual trial tokens. This patch lays the groundwork for these, but does not actually provide those extra features. The component is not required to be present in order for origin trials to work (the default key will be used in that case), but if it is, it should include the public key in its manifest as a base64-encoded string representing 32 bytes, like this: "origin-trials": { "public-key": "abcdefghjijklmnopqrstuvwxabcdefghjijklmnopq=" } BUG=603588 Review-Url: https://codereview.chromium.org/1887743003 Cr-Commit-Position: refs/heads/master@{#390636}
- Loading branch information
Showing
6 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
chrome/browser/component_updater/origin_trials_component_installer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// 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/origin_trials_component_installer.h" | ||
|
||
#include "base/bind.h" | ||
#include "base/command_line.h" | ||
#include "base/files/file_path.h" | ||
#include "base/path_service.h" | ||
#include "chrome/common/chrome_switches.h" | ||
#include "components/component_updater/component_updater_paths.h" | ||
|
||
// The client-side configuration for the origin trial framework can be | ||
// overridden by an installed component named 'OriginTrials' (extension id | ||
// kfoklmclfodeliojeaekpoflbkkhojea. This component currently consists of just a | ||
// manifest.json file, which can contain a custom key named 'origin-trials'. The | ||
// value of this key is a dictionary: | ||
// | ||
// { | ||
// "public-key": "<base64-encoding of replacement public key>", | ||
// "disabled-features": [<list of features to disable>], | ||
// "revoked-tokens": "<base64-encoded data>" | ||
// } | ||
// | ||
// TODO(iclelland): Implement support for revoked tokens and disabled features. | ||
// | ||
// If the component is not present in the user data directory, the default | ||
// configuration will be used. | ||
|
||
namespace component_updater { | ||
|
||
namespace { | ||
|
||
// Extension id is kfoklmclfodeliojeaekpoflbkkhojea | ||
const uint8_t kSha256Hash[] = {0xa5, 0xea, 0xbc, 0x2b, 0x5e, 0x34, 0xb8, 0xe9, | ||
0x40, 0x4a, 0xfe, 0x5b, 0x1a, 0xa7, 0xe9, 0x40, | ||
0xa8, 0xc5, 0xef, 0xa1, 0x9e, 0x20, 0x5a, 0x39, | ||
0x73, 0x98, 0x98, 0x0f, 0x7a, 0x76, 0x62, 0xfa}; | ||
|
||
} // namespace | ||
|
||
bool OriginTrialsComponentInstallerTraits::VerifyInstallation( | ||
const base::DictionaryValue& manifest, | ||
const base::FilePath& install_dir) const { | ||
// Test if the "origin-trials" key is present in the manifest. | ||
return manifest.HasKey("origin-trials"); | ||
} | ||
|
||
bool OriginTrialsComponentInstallerTraits::CanAutoUpdate() const { | ||
return true; | ||
} | ||
|
||
bool OriginTrialsComponentInstallerTraits::RequiresNetworkEncryption() const { | ||
return true; | ||
} | ||
|
||
bool OriginTrialsComponentInstallerTraits::OnCustomInstall( | ||
const base::DictionaryValue& manifest, | ||
const base::FilePath& install_dir) { | ||
return true; | ||
} | ||
|
||
void OriginTrialsComponentInstallerTraits::ComponentReady( | ||
const base::Version& version, | ||
const base::FilePath& install_dir, | ||
std::unique_ptr<base::DictionaryValue> manifest) { | ||
// Read the public key from the manifest and set the command line. | ||
std::string override_public_key; | ||
if (manifest->GetString("origin-trials.public-key", &override_public_key)) { | ||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | ||
command_line->AppendSwitchASCII(switches::kOriginTrialPublicKey, | ||
override_public_key); | ||
} | ||
} | ||
|
||
base::FilePath OriginTrialsComponentInstallerTraits::GetBaseDirectory() const { | ||
base::FilePath result; | ||
PathService::Get(DIR_ORIGIN_TRIAL_KEYS, &result); | ||
return result; | ||
} | ||
|
||
void OriginTrialsComponentInstallerTraits::GetHash( | ||
std::vector<uint8_t>* hash) const { | ||
if (!hash) | ||
return; | ||
hash->assign(kSha256Hash, kSha256Hash + arraysize(kSha256Hash)); | ||
} | ||
|
||
std::string OriginTrialsComponentInstallerTraits::GetName() const { | ||
return "Origin Trials"; | ||
} | ||
|
||
std::string OriginTrialsComponentInstallerTraits::GetAp() const { | ||
return std::string(); | ||
} | ||
|
||
void RegisterOriginTrialsComponent(ComponentUpdateService* cus, | ||
const base::FilePath& user_data_dir) { | ||
std::unique_ptr<ComponentInstallerTraits> traits( | ||
new OriginTrialsComponentInstallerTraits()); | ||
// |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 |
54 changes: 54 additions & 0 deletions
54
chrome/browser/component_updater/origin_trials_component_installer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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. | ||
|
||
#ifndef CHROME_BROWSER_COMPONENT_UPDATER_ORIGIN_TRIALS_COMPONENT_INSTALLER_H_ | ||
#define CHROME_BROWSER_COMPONENT_UPDATER_ORIGIN_TRIALS_COMPONENT_INSTALLER_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "base/files/file_path.h" | ||
#include "base/macros.h" | ||
#include "base/values.h" | ||
#include "base/version.h" | ||
#include "components/component_updater/default_component_installer.h" | ||
|
||
namespace component_updater { | ||
|
||
class ComponentUpdateService; | ||
|
||
class OriginTrialsComponentInstallerTraits : public ComponentInstallerTraits { | ||
public: | ||
OriginTrialsComponentInstallerTraits() = default; | ||
~OriginTrialsComponentInstallerTraits() override = default; | ||
|
||
private: | ||
bool VerifyInstallation(const base::DictionaryValue& manifest, | ||
const base::FilePath& install_dir) const override; | ||
bool CanAutoUpdate() const override; | ||
bool RequiresNetworkEncryption() const override; | ||
bool OnCustomInstall(const base::DictionaryValue& manifest, | ||
const base::FilePath& install_dir) override; | ||
void ComponentReady(const base::Version& version, | ||
const base::FilePath& install_dir, | ||
std::unique_ptr<base::DictionaryValue> manifest) override; | ||
base::FilePath GetBaseDirectory() const override; | ||
void GetHash(std::vector<uint8_t>* hash) const override; | ||
std::string GetName() const override; | ||
std::string GetAp() const override; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(OriginTrialsComponentInstallerTraits); | ||
}; | ||
|
||
// Call once during startup to make the component update service aware of | ||
// the origin trials update component. | ||
void RegisterOriginTrialsComponent(ComponentUpdateService* cus, | ||
const base::FilePath& user_data_dir); | ||
|
||
} // namespace component_updater | ||
|
||
#endif // CHROME_BROWSER_COMPONENT_UPDATER_ORIGIN_TRIALS_COMPONENT_INSTALLER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters