blob: 52e5ab90e5569fa0cd6c25d7ce617d302319e716 [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
17#include "config.h"
18
19#include <openssl/evp.h>
20#include <openssl/hmac.h>
21#include <openssl/sha.h>
22
23#include <nlohmann/json.hpp>
24#include <sdbusplus/asio/object_server.hpp>
25#include <sdbusplus/server.hpp>
26#include <xyz/openbmc_project/BIOSConfig/Password/server.hpp>
27
28#include <filesystem>
29#include <string>
30
31namespace bios_config_pwd
32{
Kuiying Wang8f706212020-12-16 18:59:24 +080033static constexpr auto objectPathPwd =
34 "/xyz/openbmc_project/bios_config/password";
35constexpr auto biosPasswordFile = "passwordData";
36constexpr auto biosSeedFile = "seedData";
Ayushi Smriti96e72ec2021-05-20 13:44:12 +053037constexpr uint8_t maxHashSize = 64;
38constexpr uint8_t maxSeedSize = 32;
39constexpr uint8_t maxPasswordLen = 32;
Snehalatha Venkatesh2f7ba732021-09-30 10:25:32 +000040constexpr int iterValue = 1000;
Kuiying Wang8f706212020-12-16 18:59:24 +080041
42using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Password;
43namespace fs = std::filesystem;
44
45/** @class Password
46 *
47 * @brief Implements the BIOS Password
48 */
49class Password : public Base
50{
51 public:
52 Password() = delete;
53 ~Password() = default;
54 Password(const Password&) = delete;
55 Password& operator=(const Password&) = delete;
56 Password(Password&&) = delete;
57 Password& operator=(Password&&) = delete;
58
59 /** @brief Constructs Password object.
60 *
61 * @param[in] objectServer - object server
62 * @param[in] systemBus - bus connection
63 */
64 Password(sdbusplus::asio::object_server& objectServer,
65 std::shared_ptr<sdbusplus::asio::connection>& systemBus);
66
67 /** @brief Set the BIOS attribute with a new value, the new value is added
68 * to the PendingAttribute.
69 *
70 * @param[in] userName - User name - user / admin.
71 * @param[in] currentPassword - Current user/ admin Password.
72 * @param[in] newPassword - New user/ admin Password.
73 */
74 void changePassword(std::string userName, std::string currentPassword,
75 std::string newPassword) override;
76
77 private:
78 void verifyPassword(std::string userName, std::string currentPassword,
79 std::string newPassword);
yesd0f034a2022-12-29 18:35:37 +053080 bool compareDigest(const EVP_MD* digestFunc, size_t digestLen,
81 const std::array<uint8_t, maxHashSize>& expected,
82 const std::array<uint8_t, maxSeedSize>& seed,
83 const std::string& rawData);
Ayushi Smriti96e72ec2021-05-20 13:44:12 +053084 bool isMatch(const std::array<uint8_t, maxHashSize>& expected,
85 const std::array<uint8_t, maxSeedSize>& seed,
George Liu616f9222021-12-29 14:25:39 +080086 const std::string& rawData, const std::string& algo);
Smriti-Ayushib3f7a792023-05-09 15:03:24 +053087 bool getParam(std::array<uint8_t, maxHashSize>& orgUsrPwdHash,
88 std::array<uint8_t, maxHashSize>& orgAdminPwdHash,
89 std::array<uint8_t, maxSeedSize>& seed,
90 std::string& hashAlgo);
yes8c22d072023-03-22 15:11:26 +053091 bool verifyIntegrityCheck(std::string& newPassword,
92 std::array<uint8_t, maxSeedSize>& seed,
93 unsigned int mdLen, const EVP_MD* digestFunc);
Kuiying Wang8f706212020-12-16 18:59:24 +080094 sdbusplus::asio::object_server& objServer;
95 std::shared_ptr<sdbusplus::asio::connection>& systemBus;
Kuiying Wang8f706212020-12-16 18:59:24 +080096 std::filesystem::path seedFile;
Ayushi Smriti96e72ec2021-05-20 13:44:12 +053097 std::array<uint8_t, maxHashSize> mNewPwdHash;
Kuiying Wang8f706212020-12-16 18:59:24 +080098};
99
100} // namespace bios_config_pwd