Commit 83cbcc4f authored by thestig's avatar thestig Committed by Commit bot

Extensions: Consolidate extension id hashing / searching.

Review URL: https://codereview.chromium.org/850853002

Cr-Commit-Position: refs/heads/master@{#313747}
parent 391ece3a
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <algorithm> #include <algorithm>
#include <set> #include <set>
#include "base/sha1.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -20,6 +19,7 @@ ...@@ -20,6 +19,7 @@
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
#include "components/crx_file/id_util.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "extensions/browser/extension_prefs.h" #include "extensions/browser/extension_prefs.h"
...@@ -292,16 +292,15 @@ bool BackgroundApplicationListModel::RequiresBackgroundModeForPushMessaging( ...@@ -292,16 +292,15 @@ bool BackgroundApplicationListModel::RequiresBackgroundModeForPushMessaging(
// uses push messaging. // uses push messaging.
// TODO(dimich): remove this whitelist once we have a better way to keep // TODO(dimich): remove this whitelist once we have a better way to keep
// listening for GCM. http://crbug.com/311268 // listening for GCM. http://crbug.com/311268
std::string id_hash = base::SHA1HashString(extension.id()); std::string hexencoded_id_hash =
std::string hexencoded_id_hash = base::HexEncode(id_hash.c_str(), crx_file::id_util::HashedIdInHex(extension.id());
id_hash.length());
// The id starting from "9A04..." is a one from unit test. // The id starting from "9A04..." is a one from unit test.
if (hexencoded_id_hash == "C41AD9DCD670210295614257EF8C9945AD68D86E" || if (hexencoded_id_hash == "C41AD9DCD670210295614257EF8C9945AD68D86E" ||
hexencoded_id_hash == "9A0417016F345C934A1A88F55CA17C05014EEEBA") hexencoded_id_hash == "9A0417016F345C934A1A88F55CA17C05014EEEBA")
return false; return false;
return true; return true;
} }
// static // static
bool BackgroundApplicationListModel::IsBackgroundApp( bool BackgroundApplicationListModel::IsBackgroundApp(
......
...@@ -28,7 +28,7 @@ namespace { ...@@ -28,7 +28,7 @@ namespace {
// This is the set of extensions that are allowed to access the internal // This is the set of extensions that are allowed to access the internal
// remoting viewer plugin. // remoting viewer plugin.
const char* kRemotingViewerWhitelist[] = { const char* const kRemotingViewerWhitelist[] = {
"gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
"kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
"odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
...@@ -83,9 +83,10 @@ bool InternalExtensionProvider::SetWebsiteSetting( ...@@ -83,9 +83,10 @@ bool InternalExtensionProvider::SetWebsiteSetting(
void InternalExtensionProvider::ClearAllContentSettingsRules( void InternalExtensionProvider::ClearAllContentSettingsRules(
ContentSettingsType content_type) {} ContentSettingsType content_type) {}
void InternalExtensionProvider::Observe(int type, void InternalExtensionProvider::Observe(
const content::NotificationSource& source, int type,
const content::NotificationDetails& details) { const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) { switch (type) {
case extensions::NOTIFICATION_EXTENSION_HOST_CREATED: { case extensions::NOTIFICATION_EXTENSION_HOST_CREATED: {
const extensions::ExtensionHost* host = const extensions::ExtensionHost* host =
...@@ -94,7 +95,7 @@ void InternalExtensionProvider::Observe(int type, ...@@ -94,7 +95,7 @@ void InternalExtensionProvider::Observe(int type,
SetContentSettingForExtension(host->extension(), CONTENT_SETTING_BLOCK); SetContentSettingForExtension(host->extension(), CONTENT_SETTING_BLOCK);
// White-list CRD's v2 app, until crbug.com/134216 is complete. // White-list CRD's v2 app, until crbug.com/134216 is complete.
const char* kAppWhitelist[] = { const char* const kAppWhitelist[] = {
"2775E568AC98F9578791F1EAB65A1BF5F8CEF414", "2775E568AC98F9578791F1EAB65A1BF5F8CEF414",
"4AA3C5D69A4AECBD236CAD7884502209F0F5C169", "4AA3C5D69A4AECBD236CAD7884502209F0F5C169",
"97B23E01B2AA064E8332EE43A7A85C628AADC3F2", "97B23E01B2AA064E8332EE43A7A85C628AADC3F2",
......
...@@ -51,7 +51,7 @@ const char kMediaStreamSourceTab[] = "tab"; ...@@ -51,7 +51,7 @@ const char kMediaStreamSourceTab[] = "tab";
// Whitelisted extensions that do not check for a browser action grant because // Whitelisted extensions that do not check for a browser action grant because
// they provide API's. // they provide API's.
const char* const whitelisted_extensions[] = { const char* const kWhitelist[] = {
"enhhojjnijigcajfphajepfemndkmdlo", // Dev "enhhojjnijigcajfphajepfemndkmdlo", // Dev
"pkedcjkdefgpdelpbcmbmeomcjbeemfm", // Trusted Tester "pkedcjkdefgpdelpbcmbmeomcjbeemfm", // Trusted Tester
"fmfcbgogabcbclcofgocippekhfcmgfj", // Staging "fmfcbgogabcbclcofgocippekhfcmgfj", // Staging
...@@ -93,9 +93,8 @@ bool TabCaptureCaptureFunction::RunSync() { ...@@ -93,9 +93,8 @@ bool TabCaptureCaptureFunction::RunSync() {
switches::kWhitelistedExtensionID) != extension_id && switches::kWhitelistedExtensionID) != extension_id &&
!SimpleFeature::IsIdInList( !SimpleFeature::IsIdInList(
extension_id, extension_id,
std::set<std::string>( std::set<std::string>(kWhitelist,
whitelisted_extensions, kWhitelist + arraysize(kWhitelist)))) {
whitelisted_extensions + arraysize(whitelisted_extensions)))) {
error_ = kGrantError; error_ = kGrantError;
return false; return false;
} }
...@@ -141,8 +140,7 @@ bool TabCaptureCaptureFunction::RunSync() { ...@@ -141,8 +140,7 @@ bool TabCaptureCaptureFunction::RunSync() {
constraint->SetString(kMediaStreamSourceId, device_id); constraint->SetString(kMediaStreamSourceId, device_id);
} }
extensions::TabCaptureRegistry* registry = TabCaptureRegistry* registry = TabCaptureRegistry::Get(GetProfile());
extensions::TabCaptureRegistry::Get(GetProfile());
if (!registry->AddRequest(target_contents, extension_id)) { if (!registry->AddRequest(target_contents, extension_id)) {
error_ = kCapturingSameTab; error_ = kCapturingSameTab;
return false; return false;
...@@ -159,8 +157,7 @@ bool TabCaptureCaptureFunction::RunSync() { ...@@ -159,8 +157,7 @@ bool TabCaptureCaptureFunction::RunSync() {
} }
bool TabCaptureGetCapturedTabsFunction::RunSync() { bool TabCaptureGetCapturedTabsFunction::RunSync() {
extensions::TabCaptureRegistry* registry = TabCaptureRegistry* registry = TabCaptureRegistry::Get(GetProfile());
extensions::TabCaptureRegistry::Get(GetProfile());
base::ListValue* const list = new base::ListValue(); base::ListValue* const list = new base::ListValue();
if (registry) if (registry)
registry->GetCapturedTabs(extension()->id(), list); registry->GetCapturedTabs(extension()->id(), list);
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "chrome/browser/extensions/external_component_loader.h" #include "chrome/browser/extensions/external_component_loader.h"
#include "base/sha1.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "chrome/browser/bookmarks/enhanced_bookmarks_features.h" #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
...@@ -15,6 +14,7 @@ ...@@ -15,6 +14,7 @@
#include "components/signin/core/browser/signin_manager.h" #include "components/signin/core/browser/signin_manager.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/extension_urls.h" #include "extensions/common/extension_urls.h"
#include "extensions/common/features/simple_feature.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "base/command_line.h" #include "base/command_line.h"
...@@ -32,16 +32,16 @@ ExternalComponentLoader::~ExternalComponentLoader() {} ...@@ -32,16 +32,16 @@ ExternalComponentLoader::~ExternalComponentLoader() {}
// static // static
bool ExternalComponentLoader::IsModifiable(const Extension* extension) { bool ExternalComponentLoader::IsModifiable(const Extension* extension) {
if (extension->location() == Manifest::EXTERNAL_COMPONENT) { if (extension->location() == Manifest::EXTERNAL_COMPONENT) {
static const char* const enhanced_extension_hashes[] = { static const char* const kEnhancedExtensions[] = {
"D5736E4B5CF695CB93A2FB57E4FDC6E5AFAB6FE2", // http://crbug.com/312900 "D5736E4B5CF695CB93A2FB57E4FDC6E5AFAB6FE2", // http://crbug.com/312900
"D57DE394F36DC1C3220E7604C575D29C51A6C495", // http://crbug.com/319444 "D57DE394F36DC1C3220E7604C575D29C51A6C495", // http://crbug.com/319444
"3F65507A3B39259B38C8173C6FFA3D12DF64CCE9" // http://crbug.com/371562 "3F65507A3B39259B38C8173C6FFA3D12DF64CCE9" // http://crbug.com/371562
}; };
std::string hash = base::SHA1HashString(extension->id()); return SimpleFeature::IsIdInList(
hash = base::HexEncode(hash.c_str(), hash.length()); extension->id(),
for (size_t i = 0; i < arraysize(enhanced_extension_hashes); i++) std::set<std::string>(
if (hash == enhanced_extension_hashes[i]) kEnhancedExtensions,
return true; kEnhancedExtensions + arraysize(kEnhancedExtensions)));
} }
return false; return false;
} }
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
#include "chrome/browser/sync/glue/extension_backed_data_type_controller.h" #include "chrome/browser/sync/glue/extension_backed_data_type_controller.h"
#include "base/sha1.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h" #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
#include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "components/crx_file/id_util.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_factory.h" #include "extensions/browser/extension_registry_factory.h"
...@@ -18,17 +18,6 @@ using content::BrowserThread; ...@@ -18,17 +18,6 @@ using content::BrowserThread;
namespace browser_sync { namespace browser_sync {
namespace {
// Helper method to generate a hash from an extension id.
std::string IdToHash(const std::string extension_id) {
std::string hash = base::SHA1HashString(extension_id);
hash = base::HexEncode(hash.c_str(), hash.length());
return hash;
}
} // namespace
ExtensionBackedDataTypeController::ExtensionBackedDataTypeController( ExtensionBackedDataTypeController::ExtensionBackedDataTypeController(
syncer::ModelType type, syncer::ModelType type,
const std::string& extension_hash, const std::string& extension_hash,
...@@ -108,7 +97,7 @@ bool ExtensionBackedDataTypeController::IsSyncingExtensionEnabled() const { ...@@ -108,7 +97,7 @@ bool ExtensionBackedDataTypeController::IsSyncingExtensionEnabled() const {
bool ExtensionBackedDataTypeController::DoesExtensionMatch( bool ExtensionBackedDataTypeController::DoesExtensionMatch(
const extensions::Extension& extension) const { const extensions::Extension& extension) const {
return IdToHash(extension.id()) == extension_hash_; return crx_file::id_util::HashedIdInHex(extension.id()) == extension_hash_;
} }
bool ExtensionBackedDataTypeController::StartModels() { bool ExtensionBackedDataTypeController::StartModels() {
......
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
#include <algorithm> #include <algorithm>
#include "base/sha1.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/api/commands/command_service.h" #include "chrome/browser/extensions/api/commands/command_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/accelerator_utils.h" #include "chrome/browser/ui/accelerator_utils.h"
#include "chrome/common/extensions/command.h" #include "chrome/common/extensions/command.h"
#include "components/crx_file/id_util.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/notification_types.h" #include "extensions/browser/notification_types.h"
#include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_constants.h"
...@@ -74,12 +74,12 @@ EnhancedBookmarkKeyService::GetEnhancedBookmarkExtension() const { ...@@ -74,12 +74,12 @@ EnhancedBookmarkKeyService::GetEnhancedBookmarkExtension() const {
extensions::ExtensionSet::const_iterator loc = extensions::ExtensionSet::const_iterator loc =
std::find_if(extensions.begin(), extensions.end(), std::find_if(extensions.begin(), extensions.end(),
[](scoped_refptr<const extensions::Extension> extension) { [](scoped_refptr<const extensions::Extension> extension) {
static const char enhanced_extension_hash[] = static const char enhanced_ext_hash[] =
// http://crbug.com/312900 // http://crbug.com/312900
"D5736E4B5CF695CB93A2FB57E4FDC6E5AFAB6FE2"; "D5736E4B5CF695CB93A2FB57E4FDC6E5AFAB6FE2";
std::string hash = base::SHA1HashString(extension->id()); std::string hashed_id =
return base::HexEncode(hash.c_str(), hash.length()) == crx_file::id_util::HashedIdInHex(extension->id());
enhanced_extension_hash; return hashed_id == enhanced_ext_hash;
}); });
return loc != extensions.end() ? loc->get() : nullptr; return loc != extensions.end() ? loc->get() : nullptr;
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "components/crx_file/id_util.h" #include "components/crx_file/id_util.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/sha1.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "crypto/sha2.h" #include "crypto/sha2.h"
...@@ -53,6 +54,12 @@ std::string GenerateIdForPath(const base::FilePath& path) { ...@@ -53,6 +54,12 @@ std::string GenerateIdForPath(const base::FilePath& path) {
return GenerateId(path_bytes); return GenerateId(path_bytes);
} }
std::string HashedIdInHex(const std::string& id) {
const std::string id_hash = base::SHA1HashString(id);
DCHECK_EQ(base::kSHA1Length, id_hash.length());
return base::HexEncode(id_hash.c_str(), id_hash.length());
}
base::FilePath MaybeNormalizePath(const base::FilePath& path) { base::FilePath MaybeNormalizePath(const base::FilePath& path) {
#if defined(OS_WIN) #if defined(OS_WIN)
// Normalize any drive letter to upper-case. We do this for consistency with // Normalize any drive letter to upper-case. We do this for consistency with
......
...@@ -21,11 +21,14 @@ extern const size_t kIdSize; ...@@ -21,11 +21,14 @@ extern const size_t kIdSize;
// always generate the same output ID. // always generate the same output ID.
std::string GenerateId(const std::string& input); std::string GenerateId(const std::string& input);
// Generate an ID for an extension in the given path. // Generates an ID for an extension in the given path.
// Used while developing extensions, before they have a key. // Used while developing extensions, before they have a key.
std::string GenerateIdForPath(const base::FilePath& path); std::string GenerateIdForPath(const base::FilePath& path);
// Normalize the path for use by the extension. On Windows, this will make // Returns the hash of an extension ID in hex.
std::string HashedIdInHex(const std::string& id);
// Normalizes the path for use by the extension. On Windows, this will make
// sure the drive letter is uppercase. // sure the drive letter is uppercase.
base::FilePath MaybeNormalizePath(const base::FilePath& path); base::FilePath MaybeNormalizePath(const base::FilePath& path);
......
...@@ -128,7 +128,7 @@ AppWindowCreateFunction::AppWindowCreateFunction() ...@@ -128,7 +128,7 @@ AppWindowCreateFunction::AppWindowCreateFunction()
bool AppWindowCreateFunction::RunAsync() { bool AppWindowCreateFunction::RunAsync() {
// Don't create app window if the system is shutting down. // Don't create app window if the system is shutting down.
if (extensions::ExtensionsBrowserClient::Get()->IsShuttingDown()) if (ExtensionsBrowserClient::Get()->IsShuttingDown())
return false; return false;
scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); scoped_ptr<Create::Params> params(Create::Params::Create(*args_));
...@@ -139,7 +139,7 @@ bool AppWindowCreateFunction::RunAsync() { ...@@ -139,7 +139,7 @@ bool AppWindowCreateFunction::RunAsync() {
// path. // path.
GURL absolute = GURL(params->url); GURL absolute = GURL(params->url);
if (absolute.has_scheme()) { if (absolute.has_scheme()) {
if (extension()->location() == extensions::Manifest::COMPONENT) { if (extension()->location() == Manifest::COMPONENT) {
url = absolute; url = absolute;
} else { } else {
// Show error when url passed isn't local. // Show error when url passed isn't local.
...@@ -208,7 +208,7 @@ bool AppWindowCreateFunction::RunAsync() { ...@@ -208,7 +208,7 @@ bool AppWindowCreateFunction::RunAsync() {
return false; return false;
if (!AppWindowClient::Get()->IsCurrentChannelOlderThanDev() || if (!AppWindowClient::Get()->IsCurrentChannelOlderThanDev() ||
extension()->location() == extensions::Manifest::COMPONENT) { extension()->location() == Manifest::COMPONENT) {
if (options->type == app_window::WINDOW_TYPE_PANEL) { if (options->type == app_window::WINDOW_TYPE_PANEL) {
create_params.window_type = AppWindow::WINDOW_TYPE_PANEL; create_params.window_type = AppWindow::WINDOW_TYPE_PANEL;
} }
...@@ -217,7 +217,7 @@ bool AppWindowCreateFunction::RunAsync() { ...@@ -217,7 +217,7 @@ bool AppWindowCreateFunction::RunAsync() {
if (!GetFrameOptions(*options, &create_params)) if (!GetFrameOptions(*options, &create_params))
return false; return false;
if (extension()->GetType() == extensions::Manifest::TYPE_EXTENSION) { if (extension()->GetType() == Manifest::TYPE_EXTENSION) {
// Whitelisted IME extensions are allowed to use this API to create IME // Whitelisted IME extensions are allowed to use this API to create IME
// specific windows to show accented characters or suggestions. // specific windows to show accented characters or suggestions.
if (!extension()->permissions_data()->HasAPIPermission( if (!extension()->permissions_data()->HasAPIPermission(
...@@ -247,7 +247,7 @@ bool AppWindowCreateFunction::RunAsync() { ...@@ -247,7 +247,7 @@ bool AppWindowCreateFunction::RunAsync() {
} }
if (options->alpha_enabled.get()) { if (options->alpha_enabled.get()) {
const char* whitelist[] = { const char* const kWhitelist[] = {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
"B58B99751225318C7EB8CF4688B5434661083E07", // http://crbug.com/410550 "B58B99751225318C7EB8CF4688B5434661083E07", // http://crbug.com/410550
"06BE211D5F014BAB34BC22D9DDA09C63A81D828E", // http://crbug.com/425539 "06BE211D5F014BAB34BC22D9DDA09C63A81D828E", // http://crbug.com/425539
...@@ -265,10 +265,10 @@ bool AppWindowCreateFunction::RunAsync() { ...@@ -265,10 +265,10 @@ bool AppWindowCreateFunction::RunAsync() {
"0F585FB1D0FDFBEBCE1FEB5E9DFFB6DA476B8C9B" "0F585FB1D0FDFBEBCE1FEB5E9DFFB6DA476B8C9B"
}; };
if (AppWindowClient::Get()->IsCurrentChannelOlderThanDev() && if (AppWindowClient::Get()->IsCurrentChannelOlderThanDev() &&
!extensions::SimpleFeature::IsIdInList( !SimpleFeature::IsIdInList(
extension_id(), extension_id(),
std::set<std::string>(whitelist, std::set<std::string>(kWhitelist,
whitelist + arraysize(whitelist)))) { kWhitelist + arraysize(kWhitelist)))) {
error_ = app_window_constants::kAlphaEnabledWrongChannel; error_ = app_window_constants::kAlphaEnabledWrongChannel;
return false; return false;
} }
...@@ -495,9 +495,9 @@ AppWindow::Frame AppWindowCreateFunction::GetFrameFromString( ...@@ -495,9 +495,9 @@ AppWindow::Frame AppWindowCreateFunction::GetFrameFromString(
switches::kEnableExperimentalExtensionApis))) { switches::kEnableExperimentalExtensionApis))) {
inject_html_titlebar_ = true; inject_html_titlebar_ = true;
return AppWindow::FRAME_NONE; return AppWindow::FRAME_NONE;
} }
if (frame_string == kNoneFrameOption) if (frame_string == kNoneFrameOption)
return AppWindow::FRAME_NONE; return AppWindow::FRAME_NONE;
return AppWindow::FRAME_CHROME; return AppWindow::FRAME_CHROME;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment