blob: 79afc23dc1b5281d064ad3702e932a54479629f8 [file] [log] [blame]
Sumanth Bhate4e633e2019-05-14 12:13:57 +00001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17#include "channel_layer.hpp"
18
19#include <ipmid/message/types.hpp>
20#include <map>
21#include <nlohmann/json.hpp>
22
23namespace ipmi
24{
25static const std::string csPrivDefaultFileName =
26 "/usr/share/ipmi-providers/cs_privilege_levels.json";
27
28static const std::string csPrivFileName =
29 "/var/lib/ipmi/cs_privilege_levels.json";
30
31static const size_t maxCSRecords = 16;
32
33using ChannelNumCipherIDPair = std::pair<uint8_t, uint8_t>;
34using privMap = std::map<ChannelNumCipherIDPair, uint4_t>;
35
36/** @class CipherConfig
37 * @brief Class to provide cipher suite functionalities
38 */
39class CipherConfig
40{
41 public:
42 ~CipherConfig() = default;
43 explicit CipherConfig(const std::string& csFileName,
44 const std::string& csDefaultFileName);
45 CipherConfig() = delete;
46
47 private:
48 std::string cipherSuitePrivFileName, cipherSuiteDefaultPrivFileName;
49
50 privMap csPrivilegeMap;
51
52 /** @brief function to read json config file
53 *
54 * @return nlohmann::json object
55 */
56 nlohmann::json readCSPrivilegeLevels(const std::string& csFileName);
57
58 /** @brief function to write json config file
59 *
60 * @param[in] jsonData - json object
61 *
62 * @return 0 for success, -errno for failure.
63 */
64 int writeCSPrivilegeLevels(const nlohmann::json& jsonData);
65
66 /** @brief convert to cipher suite privilege from string to value
67 *
68 * @param[in] value - privilege value
69 *
70 * @return cipher suite privilege index
71 */
72 uint4_t convertToPrivLimitIndex(const std::string& value);
73
74 /** @brief function to convert privilege value to string
75 *
76 * @param[in] value - privilege value
77 *
78 * @return privilege in string
79 */
80 std::string convertToPrivLimitString(const uint4_t& value);
81
82 /** @brief function to load CS Privilege Levels from json file/files to map
83 *
84 */
85 void loadCSPrivilegesToMap();
86
87 /** @brief function to update CS privileges map from json object data,
88 * jsonData
89 *
90 */
91 void updateCSPrivilegesMap(const nlohmann::json& jsonData);
92};
93
94/** @brief function to create static CipherConfig object
95 *
96 * @param[in] csFileName - user setting cipher suite privilege file name
97 * @param[in] csDefaultFileName - default cipher suite privilege file name
98 *
99 * @return static CipherConfig object
100 */
101CipherConfig& getCipherConfigObject(const std::string& csFileName,
102 const std::string& csDefaultFileName);
103} // namespace ipmi