blob: 26a3f587b49cdea3e4913ce0e08eeade6d1853a0 [file] [log] [blame]
cfroussiosb013c15b2016-09-03 01:10:161// 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
5#ifndef COMPONENTS_OS_CRYPT_KEY_STORAGE_KEYRING_H_
6#define COMPONENTS_OS_CRYPT_KEY_STORAGE_KEYRING_H_
7
8#include <string>
9
Matt Menkeef8aab12018-07-31 14:42:1710#include "base/component_export.h"
cfroussiosb013c15b2016-09-03 01:10:1611#include "base/macros.h"
Christos Froussios494196d2017-07-14 10:10:0412#include "base/memory/ref_counted.h"
cfroussiosb013c15b2016-09-03 01:10:1613#include "components/os_crypt/key_storage_linux.h"
Anton Bikineev1156b5f2021-05-15 22:35:3614#include "third_party/abseil-cpp/absl/types/optional.h"
cfroussiosb013c15b2016-09-03 01:10:1615
16namespace base {
17class SingleThreadTaskRunner;
cfroussiosb013c15b2016-09-03 01:10:1618} // namespace base
19
20// Specialisation of KeyStorageLinux that uses Libsecret.
Matt Menkeef8aab12018-07-31 14:42:1721class COMPONENT_EXPORT(OS_CRYPT) KeyStorageKeyring : public KeyStorageLinux {
cfroussiosb013c15b2016-09-03 01:10:1622 public:
23 explicit KeyStorageKeyring(
24 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner);
25 ~KeyStorageKeyring() override;
26
cfroussiosb013c15b2016-09-03 01:10:1627 protected:
28 // KeyStorageLinux
Christos Froussiosd6cfe11e2017-12-01 19:28:2629 base::SequencedTaskRunner* GetTaskRunner() override;
cfroussiosb013c15b2016-09-03 01:10:1630 bool Init() override;
Anton Bikineev1156b5f2021-05-15 22:35:3631 absl::optional<std::string> GetKeyImpl() override;
cfroussiosb013c15b2016-09-03 01:10:1632
33 private:
cfroussiosb013c15b2016-09-03 01:10:1634 // Generate a random string and store it as OScrypt's new password.
Anton Bikineev1156b5f2021-05-15 22:35:3635 absl::optional<std::string> AddRandomPasswordInKeyring();
cfroussiosb013c15b2016-09-03 01:10:1636
37 // Keyring calls need to originate from the main thread.
38 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_;
39
40 DISALLOW_COPY_AND_ASSIGN(KeyStorageKeyring);
41};
42
43#endif // COMPONENTS_OS_CRYPT_KEY_STORAGE_KEYRING_H_