1 /* 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 31 namespace bios_config_pwd 32 { 33 34 static constexpr auto servicePwd = "xyz.openbmc_project.BIOSConfigPassword"; 35 static constexpr auto objectPathPwd = 36 "/xyz/openbmc_project/bios_config/password"; 37 constexpr auto biosPasswordFile = "passwordData"; 38 constexpr auto biosSeedFile = "seedData"; 39 40 using Base = sdbusplus::xyz::openbmc_project::BIOSConfig::server::Password; 41 namespace fs = std::filesystem; 42 43 /** @class Password 44 * 45 * @brief Implements the BIOS Password 46 */ 47 class Password : public Base 48 { 49 public: 50 Password() = delete; 51 ~Password() = default; 52 Password(const Password&) = delete; 53 Password& operator=(const Password&) = delete; 54 Password(Password&&) = delete; 55 Password& operator=(Password&&) = delete; 56 57 /** @brief Constructs Password object. 58 * 59 * @param[in] objectServer - object server 60 * @param[in] systemBus - bus connection 61 */ 62 Password(sdbusplus::asio::object_server& objectServer, 63 std::shared_ptr<sdbusplus::asio::connection>& systemBus); 64 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); 78 bool isMatch(const std::string expected, const std::string seed, 79 const std::string rawData, const std::string algo); 80 sdbusplus::asio::object_server& objServer; 81 std::shared_ptr<sdbusplus::asio::connection>& systemBus; 82 std::filesystem::path passwordFile; 83 std::filesystem::path seedFile; 84 std::string mNewPassword; 85 }; 86 87 } // namespace bios_config_pwd 88