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

Side by Side Diff: components/os_crypt/key_storage_util_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
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_util_linux.h" 5 #include "components/os_crypt/key_storage_util_linux.h"
6 6
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
7 #include "base/logging.h" 9 #include "base/logging.h"
8 10
11 namespace {
12
13 // OSCrypt has a setting that determines whether a backend will be used.
14 // The presense of this file in the file system means that the backend
15 // should be ignored. It's absence means we should use the backend.
16 constexpr const char kPreferenceFileName[] = "Disable Local Encryption";
17
18 bool ReadBackendUse(const base::FilePath& user_data_dir, bool* use) {
19 if (user_data_dir.empty())
20 return false;
21 base::FilePath pref_path = user_data_dir.Append(kPreferenceFileName);
22 *use = !base::PathExists(pref_path);
23 return true;
24 }
25
26 } // namespace
27
9 namespace os_crypt { 28 namespace os_crypt {
10 29
11 SelectedLinuxBackend SelectBackend(const std::string& type, 30 SelectedLinuxBackend SelectBackend(const std::string& type,
31 bool use_backend,
12 base::nix::DesktopEnvironment desktop_env) { 32 base::nix::DesktopEnvironment desktop_env) {
33 // Explicitly requesting a store overrides other production logic.
13 if (type == "kwallet") 34 if (type == "kwallet")
14 return SelectedLinuxBackend::KWALLET; 35 return SelectedLinuxBackend::KWALLET;
15 if (type == "kwallet5") 36 if (type == "kwallet5")
16 return SelectedLinuxBackend::KWALLET5; 37 return SelectedLinuxBackend::KWALLET5;
17 if (type == "gnome") 38 if (type == "gnome")
18 return SelectedLinuxBackend::GNOME_ANY; 39 return SelectedLinuxBackend::GNOME_ANY;
19 if (type == "gnome-keyring") 40 if (type == "gnome-keyring")
20 return SelectedLinuxBackend::GNOME_KEYRING; 41 return SelectedLinuxBackend::GNOME_KEYRING;
21 if (type == "gnome-libsecret") 42 if (type == "gnome-libsecret")
22 return SelectedLinuxBackend::GNOME_LIBSECRET; 43 return SelectedLinuxBackend::GNOME_LIBSECRET;
23 if (type == "basic") 44 if (type == "basic")
24 return SelectedLinuxBackend::BASIC_TEXT; 45 return SelectedLinuxBackend::BASIC_TEXT;
25 46
47 // Ignore the backends if requested to.
48 if (!use_backend)
49 return SelectedLinuxBackend::BASIC_TEXT;
50
51 // Detect the store to use automatically.
26 const char* name = base::nix::GetDesktopEnvironmentName(desktop_env); 52 const char* name = base::nix::GetDesktopEnvironmentName(desktop_env);
27 VLOG(1) << "Password storage detected desktop environment: " 53 VLOG(1) << "Password storage detected desktop environment: "
28 << (name ? name : "(unknown)"); 54 << (name ? name : "(unknown)");
29
30 // Detect the store to use automatically.
31 switch (desktop_env) { 55 switch (desktop_env) {
32 case base::nix::DESKTOP_ENVIRONMENT_KDE4: 56 case base::nix::DESKTOP_ENVIRONMENT_KDE4:
33 return SelectedLinuxBackend::KWALLET; 57 return SelectedLinuxBackend::KWALLET;
34 case base::nix::DESKTOP_ENVIRONMENT_KDE5: 58 case base::nix::DESKTOP_ENVIRONMENT_KDE5:
35 return SelectedLinuxBackend::KWALLET5; 59 return SelectedLinuxBackend::KWALLET5;
36 case base::nix::DESKTOP_ENVIRONMENT_GNOME: 60 case base::nix::DESKTOP_ENVIRONMENT_GNOME:
37 case base::nix::DESKTOP_ENVIRONMENT_UNITY: 61 case base::nix::DESKTOP_ENVIRONMENT_UNITY:
38 case base::nix::DESKTOP_ENVIRONMENT_XFCE: 62 case base::nix::DESKTOP_ENVIRONMENT_XFCE:
39 return SelectedLinuxBackend::GNOME_ANY; 63 return SelectedLinuxBackend::GNOME_ANY;
40 // KDE3 didn't use DBus, which our KWallet store uses. 64 // KDE3 didn't use DBus, which our KWallet store uses.
41 case base::nix::DESKTOP_ENVIRONMENT_KDE3: 65 case base::nix::DESKTOP_ENVIRONMENT_KDE3:
42 case base::nix::DESKTOP_ENVIRONMENT_OTHER: 66 case base::nix::DESKTOP_ENVIRONMENT_OTHER:
43 return SelectedLinuxBackend::BASIC_TEXT; 67 return SelectedLinuxBackend::BASIC_TEXT;
44 } 68 }
45 69
46 NOTREACHED(); 70 NOTREACHED();
47 return SelectedLinuxBackend::BASIC_TEXT; 71 return SelectedLinuxBackend::BASIC_TEXT;
48 } 72 }
49 73
74 bool WriteBackendUse(const base::FilePath& user_data_dir, bool use) {
75 if (user_data_dir.empty())
76 return false;
77 base::FilePath pref_path = user_data_dir.Append(kPreferenceFileName);
78 if (use)
79 return base::DeleteFile(pref_path, false);
80 FILE* f = base::OpenFile(pref_path, "w");
81 return f != nullptr && base::CloseFile(f);
82 }
83
84 bool GetBackendUse(const base::FilePath& user_data_dir) {
85 bool setting;
86 if (ReadBackendUse(user_data_dir, &setting))
87 return setting;
88 return true;
89 }
90
50 } // namespace os_crypt 91 } // namespace os_crypt
OLDNEW
« no previous file with comments | « components/os_crypt/key_storage_util_linux.h ('k') | components/os_crypt/key_storage_util_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698