blob: 3156a4ed7302f24cfed1e6337e0aa407878b743b [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{
33
34static constexpr auto servicePwd = "xyz.openbmc_project.BIOSConfigPassword";
35static constexpr auto objectPathPwd =
36 "/xyz/openbmc_project/bios_config/password";
37constexpr auto biosPasswordFile = "passwordData";
38constexpr auto biosSeedFile = "seedData";
Ayushi Smriti96e72ec2021-05-20 13:44:12 +053039constexpr uint8_t maxHashSize = 64;
40constexpr uint8_t maxSeedSize = 32;
41constexpr uint8_t maxPasswordLen = 32;
Kuiying Wang8f706212020-12-16 18:59:24 +080042
43using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Password;
44namespace fs = std::filesystem;
45
46/** @class Password
47 *
48 * @brief Implements the BIOS Password
49 */
50class Password : public Base
51{
52 public:
53 Password() = delete;
54 ~Password() = default;
55 Password(const Password&) = delete;
56 Password& operator=(const Password&) = delete;
57 Password(Password&&) = delete;
58 Password& operator=(Password&&) = delete;
59
60 /** @brief Constructs Password object.
61 *
62 * @param[in] objectServer - object server
63 * @param[in] systemBus - bus connection
64 */
65 Password(sdbusplus::asio::object_server& objectServer,
66 std::shared_ptr<sdbusplus::asio::connection>& systemBus);
67
68 /** @brief Set the BIOS attribute with a new value, the new value is added
69 * to the PendingAttribute.
70 *
71 * @param[in] userName - User name - user / admin.
72 * @param[in] currentPassword - Current user/ admin Password.
73 * @param[in] newPassword - New user/ admin Password.
74 */
75 void changePassword(std::string userName, std::string currentPassword,
76 std::string newPassword) override;
77
78 private:
Ayushi Smriti96e72ec2021-05-20 13:44:12 +053079 uint8_t convertUnicode(const std::string& pwd,
80 std::array<uint16_t, maxPasswordLen>& unicodePwd);
Kuiying Wang8f706212020-12-16 18:59:24 +080081 void verifyPassword(std::string userName, std::string currentPassword,
82 std::string newPassword);
Ayushi Smriti96e72ec2021-05-20 13:44:12 +053083 bool isMatch(const std::array<uint8_t, maxHashSize>& expected,
84 const std::array<uint8_t, maxSeedSize>& seed,
Kuiying Wang8f706212020-12-16 18:59:24 +080085 const std::string rawData, const std::string algo);
86 sdbusplus::asio::object_server& objServer;
87 std::shared_ptr<sdbusplus::asio::connection>& systemBus;
Kuiying Wang8f706212020-12-16 18:59:24 +080088 std::filesystem::path seedFile;
Ayushi Smriti96e72ec2021-05-20 13:44:12 +053089 std::array<uint8_t, maxHashSize> mNewPwdHash;
Kuiying Wang8f706212020-12-16 18:59:24 +080090};
91
92} // namespace bios_config_pwd