blob: e3ddc52eb0e0ee8a7468cb1ebbc318648019e6fb [file] [log] [blame]
cfroussios3b5a4e42016-05-31 11:02:181// 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"
cfroussiosb013c15b2016-09-03 01:10:1612
Christos Froussios494196d2017-07-14 10:10:0413namespace os_crypt {
14struct Config;
15}
cfroussios3b5a4e42016-05-31 11:02:1816
17// An API for retrieving OSCrypt's password from the system's password storage
18// service.
19class KeyStorageLinux {
20 public:
21 KeyStorageLinux() = default;
22 virtual ~KeyStorageLinux() = default;
23
cfroussios3ea4c692016-07-18 19:15:1424 // Tries to load the appropriate key storage. Returns null if none succeed.
Christos Froussios494196d2017-07-14 10:10:0425 static std::unique_ptr<KeyStorageLinux> CreateService(
26 const os_crypt::Config& config);
cfroussios3b5a4e42016-05-31 11:02:1827
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 Froussios985d1aac2017-11-09 11:01:0730 std::string GetKey();
cfroussios3b5a4e42016-05-31 11:02:1831
32 protected:
33 // Loads the key storage. Returns false if the service is not available.
34 virtual bool Init() = 0;
35
Christos Froussios985d1aac2017-11-09 11:01:0736 // 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
cfroussios2e6729a42016-07-26 09:18:1240 // 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
cfroussios3b5a4e42016-05-31 11:02:1845 private:
46 DISALLOW_COPY_AND_ASSIGN(KeyStorageLinux);
47};
48
49#endif // COMPONENTS_OS_CRYPT_KEY_STORAGE_LINUX_H_