Commit 1916748c authored by Peter Kvitek's avatar Peter Kvitek Committed by Chromium LUCI CQ

[headless] Ensure OSCrypt::SetRawEncryptionKey() is called only once.

This is a followup to http://crrev.com/c/2570447 that introduced extra
check in OSCrypt::SetRawEncryptionKey() that is now removed.

Bug: 1157539
Change-Id: I0d35502068958a93654565301d84ae04e4760272
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2596873Reviewed-by: default avatarChristos Froussios <cfroussios@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Commit-Queue: Peter Kvitek <kvitekp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841115}
parent 0ad5921d
......@@ -236,10 +236,8 @@ bool OSCrypt::Init(PrefService* local_state) {
void OSCrypt::SetRawEncryptionKey(const std::string& raw_key) {
DCHECK(!g_use_mock_key) << "Mock key in use.";
DCHECK(!raw_key.empty()) << "Bad key.";
if (raw_key != GetEncryptionKeyFactory()) {
DCHECK(GetEncryptionKeyFactory().empty()) << "Key already set.";
GetEncryptionKeyFactory().assign(raw_key);
}
DCHECK(GetEncryptionKeyFactory().empty()) << "Key already set.";
GetEncryptionKeyFactory().assign(raw_key);
}
// static
......
......@@ -64,15 +64,15 @@ net::NetworkTrafficAnnotationTag GetProxyConfigTrafficAnnotationTag() {
return traffic_annotation;
}
// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
#if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
::network::mojom::CryptConfigPtr BuildCryptConfigOnce(
const base::FilePath& user_data_path) {
void SetCryptConfigOnce(const base::FilePath& user_data_path) {
static bool done_once = false;
if (done_once)
return nullptr;
return;
done_once = true;
// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
#if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
::network::mojom::CryptConfigPtr config =
::network::mojom::CryptConfig::New();
config->store = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
......@@ -80,9 +80,17 @@ net::NetworkTrafficAnnotationTag GetProxyConfigTrafficAnnotationTag() {
config->product_name = kProductName;
config->should_use_preference = false;
config->user_data_path = user_data_path;
return config;
}
content::GetNetworkService()->SetCryptConfig(std::move(config));
#elif defined(OS_WIN) && defined(HEADLESS_USE_PREFS)
// The OSCrypt keys are process bound, so if network service is out of
// process, send it the required key if it is available.
if (content::IsOutOfProcessNetworkService() &&
OSCrypt::IsEncryptionAvailable()) {
content::GetNetworkService()->SetEncryptionKey(
OSCrypt::GetRawEncryptionKey());
}
#endif
}
} // namespace
......@@ -227,21 +235,8 @@ HeadlessRequestContextManager::HeadlessRequestContextManager(
base::ThreadTaskRunnerHandle::Get());
}
}
// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
#if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
auto crypt_config = BuildCryptConfigOnce(user_data_path_);
if (crypt_config)
content::GetNetworkService()->SetCryptConfig(std::move(crypt_config));
#elif defined(OS_WIN) && defined(HEADLESS_USE_PREFS)
// The OSCrypt keys are process bound, so if network service is out of
// process, send it the required key if it is available.
if (content::IsOutOfProcessNetworkService() &&
OSCrypt::IsEncryptionAvailable()) {
content::GetNetworkService()->SetEncryptionKey(
OSCrypt::GetRawEncryptionKey());
}
#endif
SetCryptConfigOnce(user_data_path_);
}
HeadlessRequestContextManager::~HeadlessRequestContextManager() {
......
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