Commit 9331595e authored by Maksim Ivanov's avatar Maksim Ivanov Committed by Commit Bot

Hardcode ID in TestCertificateProviderExtension

Make the TestCertificateProviderExtension's test extension have a fixed
extension ID (by putting its public key into the manifest.json file),
and update the class to expose this ID as a constant.

This is a preparation step for getting rid of the
TestCertificateProviderExtensionLoginScreenMixin (in favor of
ExtensionForceInstallMixin).

Bug: 1090941
Change-Id: Ic27ed9f0161631b6415a07d3a8e73b8329ec34eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2312817
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarFabian Sommer <fabiansommer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791055}
parent 515b9ac4
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
namespace { namespace {
constexpr char kExtensionId[] = "ecmhnokcdiianioonpgakiooenfnonid";
// List of algorithms that the extension claims to support for the returned // List of algorithms that the extension claims to support for the returned
// certificates. // certificates.
constexpr extensions::api::certificate_provider::Hash kSupportedHashes[] = { constexpr extensions::api::certificate_provider::Hash kSupportedHashes[] = {
...@@ -116,6 +118,11 @@ bssl::UniquePtr<EVP_PKEY> LoadPrivateKeyFromPem(const base::FilePath& path) { ...@@ -116,6 +118,11 @@ bssl::UniquePtr<EVP_PKEY> LoadPrivateKeyFromPem(const base::FilePath& path) {
} // namespace } // namespace
// static
extensions::ExtensionId TestCertificateProviderExtension::extension_id() {
return kExtensionId;
}
// static // static
scoped_refptr<net::X509Certificate> scoped_refptr<net::X509Certificate>
TestCertificateProviderExtension::GetCertificate() { TestCertificateProviderExtension::GetCertificate() {
...@@ -135,15 +142,12 @@ std::string TestCertificateProviderExtension::GetCertificateSpki() { ...@@ -135,15 +142,12 @@ std::string TestCertificateProviderExtension::GetCertificateSpki() {
} }
TestCertificateProviderExtension::TestCertificateProviderExtension( TestCertificateProviderExtension::TestCertificateProviderExtension(
content::BrowserContext* browser_context, content::BrowserContext* browser_context)
const std::string& extension_id)
: browser_context_(browser_context), : browser_context_(browser_context),
extension_id_(extension_id),
certificate_(GetCertificate()), certificate_(GetCertificate()),
private_key_(LoadPrivateKeyFromPem(net::GetTestCertsDirectory().Append( private_key_(LoadPrivateKeyFromPem(net::GetTestCertsDirectory().Append(
FILE_PATH_LITERAL("client_1.key")))) { FILE_PATH_LITERAL("client_1.key")))) {
DCHECK(browser_context_); DCHECK(browser_context_);
DCHECK(!extension_id_.empty());
CHECK(certificate_); CHECK(certificate_);
CHECK(private_key_); CHECK(private_key_);
notification_registrar_.Add(this, notification_registrar_.Add(this,
...@@ -161,7 +165,7 @@ void TestCertificateProviderExtension::Observe( ...@@ -161,7 +165,7 @@ void TestCertificateProviderExtension::Observe(
extensions::TestSendMessageFunction* function = extensions::TestSendMessageFunction* function =
content::Source<extensions::TestSendMessageFunction>(source).ptr(); content::Source<extensions::TestSendMessageFunction>(source).ptr();
if (!function->extension() || function->extension_id() != extension_id_ || if (!function->extension() || function->extension_id() != kExtensionId ||
function->browser_context() != browser_context_) { function->browser_context() != browser_context_) {
// Ignore messages targeted to other extensions. // Ignore messages targeted to other extensions.
return; return;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/values.h" #include "base/values.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "extensions/common/extension_id.h"
#include "net/cert/x509_certificate.h" #include "net/cert/x509_certificate.h"
#include "third_party/boringssl/src/include/openssl/base.h" #include "third_party/boringssl/src/include/openssl/base.h"
#include "third_party/boringssl/src/include/openssl/evp.h" #include "third_party/boringssl/src/include/openssl/evp.h"
...@@ -39,12 +40,13 @@ class BrowserContext; ...@@ -39,12 +40,13 @@ class BrowserContext;
class TestCertificateProviderExtension final class TestCertificateProviderExtension final
: public content::NotificationObserver { : public content::NotificationObserver {
public: public:
static extensions::ExtensionId extension_id();
// Returns the certificate provided by the extension. // Returns the certificate provided by the extension.
static scoped_refptr<net::X509Certificate> GetCertificate(); static scoped_refptr<net::X509Certificate> GetCertificate();
static std::string GetCertificateSpki(); static std::string GetCertificateSpki();
TestCertificateProviderExtension(content::BrowserContext* browser_context, explicit TestCertificateProviderExtension(
const std::string& extension_id); content::BrowserContext* browser_context);
~TestCertificateProviderExtension() override; ~TestCertificateProviderExtension() override;
int certificate_request_count() const { return certificate_request_count_; } int certificate_request_count() const { return certificate_request_count_; }
...@@ -83,7 +85,6 @@ class TestCertificateProviderExtension final ...@@ -83,7 +85,6 @@ class TestCertificateProviderExtension final
ReplyToJsCallback callback); ReplyToJsCallback callback);
content::BrowserContext* const browser_context_; content::BrowserContext* const browser_context_;
const std::string extension_id_;
const scoped_refptr<net::X509Certificate> certificate_; const scoped_refptr<net::X509Certificate> certificate_;
const bssl::UniquePtr<EVP_PKEY> private_key_; const bssl::UniquePtr<EVP_PKEY> private_key_;
int certificate_request_count_ = 0; int certificate_request_count_ = 0;
......
...@@ -22,9 +22,6 @@ ...@@ -22,9 +22,6 @@
namespace { namespace {
// Extension ID of the test certificate provider extension.
constexpr char kTestCertProviderExtensionId[] =
"ecmhnokcdiianioonpgakiooenfnonid";
// Path to the update manifest XML file of the test certificate provider // Path to the update manifest XML file of the test certificate provider
// extension. // extension.
constexpr char kTestCertProviderExtensionUpdateManifestPath[] = constexpr char kTestCertProviderExtensionUpdateManifestPath[] =
...@@ -36,11 +33,6 @@ Profile* GetProfile() { ...@@ -36,11 +33,6 @@ Profile* GetProfile() {
} // namespace } // namespace
// static
std::string TestCertificateProviderExtensionLoginScreenMixin::GetExtensionId() {
return kTestCertProviderExtensionId;
}
TestCertificateProviderExtensionLoginScreenMixin:: TestCertificateProviderExtensionLoginScreenMixin::
TestCertificateProviderExtensionLoginScreenMixin( TestCertificateProviderExtensionLoginScreenMixin(
InProcessBrowserTestMixinHost* host, InProcessBrowserTestMixinHost* host,
...@@ -49,7 +41,7 @@ TestCertificateProviderExtensionLoginScreenMixin:: ...@@ -49,7 +41,7 @@ TestCertificateProviderExtensionLoginScreenMixin::
: InProcessBrowserTestMixin(host), : InProcessBrowserTestMixin(host),
device_state_mixin_(device_state_mixin), device_state_mixin_(device_state_mixin),
load_extension_immediately_(load_extension_immediately), load_extension_immediately_(load_extension_immediately),
feature_allowlist_(kTestCertProviderExtensionId) { feature_allowlist_(TestCertificateProviderExtension::extension_id()) {
base::FilePath test_data_dir; base::FilePath test_data_dir;
base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
embedded_test_server_.ServeFilesFromDirectory(test_data_dir); embedded_test_server_.ServeFilesFromDirectory(test_data_dir);
...@@ -65,8 +57,7 @@ TestCertificateProviderExtensionLoginScreenMixin:: ...@@ -65,8 +57,7 @@ TestCertificateProviderExtensionLoginScreenMixin::
void TestCertificateProviderExtensionLoginScreenMixin::SetUpOnMainThread() { void TestCertificateProviderExtensionLoginScreenMixin::SetUpOnMainThread() {
test_certificate_provider_extension_ = test_certificate_provider_extension_ =
std::make_unique<TestCertificateProviderExtension>(GetProfile(), std::make_unique<TestCertificateProviderExtension>(GetProfile());
GetExtensionId());
ASSERT_TRUE(embedded_test_server_.Start()); ASSERT_TRUE(embedded_test_server_.Start());
if (load_extension_immediately_) { if (load_extension_immediately_) {
AddExtensionForForceInstallation(); AddExtensionForForceInstallation();
...@@ -83,7 +74,10 @@ void TestCertificateProviderExtensionLoginScreenMixin:: ...@@ -83,7 +74,10 @@ void TestCertificateProviderExtensionLoginScreenMixin::
const GURL update_manifest_url = embedded_test_server_.GetURL( const GURL update_manifest_url = embedded_test_server_.GetURL(
kTestCertProviderExtensionUpdateManifestPath); kTestCertProviderExtensionUpdateManifestPath);
const std::string policy_item_value = base::ReplaceStringPlaceholders( const std::string policy_item_value = base::ReplaceStringPlaceholders(
"$1;$2", {GetExtensionId(), update_manifest_url.spec()}, nullptr); "$1;$2",
{TestCertificateProviderExtension::extension_id(),
update_manifest_url.spec()},
nullptr);
device_state_mixin_->RequestDevicePolicyUpdate() device_state_mixin_->RequestDevicePolicyUpdate()
->policy_payload() ->policy_payload()
->mutable_device_login_screen_extensions() ->mutable_device_login_screen_extensions()
...@@ -93,6 +87,6 @@ void TestCertificateProviderExtensionLoginScreenMixin:: ...@@ -93,6 +87,6 @@ void TestCertificateProviderExtensionLoginScreenMixin::
void TestCertificateProviderExtensionLoginScreenMixin:: void TestCertificateProviderExtensionLoginScreenMixin::
WaitUntilExtensionLoaded() { WaitUntilExtensionLoaded() {
extensions::TestBackgroundPageFirstLoadObserver bg_page_first_load_observer( extensions::TestBackgroundPageFirstLoadObserver bg_page_first_load_observer(
GetProfile(), GetExtensionId()); GetProfile(), TestCertificateProviderExtension::extension_id());
bg_page_first_load_observer.Wait(); bg_page_first_load_observer.Wait();
} }
...@@ -25,8 +25,6 @@ class TestCertificateProviderExtension; ...@@ -25,8 +25,6 @@ class TestCertificateProviderExtension;
class TestCertificateProviderExtensionLoginScreenMixin final class TestCertificateProviderExtensionLoginScreenMixin final
: public InProcessBrowserTestMixin { : public InProcessBrowserTestMixin {
public: public:
static std::string GetExtensionId();
// If |load_extension_immediately| is false, // If |load_extension_immediately| is false,
// |AddExtensionForForceInstallation()| needs to be called by the test. // |AddExtensionForForceInstallation()| needs to be called by the test.
// Otherwise, the extension will be installed during setup. // Otherwise, the extension will be installed during setup.
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "extensions/browser/pref_names.h" #include "extensions/browser/pref_names.h"
#include "extensions/browser/process_manager.h" #include "extensions/browser/process_manager.h"
#include "extensions/browser/process_manager_observer.h" #include "extensions/browser/process_manager_observer.h"
#include "extensions/common/extension_id.h"
namespace chromeos { namespace chromeos {
...@@ -76,10 +77,8 @@ class ChallengeResponseAuthKeysLoaderBrowserTest : public OobeBaseTest { ...@@ -76,10 +77,8 @@ class ChallengeResponseAuthKeysLoaderBrowserTest : public OobeBaseTest {
std::vector<ChallengeResponseKey> challenge_response_keys; std::vector<ChallengeResponseKey> challenge_response_keys;
ChallengeResponseKey challenge_response_key; ChallengeResponseKey challenge_response_key;
challenge_response_key.set_public_key_spki_der(GetSpki()); challenge_response_key.set_public_key_spki_der(GetSpki());
if (with_extension_id) { if (with_extension_id)
challenge_response_key.set_extension_id( challenge_response_key.set_extension_id(extension_id());
cert_provider_extension_mixin_.GetExtensionId());
}
challenge_response_keys.push_back(challenge_response_key); challenge_response_keys.push_back(challenge_response_key);
base::Value challenge_response_keys_value = base::Value challenge_response_keys_value =
...@@ -139,7 +138,7 @@ class ChallengeResponseAuthKeysLoaderBrowserTest : public OobeBaseTest { ...@@ -139,7 +138,7 @@ class ChallengeResponseAuthKeysLoaderBrowserTest : public OobeBaseTest {
EXPECT_EQ(pref->GetValue()->DictSize(), static_cast<size_t>(1)); EXPECT_EQ(pref->GetValue()->DictSize(), static_cast<size_t>(1));
for (const auto& item : pref->GetValue()->DictItems()) { for (const auto& item : pref->GetValue()->DictItems()) {
EXPECT_EQ(item.first, GetExtensionId()); EXPECT_EQ(item.first, extension_id());
} }
} }
...@@ -158,8 +157,8 @@ class ChallengeResponseAuthKeysLoaderBrowserTest : public OobeBaseTest { ...@@ -158,8 +157,8 @@ class ChallengeResponseAuthKeysLoaderBrowserTest : public OobeBaseTest {
->GetCertificateSpki(); ->GetCertificateSpki();
} }
std::string GetExtensionId() const { static extensions::ExtensionId extension_id() {
return cert_provider_extension_mixin_.GetExtensionId(); return TestCertificateProviderExtension::extension_id();
} }
AccountId account_id() const { return account_id_; } AccountId account_id() const { return account_id_; }
...@@ -256,7 +255,7 @@ IN_PROC_BROWSER_TEST_F(ChallengeResponseAuthKeysLoaderBrowserTest, ...@@ -256,7 +255,7 @@ IN_PROC_BROWSER_TEST_F(ChallengeResponseAuthKeysLoaderBrowserTest,
std::vector<ChallengeResponseKey> challenge_response_keys = std::vector<ChallengeResponseKey> challenge_response_keys =
LoadChallengeResponseKeys(); LoadChallengeResponseKeys();
ASSERT_EQ(challenge_response_keys.size(), static_cast<size_t>(1)); ASSERT_EQ(challenge_response_keys.size(), static_cast<size_t>(1));
EXPECT_EQ(challenge_response_keys.at(0).extension_id(), GetExtensionId()); EXPECT_EQ(challenge_response_keys.at(0).extension_id(), extension_id());
EXPECT_EQ(challenge_response_keys.at(0).public_key_spki_der(), GetSpki()); EXPECT_EQ(challenge_response_keys.at(0).public_key_spki_der(), GetSpki());
} }
...@@ -278,7 +277,7 @@ IN_PROC_BROWSER_TEST_F(ChallengeResponseAuthKeysLoaderBrowserTest, ...@@ -278,7 +277,7 @@ IN_PROC_BROWSER_TEST_F(ChallengeResponseAuthKeysLoaderBrowserTest,
std::vector<ChallengeResponseKey> challenge_response_keys = std::vector<ChallengeResponseKey> challenge_response_keys =
LoadChallengeResponseKeys(); LoadChallengeResponseKeys();
ASSERT_EQ(challenge_response_keys.size(), static_cast<size_t>(1)); ASSERT_EQ(challenge_response_keys.size(), static_cast<size_t>(1));
EXPECT_EQ(challenge_response_keys.at(0).extension_id(), GetExtensionId()); EXPECT_EQ(challenge_response_keys.at(0).extension_id(), extension_id());
EXPECT_EQ(challenge_response_keys.at(0).public_key_spki_der(), GetSpki()); EXPECT_EQ(challenge_response_keys.at(0).public_key_spki_der(), GetSpki());
} }
...@@ -315,7 +314,7 @@ IN_PROC_BROWSER_TEST_F(ChallengeResponseAuthKeysLoaderBrowserTest, ...@@ -315,7 +314,7 @@ IN_PROC_BROWSER_TEST_F(ChallengeResponseAuthKeysLoaderBrowserTest,
std::vector<ChallengeResponseKey> challenge_response_keys = std::vector<ChallengeResponseKey> challenge_response_keys =
LoadChallengeResponseKeys(); LoadChallengeResponseKeys();
ASSERT_EQ(challenge_response_keys.size(), static_cast<size_t>(1)); ASSERT_EQ(challenge_response_keys.size(), static_cast<size_t>(1));
EXPECT_EQ(challenge_response_keys.at(0).extension_id(), GetExtensionId()); EXPECT_EQ(challenge_response_keys.at(0).extension_id(), extension_id());
EXPECT_EQ(challenge_response_keys.at(0).public_key_spki_der(), GetSpki()); EXPECT_EQ(challenge_response_keys.at(0).public_key_spki_der(), GetSpki());
} }
...@@ -411,7 +410,7 @@ class ChallengeResponseExtensionLoadObserverTest ...@@ -411,7 +410,7 @@ class ChallengeResponseExtensionLoadObserverTest
void OnBackgroundHostCreated( void OnBackgroundHostCreated(
extensions::ExtensionHost* extension_host) override { extensions::ExtensionHost* extension_host) override {
if (extension_host->extension_id() == GetExtensionId()) { if (extension_host->extension_id() == extension_id()) {
extension_host_ = extension_host; extension_host_ = extension_host;
extension_host_created_loop_->Quit(); extension_host_created_loop_->Quit();
} }
......
...@@ -225,7 +225,7 @@ class SecurityTokenLoginTest : public MixinBasedInProcessBrowserTest, ...@@ -225,7 +225,7 @@ class SecurityTokenLoginTest : public MixinBasedInProcessBrowserTest,
challenge_response_key.set_public_key_spki_der( challenge_response_key.set_public_key_spki_der(
TestCertificateProviderExtension::GetCertificateSpki()); TestCertificateProviderExtension::GetCertificateSpki());
challenge_response_key.set_extension_id( challenge_response_key.set_extension_id(
TestCertificateProviderExtensionLoginScreenMixin::GetExtensionId()); TestCertificateProviderExtension::extension_id());
base::Value challenge_response_keys_value = base::Value challenge_response_keys_value =
SerializeChallengeResponseKeysForKnownUser({challenge_response_key}); SerializeChallengeResponseKeysForKnownUser({challenge_response_key});
......
...@@ -577,17 +577,19 @@ IN_PROC_BROWSER_TEST_F(CertificateProviderApiTest, LazyBackgroundPage) { ...@@ -577,17 +577,19 @@ IN_PROC_BROWSER_TEST_F(CertificateProviderApiTest, LazyBackgroundPage) {
extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1); extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1);
// Load the test extension. // Load the test extension.
base::FilePath test_data_dir; TestCertificateProviderExtension test_certificate_provider_extension(
base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); profile());
extensions::TestBackgroundPageFirstLoadObserver
test_background_page_first_load_observer(
profile(), TestCertificateProviderExtension::extension_id());
const extensions::Extension* const extension = const extensions::Extension* const extension =
LoadExtension(test_data_dir.AppendASCII("extensions") LoadExtension(base::PathService::CheckedGet(chrome::DIR_TEST_DATA)
.AppendASCII("extensions")
.AppendASCII("test_certificate_provider") .AppendASCII("test_certificate_provider")
.AppendASCII("extension")); .AppendASCII("extension"));
ASSERT_TRUE(extension); ASSERT_TRUE(extension);
TestCertificateProviderExtension test_certificate_provider_extension( EXPECT_EQ(extension->id(), TestCertificateProviderExtension::extension_id());
profile(), extension->id()); test_background_page_first_load_observer.Wait();
extensions::TestBackgroundPageFirstLoadObserver(profile(), extension->id())
.Wait();
// Navigate to the page that requests the client authentication. Use the // Navigate to the page that requests the client authentication. Use the
// incognito profile in order to force re-authentication in the later request // incognito profile in order to force re-authentication in the later request
......
{ {
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4m1mCBTJAmawIS/QWFzsfPCj8+5QAOfVUA4mapvwIBbZ5auGbkcO92U/yfXlNVPAFL6jm44ALqxgI7QLMmucJzNpKGk20e0Kgz4ZURx8kZ5nKHLrRB89vlrUQ8v5B3YlJ5uzk/WT511IcvbwjOru9PMlqNghC/NvyDWIvuo91zbO49twcIhsSFlN/+oYe9n6hKusk6ErX3BvdhBfMlXIjPPlGciOozYl+tOdTgy3nna2sMbmAAsw5k8YB4rgwmCLfMvzJ7+XOUp9sLDGjQmrqX1mCSWCZOsmhOVe2qmEtaV2aJbh2xnFcePQswVB8uys9X5a8Bo5Dgsd0x/8E9TqUwIDAQAB",
"name": "Test Certificate Provider", "name": "Test Certificate Provider",
"version": "1.0", "version": "1.0",
"manifest_version": 2, "manifest_version": 2,
......
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