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 <string.h> |
| 8 |
| 9 #include "base/environment.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/nix/xdg_util.h" |
7 #include "components/os_crypt/key_storage_libsecret.h" | 12 #include "components/os_crypt/key_storage_libsecret.h" |
8 | 13 |
| 14 const char* KeyStorageLinux::s_store_ = nullptr; |
| 15 |
| 16 // static |
| 17 void KeyStorageLinux::SetStore(const std::string& store_type) { |
| 18 delete s_store_; |
| 19 s_store_ = strdup(store_type.data()); |
| 20 } |
| 21 |
9 // static | 22 // static |
10 std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() { | 23 std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() { |
11 std::unique_ptr<KeyStorageLinux> key_storage(new KeyStorageLibsecret()); | 24 base::nix::DesktopEnvironment used_desktop_env; |
| 25 std::string store(s_store_ ? s_store_ : ""); |
| 26 if (store == "kwallet") { |
| 27 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; |
| 28 } else if (store == "kwallet5") { |
| 29 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE5; |
| 30 } else if (store == "gnome") { |
| 31 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME; |
| 32 } else if (store == "basic") { |
| 33 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_OTHER; |
| 34 } else { |
| 35 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| 36 used_desktop_env = base::nix::GetDesktopEnvironment(env.get()); |
| 37 } |
12 | 38 |
13 if (key_storage->Init()) | 39 // Try initializing the appropriate store for our environment. |
14 return key_storage; | 40 std::unique_ptr<KeyStorageLinux> key_storage; |
| 41 if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_GNOME || |
| 42 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_UNITY || |
| 43 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) { |
| 44 #if defined(USE_LIBSECRET) |
| 45 key_storage.reset(new KeyStorageLibsecret()); |
| 46 if (key_storage->Init()) { |
| 47 VLOG(1) << "OSCrypt using Libsecret as backend."; |
| 48 return key_storage; |
| 49 } |
| 50 #endif |
| 51 } |
15 | 52 |
| 53 // The appropriate store was not available. |
| 54 VLOG(1) << "OSCrypt could not initialize a backend."; |
16 return nullptr; | 55 return nullptr; |
17 } | 56 } |
OLD | NEW |