Ravi Teja | a49895e | 2020-06-16 03:57:58 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "ca_certs_manager.hpp" |
| 4 | |
| 5 | #include <filesystem> |
| 6 | #include <fstream> |
| 7 | #include <phosphor-logging/elog-errors.hpp> |
| 8 | #include <phosphor-logging/elog.hpp> |
| 9 | #include <phosphor-logging/log.hpp> |
| 10 | #include <xyz/openbmc_project/Common/error.hpp> |
| 11 | |
Nan Zhou | e1289ad | 2021-12-28 11:02:56 -0800 | [diff] [blame^] | 12 | namespace ca::cert |
Ravi Teja | a49895e | 2020-06-16 03:57:58 -0500 | [diff] [blame] | 13 | { |
Ravi Teja | a49895e | 2020-06-16 03:57:58 -0500 | [diff] [blame] | 14 | static constexpr auto maxCertSize = 4096; |
| 15 | namespace fs = std::filesystem; |
| 16 | using namespace phosphor::logging; |
| 17 | using InvalidArgument = |
| 18 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; |
| 19 | using Argument = xyz::openbmc_project::Common::InvalidArgument; |
| 20 | |
| 21 | sdbusplus::message::object_path CACertMgr::signCSR(std::string csr) |
| 22 | { |
| 23 | std::string objPath; |
| 24 | try |
| 25 | { |
| 26 | if (csr.size() > maxCertSize) |
| 27 | { |
| 28 | log<level::ERR>("Invalid CSR size"); |
| 29 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("CSR"), |
| 30 | Argument::ARGUMENT_VALUE(csr.c_str())); |
| 31 | } |
| 32 | auto id = lastEntryId + 1; |
Ravi Teja | 11d0906 | 2021-04-20 11:52:42 -0500 | [diff] [blame] | 33 | objPath = fs::path(OBJPATH) / "ca" / "entry" / std::to_string(id); |
Ravi Teja | a49895e | 2020-06-16 03:57:58 -0500 | [diff] [blame] | 34 | std::string cert; |
| 35 | // Creating the dbus object here with the empty certificate string |
| 36 | // actual signing is being done by the hypervisor, once it signs then |
| 37 | // the certificate string would be updated with actual certificate. |
| 38 | entries.insert(std::make_pair( |
| 39 | id, std::make_unique<Entry>(bus, objPath, id, csr, cert, *this))); |
| 40 | lastEntryId++; |
| 41 | } |
| 42 | catch (const std::invalid_argument& e) |
| 43 | { |
| 44 | log<level::ERR>(e.what()); |
| 45 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("csr"), |
| 46 | Argument::ARGUMENT_VALUE(csr.c_str())); |
| 47 | } |
| 48 | return objPath; |
| 49 | } |
| 50 | |
| 51 | void CACertMgr::erase(uint32_t entryId) |
| 52 | { |
| 53 | entries.erase(entryId); |
| 54 | } |
| 55 | |
| 56 | void CACertMgr::deleteAll() |
| 57 | { |
| 58 | auto iter = entries.begin(); |
| 59 | while (iter != entries.end()) |
| 60 | { |
| 61 | auto& entry = iter->second; |
| 62 | ++iter; |
| 63 | entry->delete_(); |
| 64 | } |
| 65 | } |
| 66 | |
Nan Zhou | e1289ad | 2021-12-28 11:02:56 -0800 | [diff] [blame^] | 67 | } // namespace ca::cert |