Compare commits

...

3 Commits

Author SHA1 Message Date
Keeley Hammond
cdbd09ef1e fix: add additional key providers 2026-01-12 15:34:37 -08:00
Keeley Hammond
3f9d4b84e8 fix: add async macos key provider 2026-01-12 14:33:18 -08:00
Keeley Hammond
a7d2a2c2a5 fix: support cookie encryption provider cross-platform 2026-01-12 11:22:02 -08:00
2 changed files with 84 additions and 8 deletions

View File

@@ -465,6 +465,8 @@ source_set("electron_lib") {
"//components/os_crypt/async/browser", "//components/os_crypt/async/browser",
"//components/os_crypt/async/browser:key_provider_interface", "//components/os_crypt/async/browser:key_provider_interface",
"//components/os_crypt/sync", "//components/os_crypt/sync",
"//components/password_manager/core/browser:password_switches",
"//components/password_manager/core/common:features",
"//components/pref_registry", "//components/pref_registry",
"//components/prefs", "//components/prefs",
"//components/security_state/content", "//components/security_state/content",
@@ -595,6 +597,7 @@ source_set("electron_lib") {
use_libcxx_modules = false use_libcxx_modules = false
deps += [ deps += [
"//components/os_crypt/async/browser:keychain_key_provider",
"//components/os_crypt/common:keychain_password_mac", "//components/os_crypt/common:keychain_password_mac",
"//components/remote_cocoa/app_shim", "//components/remote_cocoa/app_shim",
"//components/remote_cocoa/browser", "//components/remote_cocoa/browser",
@@ -657,6 +660,8 @@ source_set("electron_lib") {
":libnotify_loader", ":libnotify_loader",
"//build/config/linux/gtk", "//build/config/linux/gtk",
"//components/crash/content/browser", "//components/crash/content/browser",
"//components/os_crypt/async/browser:freedesktop_secret_key_provider",
"//components/os_crypt/async/browser:posix_key_provider",
"//dbus", "//dbus",
"//device/bluetooth", "//device/bluetooth",
"//third_party/crashpad/crashpad/client", "//third_party/crashpad/crashpad/client",
@@ -697,6 +702,7 @@ source_set("electron_lib") {
deps += [ deps += [
"//components/app_launch_prefetch", "//components/app_launch_prefetch",
"//components/crash/core/app:crash_export_thunks", "//components/crash/core/app:crash_export_thunks",
"//components/os_crypt/async/browser:dpapi_key_provider",
"//third_party/libxml:xml_writer", "//third_party/libxml:xml_writer",
"//ui/wm", "//ui/wm",
"//ui/wm/public", "//ui/wm/public",

View File

@@ -12,11 +12,27 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/notimplemented.h" #include "base/notimplemented.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "components/os_crypt/async/browser/key_provider.h" #include "components/os_crypt/async/browser/key_provider.h"
#include "components/os_crypt/async/browser/os_crypt_async.h" #include "components/os_crypt/async/browser/os_crypt_async.h"
#include "components/os_crypt/sync/os_crypt.h" #include "components/os_crypt/sync/os_crypt.h"
#include "components/password_manager/core/browser/password_manager_switches.h"
#if BUILDFLAG(IS_WIN)
#include "components/os_crypt/async/browser/dpapi_key_provider.h"
#endif
#if BUILDFLAG(IS_LINUX)
#include "components/os_crypt/async/browser/freedesktop_secret_key_provider.h"
#include "components/os_crypt/async/browser/posix_key_provider.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "components/os_crypt/async/browser/keychain_key_provider.h"
#endif
#include "components/prefs/in_memory_pref_store.h" #include "components/prefs/in_memory_pref_store.h"
#include "components/prefs/json_pref_store.h" #include "components/prefs/json_pref_store.h"
#include "components/prefs/overlay_user_pref_store.h" #include "components/prefs/overlay_user_pref_store.h"
@@ -406,15 +422,69 @@ void BrowserProcessImpl::CreateNetworkQualityObserver() {
} }
void BrowserProcessImpl::CreateOSCryptAsync() { void BrowserProcessImpl::CreateOSCryptAsync() {
// source: https://chromium-review.googlesource.com/c/chromium/src/+/4455776 // Initialize OSCryptAsync with platform-specific key providers.
// See https://chromium-review.googlesource.com/c/chromium/src/+/6996667
std::vector<std::pair<size_t, std::unique_ptr<os_crypt_async::KeyProvider>>>
providers;
// For now, initialize OSCryptAsync with no providers. This delegates all #if BUILDFLAG(IS_WIN)
// encryption operations to OSCrypt. // The DPAPI key provider requires OSCrypt::Init to have already been called
// TODO(crbug.com/1373092): Add providers behind features, as support for them // to initialize the key storage. This happens in
// is added. // ChromeBrowserMainPartsWin::PreCreateMainMessageLoop.
os_crypt_async_ = std::make_unique<os_crypt_async::OSCryptAsync>( providers.emplace_back(std::make_pair(
std::vector< /*precedence=*/10u,
std::pair<size_t, std::unique_ptr<os_crypt_async::KeyProvider>>>()); std::make_unique<os_crypt_async::DPAPIKeyProvider>(local_state())));
providers.emplace_back(std::make_pair(
// Note: 15 is chosen to be higher than the 10 precedence above for
// DPAPI. This ensures that when the the provider is enabled for
// encryption, the App-Bound encryption key is used and not the DPAPI
// one.
/*precedence=*/15u,
std::make_unique<os_crypt_async::AppBoundEncryptionProviderWin>(
local_state())));
#endif // BUILDFLAG(IS_WIN)
#if BUILDFLAG(IS_LINUX)
// On Linux, use FreedesktopSecretKeyProvider (for GNOME Keyring, KWallet,
// etc.) with PosixKeyProvider as fallback.
base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
const auto password_store =
cmd_line->GetSwitchValueASCII(password_manager::kPasswordStore);
if (password_store != "basic") {
if (base::FeatureList::IsEnabled(features::kDbusSecretPortal)) {
// Use a higher priority than the FreedesktopSecretKeyProvider.
providers.emplace_back(
/*precedence=*/15u,
std::make_unique<os_crypt_async::SecretPortalKeyProvider>(
local_state(),
base::FeatureList::IsEnabled(
features::kSecretPortalKeyProviderUseForEncryption)));
}
}
providers.emplace_back(
/*precedence=*/10u,
std::make_unique<os_crypt_async::FreedesktopSecretKeyProvider>(
password_store, l10n_util::GetStringUTF8(IDS_PRODUCT_NAME), nullptr));
#endif // BUILDFLAG(IS_LINUX)
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
// On other POSIX systems, this is the only key provider. On Linux, it is used
// as a fallback.
providers.emplace_back(
/*precedence=*/5u, std::make_unique<os_crypt_async::PosixKeyProvider>());
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_LINUX)
#if BUILDFLAG(IS_MAC)
// On macOS, use KeychainKeyProvider for cookie encryption.
// This is enabled by default in Chrome via features::kUseKeychainKeyProvider.
providers.emplace_back(
/*precedence=*/10u,
std::make_unique<os_crypt_async::KeychainKeyProvider>());
#endif // BUILDFLAG(IS_MAC)
os_crypt_async_ =
std::make_unique<os_crypt_async::OSCryptAsync>(std::move(providers));
// Trigger async initialization of OSCrypt key providers. // Trigger async initialization of OSCrypt key providers.
os_crypt_async_->GetInstance(base::DoNothing()); os_crypt_async_->GetInstance(base::DoNothing());