| #include "certs_manager.hpp" |
| |
| #include <phosphor-logging/elog-errors.hpp> |
| #include <xyz/openbmc_project/Certs/error.hpp> |
| #include <xyz/openbmc_project/Common/error.hpp> |
| namespace phosphor |
| { |
| namespace certs |
| { |
| |
| using InternalFailure = |
| sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| |
| /** @brief Constructor to put object onto bus at a dbus path. |
| * @param[in] bus - Bus to attach to. |
| * @param[in] path - Path to attach at. |
| * @param[in] type - Type of the certificate. |
| * @param[in] unit - Unit consumed by this certificate. |
| * @param[in] installPath - Certificate installation path. |
| */ |
| Manager::Manager(sdbusplus::bus::bus& bus, const char* path, |
| const CertificateType& type, UnitsToRestart&& unit, |
| CertInstallPath&& installPath) : |
| Ifaces(bus, path), |
| bus(bus), objectPath(path), certType(type), unitToRestart(std::move(unit)), |
| certInstallPath(std::move(installPath)) |
| { |
| using InvalidCertificate = |
| sdbusplus::xyz::openbmc_project::Certs::Error::InvalidCertificate; |
| using Reason = xyz::openbmc_project::Certs::InvalidCertificate::REASON; |
| if (fs::exists(certInstallPath)) |
| { |
| try |
| { |
| // TODO: Issue#3 At present supporting only one certificate to be |
| // uploaded this need to be revisited to support multiple |
| // certificates |
| auto certObjectPath = objectPath + '/' + '1'; |
| certificatePtr = std::make_unique<Certificate>( |
| bus, certObjectPath, certType, unitToRestart, certInstallPath, |
| certInstallPath); |
| } |
| catch (const InternalFailure& e) |
| { |
| report<InternalFailure>(); |
| } |
| catch (const InvalidCertificate& e) |
| { |
| report<InvalidCertificate>( |
| Reason("Existing certificate file is corrupted")); |
| } |
| } |
| } |
| |
| void Manager::install(const std::string filePath) |
| { |
| using NotAllowed = |
| sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed; |
| using Reason = xyz::openbmc_project::Common::NotAllowed::REASON; |
| // TODO: Issue#3 At present supporting only one certificate to be |
| // uploaded this need to be revisited to support multiple |
| // certificates |
| if (certificatePtr != nullptr) |
| { |
| elog<NotAllowed>(Reason("Certificate already exist")); |
| } |
| auto certObjectPath = objectPath + '/' + '1'; |
| certificatePtr = |
| std::make_unique<Certificate>(bus, certObjectPath, certType, |
| unitToRestart, certInstallPath, filePath); |
| } |
| |
| void Manager::delete_() |
| { |
| // TODO: #Issue 4 when a certificate is deleted system auto generates |
| // certificate file. At present we are not supporting creation of |
| // certificate object for the auto-generated certificate file as |
| // deletion if only applicable for REST server and Bmcweb does not allow |
| // deletion of certificates |
| if (certificatePtr != nullptr) |
| { |
| certificatePtr.reset(nullptr); |
| } |
| } |
| } // namespace certs |
| } // namespace phosphor |