blob: 7170605b10c72dfb5e3dc05fce310c0debe7d5b2 [file] [log] [blame]
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -05001#include "certs_manager.hpp"
2
Marri Devender Rao6ceec402019-02-01 03:15:19 -06003#include <phosphor-logging/elog-errors.hpp>
4#include <xyz/openbmc_project/Certs/Install/error.hpp>
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -05005#include <xyz/openbmc_project/Common/error.hpp>
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -05006namespace phosphor
7{
8namespace certs
9{
10
Marri Devender Raobf7c5882019-02-27 08:41:07 -060011using namespace sdbusplus::xyz::openbmc_project::Common::Error;
12using InvalidCertificate =
13 sdbusplus::xyz::openbmc_project::Certs::Install::Error::InvalidCertificate;
Marri Devender Rao6ceec402019-02-01 03:15:19 -060014using Reason = xyz::openbmc_project::Certs::Install::InvalidCertificate::REASON;
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050015
Marri Devender Rao6ceec402019-02-01 03:15:19 -060016/** @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 */
23Manager::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 Othayothcfbc8dc2018-09-03 07:22:27 -050029{
Marri Devender Raobf7c5882019-02-27 08:41:07 -060030 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 Othayothcfbc8dc2018-09-03 07:22:27 -050054}
55
Marri Devender Rao6ceec402019-02-01 03:15:19 -060056void Manager::install(const std::string filePath)
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050057{
Jayanth Othayoth589159f2018-09-28 08:32:39 -050058}
Deepak Kodihalliae70b3d2018-09-30 05:42:00 -050059
60void Manager::delete_()
61{
Marri Devender Rao6ceec402019-02-01 03:15:19 -060062 // 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 Kodihalliae70b3d2018-09-30 05:42:00 -050068 {
Marri Devender Rao6ceec402019-02-01 03:15:19 -060069 certificatePtr.reset(nullptr);
Deepak Kodihalliae70b3d2018-09-30 05:42:00 -050070 }
71}
Jayanth Othayothcfbc8dc2018-09-03 07:22:27 -050072} // namespace certs
73} // namespace phosphor