blob: 4b2d7884e2a992663d08935c5a65b29edd6b5198 [file] [log] [blame]
Kuiying Wang8f706212020-12-16 18:59:24 +08001/*
2// Copyright (c) 2020 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
Kuiying Wang8f706212020-12-16 18:59:24 +080017#include <openssl/evp.h>
18#include <openssl/hmac.h>
19#include <openssl/sha.h>
20
21#include <nlohmann/json.hpp>
22#include <sdbusplus/asio/object_server.hpp>
23#include <sdbusplus/server.hpp>
24#include <xyz/openbmc_project/BIOSConfig/Password/server.hpp>
25
26#include <filesystem>
27#include <string>
28
29namespace bios_config_pwd
30{
Kuiying Wang8f706212020-12-16 18:59:24 +080031static constexpr auto objectPathPwd =
32 "/xyz/openbmc_project/bios_config/password";
Kuiying Wang8f706212020-12-16 18:59:24 +080033constexpr auto biosSeedFile = "seedData";
Ayushi Smriti96e72ec2021-05-20 13:44:12 +053034constexpr uint8_t maxHashSize = 64;
35constexpr uint8_t maxSeedSize = 32;
36constexpr uint8_t maxPasswordLen = 32;
Snehalatha Venkatesh2f7ba732021-09-30 10:25:32 +000037constexpr int iterValue = 1000;
Kuiying Wang8f706212020-12-16 18:59:24 +080038
39using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Password;
40namespace fs = std::filesystem;
41
42/** @class Password
43 *
44 * @brief Implements the BIOS Password
45 */
46class Password : public Base
47{
48 public:
49 Password() = delete;
50 ~Password() = default;
51 Password(const Password&) = delete;
52 Password& operator=(const Password&) = delete;
53 Password(Password&&) = delete;
54 Password& operator=(Password&&) = delete;
55
56 /** @brief Constructs Password object.
57 *
58 * @param[in] objectServer - object server
59 * @param[in] systemBus - bus connection
60 */
61 Password(sdbusplus::asio::object_server& objectServer,
Patrick Williams773c9222024-10-18 21:39:55 -040062 std::shared_ptr<sdbusplus::asio::connection>& systemBus,
63 std::string persistPath);
Kuiying Wang8f706212020-12-16 18:59:24 +080064
65 /** @brief Set the BIOS attribute with a new value, the new value is added
66 * to the PendingAttribute.
67 *
68 * @param[in] userName - User name - user / admin.
69 * @param[in] currentPassword - Current user/ admin Password.
70 * @param[in] newPassword - New user/ admin Password.
71 */
72 void changePassword(std::string userName, std::string currentPassword,
73 std::string newPassword) override;
74
75 private:
76 void verifyPassword(std::string userName, std::string currentPassword,
77 std::string newPassword);
yesd0f034a2022-12-29 18:35:37 +053078 bool compareDigest(const EVP_MD* digestFunc, size_t digestLen,
79 const std::array<uint8_t, maxHashSize>& expected,
80 const std::array<uint8_t, maxSeedSize>& seed,
81 const std::string& rawData);
Ayushi Smriti96e72ec2021-05-20 13:44:12 +053082 bool isMatch(const std::array<uint8_t, maxHashSize>& expected,
83 const std::array<uint8_t, maxSeedSize>& seed,
George Liu616f9222021-12-29 14:25:39 +080084 const std::string& rawData, const std::string& algo);
Smriti-Ayushib3f7a792023-05-09 15:03:24 +053085 bool getParam(std::array<uint8_t, maxHashSize>& orgUsrPwdHash,
86 std::array<uint8_t, maxHashSize>& orgAdminPwdHash,
87 std::array<uint8_t, maxSeedSize>& seed,
88 std::string& hashAlgo);
yes8c22d072023-03-22 15:11:26 +053089 bool verifyIntegrityCheck(std::string& newPassword,
90 std::array<uint8_t, maxSeedSize>& seed,
91 unsigned int mdLen, const EVP_MD* digestFunc);
Kuiying Wang8f706212020-12-16 18:59:24 +080092 sdbusplus::asio::object_server& objServer;
93 std::shared_ptr<sdbusplus::asio::connection>& systemBus;
Kuiying Wang8f706212020-12-16 18:59:24 +080094 std::filesystem::path seedFile;
Ayushi Smriti96e72ec2021-05-20 13:44:12 +053095 std::array<uint8_t, maxHashSize> mNewPwdHash;
Kuiying Wang8f706212020-12-16 18:59:24 +080096};
97
98} // namespace bios_config_pwd