cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [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_LINUX_H_ |
| 6 | #define COMPONENTS_OS_CRYPT_KEY_STORAGE_LINUX_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
| 11 | #include "base/macros.h" |
cfroussios | b013c15b | 2016-09-03 01:10:16 | [diff] [blame] | 12 | |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 13 | namespace os_crypt { |
| 14 | struct Config; |
| 15 | } |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 16 | |
| 17 | // An API for retrieving OSCrypt's password from the system's password storage |
| 18 | // service. |
| 19 | class KeyStorageLinux { |
| 20 | public: |
| 21 | KeyStorageLinux() = default; |
| 22 | virtual ~KeyStorageLinux() = default; |
| 23 | |
cfroussios | 3ea4c69 | 2016-07-18 19:15:14 | [diff] [blame] | 24 | // Tries to load the appropriate key storage. Returns null if none succeed. |
Christos Froussios | 494196d | 2017-07-14 10:10:04 | [diff] [blame] | 25 | static std::unique_ptr<KeyStorageLinux> CreateService( |
| 26 | const os_crypt::Config& config); |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 27 | |
| 28 | // Gets the encryption key from the OS password-managing library. If a key is |
| 29 | // not found, a new key will be generated, stored and returned. |
Christos Froussios | 985d1aac | 2017-11-09 11:01:07 | [diff] [blame^] | 30 | std::string GetKey(); |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 31 | |
| 32 | protected: |
| 33 | // Loads the key storage. Returns false if the service is not available. |
| 34 | virtual bool Init() = 0; |
| 35 | |
Christos Froussios | 985d1aac | 2017-11-09 11:01:07 | [diff] [blame^] | 36 | // The implementation of GetKey() for a specific backend. This will be called |
| 37 | // on the backend's preferred thread. |
| 38 | virtual std::string GetKeyImpl() = 0; |
| 39 | |
cfroussios | 2e6729a4 | 2016-07-26 09:18:12 | [diff] [blame] | 40 | // The name of the group, if any, containing the key. |
| 41 | static const char kFolderName[]; |
| 42 | // The name of the entry with the encryption key. |
| 43 | static const char kKey[]; |
| 44 | |
cfroussios | 3b5a4e4 | 2016-05-31 11:02:18 | [diff] [blame] | 45 | private: |
| 46 | DISALLOW_COPY_AND_ASSIGN(KeyStorageLinux); |
| 47 | }; |
| 48 | |
| 49 | #endif // COMPONENTS_OS_CRYPT_KEY_STORAGE_LINUX_H_ |