Skip to content

Commit 0e09738

Browse files
author
John Kleinschmidt
committed
1 parent c2888b8 commit 0e09738

File tree

2 files changed

+23
-34
lines changed

2 files changed

+23
-34
lines changed

shell/browser/electron_browser_main_parts.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include "base/strings/string_number_conversions.h"
1818
#include "base/strings/utf_string_conversions.h"
1919
#include "chrome/browser/icon_manager.h"
20+
#include "chrome/common/chrome_paths.h"
21+
#include "chrome/common/chrome_switches.h"
22+
#include "components/os_crypt/key_storage_config_linux.h"
2023
#include "components/os_crypt/os_crypt.h"
2124
#include "content/browser/browser_main_loop.h" // nogncheck
2225
#include "content/public/browser/browser_thread.h"
@@ -465,6 +468,26 @@ void ElectronBrowserMainParts::PostCreateMainMessageLoop() {
465468
ui::OzonePlatform::GetInstance()->PostCreateMainMessageLoop(
466469
std::move(shutdown_cb));
467470
bluez::DBusBluezManagerWrapperLinux::Initialize();
471+
472+
// Set up crypt config. This needs to be done before anything starts the
473+
// network service, as the raw encryption key needs to be shared with the
474+
// network service for encrypted cookie storage.
475+
std::string app_name = electron::Browser::Get()->GetName();
476+
const base::CommandLine& command_line =
477+
*base::CommandLine::ForCurrentProcess();
478+
std::unique_ptr<os_crypt::Config> config =
479+
std::make_unique<os_crypt::Config>();
480+
// Forward to os_crypt the flag to use a specific password store.
481+
config->store = command_line.GetSwitchValueASCII(::switches::kPasswordStore);
482+
config->product_name = app_name;
483+
config->application_name = app_name;
484+
config->main_thread_runner = base::ThreadTaskRunnerHandle::Get();
485+
// c.f.
486+
// https://source.chromium.org/chromium/chromium/src/+/master:chrome/common/chrome_switches.cc;l=689;drc=9d82515060b9b75fa941986f5db7390299669ef1
487+
config->should_use_preference =
488+
command_line.HasSwitch(::switches::kEnableEncryptionSelection);
489+
base::PathService::Get(chrome::DIR_USER_DATA, &config->user_data_path);
490+
OSCrypt::SetConfig(std::move(config));
468491
#endif
469492
#if defined(OS_POSIX)
470493
// Exit in response to SIGINT, SIGTERM, etc.

shell/browser/net/system_network_context_manager.cc

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -302,48 +302,14 @@ void SystemNetworkContextManager::OnNetworkServiceCreated(
302302
KeychainPassword::GetServiceName() = app_name + " Safe Storage";
303303
KeychainPassword::GetAccountName() = app_name;
304304
#endif
305-
#if defined(OS_LINUX)
306-
// c.f.
307-
// https://source.chromium.org/chromium/chromium/src/+/master:chrome/browser/net/system_network_context_manager.cc;l=515;drc=9d82515060b9b75fa941986f5db7390299669ef1;bpv=1;bpt=1
308-
const base::CommandLine& command_line =
309-
*base::CommandLine::ForCurrentProcess();
310-
311-
auto config = std::make_unique<os_crypt::Config>();
312-
config->store = command_line.GetSwitchValueASCII(::switches::kPasswordStore);
313-
config->product_name = app_name;
314-
config->application_name = app_name;
315-
config->main_thread_runner = base::ThreadTaskRunnerHandle::Get();
316-
// c.f.
317-
// https://source.chromium.org/chromium/chromium/src/+/master:chrome/common/chrome_switches.cc;l=689;drc=9d82515060b9b75fa941986f5db7390299669ef1
318-
config->should_use_preference =
319-
command_line.HasSwitch(::switches::kEnableEncryptionSelection);
320-
base::PathService::Get(chrome::DIR_USER_DATA, &config->user_data_path);
321-
#endif
322305

323306
// The OSCrypt keys are process bound, so if network service is out of
324307
// process, send it the required key.
325308
if (content::IsOutOfProcessNetworkService() &&
326309
electron::fuses::IsCookieEncryptionEnabled()) {
327-
#if defined(OS_LINUX)
328-
network::mojom::CryptConfigPtr network_crypt_config =
329-
network::mojom::CryptConfig::New();
330-
network_crypt_config->application_name = config->application_name;
331-
network_crypt_config->product_name = config->product_name;
332-
network_crypt_config->store = config->store;
333-
network_crypt_config->should_use_preference = config->should_use_preference;
334-
network_crypt_config->user_data_path = config->user_data_path;
335-
336-
network_service->SetCryptConfig(std::move(network_crypt_config));
337-
338-
#else
339310
network_service->SetEncryptionKey(OSCrypt::GetRawEncryptionKey());
340-
#endif
341311
}
342312

343-
#if defined(OS_LINUX)
344-
OSCrypt::SetConfig(std::move(config));
345-
#endif
346-
347313
#if DCHECK_IS_ON()
348314
electron::safestorage::SetElectronCryptoReady(true);
349315
#endif

0 commit comments

Comments
 (0)