1 #pragma once
2 
3 #include "ca_cert_entry.hpp"
4 #include "xyz/openbmc_project/Certs/Authority/server.hpp"
5 #include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
6 
7 #include <sdbusplus/bus.hpp>
8 #include <sdbusplus/server/object.hpp>
9 
10 namespace ca::cert
11 {
12 
13 namespace internal
14 {
15 using ManagerInterface = sdbusplus::server::object_t<
16     sdbusplus::xyz::openbmc_project::Certs::server::Authority,
17     sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
18 }
19 
20 class CACertMgr;
21 
22 /** @class Manager
23  *  @brief Implementation for the
24  *         xyz.openbmc_project.Certs.ca.authority.Manager DBus API.
25  */
26 class CACertMgr : public internal::ManagerInterface
27 {
28   public:
29     CACertMgr() = delete;
30     CACertMgr(const CACertMgr&) = delete;
31     CACertMgr& operator=(const CACertMgr&) = delete;
32     CACertMgr(CACertMgr&&) = delete;
33     CACertMgr& operator=(CACertMgr&&) = delete;
34     virtual ~CACertMgr() = default;
35 
36     /** @brief Constructor to put object onto bus at a dbus path.
37      *  @param[in] bus - Bus to attach to.
38      *  @param[in] path - Path to attach at.
39      */
CACertMgr(sdbusplus::bus_t & bus,const char * path)40     CACertMgr(sdbusplus::bus_t& bus, const char* path) :
41         internal::ManagerInterface(bus, path), bus(bus), objectPath(path),
42         lastEntryId(0){};
43 
44     /** @brief This method provides signing authority functionality.
45                It signs the certificate and creates the CSR request entry Dbus
46      Object.
47      *  @param[in] csr - csr string
48      *  @return Object path
49      */
50     sdbusplus::message::object_path signCSR(std::string csr) override;
51 
52     /** @brief Erase specified entry d-bus object
53      *  @param[in] entryId - unique identifier of the entry
54      */
55     void erase(uint32_t entryId);
56 
57     /** @brief  Erase all entries
58      */
59     void deleteAll() override;
60 
61   protected:
62     std::map<uint32_t, std::unique_ptr<Entry>> entries;
63 
64   private:
65     /** @brief sdbusplus DBus bus connection. */
66     sdbusplus::bus_t& bus;
67     /** @brief object path */
68     std::string objectPath;
69     /** @brief Id of the last certificate entry */
70     uint32_t lastEntryId;
71 };
72 
73 } // namespace ca::cert
74