Chromium Code Reviews| 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" | 7 #include "base/environment.h" |
| 10 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 9 #include "base/logging.h" |
| 12 #include "base/nix/xdg_util.h" | 10 #include "base/nix/xdg_util.h" |
| 13 | 11 |
| 14 #if defined(USE_LIBSECRET) | 12 #if defined(USE_LIBSECRET) |
| 15 #include "components/os_crypt/key_storage_libsecret.h" | 13 #include "components/os_crypt/key_storage_libsecret.h" |
| 16 #endif | 14 #endif |
| 17 | 15 |
| 18 base::LazyInstance<std::string> g_store_ = LAZY_INSTANCE_INITIALIZER; | 16 #if defined(USE_KWALLET) |
| 17 #include "components/os_crypt/key_storage_kwallet.h" | |
| 18 #endif | |
| 19 | |
| 20 #if defined(OFFICIAL_BUILD) | |
|
pdknsk
2016/08/21 07:36:53
There is a minor bug here in Chromium reporting it
Lei Zhang
2016/08/22 17:09:50
Thanks for noticing. Will fix.
| |
| 21 const char KeyStorageLinux::kFolderName[] = "Chrome Keys"; | |
| 22 const char KeyStorageLinux::kKey[] = "Chrome Safe Storage"; | |
| 23 #else | |
| 24 const char KeyStorageLinux::kFolderName[] = "Chromium Keys"; | |
| 25 const char KeyStorageLinux::kKey[] = "Chromium Safe Storage"; | |
| 26 #endif | |
| 27 | |
| 28 base::LazyInstance<std::string> g_store = LAZY_INSTANCE_INITIALIZER; | |
| 29 base::LazyInstance<std::string> g_product_name = LAZY_INSTANCE_INITIALIZER; | |
| 19 | 30 |
| 20 // static | 31 // static |
| 21 void KeyStorageLinux::SetStore(const std::string& store_type) { | 32 void KeyStorageLinux::SetStore(const std::string& store_type) { |
| 22 g_store_.Get() = store_type; | 33 g_store.Get() = store_type; |
| 23 VLOG(1) << "OSCrypt store set to " << store_type; | 34 VLOG(1) << "OSCrypt store set to " << store_type; |
| 24 } | 35 } |
| 25 | 36 |
| 26 // static | 37 // static |
| 38 void KeyStorageLinux::SetProductName(const std::string& product_name) { | |
| 39 g_product_name.Get() = product_name; | |
| 40 } | |
| 41 | |
| 42 // static | |
| 27 std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() { | 43 std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() { |
| 28 base::nix::DesktopEnvironment used_desktop_env; | 44 base::nix::DesktopEnvironment used_desktop_env; |
| 29 if (g_store_.Get() == "kwallet") { | 45 if (g_store.Get() == "kwallet") { |
| 30 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; | 46 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; |
| 31 } else if (g_store_.Get() == "kwallet5") { | 47 } else if (g_store.Get() == "kwallet5") { |
| 32 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE5; | 48 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE5; |
| 33 } else if (g_store_.Get() == "gnome") { | 49 } else if (g_store.Get() == "gnome") { |
| 34 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME; | 50 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME; |
| 35 } else if (g_store_.Get() == "basic") { | 51 } else if (g_store.Get() == "basic") { |
| 36 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_OTHER; | 52 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_OTHER; |
| 37 } else { | 53 } else { |
| 38 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 54 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| 39 used_desktop_env = base::nix::GetDesktopEnvironment(env.get()); | 55 used_desktop_env = base::nix::GetDesktopEnvironment(env.get()); |
| 40 } | 56 } |
| 41 | 57 |
| 42 // Try initializing the appropriate store for our environment. | 58 // Try initializing the appropriate store for our environment. |
| 43 std::unique_ptr<KeyStorageLinux> key_storage; | 59 std::unique_ptr<KeyStorageLinux> key_storage; |
| 44 if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_GNOME || | 60 if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_GNOME || |
| 45 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_UNITY || | 61 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_UNITY || |
| 46 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) { | 62 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) { |
| 47 #if defined(USE_LIBSECRET) | 63 #if defined(USE_LIBSECRET) |
| 48 key_storage.reset(new KeyStorageLibsecret()); | 64 key_storage.reset(new KeyStorageLibsecret()); |
| 49 if (key_storage->Init()) { | 65 if (key_storage->Init()) { |
| 50 VLOG(1) << "OSCrypt using Libsecret as backend."; | 66 VLOG(1) << "OSCrypt using Libsecret as backend."; |
| 51 return key_storage; | 67 return key_storage; |
| 52 } | 68 } |
| 53 #endif | 69 #endif |
| 70 } else if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4 || | |
| 71 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE5) { | |
| 72 #if defined(USE_KWALLET) | |
| 73 DCHECK(!g_product_name.Get().empty()); | |
| 74 key_storage.reset( | |
| 75 new KeyStorageKWallet(used_desktop_env, g_product_name.Get())); | |
| 76 if (key_storage->Init()) { | |
| 77 VLOG(1) << "OSCrypt using KWallet as backend."; | |
| 78 return key_storage; | |
| 79 } | |
| 80 #endif | |
| 54 } | 81 } |
| 55 | 82 |
| 56 // The appropriate store was not available. | 83 // The appropriate store was not available. |
| 57 VLOG(1) << "OSCrypt could not initialize a backend."; | 84 VLOG(1) << "OSCrypt could not initialize a backend."; |
| 58 return nullptr; | 85 return nullptr; |
| 59 } | 86 } |
| OLD | NEW |