| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/os_crypt/key_storage_linux.h" | 5 #include "components/os_crypt/key_storage_linux.h" |
| 6 | 6 |
| 7 #include "base/environment.h" | 7 #include "base/environment.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/nix/xdg_util.h" | 10 #include "base/nix/xdg_util.h" |
| 11 #include "components/os_crypt/key_storage_util_linux.h" |
| 11 | 12 |
| 12 #if defined(USE_LIBSECRET) | 13 #if defined(USE_LIBSECRET) |
| 13 #include "components/os_crypt/key_storage_libsecret.h" | 14 #include "components/os_crypt/key_storage_libsecret.h" |
| 14 #endif | 15 #endif |
| 15 | 16 |
| 16 #if defined(USE_KWALLET) | 17 #if defined(USE_KWALLET) |
| 17 #include "components/os_crypt/key_storage_kwallet.h" | 18 #include "components/os_crypt/key_storage_kwallet.h" |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 #if defined(OFFICIAL_BUILD) | 21 #if defined(OFFICIAL_BUILD) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 VLOG(1) << "OSCrypt store set to " << store_type; | 35 VLOG(1) << "OSCrypt store set to " << store_type; |
| 35 } | 36 } |
| 36 | 37 |
| 37 // static | 38 // static |
| 38 void KeyStorageLinux::SetProductName(const std::string& product_name) { | 39 void KeyStorageLinux::SetProductName(const std::string& product_name) { |
| 39 g_product_name.Get() = product_name; | 40 g_product_name.Get() = product_name; |
| 40 } | 41 } |
| 41 | 42 |
| 42 // static | 43 // static |
| 43 std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() { | 44 std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() { |
| 44 base::nix::DesktopEnvironment used_desktop_env; | 45 // Select a backend. |
| 45 if (g_store.Get() == "kwallet") { | 46 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| 46 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; | 47 base::nix::DesktopEnvironment desktop_env = |
| 47 } else if (g_store.Get() == "kwallet5") { | 48 base::nix::GetDesktopEnvironment(env.get()); |
| 48 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE5; | 49 os_crypt::SelectedLinuxBackend selected_backend = |
| 49 } else if (g_store.Get() == "gnome") { | 50 os_crypt::SelectBackend(g_store.Get(), desktop_env); |
| 50 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME; | |
| 51 } else if (g_store.Get() == "basic") { | |
| 52 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_OTHER; | |
| 53 } else { | |
| 54 std::unique_ptr<base::Environment> env(base::Environment::Create()); | |
| 55 used_desktop_env = base::nix::GetDesktopEnvironment(env.get()); | |
| 56 } | |
| 57 | 51 |
| 58 // Try initializing the appropriate store for our environment. | 52 // Try initializing the selected backend. |
| 59 std::unique_ptr<KeyStorageLinux> key_storage; | 53 std::unique_ptr<KeyStorageLinux> key_storage; |
| 60 if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_GNOME || | 54 if (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY || |
| 61 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_UNITY || | 55 selected_backend == os_crypt::SelectedLinuxBackend::GNOME_LIBSECRET) { |
| 62 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) { | |
| 63 #if defined(USE_LIBSECRET) | 56 #if defined(USE_LIBSECRET) |
| 64 key_storage.reset(new KeyStorageLibsecret()); | 57 key_storage.reset(new KeyStorageLibsecret()); |
| 65 if (key_storage->Init()) { | 58 if (key_storage->Init()) { |
| 66 VLOG(1) << "OSCrypt using Libsecret as backend."; | 59 VLOG(1) << "OSCrypt using Libsecret as backend."; |
| 67 return key_storage; | 60 return key_storage; |
| 68 } | 61 } |
| 69 #endif | 62 #endif |
| 70 } else if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4 || | 63 } else if (selected_backend == os_crypt::SelectedLinuxBackend::KWALLET || |
| 71 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE5) { | 64 selected_backend == os_crypt::SelectedLinuxBackend::KWALLET5) { |
| 72 #if defined(USE_KWALLET) | 65 #if defined(USE_KWALLET) |
| 73 DCHECK(!g_product_name.Get().empty()); | 66 DCHECK(!g_product_name.Get().empty()); |
| 67 base::nix::DesktopEnvironment used_desktop_env = |
| 68 selected_backend == os_crypt::SelectedLinuxBackend::KWALLET |
| 69 ? base::nix::DESKTOP_ENVIRONMENT_KDE4 |
| 70 : base::nix::DESKTOP_ENVIRONMENT_KDE5; |
| 74 key_storage.reset( | 71 key_storage.reset( |
| 75 new KeyStorageKWallet(used_desktop_env, g_product_name.Get())); | 72 new KeyStorageKWallet(used_desktop_env, g_product_name.Get())); |
| 76 if (key_storage->Init()) { | 73 if (key_storage->Init()) { |
| 77 VLOG(1) << "OSCrypt using KWallet as backend."; | 74 VLOG(1) << "OSCrypt using KWallet as backend."; |
| 78 return key_storage; | 75 return key_storage; |
| 79 } | 76 } |
| 80 #endif | 77 #endif |
| 81 } | 78 } |
| 82 | 79 |
| 83 // The appropriate store was not available. | 80 // The appropriate store was not available. |
| 84 VLOG(1) << "OSCrypt could not initialize a backend."; | 81 VLOG(1) << "OSCrypt could not initialize a backend."; |
| 85 return nullptr; | 82 return nullptr; |
| 86 } | 83 } |
| OLD | NEW |