key_storage_kwallet.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_OS_CRYPT_KEY_STORAGE_KWALLET_H_
  5. #define COMPONENTS_OS_CRYPT_KEY_STORAGE_KWALLET_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/component_export.h"
  9. #include "components/os_crypt/key_storage_linux.h"
  10. #include "components/os_crypt/kwallet_dbus.h"
  11. class COMPONENT_EXPORT(OS_CRYPT) KeyStorageKWallet : public KeyStorageLinux {
  12. public:
  13. KeyStorageKWallet(base::nix::DesktopEnvironment desktop_env,
  14. std::string app_name);
  15. KeyStorageKWallet(const KeyStorageKWallet&) = delete;
  16. KeyStorageKWallet& operator=(const KeyStorageKWallet&) = delete;
  17. ~KeyStorageKWallet() override;
  18. // Initialize using an optional KWalletDBus mock.
  19. // A DBus session will not be created if a mock is provided.
  20. bool InitWithKWalletDBus(std::unique_ptr<KWalletDBus> mock_kwallet_dbus_ptr);
  21. protected:
  22. // KeyStorageLinux
  23. bool Init() override;
  24. absl::optional<std::string> GetKeyImpl() override;
  25. private:
  26. enum class InitResult {
  27. SUCCESS,
  28. TEMPORARY_FAIL,
  29. PERMANENT_FAIL,
  30. };
  31. static constexpr int kInvalidHandle = -1;
  32. // Check whether KWallet is enabled and set |wallet_name_|
  33. InitResult InitWallet();
  34. // Create Chrome's folder in the wallet, if it doesn't exist.
  35. bool InitFolder();
  36. const base::nix::DesktopEnvironment desktop_env_;
  37. int32_t handle_ = kInvalidHandle;
  38. std::string wallet_name_;
  39. const std::string app_name_;
  40. std::unique_ptr<KWalletDBus> kwallet_dbus_;
  41. };
  42. #endif // COMPONENTS_OS_CRYPT_KEY_STORAGE_KWALLET_H_