blob: 2b320a5aeb3ac3176606f437a06fa28fd71ed84f [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,
62 std::shared_ptr<sdbusplus::asio::connection>& systemBus);
63
64 /** @brief Set the BIOS attribute with a new value, the new value is added
65 * to the PendingAttribute.
66 *
67 * @param[in] userName - User name - user / admin.
68 * @param[in] currentPassword - Current user/ admin Password.
69 * @param[in] newPassword - New user/ admin Password.
70 */
71 void changePassword(std::string userName, std::string currentPassword,
72 std::string newPassword) override;
73
74 private:
75 void verifyPassword(std::string userName, std::string currentPassword,
76 std::string newPassword);
yesd0f034a2022-12-29 18:35:37 +053077 bool compareDigest(const EVP_MD* digestFunc, size_t digestLen,
78 const std::array<uint8_t, maxHashSize>& expected,
79 const std::array<uint8_t, maxSeedSize>& seed,
80 const std::string& rawData);
Ayushi Smriti96e72ec2021-05-20 13:44:12 +053081 bool isMatch(const std::array<uint8_t, maxHashSize>& expected,
82 const std::array<uint8_t, maxSeedSize>& seed,
George Liu616f9222021-12-29 14:25:39 +080083 const std::string& rawData, const std::string& algo);
Smriti-Ayushib3f7a792023-05-09 15:03:24 +053084 bool getParam(std::array<uint8_t, maxHashSize>& orgUsrPwdHash,
85 std::array<uint8_t, maxHashSize>& orgAdminPwdHash,
86 std::array<uint8_t, maxSeedSize>& seed,
87 std::string& hashAlgo);
yes8c22d072023-03-22 15:11:26 +053088 bool verifyIntegrityCheck(std::string& newPassword,
89 std::array<uint8_t, maxSeedSize>& seed,
90 unsigned int mdLen, const EVP_MD* digestFunc);
Kuiying Wang8f706212020-12-16 18:59:24 +080091 sdbusplus::asio::object_server& objServer;
92 std::shared_ptr<sdbusplus::asio::connection>& systemBus;
Kuiying Wang8f706212020-12-16 18:59:24 +080093 std::filesystem::path seedFile;
Ayushi Smriti96e72ec2021-05-20 13:44:12 +053094 std::array<uint8_t, maxHashSize> mNewPwdHash;
Kuiying Wang8f706212020-12-16 18:59:24 +080095};
96
97} // namespace bios_config_pwd