| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/password_manager/password_store_factory.h" | 5 #include "chrome/browser/password_manager/password_store_factory.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/environment.h" | 11 #include "base/environment.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/browser/profiles/incognito_helpers.h" | 16 #include "chrome/browser/profiles/incognito_helpers.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/sync/glue/sync_start_util.h" | 18 #include "chrome/browser/sync/glue/sync_start_util.h" |
| 19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 19 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 20 #include "chrome/browser/web_data_service_factory.h" | 20 #include "chrome/browser/web_data_service_factory.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "components/browser_sync/browser/profile_sync_service.h" | 22 #include "components/browser_sync/browser/profile_sync_service.h" |
| 23 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 23 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 24 #include "components/os_crypt/key_storage_util_linux.h" |
| 24 #include "components/os_crypt/os_crypt_switches.h" | 25 #include "components/os_crypt/os_crypt_switches.h" |
| 25 #include "components/password_manager/core/browser/login_database.h" | 26 #include "components/password_manager/core/browser/login_database.h" |
| 26 #include "components/password_manager/core/browser/password_store.h" | 27 #include "components/password_manager/core/browser/password_store.h" |
| 27 #include "components/password_manager/core/browser/password_store_default.h" | 28 #include "components/password_manager/core/browser/password_store_default.h" |
| 28 #include "components/password_manager/core/browser/password_store_factory_util.h
" | 29 #include "components/password_manager/core/browser/password_store_factory_util.h
" |
| 29 #include "components/password_manager/core/common/password_manager_pref_names.h" | 30 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 30 #include "components/pref_registry/pref_registry_syncable.h" | 31 #include "components/pref_registry/pref_registry_syncable.h" |
| 31 #include "components/prefs/pref_service.h" | 32 #include "components/prefs/pref_service.h" |
| 32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 33 | 34 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID) | 177 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 177 // For now, we use PasswordStoreDefault. We might want to make a native | 178 // For now, we use PasswordStoreDefault. We might want to make a native |
| 178 // backend for PasswordStoreX (see below) in the future though. | 179 // backend for PasswordStoreX (see below) in the future though. |
| 179 ps = new password_manager::PasswordStoreDefault( | 180 ps = new password_manager::PasswordStoreDefault( |
| 180 main_thread_runner, db_thread_runner, std::move(login_db)); | 181 main_thread_runner, db_thread_runner, std::move(login_db)); |
| 181 #elif defined(USE_X11) | 182 #elif defined(USE_X11) |
| 182 // On POSIX systems, we try to use the "native" password management system of | 183 // On POSIX systems, we try to use the "native" password management system of |
| 183 // the desktop environment currently running, allowing GNOME Keyring in XFCE. | 184 // the desktop environment currently running, allowing GNOME Keyring in XFCE. |
| 184 // (In all cases we fall back on the basic store in case of failure.) | 185 // (In all cases we fall back on the basic store in case of failure.) |
| 185 base::nix::DesktopEnvironment desktop_env = GetDesktopEnvironment(); | 186 base::nix::DesktopEnvironment desktop_env = GetDesktopEnvironment(); |
| 186 base::nix::DesktopEnvironment used_desktop_env; | |
| 187 std::string store_type = | 187 std::string store_type = |
| 188 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 188 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 189 switches::kPasswordStore); | 189 switches::kPasswordStore); |
| 190 LinuxBackendUsed used_backend = PLAINTEXT; | 190 LinuxBackendUsed used_backend = PLAINTEXT; |
| 191 if (store_type == "kwallet") { | |
| 192 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; | |
| 193 } else if (store_type == "kwallet5") { | |
| 194 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE5; | |
| 195 } else if (store_type == "gnome") { | |
| 196 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME; | |
| 197 } else if (store_type == "basic") { | |
| 198 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_OTHER; | |
| 199 } else { | |
| 200 // Detect the store to use automatically. | |
| 201 used_desktop_env = desktop_env; | |
| 202 const char* name = base::nix::GetDesktopEnvironmentName(desktop_env); | |
| 203 VLOG(1) << "Password storage detected desktop environment: " | |
| 204 << (name ? name : "(unknown)"); | |
| 205 } | |
| 206 | 191 |
| 207 PrefService* prefs = profile->GetPrefs(); | 192 PrefService* prefs = profile->GetPrefs(); |
| 208 LocalProfileId id = GetLocalProfileId(prefs); | 193 LocalProfileId id = GetLocalProfileId(prefs); |
| 209 | 194 |
| 195 os_crypt::SelectedLinuxBackend selected_backend = |
| 196 os_crypt::SelectBackend(store_type, desktop_env); |
| 197 |
| 210 std::unique_ptr<PasswordStoreX::NativeBackend> backend; | 198 std::unique_ptr<PasswordStoreX::NativeBackend> backend; |
| 211 if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4 || | 199 if (selected_backend == os_crypt::SelectedLinuxBackend::KWALLET || |
| 212 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE5) { | 200 selected_backend == os_crypt::SelectedLinuxBackend::KWALLET5) { |
| 213 // KDE3 didn't use DBus, which our KWallet store uses. | |
| 214 VLOG(1) << "Trying KWallet for password storage."; | 201 VLOG(1) << "Trying KWallet for password storage."; |
| 202 base::nix::DesktopEnvironment used_desktop_env = |
| 203 selected_backend == os_crypt::SelectedLinuxBackend::KWALLET |
| 204 ? base::nix::DESKTOP_ENVIRONMENT_KDE4 |
| 205 : base::nix::DESKTOP_ENVIRONMENT_KDE5; |
| 215 backend.reset(new NativeBackendKWallet(id, used_desktop_env)); | 206 backend.reset(new NativeBackendKWallet(id, used_desktop_env)); |
| 216 if (backend->Init()) { | 207 if (backend->Init()) { |
| 217 VLOG(1) << "Using KWallet for password storage."; | 208 VLOG(1) << "Using KWallet for password storage."; |
| 218 used_backend = KWALLET; | 209 used_backend = KWALLET; |
| 219 } else { | 210 } else { |
| 220 backend.reset(); | 211 backend.reset(); |
| 221 } | 212 } |
| 222 } else if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_GNOME || | 213 } else if (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY || |
| 223 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_UNITY || | 214 selected_backend == |
| 224 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) { | 215 os_crypt::SelectedLinuxBackend::GNOME_KEYRING || |
| 216 selected_backend == |
| 217 os_crypt::SelectedLinuxBackend::GNOME_LIBSECRET) { |
| 225 #if defined(USE_LIBSECRET) | 218 #if defined(USE_LIBSECRET) |
| 226 VLOG(1) << "Trying libsecret for password storage."; | 219 if (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY || |
| 227 backend.reset(new NativeBackendLibsecret(id)); | 220 selected_backend == os_crypt::SelectedLinuxBackend::GNOME_LIBSECRET) { |
| 228 if (backend->Init()) { | 221 VLOG(1) << "Trying libsecret for password storage."; |
| 229 VLOG(1) << "Using libsecret keyring for password storage."; | 222 backend.reset(new NativeBackendLibsecret(id)); |
| 230 used_backend = LIBSECRET; | 223 if (backend->Init()) { |
| 231 } else { | 224 VLOG(1) << "Using libsecret keyring for password storage."; |
| 232 backend.reset(); | 225 used_backend = LIBSECRET; |
| 226 } else { |
| 227 backend.reset(); |
| 228 } |
| 233 } | 229 } |
| 234 #endif // defined(USE_LIBSECRET) | 230 #endif // defined(USE_LIBSECRET) |
| 235 if (!backend.get()) { | |
| 236 #if defined(USE_GNOME_KEYRING) | 231 #if defined(USE_GNOME_KEYRING) |
| 232 if (!backend.get() && |
| 233 (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY || |
| 234 selected_backend == os_crypt::SelectedLinuxBackend::GNOME_KEYRING)) { |
| 237 VLOG(1) << "Trying GNOME keyring for password storage."; | 235 VLOG(1) << "Trying GNOME keyring for password storage."; |
| 238 backend.reset(new NativeBackendGnome(id)); | 236 backend.reset(new NativeBackendGnome(id)); |
| 239 if (backend->Init()) { | 237 if (backend->Init()) { |
| 240 VLOG(1) << "Using GNOME keyring for password storage."; | 238 VLOG(1) << "Using GNOME keyring for password storage."; |
| 241 used_backend = GNOME_KEYRING; | 239 used_backend = GNOME_KEYRING; |
| 242 } else { | 240 } else { |
| 243 backend.reset(); | 241 backend.reset(); |
| 244 } | 242 } |
| 243 } |
| 245 #endif // defined(USE_GNOME_KEYRING) | 244 #endif // defined(USE_GNOME_KEYRING) |
| 246 } | |
| 247 } | 245 } |
| 248 | 246 |
| 249 if (!backend.get()) { | 247 if (!backend.get()) { |
| 250 LOG(WARNING) << "Using basic (unencrypted) store for password storage. " | 248 LOG(WARNING) << "Using basic (unencrypted) store for password storage. " |
| 251 "See " | 249 "See " |
| 252 "https://chromium.googlesource.com/chromium/src/+/master/docs/linux_pass
word_storage.md" | 250 "https://chromium.googlesource.com/chromium/src/+/master/docs/linux_pass
word_storage.md" |
| 253 " for more information about password storage options."; | 251 " for more information about password storage options."; |
| 254 } | 252 } |
| 255 | 253 |
| 256 ps = new PasswordStoreX(main_thread_runner, db_thread_runner, | 254 ps = new PasswordStoreX(main_thread_runner, db_thread_runner, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 break; | 350 break; |
| 353 case LIBSECRET: | 351 case LIBSECRET: |
| 354 usage = OTHER_LIBSECRET; | 352 usage = OTHER_LIBSECRET; |
| 355 break; | 353 break; |
| 356 } | 354 } |
| 357 } | 355 } |
| 358 UMA_HISTOGRAM_ENUMERATION("PasswordManager.LinuxBackendStatistics", usage, | 356 UMA_HISTOGRAM_ENUMERATION("PasswordManager.LinuxBackendStatistics", usage, |
| 359 MAX_BACKEND_USAGE_VALUE); | 357 MAX_BACKEND_USAGE_VALUE); |
| 360 } | 358 } |
| 361 #endif | 359 #endif |
| OLD | NEW |