#include "cryptErase.hpp" #include "cryptsetupInterface.hpp" #include "erase.hpp" #include #include #include #include #include #include namespace estoraged { using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; using sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound; CryptErase::CryptErase( std::string_view devPathIn, std::unique_ptr inCryptIface) : Erase(devPathIn), cryptIface(std::move(inCryptIface)) {} void CryptErase::doErase() { /* get cryptHandle */ CryptHandle cryptHandle{devPath}; /* cryptLoad */ if (cryptIface->cryptLoad(cryptHandle.get(), CRYPT_LUKS2, nullptr) != 0) { lg2::error("Failed to load the key slots for destruction", "REDFISH_MESSAGE_ID", std::string("OpenBMC.0.1.EraseFailure")); throw ResourceNotFound(); } /* find key slots */ int nKeySlots = cryptIface->cryptKeySlotMax(CRYPT_LUKS2); if (nKeySlots < 0) { lg2::error("Failed to find the max keyslots", "REDFISH_MESSAGE_ID", std::string("OpenBMC.0.1.EraseFailure")); throw ResourceNotFound(); } if (nKeySlots == 0) { lg2::error("Max keyslots should never be zero", "REDFISH_MESSAGE_ID", std::string("OpenBMC.0.1.EraseFailure")); throw ResourceNotFound(); } /* destory working keyslots */ bool keySlotIssue = false; for (int i = 0; i < nKeySlots; i++) { crypt_keyslot_info ki = cryptIface->cryptKeySlotStatus(cryptHandle.get(), i); if (ki == CRYPT_SLOT_ACTIVE || ki == CRYPT_SLOT_ACTIVE_LAST) { if (cryptIface->cryptKeyslotDestroy(cryptHandle.get(), i) != 0) { lg2::error( "Estoraged erase failed to destroy keyslot, continuing", "REDFISH_MESSAGE_ID", std::string("eStorageD.1.0.EraseFailure")); keySlotIssue = true; } } } if (keySlotIssue) { throw InternalFailure(); } } } // namespace estoraged