-
Notifications
You must be signed in to change notification settings - Fork 921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use extension for data file updates #76
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
581b1b4
Use extension for data file updates
emerick 5238405
Incorporate code review feedback and get browser tests working again
emerick f9de927
Reinitialize clients when consuming a new dat file
emerick 182b52f
Incorporate code review feedback
emerick 98e22c9
Add browser test for tracking protection service
emerick be7c777
Redirect extension update requests to Brave's extension server
emerick 17b725c
Specify correct scheme for fallback component updater URLs
emerick da54481
Override update_client::Configurator so we can disable CUP signing
emerick 9ae1117
Call OnDemandUpdate to force component install once component is regi…
emerick 52c516f
Specify test public keys in test manifests
emerick a4c1718
Update tracking_protection_service.cc
bbondy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/component_updater/brave_component_installer.h" | ||
|
||
#include <utility> | ||
|
||
#include "base/base64.h" | ||
#include "base/bind.h" | ||
#include "base/bind_helpers.h" | ||
#include "base/files/file_path.h" | ||
#include "base/files/file_util.h" | ||
#include "base/json/json_string_value_serializer.h" | ||
#include "base/macros.h" | ||
#include "base/values.h" | ||
#include "base/version.h" | ||
#include "components/component_updater/component_updater_service.h" | ||
#include "components/crx_file/id_util.h" | ||
#include "components/update_client/update_client.h" | ||
#include "components/update_client/update_client_errors.h" | ||
#include "components/update_client/utils.h" | ||
#include "crypto/sha2.h" | ||
#include "extensions/common/constants.h" | ||
#include "extensions/common/manifest_constants.h" | ||
|
||
namespace { | ||
using Result = update_client::CrxInstaller::Result; | ||
using InstallError = update_client::InstallError; | ||
} // namespace | ||
|
||
namespace { | ||
bool RewriteManifestFile( | ||
const base::FilePath& extension_root, | ||
const base::DictionaryValue& manifest, | ||
const std::string &public_key) { | ||
|
||
// Add the public key | ||
DCHECK(!public_key.empty()); | ||
|
||
std::unique_ptr<base::DictionaryValue> final_manifest(manifest.DeepCopy()); | ||
final_manifest->SetString(extensions::manifest_keys::kPublicKey, public_key); | ||
|
||
std::string manifest_json; | ||
JSONStringValueSerializer serializer(&manifest_json); | ||
serializer.set_pretty_print(true); | ||
if (!serializer.Serialize(*final_manifest)) { | ||
return false; | ||
} | ||
|
||
base::FilePath manifest_path = | ||
extension_root.Append(extensions::kManifestFilename); | ||
int size = base::checked_cast<int>(manifest_json.size()); | ||
if (base::WriteFile(manifest_path, manifest_json.data(), size) != size) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} // namespace | ||
|
||
namespace brave { | ||
|
||
BraveComponentInstallerPolicy::BraveComponentInstallerPolicy( | ||
const std::string& name, | ||
const std::string& base64_public_key, | ||
const ReadyCallback& ready_callback) | ||
: name_(name), | ||
base64_public_key_(base64_public_key), | ||
ready_callback_(ready_callback) { | ||
base::Base64Decode(base64_public_key, &public_key_); | ||
} | ||
|
||
BraveComponentInstallerPolicy::~BraveComponentInstallerPolicy() {} | ||
|
||
bool BraveComponentInstallerPolicy::VerifyInstallation( | ||
const base::DictionaryValue& manifest, | ||
const base::FilePath& install_dir) const { | ||
// The manifest file will generate a random ID if we don't provide one. | ||
// We want to write one with the actual extensions public key so we get | ||
// the same extensionID which is generated from the public key. | ||
if (!RewriteManifestFile(install_dir, manifest, base64_public_key_)) { | ||
return false; | ||
} | ||
return base::PathExists( | ||
install_dir.Append(FILE_PATH_LITERAL("manifest.json"))); | ||
} | ||
|
||
bool BraveComponentInstallerPolicy::SupportsGroupPolicyEnabledComponentUpdates() const { | ||
return false; | ||
} | ||
|
||
bool BraveComponentInstallerPolicy::RequiresNetworkEncryption() const { | ||
return false; | ||
} | ||
|
||
update_client::CrxInstaller::Result BraveComponentInstallerPolicy::OnCustomInstall( | ||
const base::DictionaryValue& manifest, | ||
const base::FilePath& install_dir) { | ||
return Result(InstallError::NONE); | ||
} | ||
|
||
void BraveComponentInstallerPolicy::OnCustomUninstall() { | ||
} | ||
|
||
void BraveComponentInstallerPolicy::ComponentReady( | ||
const base::Version& version, | ||
const base::FilePath& install_dir, | ||
std::unique_ptr<base::DictionaryValue> manifest) { | ||
ready_callback_.Run(install_dir); | ||
} | ||
|
||
base::FilePath BraveComponentInstallerPolicy::GetRelativeInstallDir() const { | ||
// Get the extension ID from the public key | ||
std::string extension_id = crx_file::id_util::GenerateId(public_key_); | ||
return base::FilePath( | ||
// Convert to wstring or string depending on OS | ||
base::FilePath::StringType(extension_id.begin(), extension_id.end())); | ||
} | ||
|
||
void BraveComponentInstallerPolicy::GetHash(std::vector<uint8_t>* hash) const { | ||
const std::string public_key_sha256 = crypto::SHA256HashString(public_key_); | ||
hash->assign(public_key_sha256.begin(), public_key_sha256.end()); | ||
} | ||
|
||
std::string BraveComponentInstallerPolicy::GetName() const { | ||
return name_; | ||
} | ||
|
||
std::vector<std::string> BraveComponentInstallerPolicy::GetMimeTypes() const { | ||
return std::vector<std::string>(); | ||
} | ||
|
||
update_client::InstallerAttributes BraveComponentInstallerPolicy::GetInstallerAttributes() const { | ||
return update_client::InstallerAttributes(); | ||
} | ||
|
||
void RegisterComponent( | ||
component_updater::ComponentUpdateService* cus, | ||
const std::string& name, | ||
const std::string& base64_public_key, | ||
const base::Closure& registered_callback, | ||
const ReadyCallback& ready_callback) { | ||
auto installer = base::MakeRefCounted<component_updater::ComponentInstaller>( | ||
std::make_unique<BraveComponentInstallerPolicy>(name, base64_public_key, ready_callback)); | ||
installer->Register(cus, registered_callback); | ||
} | ||
|
||
} // namespace brave |
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,73 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_BRAVE_COMPONENT_INSTALLER_H_ | ||
#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_BRAVE_COMPONENT_INSTALLER_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "base/bind.h" | ||
#include "base/files/file_path.h" | ||
#include "base/macros.h" | ||
#include "components/component_updater/component_installer.h" | ||
#include "components/update_client/update_client.h" | ||
|
||
namespace base { | ||
class FilePath; | ||
} // namespace base | ||
|
||
using ReadyCallback = base::Callback<void(const base::FilePath&)>; | ||
|
||
namespace brave { | ||
|
||
class BraveComponentInstallerPolicy : | ||
public component_updater::ComponentInstallerPolicy { | ||
public: | ||
explicit BraveComponentInstallerPolicy(const std::string& name, | ||
const std::string& base64_public_key, | ||
const ReadyCallback& ready_callback); | ||
|
||
~BraveComponentInstallerPolicy() override; | ||
|
||
private: | ||
// The following methods override ComponentInstallerPolicy | ||
bool VerifyInstallation(const base::DictionaryValue& manifest, | ||
const base::FilePath& install_dir) const override; | ||
bool SupportsGroupPolicyEnabledComponentUpdates() const override; | ||
bool RequiresNetworkEncryption() const override; | ||
update_client::CrxInstaller::Result OnCustomInstall( | ||
const base::DictionaryValue& manifest, | ||
const base::FilePath& install_dir) override; | ||
void OnCustomUninstall() override; | ||
void ComponentReady( | ||
const base::Version& version, | ||
const base::FilePath& install_dir, | ||
std::unique_ptr<base::DictionaryValue> manifest) override; | ||
base::FilePath GetRelativeInstallDir() const override; | ||
void GetHash(std::vector<uint8_t>* hash) const override; | ||
std::string GetName() const override; | ||
std::vector<std::string> GetMimeTypes() const override; | ||
update_client::InstallerAttributes GetInstallerAttributes() const override; | ||
|
||
std::string name_; | ||
std::string base64_public_key_; | ||
std::string public_key_; | ||
ReadyCallback ready_callback_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(BraveComponentInstallerPolicy); | ||
}; | ||
|
||
void RegisterComponent(component_updater::ComponentUpdateService* cus, | ||
const std::string& name, | ||
const std::string& base64_public_key, | ||
const base::Closure& registered_callback, | ||
const ReadyCallback& ready_callback); | ||
|
||
} // namespace brave | ||
|
||
#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_BRAVE_COMPONENT_INSTALLER_H_ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing commas are OK for future ref in .gn files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not just ok, trailing commas are preferred