| Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 1 | #include "certs_manager.hpp" | 
|  | 2 |  | 
| Marri Devender Rao | 6ceec40 | 2019-02-01 03:15:19 -0600 | [diff] [blame] | 3 | #include <phosphor-logging/elog-errors.hpp> | 
|  | 4 | #include <xyz/openbmc_project/Certs/Install/error.hpp> | 
| Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 5 | #include <xyz/openbmc_project/Common/error.hpp> | 
| Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 6 | namespace phosphor | 
|  | 7 | { | 
|  | 8 | namespace certs | 
|  | 9 | { | 
|  | 10 |  | 
| Marri Devender Rao | bf7c588 | 2019-02-27 08:41:07 -0600 | [diff] [blame^] | 11 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; | 
|  | 12 | using InvalidCertificate = | 
|  | 13 | sdbusplus::xyz::openbmc_project::Certs::Install::Error::InvalidCertificate; | 
| Marri Devender Rao | 6ceec40 | 2019-02-01 03:15:19 -0600 | [diff] [blame] | 14 | using Reason = xyz::openbmc_project::Certs::Install::InvalidCertificate::REASON; | 
| Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 15 |  | 
| Marri Devender Rao | 6ceec40 | 2019-02-01 03:15:19 -0600 | [diff] [blame] | 16 | /** @brief Constructor to put object onto bus at a dbus path. | 
|  | 17 | *  @param[in] bus - Bus to attach to. | 
|  | 18 | *  @param[in] path - Path to attach at. | 
|  | 19 | *  @param[in] type - Type of the certificate. | 
|  | 20 | *  @param[in] unit - Unit consumed by this certificate. | 
|  | 21 | *  @param[in] installPath - Certificate installation path. | 
|  | 22 | */ | 
|  | 23 | Manager::Manager(sdbusplus::bus::bus& bus, const char* path, | 
|  | 24 | const CertificateType& type, UnitsToRestart&& unit, | 
|  | 25 | CertInstallPath&& installPath) : | 
|  | 26 | Ifaces(bus, path), | 
|  | 27 | bus(bus), objectPath(path), certType(type), unitToRestart(std::move(unit)), | 
|  | 28 | certInstallPath(std::move(installPath)) | 
| Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 29 | { | 
| Marri Devender Rao | bf7c588 | 2019-02-27 08:41:07 -0600 | [diff] [blame^] | 30 | if (fs::exists(certInstallPath)) | 
|  | 31 | { | 
|  | 32 | try | 
|  | 33 | { | 
|  | 34 | // TODO: Issue#3 At present supporting only one certificate to be | 
|  | 35 | // uploaded this need to be revisited to support multiple | 
|  | 36 | // certificates | 
|  | 37 | auto certObjectPath = objectPath + '/' + '1'; | 
|  | 38 | certificatePtr = std::make_unique<Certificate>( | 
|  | 39 | bus, certObjectPath, certType, unitToRestart, certInstallPath, | 
|  | 40 | certInstallPath); | 
|  | 41 | } | 
|  | 42 | catch (const InternalFailure& e) | 
|  | 43 | { | 
|  | 44 | certificatePtr.reset(nullptr); | 
|  | 45 | report<InternalFailure>(); | 
|  | 46 | } | 
|  | 47 | catch (const InvalidCertificate& e) | 
|  | 48 | { | 
|  | 49 | certificatePtr.reset(nullptr); | 
|  | 50 | report<InvalidCertificate>( | 
|  | 51 | Reason("Existing certificate file is corrupted")); | 
|  | 52 | } | 
|  | 53 | } | 
| Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 54 | } | 
|  | 55 |  | 
| Marri Devender Rao | 6ceec40 | 2019-02-01 03:15:19 -0600 | [diff] [blame] | 56 | void Manager::install(const std::string filePath) | 
| Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 57 | { | 
| Jayanth Othayoth | 589159f | 2018-09-28 08:32:39 -0500 | [diff] [blame] | 58 | } | 
| Deepak Kodihalli | ae70b3d | 2018-09-30 05:42:00 -0500 | [diff] [blame] | 59 |  | 
|  | 60 | void Manager::delete_() | 
|  | 61 | { | 
| Marri Devender Rao | 6ceec40 | 2019-02-01 03:15:19 -0600 | [diff] [blame] | 62 | // TODO: #Issue 4 when a certificate is deleted system auto generates | 
|  | 63 | // certificate file. At present we are not supporting creation of | 
|  | 64 | // certificate object for the auto-generated certificate file as | 
|  | 65 | // deletion if only applicable for REST server and Bmcweb does not allow | 
|  | 66 | // deletion of certificates | 
|  | 67 | if (certificatePtr != nullptr) | 
| Deepak Kodihalli | ae70b3d | 2018-09-30 05:42:00 -0500 | [diff] [blame] | 68 | { | 
| Marri Devender Rao | 6ceec40 | 2019-02-01 03:15:19 -0600 | [diff] [blame] | 69 | certificatePtr.reset(nullptr); | 
| Deepak Kodihalli | ae70b3d | 2018-09-30 05:42:00 -0500 | [diff] [blame] | 70 | } | 
|  | 71 | } | 
| Jayanth Othayoth | cfbc8dc | 2018-09-03 07:22:27 -0500 | [diff] [blame] | 72 | } // namespace certs | 
|  | 73 | } // namespace phosphor |