cfroussios | b013c15b | 2016-09-03 01:10:16 | [diff] [blame] | 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 | |
| 5 | #ifndef COMPONENTS_OS_CRYPT_KEY_STORAGE_KEYRING_H_ |
| 6 | #define COMPONENTS_OS_CRYPT_KEY_STORAGE_KEYRING_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/macros.h" |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame^] | 11 | #include "base/memory/ref_counted.h" |
cfroussios | b013c15b | 2016-09-03 01:10:16 | [diff] [blame] | 12 | #include "components/os_crypt/key_storage_linux.h" |
| 13 | |
| 14 | namespace base { |
| 15 | class SingleThreadTaskRunner; |
| 16 | class WaitableEvent; |
| 17 | } // namespace base |
| 18 | |
| 19 | // Specialisation of KeyStorageLinux that uses Libsecret. |
| 20 | class KeyStorageKeyring : public KeyStorageLinux { |
| 21 | public: |
| 22 | explicit KeyStorageKeyring( |
| 23 | scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner); |
| 24 | ~KeyStorageKeyring() override; |
| 25 | |
| 26 | // KeyStorageLinux |
| 27 | std::string GetKey() override; |
| 28 | |
| 29 | protected: |
| 30 | // KeyStorageLinux |
| 31 | bool Init() override; |
| 32 | |
| 33 | private: |
| 34 | // Gnome keyring requires calls to originate from the main thread. |
| 35 | // This is the part of GetKey() that gets dispatched to the main thread. |
| 36 | // The password is stored in |password_ptr|. If |password_loaded_ptr| is not |
| 37 | // null, it will be signaled when |password_ptr| is safe to read. |
| 38 | void GetKeyDelegate(std::string* password_ptr, |
| 39 | base::WaitableEvent* password_loaded_ptr); |
| 40 | |
| 41 | // Generate a random string and store it as OScrypt's new password. |
| 42 | std::string AddRandomPasswordInKeyring(); |
| 43 | |
| 44 | // Keyring calls need to originate from the main thread. |
| 45 | scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; |
| 46 | |
| 47 | DISALLOW_COPY_AND_ASSIGN(KeyStorageKeyring); |
| 48 | }; |
| 49 | |
| 50 | #endif // COMPONENTS_OS_CRYPT_KEY_STORAGE_KEYRING_H_ |