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