| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | FileCredStorage.h |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | DPAPI-encrypted JSON file credential storage backend. |
| 12 | |
| 13 | --*/ |
| 14 | #pragma once |
| 15 | |
| 16 | #include "ICredentialStorage.h" |
| 17 | #include "JsonUtils.h" |
| 18 | |
| 19 | namespace wsl::windows::wslc::services { |
| 20 | |
| 21 | inline constexpr int CredentialFileVersion = 1; |
| 22 | |
| 23 | struct CredentialEntry |
| 24 | { |
| 25 | std::string UserName; |
| 26 | std::string Secret; |
| 27 | NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(CredentialEntry, UserName, Secret); |
| 28 | }; |
| 29 | |
| 30 | struct CredentialFile |
| 31 | { |
| 32 | int Version = CredentialFileVersion; |
| 33 | std::map<std::string, CredentialEntry> Credentials; |
| 34 | |
| 35 | NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(CredentialFile, Version, Credentials); |
| 36 | }; |
| 37 | |
| 38 | class FileCredStorage final : public ICredentialStorage |
| 39 | { |
| 40 | public: |
| 41 | void Store(const std::string& serverAddress, const std::string& username, const std::string& secret) override; |
| 42 | std::pair<std::string, std::string> Get(const std::string& serverAddress) override; |
| 43 | void Erase(const std::string& serverAddress) override; |
| 44 | std::vector<std::wstring> List() override; |
| 45 | }; |
| 46 | |
| 47 | } // namespace wsl::windows::wslc::services |