Commit 646faed8 authored by Nick Harper's avatar Nick Harper Committed by Commit Bot

Check that Channel ID is in use before providing Channel IDs to extensions

Change-Id: Iabe9977651ec3e38f43d2495e790af508a43e0e5
Reviewed-on: https://chromium-review.googlesource.com/1055676
Commit-Queue: Nick Harper <nharper@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558096}
parent 2b8389a3
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/crx_file/id_util.h" #include "components/crx_file/id_util.h"
#include "components/network_session_configurator/common/network_features.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
...@@ -86,6 +87,10 @@ void CreateDomainBoundCertOnIOThread( ...@@ -86,6 +87,10 @@ void CreateDomainBoundCertOnIOThread(
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
net::ChannelIDService* channel_id_service = net::ChannelIDService* channel_id_service =
request_context_getter->GetURLRequestContext()->channel_id_service(); request_context_getter->GetURLRequestContext()->channel_id_service();
if (!channel_id_service) {
waitable_event->Signal();
return;
}
int status = channel_id_service->GetOrCreateChannelID( int status = channel_id_service->GetOrCreateChannelID(
url.host(), channel_id_key, url.host(), channel_id_key,
base::BindRepeating(&GotDomainBoundCert, waitable_event), request); base::BindRepeating(&GotDomainBoundCert, waitable_event), request);
...@@ -111,7 +116,7 @@ std::string CreateTlsChannelId( ...@@ -111,7 +116,7 @@ std::string CreateTlsChannelId(
waitable_event.Wait(); waitable_event.Wait();
// Create the expected value. // Create the expected value.
std::vector<uint8_t> spki_vector; std::vector<uint8_t> spki_vector;
if (!channel_id_key->ExportPublicKey(&spki_vector)) if (!channel_id_key || !channel_id_key->ExportPublicKey(&spki_vector))
return std::string(); return std::string();
base::StringPiece spki(reinterpret_cast<char*>(spki_vector.data()), base::StringPiece spki(reinterpret_cast<char*>(spki_vector.data()),
spki_vector.size()); spki_vector.size());
...@@ -1190,6 +1195,54 @@ IN_PROC_BROWSER_TEST_P(ExternallyConnectableMessagingTest, ...@@ -1190,6 +1195,54 @@ IN_PROC_BROWSER_TEST_P(ExternallyConnectableMessagingTest,
EXPECT_EQ(tls_channel_id, tls_channel_id2); EXPECT_EQ(tls_channel_id, tls_channel_id2);
} }
class ExternallyConnectableMessagingTestNoChannelID
: public ExternallyConnectableMessagingTest {
public:
ExternallyConnectableMessagingTestNoChannelID() {}
~ExternallyConnectableMessagingTestNoChannelID() override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
std::vector<base::Feature> enabled_features;
std::vector<base::Feature> disabled_features = {::features::kChannelID,
::features::kTokenBinding};
scoped_feature_list_.InitWithFeatures(enabled_features, disabled_features);
ExternallyConnectableMessagingTest::SetUpCommandLine(command_line);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(ExternallyConnectableMessagingTestNoChannelID);
};
IN_PROC_BROWSER_TEST_P(ExternallyConnectableMessagingTestNoChannelID,
TlsChannelIdEmptyWhenDisabled) {
std::string expected_tls_channel_id_value =
CreateTlsChannelId(profile()->GetRequestContext(), chromium_org_url());
scoped_refptr<const Extension> chromium_connectable =
LoadChromiumConnectableExtensionWithTlsChannelId();
ASSERT_TRUE(chromium_connectable.get());
ui_test_utils::NavigateToURL(browser(), chromium_org_url());
// Check that both connect and sendMessage don't report a Channel ID.
std::string tls_channel_id_from_port_connect =
GetTlsChannelIdFromPortConnect(chromium_connectable.get(), true);
EXPECT_EQ(0u, tls_channel_id_from_port_connect.size());
std::string tls_channel_id_from_send_message =
GetTlsChannelIdFromSendMessage(chromium_connectable.get(), true);
EXPECT_EQ(0u, tls_channel_id_from_send_message.size());
}
INSTANTIATE_TEST_CASE_P(NativeBindingsNoChannelID,
ExternallyConnectableMessagingTestNoChannelID,
::testing::Values(NATIVE_BINDINGS));
INSTANTIATE_TEST_CASE_P(JavaScriptBindingsNoChannelID,
ExternallyConnectableMessagingTestNoChannelID,
::testing::Values(JAVASCRIPT_BINDINGS));
// Tests a web connectable extension that receives TLS channel id, but // Tests a web connectable extension that receives TLS channel id, but
// immediately closes its background page upon receipt of a message. // immediately closes its background page upon receipt of a message.
// Same flakiness seen in http://crbug.com/297866 // Same flakiness seen in http://crbug.com/297866
......
...@@ -62,12 +62,19 @@ void MessagePropertyProvider::GetChannelIDOnIOThread( ...@@ -62,12 +62,19 @@ void MessagePropertyProvider::GetChannelIDOnIOThread(
const std::string& host, const std::string& host,
const ChannelIDCallback& reply) { const ChannelIDCallback& reply) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO); DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
net::ChannelIDService* channel_id_service = const net::HttpNetworkSession::Params* network_params =
request_context_getter->GetURLRequestContext()->channel_id_service(); request_context_getter->GetURLRequestContext()->GetNetworkSessionParams();
GetChannelIDOutput* output = new GetChannelIDOutput(); GetChannelIDOutput* output = new GetChannelIDOutput();
net::CompletionCallback net_completion_callback = net::CompletionCallback net_completion_callback =
base::Bind(&MessagePropertyProvider::GotChannelID, original_task_runner, base::Bind(&MessagePropertyProvider::GotChannelID, original_task_runner,
base::Owned(output), reply); base::Owned(output), reply);
if (!network_params->enable_token_binding &&
!network_params->enable_channel_id) {
GotChannelID(original_task_runner, output, reply, net::ERR_FILE_NOT_FOUND);
return;
}
net::ChannelIDService* channel_id_service =
request_context_getter->GetURLRequestContext()->channel_id_service();
int status = channel_id_service->GetChannelID( int status = channel_id_service->GetChannelID(
host, &output->channel_id_key, net_completion_callback, &output->request); host, &output->channel_id_key, net_completion_callback, &output->request);
if (status == net::ERR_IO_PENDING) if (status == net::ERR_IO_PENDING)
......
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