Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: components/os_crypt/key_storage_linux.cc

Issue 2948783002: Create setting that disables password stores (Closed)
Patch Set: nits + tests Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/os_crypt/key_storage_linux.h ('k') | components/os_crypt/key_storage_util_linux.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/files/file.h"
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
8 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
9 #include "base/logging.h" 12 #include "base/logging.h"
10 #include "base/nix/xdg_util.h" 13 #include "base/nix/xdg_util.h"
11 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
12 #include "components/os_crypt/key_storage_util_linux.h" 15 #include "components/os_crypt/key_storage_util_linux.h"
13 16
14 #if defined(USE_LIBSECRET) 17 #if defined(USE_LIBSECRET)
15 #include "components/os_crypt/key_storage_libsecret.h" 18 #include "components/os_crypt/key_storage_libsecret.h"
16 #endif 19 #endif
17 #if defined(USE_KEYRING) 20 #if defined(USE_KEYRING)
(...skipping 12 matching lines...) Expand all
30 #endif 33 #endif
31 34
32 namespace { 35 namespace {
33 36
34 // Parameters to OSCrypt, which are set before the first call to OSCrypt, are 37 // Parameters to OSCrypt, which are set before the first call to OSCrypt, are
35 // stored here. 38 // stored here.
36 struct Configuration { 39 struct Configuration {
37 std::string store; 40 std::string store;
38 std::string product_name; 41 std::string product_name;
39 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner; 42 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner;
43 bool should_use_preference;
44 base::FilePath user_data_path;
40 }; 45 };
41 46
42 base::LazyInstance<Configuration>::DestructorAtExit g_config = 47 base::LazyInstance<Configuration>::DestructorAtExit g_config =
43 LAZY_INSTANCE_INITIALIZER; 48 LAZY_INSTANCE_INITIALIZER;
44 49
45 } // namespace 50 } // namespace
46 51
47 // static 52 // static
48 void KeyStorageLinux::SetStore(const std::string& store_type) { 53 void KeyStorageLinux::SetStore(const std::string& store_type) {
49 g_config.Get().store = store_type; 54 g_config.Get().store = store_type;
50 VLOG(1) << "OSCrypt store set to " << store_type; 55 VLOG(1) << "OSCrypt store set to " << store_type;
51 } 56 }
52 57
53 // static 58 // static
54 void KeyStorageLinux::SetProductName(const std::string& product_name) { 59 void KeyStorageLinux::SetProductName(const std::string& product_name) {
55 g_config.Get().product_name = product_name; 60 g_config.Get().product_name = product_name;
56 } 61 }
57 62
58 // static 63 // static
59 void KeyStorageLinux::SetMainThreadRunner( 64 void KeyStorageLinux::SetMainThreadRunner(
60 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner) { 65 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner) {
61 g_config.Get().main_thread_runner = main_thread_runner; 66 g_config.Get().main_thread_runner = main_thread_runner;
62 } 67 }
63 68
64 // static 69 // static
70 void KeyStorageLinux::ShouldUsePreference(bool should_use_preference) {
71 g_config.Get().should_use_preference = should_use_preference;
72 }
73
74 // static
75 void KeyStorageLinux::SetUserDataPath(const base::FilePath& path) {
76 g_config.Get().user_data_path = path;
77 }
78
79 // static
65 std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() { 80 std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() {
66 #if defined(USE_LIBSECRET) || defined(USE_KEYRING) || defined(USE_KWALLET) 81 #if defined(USE_LIBSECRET) || defined(USE_KEYRING) || defined(USE_KWALLET)
67 // Select a backend. 82 // Select a backend.
83 bool use_backend = !g_config.Get().should_use_preference ||
84 os_crypt::GetBackendUse(g_config.Get().user_data_path);
68 std::unique_ptr<base::Environment> env(base::Environment::Create()); 85 std::unique_ptr<base::Environment> env(base::Environment::Create());
69 base::nix::DesktopEnvironment desktop_env = 86 base::nix::DesktopEnvironment desktop_env =
70 base::nix::GetDesktopEnvironment(env.get()); 87 base::nix::GetDesktopEnvironment(env.get());
71 os_crypt::SelectedLinuxBackend selected_backend = 88 os_crypt::SelectedLinuxBackend selected_backend =
72 os_crypt::SelectBackend(g_config.Get().store, desktop_env); 89 os_crypt::SelectBackend(g_config.Get().store, use_backend, desktop_env);
73 90
74 // Try initializing the selected backend. 91 // Try initializing the selected backend.
75 // In case of GNOME_ANY, prefer Libsecret 92 // In case of GNOME_ANY, prefer Libsecret
76 std::unique_ptr<KeyStorageLinux> key_storage; 93 std::unique_ptr<KeyStorageLinux> key_storage;
77 94
78 #if defined(USE_LIBSECRET) 95 #if defined(USE_LIBSECRET)
79 if (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY || 96 if (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY ||
80 selected_backend == os_crypt::SelectedLinuxBackend::GNOME_LIBSECRET) { 97 selected_backend == os_crypt::SelectedLinuxBackend::GNOME_LIBSECRET) {
81 key_storage.reset(new KeyStorageLibsecret()); 98 key_storage.reset(new KeyStorageLibsecret());
82 if (key_storage->Init()) { 99 if (key_storage->Init()) {
(...skipping 27 matching lines...) Expand all
110 if (key_storage->Init()) { 127 if (key_storage->Init()) {
111 VLOG(1) << "OSCrypt using KWallet as backend."; 128 VLOG(1) << "OSCrypt using KWallet as backend.";
112 return key_storage; 129 return key_storage;
113 } 130 }
114 } 131 }
115 #endif // defined(USE_KWALLET) 132 #endif // defined(USE_KWALLET)
116 #endif // defined(USE_LIBSECRET) || defined(USE_KEYRING) || 133 #endif // defined(USE_LIBSECRET) || defined(USE_KEYRING) ||
117 // defined(USE_KWALLET) 134 // defined(USE_KWALLET)
118 135
119 // The appropriate store was not available. 136 // The appropriate store was not available.
120 VLOG(1) << "OSCrypt could not initialize a backend."; 137 VLOG(1) << "OSCrypt did not initialize a backend.";
121 return nullptr; 138 return nullptr;
122 } 139 }
OLDNEW
« no previous file with comments | « components/os_crypt/key_storage_linux.h ('k') | components/os_crypt/key_storage_util_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698