Commit 713a241e authored by Andrey Lushnikov's avatar Andrey Lushnikov Committed by Commit Bot

Headless: use cookie encryption to match non-headless mode

This patch starts using cookie encryption for Chrome Headless. This
makes sure that cookies written in non-headless mode can be read in
headless mode.

The patch also has a special handling for Linux since OsCrypt has
to be configured on this platform.

Change-Id: I007e68920369d2ab492294323c394cc8351176a2
Reviewed-on: https://chromium-review.googlesource.com/752743Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarDavid Vallet <dvallet@chromium.org>
Commit-Queue: Andrey Lushnikov <lushnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513738}
parent f058e42e
......@@ -388,6 +388,7 @@ component("headless") {
":headless_render_frame_controller",
":tab_socket",
":version_header",
"//components/cookie_config",
"//components/security_state/core",
"//content/public/common",
"//content/public/common:service_names",
......@@ -399,6 +400,10 @@ component("headless") {
"//url",
]
if (is_linux && !is_chromeos) {
deps += [ "//components/os_crypt" ]
}
if (is_component_build) {
sources += [
"lib/browser/headless_content_browser_client.cc",
......
include_rules = [
"+components/cookie_config",
"+components/crash/content/app",
"+components/crash/content/browser",
"+components/os_crypt",
"+components/printing/service/public/cpp",
"+components/printing/service/public/interfaces",
"+content/public/app",
......
......@@ -33,6 +33,16 @@ const char kDumpDom[] = "dump-dom";
// Hide scrollbars from screenshots.
const char kHideScrollbars[] = "hide-scrollbars";
// Specifies which encryption storage backend to use. Possible values are
// kwallet, kwallet5, gnome, gnome-keyring, gnome-libsecret, basic. Any other
// value will lead to Chrome detecting the best backend automatically.
// TODO(crbug.com/571003): Once PasswordStore no longer uses the Keyring or
// KWallet for storing passwords, rename this flag to stop referencing
// passwords. Do not rename it sooner, though; developers and testers might
// rely on it keeping large amounts of testing passwords out of their Keyrings
// or KWallets.
const char kPasswordStore[] = "password-store";
// Save a pdf file of the loaded page.
const char kPrintToPDF[] = "print-to-pdf";
......
......@@ -17,6 +17,7 @@ extern const char kDisableCrashReporter[];
extern const char kDumpDom[];
extern const char kEnableCrashReporter[];
extern const char kHideScrollbars[];
extern const char kPasswordStore[];
extern const char kPrintToPDF[];
extern const char kProxyBypassList[];
extern const char kProxyServer[];
......
......@@ -10,9 +10,12 @@
#include "base/memory/ptr_util.h"
#include "base/task_scheduler/post_task.h"
#include "build/build_config.h"
#include "components/cookie_config/cookie_store_util.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/cookie_store_factory.h"
#include "content/public/browser/devtools_network_transaction_factory.h"
#include "headless/app/headless_shell_switches.h"
#include "headless/lib/browser/headless_browser_context_impl.h"
#include "headless/lib/browser/headless_browser_context_options.h"
#include "headless/lib/browser/headless_network_delegate.h"
......@@ -26,6 +29,12 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#include "base/command_line.h"
#include "components/os_crypt/key_storage_config_linux.h"
#include "components/os_crypt/os_crypt.h"
#endif
namespace headless {
HeadlessURLRequestContextGetter::HeadlessURLRequestContextGetter(
......@@ -88,10 +97,29 @@ HeadlessURLRequestContextGetter::GetURLRequestContext() {
if (headless_browser_context_ &&
!headless_browser_context_->IsOffTheRecord() &&
!headless_browser_context_->options()->user_data_dir().empty()) {
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
std::unique_ptr<os_crypt::Config> config(new os_crypt::Config());
base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
config->store =
command_line->GetSwitchValueASCII(switches::kPasswordStore);
config->product_name = "HeadlessChrome";
// OSCrypt may target keyring, which requires calls from the main
// thread.
config->main_thread_runner =
content::BrowserThread::GetTaskRunnerForThread(
content::BrowserThread::UI);
config->should_use_preference = false;
config->user_data_path = headless_browser_context_->GetPath();
OSCrypt::SetConfig(std::move(config));
#endif
content::CookieStoreConfig cookie_config(
headless_browser_context_->GetPath().Append(
FILE_PATH_LITERAL("Cookies")),
content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES, NULL);
cookie_config.crypto_delegate =
cookie_config::GetCookieCryptoDelegate();
std::unique_ptr<net::CookieStore> cookie_store =
CreateCookieStore(cookie_config);
std::unique_ptr<net::ChannelIDService> channel_id_service =
......
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