cryptoErase.cpp (59dffa63af63ac1021f372e4505fb8c1b9084906) cryptoErase.cpp (82897c35761f505c2b881f72c61f726f7d562692)
1#include "cryptErase.hpp"
2#include "cryptsetupInterface.hpp"
3#include "erase.hpp"
4
5#include <libcryptsetup.h>
6
7#include <phosphor-logging/lg2.hpp>
8#include <xyz/openbmc_project/Common/error.hpp>

--- 20 unchanged lines hidden (view full) ---

29 CryptHandle cryptHandle(std::string(devPath).c_str());
30 if (cryptHandle.get() == nullptr)
31 {
32 lg2::error("Failed to initialize crypt device", "REDFISH_MESSAGE_ID",
33 std::string("OpenBMC.0.1.EraseFailure"));
34 throw ResourceNotFound();
35 }
36 /* cryptLoad */
1#include "cryptErase.hpp"
2#include "cryptsetupInterface.hpp"
3#include "erase.hpp"
4
5#include <libcryptsetup.h>
6
7#include <phosphor-logging/lg2.hpp>
8#include <xyz/openbmc_project/Common/error.hpp>

--- 20 unchanged lines hidden (view full) ---

29 CryptHandle cryptHandle(std::string(devPath).c_str());
30 if (cryptHandle.get() == nullptr)
31 {
32 lg2::error("Failed to initialize crypt device", "REDFISH_MESSAGE_ID",
33 std::string("OpenBMC.0.1.EraseFailure"));
34 throw ResourceNotFound();
35 }
36 /* cryptLoad */
37 if (cryptIface.get()->cryptLoad(cryptHandle.get(), CRYPT_LUKS2, nullptr) !=
38 0)
37 if (cryptIface->cryptLoad(cryptHandle.get(), CRYPT_LUKS2, nullptr) != 0)
39 {
40 lg2::error("Failed to load the key slots for destruction",
41 "REDFISH_MESSAGE_ID",
42 std::string("OpenBMC.0.1.EraseFailure"));
43 throw ResourceNotFound();
44 }
45
46 /* find key slots */
38 {
39 lg2::error("Failed to load the key slots for destruction",
40 "REDFISH_MESSAGE_ID",
41 std::string("OpenBMC.0.1.EraseFailure"));
42 throw ResourceNotFound();
43 }
44
45 /* find key slots */
47 int nKeySlots = cryptIface.get()->cryptKeySlotMax(CRYPT_LUKS2);
46 int nKeySlots = cryptIface->cryptKeySlotMax(CRYPT_LUKS2);
48 if (nKeySlots < 0)
49 {
50 lg2::error("Failed to find the max keyslots", "REDFISH_MESSAGE_ID",
51 std::string("OpenBMC.0.1.EraseFailure"));
52 throw ResourceNotFound();
53 }
54
55 if (nKeySlots == 0)
56 {
57 lg2::error("Max keyslots should never be zero", "REDFISH_MESSAGE_ID",
58 std::string("OpenBMC.0.1.EraseFailure"));
59 throw ResourceNotFound();
60 }
61
62 /* destory working keyslots */
63 bool keySlotIssue = false;
64 for (int i = 0; i < nKeySlots; i++)
65 {
66 crypt_keyslot_info ki =
47 if (nKeySlots < 0)
48 {
49 lg2::error("Failed to find the max keyslots", "REDFISH_MESSAGE_ID",
50 std::string("OpenBMC.0.1.EraseFailure"));
51 throw ResourceNotFound();
52 }
53
54 if (nKeySlots == 0)
55 {
56 lg2::error("Max keyslots should never be zero", "REDFISH_MESSAGE_ID",
57 std::string("OpenBMC.0.1.EraseFailure"));
58 throw ResourceNotFound();
59 }
60
61 /* destory working keyslots */
62 bool keySlotIssue = false;
63 for (int i = 0; i < nKeySlots; i++)
64 {
65 crypt_keyslot_info ki =
67 cryptIface.get()->cryptKeySlotStatus(cryptHandle.get(), i);
66 cryptIface->cryptKeySlotStatus(cryptHandle.get(), i);
68
69 if (ki == CRYPT_SLOT_ACTIVE || ki == CRYPT_SLOT_ACTIVE_LAST)
70 {
67
68 if (ki == CRYPT_SLOT_ACTIVE || ki == CRYPT_SLOT_ACTIVE_LAST)
69 {
71 if (cryptIface.get()->cryptKeyslotDestroy(cryptHandle.get(), i) !=
72 0)
70 if (cryptIface->cryptKeyslotDestroy(cryptHandle.get(), i) != 0)
73 {
74 lg2::error(
75 "Estoraged erase failed to destroy keyslot, continuing",
76 "REDFISH_MESSAGE_ID",
77 std::string("eStorageD.1.0.EraseFailure"));
78 keySlotIssue = true;
79 }
80 }
81 }
82 if (keySlotIssue)
83 {
84 throw InternalFailure();
85 }
86}
87
88} // namespace estoraged
71 {
72 lg2::error(
73 "Estoraged erase failed to destroy keyslot, continuing",
74 "REDFISH_MESSAGE_ID",
75 std::string("eStorageD.1.0.EraseFailure"));
76 keySlotIssue = true;
77 }
78 }
79 }
80 if (keySlotIssue)
81 {
82 throw InternalFailure();
83 }
84}
85
86} // namespace estoraged