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 "base/single_thread_task_runner.h" |
11 #include "components/os_crypt/key_storage_util_linux.h" | 12 #include "components/os_crypt/key_storage_util_linux.h" |
12 | 13 |
13 #if defined(USE_LIBSECRET) | 14 #if defined(USE_LIBSECRET) |
14 #include "components/os_crypt/key_storage_libsecret.h" | 15 #include "components/os_crypt/key_storage_libsecret.h" |
15 #endif | 16 #endif |
16 | 17 #if defined(USE_KEYRING) |
| 18 #include "components/os_crypt/key_storage_keyring.h" |
| 19 #endif |
17 #if defined(USE_KWALLET) | 20 #if defined(USE_KWALLET) |
18 #include "components/os_crypt/key_storage_kwallet.h" | 21 #include "components/os_crypt/key_storage_kwallet.h" |
19 #endif | 22 #endif |
20 | 23 |
21 #if defined(GOOGLE_CHROME_BUILD) | 24 #if defined(GOOGLE_CHROME_BUILD) |
22 const char KeyStorageLinux::kFolderName[] = "Chrome Keys"; | 25 const char KeyStorageLinux::kFolderName[] = "Chrome Keys"; |
23 const char KeyStorageLinux::kKey[] = "Chrome Safe Storage"; | 26 const char KeyStorageLinux::kKey[] = "Chrome Safe Storage"; |
24 #else | 27 #else |
25 const char KeyStorageLinux::kFolderName[] = "Chromium Keys"; | 28 const char KeyStorageLinux::kFolderName[] = "Chromium Keys"; |
26 const char KeyStorageLinux::kKey[] = "Chromium Safe Storage"; | 29 const char KeyStorageLinux::kKey[] = "Chromium Safe Storage"; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // static | 63 // static |
61 std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() { | 64 std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() { |
62 // Select a backend. | 65 // Select a backend. |
63 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 66 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
64 base::nix::DesktopEnvironment desktop_env = | 67 base::nix::DesktopEnvironment desktop_env = |
65 base::nix::GetDesktopEnvironment(env.get()); | 68 base::nix::GetDesktopEnvironment(env.get()); |
66 os_crypt::SelectedLinuxBackend selected_backend = | 69 os_crypt::SelectedLinuxBackend selected_backend = |
67 os_crypt::SelectBackend(g_config.Get().store, desktop_env); | 70 os_crypt::SelectBackend(g_config.Get().store, desktop_env); |
68 | 71 |
69 // Try initializing the selected backend. | 72 // Try initializing the selected backend. |
| 73 // In case of GNOME_ANY, prefer Libsecret |
70 std::unique_ptr<KeyStorageLinux> key_storage; | 74 std::unique_ptr<KeyStorageLinux> key_storage; |
| 75 |
| 76 #if defined(USE_LIBSECRET) |
71 if (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY || | 77 if (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY || |
72 selected_backend == os_crypt::SelectedLinuxBackend::GNOME_LIBSECRET) { | 78 selected_backend == os_crypt::SelectedLinuxBackend::GNOME_LIBSECRET) { |
73 #if defined(USE_LIBSECRET) | |
74 key_storage.reset(new KeyStorageLibsecret()); | 79 key_storage.reset(new KeyStorageLibsecret()); |
75 if (key_storage->Init()) { | 80 if (key_storage->Init()) { |
76 VLOG(1) << "OSCrypt using Libsecret as backend."; | 81 VLOG(1) << "OSCrypt using Libsecret as backend."; |
77 return key_storage; | 82 return key_storage; |
78 } | 83 } |
| 84 } |
79 #endif | 85 #endif |
80 } else if (selected_backend == os_crypt::SelectedLinuxBackend::KWALLET || | 86 |
81 selected_backend == os_crypt::SelectedLinuxBackend::KWALLET5) { | 87 #if defined(USE_KEYRING) |
| 88 if (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY || |
| 89 selected_backend == os_crypt::SelectedLinuxBackend::GNOME_KEYRING) { |
| 90 key_storage.reset(new KeyStorageKeyring(g_config.Get().main_thread_runner)); |
| 91 if (key_storage->Init()) { |
| 92 VLOG(1) << "OSCrypt using Keyring as backend."; |
| 93 return key_storage; |
| 94 } |
| 95 } |
| 96 #endif |
| 97 |
82 #if defined(USE_KWALLET) | 98 #if defined(USE_KWALLET) |
| 99 if (selected_backend == os_crypt::SelectedLinuxBackend::KWALLET || |
| 100 selected_backend == os_crypt::SelectedLinuxBackend::KWALLET5) { |
83 DCHECK(!g_config.Get().product_name.empty()); | 101 DCHECK(!g_config.Get().product_name.empty()); |
84 base::nix::DesktopEnvironment used_desktop_env = | 102 base::nix::DesktopEnvironment used_desktop_env = |
85 selected_backend == os_crypt::SelectedLinuxBackend::KWALLET | 103 selected_backend == os_crypt::SelectedLinuxBackend::KWALLET |
86 ? base::nix::DESKTOP_ENVIRONMENT_KDE4 | 104 ? base::nix::DESKTOP_ENVIRONMENT_KDE4 |
87 : base::nix::DESKTOP_ENVIRONMENT_KDE5; | 105 : base::nix::DESKTOP_ENVIRONMENT_KDE5; |
88 key_storage.reset( | 106 key_storage.reset( |
89 new KeyStorageKWallet(used_desktop_env, g_config.Get().product_name)); | 107 new KeyStorageKWallet(used_desktop_env, g_config.Get().product_name)); |
90 if (key_storage->Init()) { | 108 if (key_storage->Init()) { |
91 VLOG(1) << "OSCrypt using KWallet as backend."; | 109 VLOG(1) << "OSCrypt using KWallet as backend."; |
92 return key_storage; | 110 return key_storage; |
93 } | 111 } |
| 112 } |
94 #endif | 113 #endif |
95 } | |
96 | 114 |
97 // The appropriate store was not available. | 115 // The appropriate store was not available. |
98 VLOG(1) << "OSCrypt could not initialize a backend."; | 116 VLOG(1) << "OSCrypt could not initialize a backend."; |
99 return nullptr; | 117 return nullptr; |
100 } | 118 } |
OLD | NEW |