key_storage_keyring.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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_KEYRING_H_
  5. #define COMPONENTS_OS_CRYPT_KEY_STORAGE_KEYRING_H_
  6. #include <string>
  7. #include "base/component_export.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "components/os_crypt/key_storage_linux.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. namespace base {
  12. class SingleThreadTaskRunner;
  13. } // namespace base
  14. // Specialisation of KeyStorageLinux that uses Libsecret.
  15. class COMPONENT_EXPORT(OS_CRYPT) KeyStorageKeyring : public KeyStorageLinux {
  16. public:
  17. KeyStorageKeyring(
  18. scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner,
  19. std::string application_name);
  20. KeyStorageKeyring(const KeyStorageKeyring&) = delete;
  21. KeyStorageKeyring& operator=(const KeyStorageKeyring&) = delete;
  22. ~KeyStorageKeyring() override;
  23. protected:
  24. // KeyStorageLinux
  25. base::SequencedTaskRunner* GetTaskRunner() override;
  26. bool Init() override;
  27. absl::optional<std::string> GetKeyImpl() override;
  28. private:
  29. // Generate a random string and store it as OScrypt's new password.
  30. absl::optional<std::string> AddRandomPasswordInKeyring();
  31. // Keyring calls need to originate from the main thread.
  32. scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_;
  33. const std::string application_name_;
  34. };
  35. #endif // COMPONENTS_OS_CRYPT_KEY_STORAGE_KEYRING_H_