xref: /openbmc/bmcweb/features/redfish/lib/certificate_service.hpp (revision 92e11bf8fe87746f6981b9c416e6f2d26c86169f)
140e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0
240e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
35968caeeSMarri Devender Rao #pragma once
45968caeeSMarri Devender Rao 
5d7857201SEd Tanous #include "bmcweb_config.h"
6d7857201SEd Tanous 
73ccb3adbSEd Tanous #include "app.hpp"
83ccb3adbSEd Tanous #include "async_resp.hpp"
9d7857201SEd Tanous #include "dbus_singleton.hpp"
107a1dbc48SGeorge Liu #include "dbus_utility.hpp"
11d7857201SEd Tanous #include "error_messages.hpp"
121aa0c2b8SEd Tanous #include "http/parsing.hpp"
13d7857201SEd Tanous #include "http_request.hpp"
143ccb3adbSEd Tanous #include "http_response.hpp"
15d7857201SEd Tanous #include "logging.hpp"
16d7857201SEd Tanous #include "privileges.hpp"
173ccb3adbSEd Tanous #include "query.hpp"
183ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
19d7857201SEd Tanous #include "utility.hpp"
209b12d1f9SKrzysztof Grobelny #include "utils/dbus_utils.hpp"
213ccb3adbSEd Tanous #include "utils/json_utils.hpp"
223ccb3adbSEd Tanous #include "utils/time_utils.hpp"
239b12d1f9SKrzysztof Grobelny 
24d7857201SEd Tanous #include <systemd/sd-bus.h>
25d7857201SEd Tanous 
26d7857201SEd Tanous #include <boost/asio/error.hpp>
27d7857201SEd Tanous #include <boost/asio/steady_timer.hpp>
28d7857201SEd Tanous #include <boost/beast/http/field.hpp>
29d7857201SEd Tanous #include <boost/beast/http/status.hpp>
30d7857201SEd Tanous #include <boost/beast/http/verb.hpp>
31d7857201SEd Tanous #include <boost/system/result.hpp>
32ef4c65b7SEd Tanous #include <boost/url/format.hpp>
33d7857201SEd Tanous #include <boost/url/parse.hpp>
34d7857201SEd Tanous #include <boost/url/url.hpp>
35d7857201SEd Tanous #include <nlohmann/json.hpp>
363ccb3adbSEd Tanous #include <sdbusplus/bus/match.hpp>
37d7857201SEd Tanous #include <sdbusplus/message.hpp>
38d7857201SEd Tanous #include <sdbusplus/message/native_types.hpp>
399b12d1f9SKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp>
401214b7e7SGunnar Mills 
417a1dbc48SGeorge Liu #include <array>
42d7857201SEd Tanous #include <chrono>
43d7857201SEd Tanous #include <cstddef>
44d7857201SEd Tanous #include <cstdint>
45d7857201SEd Tanous #include <cstdlib>
46d7857201SEd Tanous #include <filesystem>
47d7857201SEd Tanous #include <format>
48d7857201SEd Tanous #include <fstream>
49d7857201SEd Tanous #include <functional>
50d7857201SEd Tanous #include <iterator>
513ccb3adbSEd Tanous #include <memory>
52d7857201SEd Tanous #include <optional>
53d7857201SEd Tanous #include <string>
547a1dbc48SGeorge Liu #include <string_view>
55d7857201SEd Tanous #include <system_error>
56d7857201SEd Tanous #include <utility>
57d7857201SEd Tanous #include <vector>
587a1dbc48SGeorge Liu 
595968caeeSMarri Devender Rao namespace redfish
605968caeeSMarri Devender Rao {
615968caeeSMarri Devender Rao namespace certs
625968caeeSMarri Devender Rao {
6389492a15SPatrick Williams constexpr const char* certInstallIntf = "xyz.openbmc_project.Certs.Install";
6489492a15SPatrick Williams constexpr const char* certReplaceIntf = "xyz.openbmc_project.Certs.Replace";
6589492a15SPatrick Williams constexpr const char* objDeleteIntf = "xyz.openbmc_project.Object.Delete";
6689492a15SPatrick Williams constexpr const char* certPropIntf = "xyz.openbmc_project.Certs.Certificate";
6789492a15SPatrick Williams constexpr const char* dbusPropIntf = "org.freedesktop.DBus.Properties";
6889492a15SPatrick Williams constexpr const char* dbusObjManagerIntf = "org.freedesktop.DBus.ObjectManager";
6989492a15SPatrick Williams constexpr const char* httpsServiceName =
7037cce918SMarri Devender Rao     "xyz.openbmc_project.Certs.Manager.Server.Https";
7189492a15SPatrick Williams constexpr const char* ldapServiceName =
7237cce918SMarri Devender Rao     "xyz.openbmc_project.Certs.Manager.Client.Ldap";
7389492a15SPatrick Williams constexpr const char* authorityServiceName =
74b2254ccdSMichal Orzel     "xyz.openbmc_project.Certs.Manager.Authority.Truststore";
7589492a15SPatrick Williams constexpr const char* baseObjectPath = "/xyz/openbmc_project/certs";
7689492a15SPatrick Williams constexpr const char* httpsObjectPath =
77c6a8dfb1SJiaqing Zhao     "/xyz/openbmc_project/certs/server/https";
7889492a15SPatrick Williams constexpr const char* ldapObjectPath = "/xyz/openbmc_project/certs/client/ldap";
7989492a15SPatrick Williams constexpr const char* authorityObjectPath =
80b2254ccdSMichal Orzel     "/xyz/openbmc_project/certs/authority/truststore";
815968caeeSMarri Devender Rao } // namespace certs
825968caeeSMarri Devender Rao 
835968caeeSMarri Devender Rao /**
845968caeeSMarri Devender Rao  * The Certificate schema defines a Certificate Service which represents the
855968caeeSMarri Devender Rao  * actions available to manage certificates and links to where certificates
865968caeeSMarri Devender Rao  * are installed.
875968caeeSMarri Devender Rao  */
887e860f15SJohn Edward Broadbent 
898d1b46d7Szhanghch05 inline std::string getCertificateFromReqBody(
908d1b46d7Szhanghch05     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
9158eb238fSKowalski, Kamil     const crow::Request& req)
9258eb238fSKowalski, Kamil {
931aa0c2b8SEd Tanous     nlohmann::json reqJson;
941aa0c2b8SEd Tanous     JsonParseResult ret = parseRequestAsJson(req, reqJson);
951aa0c2b8SEd Tanous     if (ret != JsonParseResult::Success)
9658eb238fSKowalski, Kamil     {
9758eb238fSKowalski, Kamil         // We did not receive JSON request, proceed as it is RAW data
9833c6b580SEd Tanous         return req.body();
9958eb238fSKowalski, Kamil     }
10058eb238fSKowalski, Kamil 
10158eb238fSKowalski, Kamil     std::string certificate;
10258eb238fSKowalski, Kamil     std::optional<std::string> certificateType = "PEM";
10358eb238fSKowalski, Kamil 
104afc474aeSMyung Bae     if (!json_util::readJsonPatch( //
105afc474aeSMyung Bae             req, asyncResp->res, //
106afc474aeSMyung Bae             "CertificateString", certificate, //
107afc474aeSMyung Bae             "CertificateType", certificateType //
108afc474aeSMyung Bae             ))
10958eb238fSKowalski, Kamil     {
11062598e31SEd Tanous         BMCWEB_LOG_ERROR("Required parameters are missing");
11158eb238fSKowalski, Kamil         messages::internalError(asyncResp->res);
112abb93cddSEd Tanous         return {};
11358eb238fSKowalski, Kamil     }
11458eb238fSKowalski, Kamil 
11558eb238fSKowalski, Kamil     if (*certificateType != "PEM")
11658eb238fSKowalski, Kamil     {
11758eb238fSKowalski, Kamil         messages::propertyValueNotInList(asyncResp->res, *certificateType,
11858eb238fSKowalski, Kamil                                          "CertificateType");
119abb93cddSEd Tanous         return {};
12058eb238fSKowalski, Kamil     }
12158eb238fSKowalski, Kamil 
12258eb238fSKowalski, Kamil     return certificate;
12358eb238fSKowalski, Kamil }
12458eb238fSKowalski, Kamil 
1255968caeeSMarri Devender Rao /**
1265968caeeSMarri Devender Rao  * Class to create a temporary certificate file for uploading to system
1275968caeeSMarri Devender Rao  */
1285968caeeSMarri Devender Rao class CertificateFile
1295968caeeSMarri Devender Rao {
1305968caeeSMarri Devender Rao   public:
1315968caeeSMarri Devender Rao     CertificateFile() = delete;
1325968caeeSMarri Devender Rao     CertificateFile(const CertificateFile&) = delete;
1335968caeeSMarri Devender Rao     CertificateFile& operator=(const CertificateFile&) = delete;
1345968caeeSMarri Devender Rao     CertificateFile(CertificateFile&&) = delete;
1355968caeeSMarri Devender Rao     CertificateFile& operator=(CertificateFile&&) = delete;
1364e23a444SEd Tanous     explicit CertificateFile(const std::string& certString)
1375968caeeSMarri Devender Rao     {
13872d52d25SEd Tanous         std::array<char, 18> dirTemplate = {'/', 't', 'm', 'p', '/', 'C',
1395207438cSEd Tanous                                             'e', 'r', 't', 's', '.', 'X',
1405207438cSEd Tanous                                             'X', 'X', 'X', 'X', 'X', '\0'};
141*92e11bf8SMyung Bae         // NOLINTNEXTLINE(misc-include-cleaner)
1425207438cSEd Tanous         char* tempDirectory = mkdtemp(dirTemplate.data());
143e662eae8SEd Tanous         if (tempDirectory != nullptr)
1445968caeeSMarri Devender Rao         {
1455968caeeSMarri Devender Rao             certDirectory = tempDirectory;
1465968caeeSMarri Devender Rao             certificateFile = certDirectory / "cert.pem";
147bd79bce8SPatrick Williams             std::ofstream out(certificateFile,
148bd79bce8SPatrick Williams                               std::ofstream::out | std::ofstream::binary |
1495968caeeSMarri Devender Rao                                   std::ofstream::trunc);
1505968caeeSMarri Devender Rao             out << certString;
1515968caeeSMarri Devender Rao             out.close();
15262598e31SEd Tanous             BMCWEB_LOG_DEBUG("Creating certificate file{}",
15362598e31SEd Tanous                              certificateFile.string());
1545968caeeSMarri Devender Rao         }
1555968caeeSMarri Devender Rao     }
1565968caeeSMarri Devender Rao     ~CertificateFile()
1575968caeeSMarri Devender Rao     {
1585968caeeSMarri Devender Rao         if (std::filesystem::exists(certDirectory))
1595968caeeSMarri Devender Rao         {
16062598e31SEd Tanous             BMCWEB_LOG_DEBUG("Removing certificate file{}",
16162598e31SEd Tanous                              certificateFile.string());
16223a21a1cSEd Tanous             std::error_code ec;
16323a21a1cSEd Tanous             std::filesystem::remove_all(certDirectory, ec);
16423a21a1cSEd Tanous             if (ec)
1655968caeeSMarri Devender Rao             {
16662598e31SEd Tanous                 BMCWEB_LOG_ERROR("Failed to remove temp directory{}",
16762598e31SEd Tanous                                  certDirectory.string());
1685968caeeSMarri Devender Rao             }
1695968caeeSMarri Devender Rao         }
1705968caeeSMarri Devender Rao     }
1715968caeeSMarri Devender Rao     std::string getCertFilePath()
1725968caeeSMarri Devender Rao     {
1735968caeeSMarri Devender Rao         return certificateFile;
1745968caeeSMarri Devender Rao     }
1755968caeeSMarri Devender Rao 
1765968caeeSMarri Devender Rao   private:
1775968caeeSMarri Devender Rao     std::filesystem::path certificateFile;
1785968caeeSMarri Devender Rao     std::filesystem::path certDirectory;
1795968caeeSMarri Devender Rao };
1805968caeeSMarri Devender Rao 
1815968caeeSMarri Devender Rao /**
1824e0453b1SGunnar Mills  * @brief Parse and update Certificate Issue/Subject property
1835968caeeSMarri Devender Rao  *
1845968caeeSMarri Devender Rao  * @param[in] asyncResp Shared pointer to the response message
1855968caeeSMarri Devender Rao  * @param[in] str  Issuer/Subject value in key=value pairs
1865968caeeSMarri Devender Rao  * @param[in] type Issuer/Subject
1875968caeeSMarri Devender Rao  * @return None
1885968caeeSMarri Devender Rao  */
1894ff0f1f4SEd Tanous inline void updateCertIssuerOrSubject(nlohmann::json& out,
19026ccae32SEd Tanous                                       std::string_view value)
1915968caeeSMarri Devender Rao {
1925968caeeSMarri Devender Rao     // example: O=openbmc-project.xyz,CN=localhost
1935968caeeSMarri Devender Rao     std::string_view::iterator i = value.begin();
1945968caeeSMarri Devender Rao     while (i != value.end())
1955968caeeSMarri Devender Rao     {
1965968caeeSMarri Devender Rao         std::string_view::iterator tokenBegin = i;
1975968caeeSMarri Devender Rao         while (i != value.end() && *i != '=')
1985968caeeSMarri Devender Rao         {
1996da47babSPatrick Williams             std::advance(i, 1);
2005968caeeSMarri Devender Rao         }
2015968caeeSMarri Devender Rao         if (i == value.end())
2025968caeeSMarri Devender Rao         {
2035968caeeSMarri Devender Rao             break;
2045968caeeSMarri Devender Rao         }
20526ccae32SEd Tanous         std::string_view key(tokenBegin, static_cast<size_t>(i - tokenBegin));
2066da47babSPatrick Williams         std::advance(i, 1);
2075968caeeSMarri Devender Rao         tokenBegin = i;
2085968caeeSMarri Devender Rao         while (i != value.end() && *i != ',')
2095968caeeSMarri Devender Rao         {
2106da47babSPatrick Williams             std::advance(i, 1);
2115968caeeSMarri Devender Rao         }
21226ccae32SEd Tanous         std::string_view val(tokenBegin, static_cast<size_t>(i - tokenBegin));
2135968caeeSMarri Devender Rao         if (key == "L")
2145968caeeSMarri Devender Rao         {
2155968caeeSMarri Devender Rao             out["City"] = val;
2165968caeeSMarri Devender Rao         }
2175968caeeSMarri Devender Rao         else if (key == "CN")
2185968caeeSMarri Devender Rao         {
2195968caeeSMarri Devender Rao             out["CommonName"] = val;
2205968caeeSMarri Devender Rao         }
2215968caeeSMarri Devender Rao         else if (key == "C")
2225968caeeSMarri Devender Rao         {
2235968caeeSMarri Devender Rao             out["Country"] = val;
2245968caeeSMarri Devender Rao         }
2255968caeeSMarri Devender Rao         else if (key == "O")
2265968caeeSMarri Devender Rao         {
2275968caeeSMarri Devender Rao             out["Organization"] = val;
2285968caeeSMarri Devender Rao         }
2295968caeeSMarri Devender Rao         else if (key == "OU")
2305968caeeSMarri Devender Rao         {
2315968caeeSMarri Devender Rao             out["OrganizationalUnit"] = val;
2325968caeeSMarri Devender Rao         }
2335968caeeSMarri Devender Rao         else if (key == "ST")
2345968caeeSMarri Devender Rao         {
2355968caeeSMarri Devender Rao             out["State"] = val;
2365968caeeSMarri Devender Rao         }
2375968caeeSMarri Devender Rao         // skip comma character
2385968caeeSMarri Devender Rao         if (i != value.end())
2395968caeeSMarri Devender Rao         {
2406da47babSPatrick Williams             std::advance(i, 1);
2415968caeeSMarri Devender Rao         }
2425968caeeSMarri Devender Rao     }
2435968caeeSMarri Devender Rao }
2445968caeeSMarri Devender Rao 
2455968caeeSMarri Devender Rao /**
246d3f92ce7SJiaqing Zhao  * @brief Retrieve the installed certificate list
247d3f92ce7SJiaqing Zhao  *
248d3f92ce7SJiaqing Zhao  * @param[in] asyncResp Shared pointer to the response message
249d3f92ce7SJiaqing Zhao  * @param[in] basePath DBus object path to search
250d3f92ce7SJiaqing Zhao  * @param[in] listPtr Json pointer to the list in asyncResp
251d3f92ce7SJiaqing Zhao  * @param[in] countPtr Json pointer to the count in asyncResp
252d3f92ce7SJiaqing Zhao  * @return None
253d3f92ce7SJiaqing Zhao  */
2544ff0f1f4SEd Tanous inline void getCertificateList(
255bd79bce8SPatrick Williams     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
256bd79bce8SPatrick Williams     const std::string& basePath, const nlohmann::json::json_pointer& listPtr,
257d3f92ce7SJiaqing Zhao     const nlohmann::json::json_pointer& countPtr)
258d3f92ce7SJiaqing Zhao {
2597a1dbc48SGeorge Liu     constexpr std::array<std::string_view, 1> interfaces = {
2607a1dbc48SGeorge Liu         certs::certPropIntf};
2617a1dbc48SGeorge Liu     dbus::utility::getSubTreePaths(
2627a1dbc48SGeorge Liu         basePath, 0, interfaces,
263d3f92ce7SJiaqing Zhao         [asyncResp, listPtr, countPtr](
2647a1dbc48SGeorge Liu             const boost::system::error_code& ec,
265d3f92ce7SJiaqing Zhao             const dbus::utility::MapperGetSubTreePathsResponse& certPaths) {
266d3f92ce7SJiaqing Zhao             if (ec)
267d3f92ce7SJiaqing Zhao             {
26862598e31SEd Tanous                 BMCWEB_LOG_ERROR("Certificate collection query failed: {}", ec);
269d3f92ce7SJiaqing Zhao                 messages::internalError(asyncResp->res);
270d3f92ce7SJiaqing Zhao                 return;
271d3f92ce7SJiaqing Zhao             }
272d3f92ce7SJiaqing Zhao 
273d3f92ce7SJiaqing Zhao             nlohmann::json& links = asyncResp->res.jsonValue[listPtr];
274d3f92ce7SJiaqing Zhao             links = nlohmann::json::array();
275d3f92ce7SJiaqing Zhao             for (const auto& certPath : certPaths)
276d3f92ce7SJiaqing Zhao             {
277d3f92ce7SJiaqing Zhao                 sdbusplus::message::object_path objPath(certPath);
278d3f92ce7SJiaqing Zhao                 std::string certId = objPath.filename();
279d3f92ce7SJiaqing Zhao                 if (certId.empty())
280d3f92ce7SJiaqing Zhao                 {
281bd79bce8SPatrick Williams                     BMCWEB_LOG_ERROR("Invalid certificate objPath {}",
282bd79bce8SPatrick Williams                                      certPath);
283d3f92ce7SJiaqing Zhao                     continue;
284d3f92ce7SJiaqing Zhao                 }
285d3f92ce7SJiaqing Zhao 
286d3f92ce7SJiaqing Zhao                 boost::urls::url certURL;
287d3f92ce7SJiaqing Zhao                 if (objPath.parent_path() == certs::httpsObjectPath)
288d3f92ce7SJiaqing Zhao                 {
289ef4c65b7SEd Tanous                     certURL = boost::urls::format(
290253f11b8SEd Tanous                         "/redfish/v1/Managers/{}/NetworkProtocol/HTTPS/Certificates/{}",
291253f11b8SEd Tanous                         BMCWEB_REDFISH_MANAGER_URI_NAME, certId);
292d3f92ce7SJiaqing Zhao                 }
293d3f92ce7SJiaqing Zhao                 else if (objPath.parent_path() == certs::ldapObjectPath)
294d3f92ce7SJiaqing Zhao                 {
295ef4c65b7SEd Tanous                     certURL = boost::urls::format(
296bd79bce8SPatrick Williams                         "/redfish/v1/AccountService/LDAP/Certificates/{}",
297bd79bce8SPatrick Williams                         certId);
298d3f92ce7SJiaqing Zhao                 }
299d3f92ce7SJiaqing Zhao                 else if (objPath.parent_path() == certs::authorityObjectPath)
300d3f92ce7SJiaqing Zhao                 {
301ef4c65b7SEd Tanous                     certURL = boost::urls::format(
302253f11b8SEd Tanous                         "/redfish/v1/Managers/{}/Truststore/Certificates/{}",
303253f11b8SEd Tanous                         BMCWEB_REDFISH_MANAGER_URI_NAME, certId);
304d3f92ce7SJiaqing Zhao                 }
305d3f92ce7SJiaqing Zhao                 else
306d3f92ce7SJiaqing Zhao                 {
307d3f92ce7SJiaqing Zhao                     continue;
308d3f92ce7SJiaqing Zhao                 }
309d3f92ce7SJiaqing Zhao 
310d3f92ce7SJiaqing Zhao                 nlohmann::json::object_t link;
311d3f92ce7SJiaqing Zhao                 link["@odata.id"] = certURL;
312d3f92ce7SJiaqing Zhao                 links.emplace_back(std::move(link));
313d3f92ce7SJiaqing Zhao             }
314d3f92ce7SJiaqing Zhao 
315d3f92ce7SJiaqing Zhao             asyncResp->res.jsonValue[countPtr] = links.size();
3167a1dbc48SGeorge Liu         });
317d3f92ce7SJiaqing Zhao }
318d3f92ce7SJiaqing Zhao 
319d3f92ce7SJiaqing Zhao /**
3205968caeeSMarri Devender Rao  * @brief Retrieve the certificates properties and append to the response
3215968caeeSMarri Devender Rao  * message
3225968caeeSMarri Devender Rao  *
3235968caeeSMarri Devender Rao  * @param[in] asyncResp Shared pointer to the response message
3245968caeeSMarri Devender Rao  * @param[in] objectPath  Path of the D-Bus service object
3255968caeeSMarri Devender Rao  * @param[in] certId  Id of the certificate
3265968caeeSMarri Devender Rao  * @param[in] certURL  URL of the certificate object
3275968caeeSMarri Devender Rao  * @param[in] name  name of the certificate
3285968caeeSMarri Devender Rao  * @return None
3295968caeeSMarri Devender Rao  */
3304ff0f1f4SEd Tanous inline void getCertificateProperties(
3318d1b46d7Szhanghch05     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
332e19e97e2SJiaqing Zhao     const std::string& objectPath, const std::string& service,
3331e312598SJiaqing Zhao     const std::string& certId, const boost::urls::url& certURL,
334e19e97e2SJiaqing Zhao     const std::string& name)
3355968caeeSMarri Devender Rao {
33662598e31SEd Tanous     BMCWEB_LOG_DEBUG("getCertificateProperties Path={} certId={} certURl={}",
33762598e31SEd Tanous                      objectPath, certId, certURL);
338deae6a78SEd Tanous     dbus::utility::getAllProperties(
339deae6a78SEd Tanous         service, objectPath, certs::certPropIntf,
340b9d36b47SEd Tanous         [asyncResp, certURL, certId,
3415e7e2dc5SEd Tanous          name](const boost::system::error_code& ec,
342b9d36b47SEd Tanous                const dbus::utility::DBusPropertiesMap& properties) {
3435968caeeSMarri Devender Rao             if (ec)
3445968caeeSMarri Devender Rao             {
34562598e31SEd Tanous                 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
346bd79bce8SPatrick Williams                 messages::resourceNotFound(asyncResp->res, "Certificate",
347bd79bce8SPatrick Williams                                            certId);
3485968caeeSMarri Devender Rao                 return;
3495968caeeSMarri Devender Rao             }
3509b12d1f9SKrzysztof Grobelny 
3519b12d1f9SKrzysztof Grobelny             const std::string* certificateString = nullptr;
3529b12d1f9SKrzysztof Grobelny             const std::vector<std::string>* keyUsage = nullptr;
3539b12d1f9SKrzysztof Grobelny             const std::string* issuer = nullptr;
3549b12d1f9SKrzysztof Grobelny             const std::string* subject = nullptr;
3559b12d1f9SKrzysztof Grobelny             const uint64_t* validNotAfter = nullptr;
3569b12d1f9SKrzysztof Grobelny             const uint64_t* validNotBefore = nullptr;
3579b12d1f9SKrzysztof Grobelny 
3589b12d1f9SKrzysztof Grobelny             const bool success = sdbusplus::unpackPropertiesNoThrow(
359bd79bce8SPatrick Williams                 dbus_utils::UnpackErrorPrinter(), properties,
360bd79bce8SPatrick Williams                 "CertificateString", certificateString, "KeyUsage", keyUsage,
361bd79bce8SPatrick Williams                 "Issuer", issuer, "Subject", subject, "ValidNotAfter",
362bd79bce8SPatrick Williams                 validNotAfter, "ValidNotBefore", validNotBefore);
3639b12d1f9SKrzysztof Grobelny 
3649b12d1f9SKrzysztof Grobelny             if (!success)
3659b12d1f9SKrzysztof Grobelny             {
3669b12d1f9SKrzysztof Grobelny                 messages::internalError(asyncResp->res);
3679b12d1f9SKrzysztof Grobelny                 return;
3689b12d1f9SKrzysztof Grobelny             }
3699b12d1f9SKrzysztof Grobelny 
3701476687dSEd Tanous             asyncResp->res.jsonValue["@odata.id"] = certURL;
3711476687dSEd Tanous             asyncResp->res.jsonValue["@odata.type"] =
3721476687dSEd Tanous                 "#Certificate.v1_0_0.Certificate";
373e19e97e2SJiaqing Zhao             asyncResp->res.jsonValue["Id"] = certId;
3741476687dSEd Tanous             asyncResp->res.jsonValue["Name"] = name;
3751476687dSEd Tanous             asyncResp->res.jsonValue["Description"] = name;
3765968caeeSMarri Devender Rao             asyncResp->res.jsonValue["CertificateString"] = "";
3779b12d1f9SKrzysztof Grobelny             asyncResp->res.jsonValue["KeyUsage"] = nlohmann::json::array();
3789b12d1f9SKrzysztof Grobelny 
3799b12d1f9SKrzysztof Grobelny             if (certificateString != nullptr)
3805968caeeSMarri Devender Rao             {
381bd79bce8SPatrick Williams                 asyncResp->res.jsonValue["CertificateString"] =
382bd79bce8SPatrick Williams                     *certificateString;
3835968caeeSMarri Devender Rao             }
3849b12d1f9SKrzysztof Grobelny 
3859b12d1f9SKrzysztof Grobelny             if (keyUsage != nullptr)
3865968caeeSMarri Devender Rao             {
3879b12d1f9SKrzysztof Grobelny                 asyncResp->res.jsonValue["KeyUsage"] = *keyUsage;
3885968caeeSMarri Devender Rao             }
3899b12d1f9SKrzysztof Grobelny 
3909b12d1f9SKrzysztof Grobelny             if (issuer != nullptr)
3915968caeeSMarri Devender Rao             {
3929b12d1f9SKrzysztof Grobelny                 updateCertIssuerOrSubject(asyncResp->res.jsonValue["Issuer"],
3939b12d1f9SKrzysztof Grobelny                                           *issuer);
3945968caeeSMarri Devender Rao             }
3959b12d1f9SKrzysztof Grobelny 
3969b12d1f9SKrzysztof Grobelny             if (subject != nullptr)
3975968caeeSMarri Devender Rao             {
3989b12d1f9SKrzysztof Grobelny                 updateCertIssuerOrSubject(asyncResp->res.jsonValue["Subject"],
3999b12d1f9SKrzysztof Grobelny                                           *subject);
4005968caeeSMarri Devender Rao             }
4019b12d1f9SKrzysztof Grobelny 
4029b12d1f9SKrzysztof Grobelny             if (validNotAfter != nullptr)
4035968caeeSMarri Devender Rao             {
4045968caeeSMarri Devender Rao                 asyncResp->res.jsonValue["ValidNotAfter"] =
4059b12d1f9SKrzysztof Grobelny                     redfish::time_utils::getDateTimeUint(*validNotAfter);
4065968caeeSMarri Devender Rao             }
4079b12d1f9SKrzysztof Grobelny 
4089b12d1f9SKrzysztof Grobelny             if (validNotBefore != nullptr)
4095968caeeSMarri Devender Rao             {
4105968caeeSMarri Devender Rao                 asyncResp->res.jsonValue["ValidNotBefore"] =
4119b12d1f9SKrzysztof Grobelny                     redfish::time_utils::getDateTimeUint(*validNotBefore);
4125968caeeSMarri Devender Rao             }
4139b12d1f9SKrzysztof Grobelny 
4141e312598SJiaqing Zhao             asyncResp->res.addHeader(
415d9f6c621SEd Tanous                 boost::beast::http::field::location,
416d9f6c621SEd Tanous                 std::string_view(certURL.data(), certURL.size()));
4179b12d1f9SKrzysztof Grobelny         });
4185968caeeSMarri Devender Rao }
4195968caeeSMarri Devender Rao 
4204ff0f1f4SEd Tanous inline void
4217a3a8f7aSJiaqing Zhao     deleteCertificate(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
4227a3a8f7aSJiaqing Zhao                       const std::string& service,
4237a3a8f7aSJiaqing Zhao                       const sdbusplus::message::object_path& objectPath)
4247a3a8f7aSJiaqing Zhao {
4257a3a8f7aSJiaqing Zhao     crow::connections::systemBus->async_method_call(
4267a3a8f7aSJiaqing Zhao         [asyncResp,
4275e7e2dc5SEd Tanous          id{objectPath.filename()}](const boost::system::error_code& ec) {
4287a3a8f7aSJiaqing Zhao             if (ec)
4297a3a8f7aSJiaqing Zhao             {
4307a3a8f7aSJiaqing Zhao                 messages::resourceNotFound(asyncResp->res, "Certificate", id);
4317a3a8f7aSJiaqing Zhao                 return;
4327a3a8f7aSJiaqing Zhao             }
43362598e31SEd Tanous             BMCWEB_LOG_INFO("Certificate deleted");
4347a3a8f7aSJiaqing Zhao             asyncResp->res.result(boost::beast::http::status::no_content);
4357a3a8f7aSJiaqing Zhao         },
4367a3a8f7aSJiaqing Zhao         service, objectPath, certs::objDeleteIntf, "Delete");
4377a3a8f7aSJiaqing Zhao }
4387a3a8f7aSJiaqing Zhao 
439828252d5SJiaqing Zhao inline void handleCertificateServiceGet(
440828252d5SJiaqing Zhao     App& app, const crow::Request& req,
441828252d5SJiaqing Zhao     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
4425968caeeSMarri Devender Rao {
443828252d5SJiaqing Zhao     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
444828252d5SJiaqing Zhao     {
445828252d5SJiaqing Zhao         return;
446828252d5SJiaqing Zhao     }
447828252d5SJiaqing Zhao 
4483e72c202SNinad Palsule     if (req.session == nullptr)
4493e72c202SNinad Palsule     {
4503e72c202SNinad Palsule         messages::internalError(asyncResp->res);
4513e72c202SNinad Palsule         return;
4523e72c202SNinad Palsule     }
4533e72c202SNinad Palsule 
454828252d5SJiaqing Zhao     asyncResp->res.jsonValue["@odata.type"] =
455828252d5SJiaqing Zhao         "#CertificateService.v1_0_0.CertificateService";
456828252d5SJiaqing Zhao     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/CertificateService";
457828252d5SJiaqing Zhao     asyncResp->res.jsonValue["Id"] = "CertificateService";
458828252d5SJiaqing Zhao     asyncResp->res.jsonValue["Name"] = "Certificate Service";
459828252d5SJiaqing Zhao     asyncResp->res.jsonValue["Description"] =
460828252d5SJiaqing Zhao         "Actions available to manage certificates";
461828252d5SJiaqing Zhao     // /redfish/v1/CertificateService/CertificateLocations is something
462828252d5SJiaqing Zhao     // only ConfigureManager can access then only display when the user
463828252d5SJiaqing Zhao     // has permissions ConfigureManager
464828252d5SJiaqing Zhao     Privileges effectiveUserPrivileges =
4653e72c202SNinad Palsule         redfish::getUserPrivileges(*req.session);
466828252d5SJiaqing Zhao     if (isOperationAllowedWithPrivileges({{"ConfigureManager"}},
467828252d5SJiaqing Zhao                                          effectiveUserPrivileges))
468828252d5SJiaqing Zhao     {
469828252d5SJiaqing Zhao         asyncResp->res.jsonValue["CertificateLocations"]["@odata.id"] =
470828252d5SJiaqing Zhao             "/redfish/v1/CertificateService/CertificateLocations";
471828252d5SJiaqing Zhao     }
472828252d5SJiaqing Zhao     nlohmann::json& actions = asyncResp->res.jsonValue["Actions"];
473828252d5SJiaqing Zhao     nlohmann::json& replace = actions["#CertificateService.ReplaceCertificate"];
474828252d5SJiaqing Zhao     replace["target"] =
475828252d5SJiaqing Zhao         "/redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate";
476828252d5SJiaqing Zhao     nlohmann::json::array_t allowed;
477ad539545SPatrick Williams     allowed.emplace_back("PEM");
478828252d5SJiaqing Zhao     replace["CertificateType@Redfish.AllowableValues"] = std::move(allowed);
479828252d5SJiaqing Zhao     actions["#CertificateService.GenerateCSR"]["target"] =
480828252d5SJiaqing Zhao         "/redfish/v1/CertificateService/Actions/CertificateService.GenerateCSR";
481828252d5SJiaqing Zhao }
482828252d5SJiaqing Zhao 
483828252d5SJiaqing Zhao inline void handleCertificateLocationsGet(
484828252d5SJiaqing Zhao     App& app, const crow::Request& req,
485828252d5SJiaqing Zhao     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
486828252d5SJiaqing Zhao {
487828252d5SJiaqing Zhao     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
488828252d5SJiaqing Zhao     {
489828252d5SJiaqing Zhao         return;
490828252d5SJiaqing Zhao     }
491828252d5SJiaqing Zhao     asyncResp->res.jsonValue["@odata.id"] =
492828252d5SJiaqing Zhao         "/redfish/v1/CertificateService/CertificateLocations";
493828252d5SJiaqing Zhao     asyncResp->res.jsonValue["@odata.type"] =
494828252d5SJiaqing Zhao         "#CertificateLocations.v1_0_0.CertificateLocations";
495828252d5SJiaqing Zhao     asyncResp->res.jsonValue["Name"] = "Certificate Locations";
496828252d5SJiaqing Zhao     asyncResp->res.jsonValue["Id"] = "CertificateLocations";
497828252d5SJiaqing Zhao     asyncResp->res.jsonValue["Description"] =
498828252d5SJiaqing Zhao         "Defines a resource that an administrator can use in order to "
499828252d5SJiaqing Zhao         "locate all certificates installed on a given service";
500828252d5SJiaqing Zhao 
501828252d5SJiaqing Zhao     getCertificateList(asyncResp, certs::baseObjectPath,
502828252d5SJiaqing Zhao                        "/Links/Certificates"_json_pointer,
503828252d5SJiaqing Zhao                        "/Links/Certificates@odata.count"_json_pointer);
504828252d5SJiaqing Zhao }
505828252d5SJiaqing Zhao 
50626d3b0fbSChandra Harkude inline void handleError(const std::string_view dbusErrorName,
50726d3b0fbSChandra Harkude                         const std::string& id, const std::string& certificate,
50826d3b0fbSChandra Harkude                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
50926d3b0fbSChandra Harkude {
51026d3b0fbSChandra Harkude     if (dbusErrorName == "org.freedesktop.DBus.Error.UnknownObject")
51126d3b0fbSChandra Harkude     {
51226d3b0fbSChandra Harkude         messages::resourceNotFound(asyncResp->res, "Certificate", id);
51326d3b0fbSChandra Harkude     }
51426d3b0fbSChandra Harkude     else if (dbusErrorName ==
51526d3b0fbSChandra Harkude              "xyz.openbmc_project.Certs.Error.InvalidCertificate")
51626d3b0fbSChandra Harkude     {
51726d3b0fbSChandra Harkude         messages::propertyValueIncorrect(asyncResp->res, "Certificate",
51826d3b0fbSChandra Harkude                                          certificate);
51926d3b0fbSChandra Harkude     }
52026d3b0fbSChandra Harkude     else
52126d3b0fbSChandra Harkude     {
52226d3b0fbSChandra Harkude         messages::internalError(asyncResp->res);
52326d3b0fbSChandra Harkude     }
52426d3b0fbSChandra Harkude }
52526d3b0fbSChandra Harkude 
526828252d5SJiaqing Zhao inline void handleReplaceCertificateAction(
527828252d5SJiaqing Zhao     App& app, const crow::Request& req,
528828252d5SJiaqing Zhao     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
529828252d5SJiaqing Zhao {
5303ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
53145ca1b86SEd Tanous     {
53245ca1b86SEd Tanous         return;
53345ca1b86SEd Tanous     }
5345968caeeSMarri Devender Rao     std::string certificate;
5357a31e336SEd Tanous     std::string certURI;
5365968caeeSMarri Devender Rao     std::optional<std::string> certificateType = "PEM";
5378d1b46d7Szhanghch05 
538afc474aeSMyung Bae     if (!json_util::readJsonAction( //
539afc474aeSMyung Bae             req, asyncResp->res, //
540afc474aeSMyung Bae             "CertificateString", certificate, //
541afc474aeSMyung Bae             "CertificateType", certificateType, //
542afc474aeSMyung Bae             "CertificateUri/@odata.id", certURI //
543afc474aeSMyung Bae             ))
5445968caeeSMarri Devender Rao     {
54562598e31SEd Tanous         BMCWEB_LOG_ERROR("Required parameters are missing");
5465968caeeSMarri Devender Rao         return;
5475968caeeSMarri Devender Rao     }
5485968caeeSMarri Devender Rao 
5495968caeeSMarri Devender Rao     if (!certificateType)
5505968caeeSMarri Devender Rao     {
5515968caeeSMarri Devender Rao         // should never happen, but it never hurts to be paranoid.
5525968caeeSMarri Devender Rao         return;
5535968caeeSMarri Devender Rao     }
5545968caeeSMarri Devender Rao     if (certificateType != "PEM")
5555968caeeSMarri Devender Rao     {
556828252d5SJiaqing Zhao         messages::actionParameterNotSupported(asyncResp->res, "CertificateType",
557828252d5SJiaqing Zhao                                               "ReplaceCertificate");
5585968caeeSMarri Devender Rao         return;
5595968caeeSMarri Devender Rao     }
5605968caeeSMarri Devender Rao 
56162598e31SEd Tanous     BMCWEB_LOG_INFO("Certificate URI to replace: {}", certURI);
5625968caeeSMarri Devender Rao 
5636fd29553SEd Tanous     boost::system::result<boost::urls::url> parsedUrl =
56475b63a2cSJiaqing Zhao         boost::urls::parse_relative_ref(certURI);
56575b63a2cSJiaqing Zhao     if (!parsedUrl)
5665968caeeSMarri Devender Rao     {
567828252d5SJiaqing Zhao         messages::actionParameterValueFormatError(
568828252d5SJiaqing Zhao             asyncResp->res, certURI, "CertificateUri", "ReplaceCertificate");
5695968caeeSMarri Devender Rao         return;
5705968caeeSMarri Devender Rao     }
57175b63a2cSJiaqing Zhao 
57275b63a2cSJiaqing Zhao     std::string id;
57375b63a2cSJiaqing Zhao     sdbusplus::message::object_path objectPath;
5745968caeeSMarri Devender Rao     std::string name;
57537cce918SMarri Devender Rao     std::string service;
576828252d5SJiaqing Zhao     if (crow::utility::readUrlSegments(*parsedUrl, "redfish", "v1", "Managers",
577828252d5SJiaqing Zhao                                        "bmc", "NetworkProtocol", "HTTPS",
578828252d5SJiaqing Zhao                                        "Certificates", std::ref(id)))
5795968caeeSMarri Devender Rao     {
58089492a15SPatrick Williams         objectPath = sdbusplus::message::object_path(certs::httpsObjectPath) /
58189492a15SPatrick Williams                      id;
5825968caeeSMarri Devender Rao         name = "HTTPS certificate";
58337cce918SMarri Devender Rao         service = certs::httpsServiceName;
58437cce918SMarri Devender Rao     }
58575b63a2cSJiaqing Zhao     else if (crow::utility::readUrlSegments(*parsedUrl, "redfish", "v1",
58675b63a2cSJiaqing Zhao                                             "AccountService", "LDAP",
58775b63a2cSJiaqing Zhao                                             "Certificates", std::ref(id)))
58837cce918SMarri Devender Rao     {
58989492a15SPatrick Williams         objectPath = sdbusplus::message::object_path(certs::ldapObjectPath) /
59089492a15SPatrick Williams                      id;
59137cce918SMarri Devender Rao         name = "LDAP certificate";
59237cce918SMarri Devender Rao         service = certs::ldapServiceName;
5935968caeeSMarri Devender Rao     }
59475b63a2cSJiaqing Zhao     else if (crow::utility::readUrlSegments(*parsedUrl, "redfish", "v1",
59575b63a2cSJiaqing Zhao                                             "Managers", "bmc", "Truststore",
59675b63a2cSJiaqing Zhao                                             "Certificates", std::ref(id)))
597cfcd5f6bSMarri Devender Rao     {
59875b63a2cSJiaqing Zhao         objectPath =
599828252d5SJiaqing Zhao             sdbusplus::message::object_path(certs::authorityObjectPath) / id;
600cfcd5f6bSMarri Devender Rao         name = "TrustStore certificate";
601cfcd5f6bSMarri Devender Rao         service = certs::authorityServiceName;
602cfcd5f6bSMarri Devender Rao     }
6035968caeeSMarri Devender Rao     else
6045968caeeSMarri Devender Rao     {
605828252d5SJiaqing Zhao         messages::actionParameterNotSupported(asyncResp->res, "CertificateUri",
606828252d5SJiaqing Zhao                                               "ReplaceCertificate");
6075968caeeSMarri Devender Rao         return;
6085968caeeSMarri Devender Rao     }
6095968caeeSMarri Devender Rao 
6105968caeeSMarri Devender Rao     std::shared_ptr<CertificateFile> certFile =
6115968caeeSMarri Devender Rao         std::make_shared<CertificateFile>(certificate);
6125968caeeSMarri Devender Rao     crow::connections::systemBus->async_method_call(
61326d3b0fbSChandra Harkude         [asyncResp, certFile, objectPath, service, url{*parsedUrl}, id, name,
61426d3b0fbSChandra Harkude          certificate](const boost::system::error_code& ec,
615d3e0859cSPatrick Williams                       sdbusplus::message_t& m) {
6165968caeeSMarri Devender Rao             if (ec)
6175968caeeSMarri Devender Rao             {
61862598e31SEd Tanous                 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
61926d3b0fbSChandra Harkude                 const sd_bus_error* dbusError = m.get_error();
62026d3b0fbSChandra Harkude                 if ((dbusError != nullptr) && (dbusError->name != nullptr))
62190d2d1e8SJiaqing Zhao                 {
62226d3b0fbSChandra Harkude                     handleError(dbusError->name, id, certificate, asyncResp);
6235968caeeSMarri Devender Rao                 }
62426d3b0fbSChandra Harkude                 else
62526d3b0fbSChandra Harkude                 {
62690d2d1e8SJiaqing Zhao                     messages::internalError(asyncResp->res);
62726d3b0fbSChandra Harkude                 }
62890d2d1e8SJiaqing Zhao                 return;
62990d2d1e8SJiaqing Zhao             }
630bd79bce8SPatrick Williams             getCertificateProperties(asyncResp, objectPath, service, id, url,
631bd79bce8SPatrick Williams                                      name);
63262598e31SEd Tanous             BMCWEB_LOG_DEBUG("HTTPS certificate install file={}",
63362598e31SEd Tanous                              certFile->getCertFilePath());
6345968caeeSMarri Devender Rao         },
6355968caeeSMarri Devender Rao         service, objectPath, certs::certReplaceIntf, "Replace",
6365968caeeSMarri Devender Rao         certFile->getCertFilePath());
637828252d5SJiaqing Zhao }
6385968caeeSMarri Devender Rao 
639cf9e417dSEd Tanous // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
640828252d5SJiaqing Zhao static std::unique_ptr<sdbusplus::bus::match_t> csrMatcher;
6415968caeeSMarri Devender Rao /**
642828252d5SJiaqing Zhao  * @brief Read data from CSR D-bus object and set to response
643828252d5SJiaqing Zhao  *
644828252d5SJiaqing Zhao  * @param[in] asyncResp Shared pointer to the response message
6458ece0e45SEd Tanous  * @param[in] certURI Link to certificate collection URI
646828252d5SJiaqing Zhao  * @param[in] service D-Bus service name
647828252d5SJiaqing Zhao  * @param[in] certObjPath certificate D-Bus object path
648828252d5SJiaqing Zhao  * @param[in] csrObjPath CSR D-Bus object path
649828252d5SJiaqing Zhao  * @return None
6505968caeeSMarri Devender Rao  */
6514ff0f1f4SEd Tanous inline void getCSR(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
652828252d5SJiaqing Zhao                    const std::string& certURI, const std::string& service,
653828252d5SJiaqing Zhao                    const std::string& certObjPath,
654828252d5SJiaqing Zhao                    const std::string& csrObjPath)
6555968caeeSMarri Devender Rao {
65662598e31SEd Tanous     BMCWEB_LOG_DEBUG("getCSR CertObjectPath{} CSRObjectPath={} service={}",
65762598e31SEd Tanous                      certObjPath, csrObjPath, service);
658828252d5SJiaqing Zhao     crow::connections::systemBus->async_method_call(
659bd79bce8SPatrick Williams         [asyncResp,
660bd79bce8SPatrick Williams          certURI](const boost::system::error_code& ec, const std::string& csr) {
661828252d5SJiaqing Zhao             if (ec)
662828252d5SJiaqing Zhao             {
66362598e31SEd Tanous                 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
664828252d5SJiaqing Zhao                 messages::internalError(asyncResp->res);
665828252d5SJiaqing Zhao                 return;
666828252d5SJiaqing Zhao             }
667828252d5SJiaqing Zhao             if (csr.empty())
668828252d5SJiaqing Zhao             {
66962598e31SEd Tanous                 BMCWEB_LOG_ERROR("CSR read is empty");
670828252d5SJiaqing Zhao                 messages::internalError(asyncResp->res);
671828252d5SJiaqing Zhao                 return;
672828252d5SJiaqing Zhao             }
673828252d5SJiaqing Zhao             asyncResp->res.jsonValue["CSRString"] = csr;
674828252d5SJiaqing Zhao             asyncResp->res.jsonValue["CertificateCollection"]["@odata.id"] =
675828252d5SJiaqing Zhao                 certURI;
676828252d5SJiaqing Zhao         },
677828252d5SJiaqing Zhao         service, csrObjPath, "xyz.openbmc_project.Certs.CSR", "CSR");
678828252d5SJiaqing Zhao }
679828252d5SJiaqing Zhao 
680828252d5SJiaqing Zhao inline void
681828252d5SJiaqing Zhao     handleGenerateCSRAction(App& app, const crow::Request& req,
682828252d5SJiaqing Zhao                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
683828252d5SJiaqing Zhao {
6843ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
68545ca1b86SEd Tanous     {
68645ca1b86SEd Tanous         return;
68745ca1b86SEd Tanous     }
688828252d5SJiaqing Zhao     static const int rsaKeyBitLength = 2048;
6895968caeeSMarri Devender Rao 
690828252d5SJiaqing Zhao     // Required parameters
691828252d5SJiaqing Zhao     std::string city;
692828252d5SJiaqing Zhao     std::string commonName;
693828252d5SJiaqing Zhao     std::string country;
694828252d5SJiaqing Zhao     std::string organization;
695828252d5SJiaqing Zhao     std::string organizationalUnit;
696828252d5SJiaqing Zhao     std::string state;
6977a31e336SEd Tanous     std::string certURI;
698828252d5SJiaqing Zhao 
699828252d5SJiaqing Zhao     // Optional parameters
700828252d5SJiaqing Zhao     std::optional<std::vector<std::string>> optAlternativeNames =
701828252d5SJiaqing Zhao         std::vector<std::string>();
702828252d5SJiaqing Zhao     std::optional<std::string> optContactPerson = "";
703828252d5SJiaqing Zhao     std::optional<std::string> optChallengePassword = "";
704828252d5SJiaqing Zhao     std::optional<std::string> optEmail = "";
705828252d5SJiaqing Zhao     std::optional<std::string> optGivenName = "";
706828252d5SJiaqing Zhao     std::optional<std::string> optInitials = "";
707828252d5SJiaqing Zhao     std::optional<int64_t> optKeyBitLength = rsaKeyBitLength;
708828252d5SJiaqing Zhao     std::optional<std::string> optKeyCurveId = "secp384r1";
709828252d5SJiaqing Zhao     std::optional<std::string> optKeyPairAlgorithm = "EC";
710828252d5SJiaqing Zhao     std::optional<std::vector<std::string>> optKeyUsage =
711828252d5SJiaqing Zhao         std::vector<std::string>();
712828252d5SJiaqing Zhao     std::optional<std::string> optSurname = "";
713828252d5SJiaqing Zhao     std::optional<std::string> optUnstructuredName = "";
714afc474aeSMyung Bae     if (!json_util::readJsonAction( //
715afc474aeSMyung Bae             req, asyncResp->res, //
716afc474aeSMyung Bae             "AlternativeNames", optAlternativeNames, //
717afc474aeSMyung Bae             "CertificateCollection/@odata.id", certURI, //
718afc474aeSMyung Bae             "ChallengePassword", optChallengePassword, //
719afc474aeSMyung Bae             "City", city, //
720afc474aeSMyung Bae             "CommonName", commonName, //
721afc474aeSMyung Bae             "ContactPerson", optContactPerson, //
722afc474aeSMyung Bae             "Country", country, //
723afc474aeSMyung Bae             "Email", optEmail, //
724afc474aeSMyung Bae             "GivenName", optGivenName, //
725afc474aeSMyung Bae             "Initials", optInitials, //
726afc474aeSMyung Bae             "KeyBitLength", optKeyBitLength, //
727afc474aeSMyung Bae             "KeyCurveId", optKeyCurveId, //
728afc474aeSMyung Bae             "KeyPairAlgorithm", optKeyPairAlgorithm, //
729afc474aeSMyung Bae             "KeyUsage", optKeyUsage, //
730afc474aeSMyung Bae             "Organization", organization, //
731afc474aeSMyung Bae             "OrganizationalUnit", organizationalUnit, //
732afc474aeSMyung Bae             "State", state, //
733afc474aeSMyung Bae             "Surname", optSurname, //
734afc474aeSMyung Bae             "UnstructuredName", optUnstructuredName //
735afc474aeSMyung Bae             ))
736828252d5SJiaqing Zhao     {
737828252d5SJiaqing Zhao         return;
7385968caeeSMarri Devender Rao     }
7395968caeeSMarri Devender Rao 
740828252d5SJiaqing Zhao     // bmcweb has no way to store or decode a private key challenge
741828252d5SJiaqing Zhao     // password, which will likely cause bmcweb to crash on startup
742828252d5SJiaqing Zhao     // if this is not set on a post so not allowing the user to set
743828252d5SJiaqing Zhao     // value
744828252d5SJiaqing Zhao     if (!optChallengePassword->empty())
7455968caeeSMarri Devender Rao     {
746828252d5SJiaqing Zhao         messages::actionParameterNotSupported(asyncResp->res, "GenerateCSR",
747828252d5SJiaqing Zhao                                               "ChallengePassword");
748828252d5SJiaqing Zhao         return;
749828252d5SJiaqing Zhao     }
750828252d5SJiaqing Zhao 
751828252d5SJiaqing Zhao     std::string objectPath;
752828252d5SJiaqing Zhao     std::string service;
753253f11b8SEd Tanous     if (certURI.starts_with(std::format(
754253f11b8SEd Tanous             "/redfish/v1/Managers/{}/NetworkProtocol/HTTPS/Certificates",
755253f11b8SEd Tanous             BMCWEB_REDFISH_MANAGER_URI_NAME)))
756828252d5SJiaqing Zhao     {
757828252d5SJiaqing Zhao         objectPath = certs::httpsObjectPath;
758828252d5SJiaqing Zhao         service = certs::httpsServiceName;
759828252d5SJiaqing Zhao     }
760828252d5SJiaqing Zhao     else if (certURI.starts_with(
761828252d5SJiaqing Zhao                  "/redfish/v1/AccountService/LDAP/Certificates"))
762828252d5SJiaqing Zhao     {
763828252d5SJiaqing Zhao         objectPath = certs::ldapObjectPath;
764828252d5SJiaqing Zhao         service = certs::ldapServiceName;
765828252d5SJiaqing Zhao     }
766828252d5SJiaqing Zhao     else
767828252d5SJiaqing Zhao     {
768828252d5SJiaqing Zhao         messages::actionParameterNotSupported(
769828252d5SJiaqing Zhao             asyncResp->res, "CertificateCollection", "GenerateCSR");
770828252d5SJiaqing Zhao         return;
771828252d5SJiaqing Zhao     }
772828252d5SJiaqing Zhao 
773828252d5SJiaqing Zhao     // supporting only EC and RSA algorithm
774828252d5SJiaqing Zhao     if (*optKeyPairAlgorithm != "EC" && *optKeyPairAlgorithm != "RSA")
775828252d5SJiaqing Zhao     {
776828252d5SJiaqing Zhao         messages::actionParameterNotSupported(
777828252d5SJiaqing Zhao             asyncResp->res, "KeyPairAlgorithm", "GenerateCSR");
778828252d5SJiaqing Zhao         return;
779828252d5SJiaqing Zhao     }
780828252d5SJiaqing Zhao 
781828252d5SJiaqing Zhao     // supporting only 2048 key bit length for RSA algorithm due to
782828252d5SJiaqing Zhao     // time consumed in generating private key
783828252d5SJiaqing Zhao     if (*optKeyPairAlgorithm == "RSA" && *optKeyBitLength != rsaKeyBitLength)
784828252d5SJiaqing Zhao     {
785e2616cc5SEd Tanous         messages::propertyValueNotInList(asyncResp->res, *optKeyBitLength,
786e2616cc5SEd Tanous                                          "KeyBitLength");
787828252d5SJiaqing Zhao         return;
788828252d5SJiaqing Zhao     }
789828252d5SJiaqing Zhao 
790828252d5SJiaqing Zhao     // validate KeyUsage supporting only 1 type based on URL
791253f11b8SEd Tanous     if (certURI.starts_with(std::format(
792253f11b8SEd Tanous             "/redfish/v1/Managers/{}/NetworkProtocol/HTTPS/Certificates",
793253f11b8SEd Tanous             BMCWEB_REDFISH_MANAGER_URI_NAME)))
794828252d5SJiaqing Zhao     {
795828252d5SJiaqing Zhao         if (optKeyUsage->empty())
796828252d5SJiaqing Zhao         {
797b2ba3072SPatrick Williams             optKeyUsage->emplace_back("ServerAuthentication");
798828252d5SJiaqing Zhao         }
799828252d5SJiaqing Zhao         else if (optKeyUsage->size() == 1)
800828252d5SJiaqing Zhao         {
801828252d5SJiaqing Zhao             if ((*optKeyUsage)[0] != "ServerAuthentication")
802828252d5SJiaqing Zhao             {
803828252d5SJiaqing Zhao                 messages::propertyValueNotInList(asyncResp->res,
804828252d5SJiaqing Zhao                                                  (*optKeyUsage)[0], "KeyUsage");
805828252d5SJiaqing Zhao                 return;
806828252d5SJiaqing Zhao             }
807828252d5SJiaqing Zhao         }
808828252d5SJiaqing Zhao         else
809828252d5SJiaqing Zhao         {
810828252d5SJiaqing Zhao             messages::actionParameterNotSupported(asyncResp->res, "KeyUsage",
811828252d5SJiaqing Zhao                                                   "GenerateCSR");
812828252d5SJiaqing Zhao             return;
813828252d5SJiaqing Zhao         }
814828252d5SJiaqing Zhao     }
815828252d5SJiaqing Zhao     else if (certURI.starts_with(
816828252d5SJiaqing Zhao                  "/redfish/v1/AccountService/LDAP/Certificates"))
817828252d5SJiaqing Zhao     {
818828252d5SJiaqing Zhao         if (optKeyUsage->empty())
819828252d5SJiaqing Zhao         {
820b2ba3072SPatrick Williams             optKeyUsage->emplace_back("ClientAuthentication");
821828252d5SJiaqing Zhao         }
822828252d5SJiaqing Zhao         else if (optKeyUsage->size() == 1)
823828252d5SJiaqing Zhao         {
824828252d5SJiaqing Zhao             if ((*optKeyUsage)[0] != "ClientAuthentication")
825828252d5SJiaqing Zhao             {
826828252d5SJiaqing Zhao                 messages::propertyValueNotInList(asyncResp->res,
827828252d5SJiaqing Zhao                                                  (*optKeyUsage)[0], "KeyUsage");
828828252d5SJiaqing Zhao                 return;
829828252d5SJiaqing Zhao             }
830828252d5SJiaqing Zhao         }
831828252d5SJiaqing Zhao         else
832828252d5SJiaqing Zhao         {
833828252d5SJiaqing Zhao             messages::actionParameterNotSupported(asyncResp->res, "KeyUsage",
834828252d5SJiaqing Zhao                                                   "GenerateCSR");
835828252d5SJiaqing Zhao             return;
836828252d5SJiaqing Zhao         }
837828252d5SJiaqing Zhao     }
838828252d5SJiaqing Zhao 
839828252d5SJiaqing Zhao     // Only allow one CSR matcher at a time so setting retry
840828252d5SJiaqing Zhao     // time-out and timer expiry to 10 seconds for now.
841828252d5SJiaqing Zhao     static const int timeOut = 10;
842828252d5SJiaqing Zhao     if (csrMatcher)
843828252d5SJiaqing Zhao     {
844828252d5SJiaqing Zhao         messages::serviceTemporarilyUnavailable(asyncResp->res,
845828252d5SJiaqing Zhao                                                 std::to_string(timeOut));
846828252d5SJiaqing Zhao         return;
847828252d5SJiaqing Zhao     }
848828252d5SJiaqing Zhao 
8498e8245dbSEd Tanous     if (req.ioService == nullptr)
8508e8245dbSEd Tanous     {
8518e8245dbSEd Tanous         messages::internalError(asyncResp->res);
8528e8245dbSEd Tanous         return;
8538e8245dbSEd Tanous     }
8548e8245dbSEd Tanous 
855828252d5SJiaqing Zhao     // Make this static so it survives outside this method
856828252d5SJiaqing Zhao     static boost::asio::steady_timer timeout(*req.ioService);
857828252d5SJiaqing Zhao     timeout.expires_after(std::chrono::seconds(timeOut));
858828252d5SJiaqing Zhao     timeout.async_wait([asyncResp](const boost::system::error_code& ec) {
859828252d5SJiaqing Zhao         csrMatcher = nullptr;
860828252d5SJiaqing Zhao         if (ec)
861828252d5SJiaqing Zhao         {
862828252d5SJiaqing Zhao             // operation_aborted is expected if timer is canceled
863828252d5SJiaqing Zhao             // before completion.
864828252d5SJiaqing Zhao             if (ec != boost::asio::error::operation_aborted)
865828252d5SJiaqing Zhao             {
86662598e31SEd Tanous                 BMCWEB_LOG_ERROR("Async_wait failed {}", ec);
867828252d5SJiaqing Zhao             }
868828252d5SJiaqing Zhao             return;
869828252d5SJiaqing Zhao         }
87062598e31SEd Tanous         BMCWEB_LOG_ERROR("Timed out waiting for Generating CSR");
871828252d5SJiaqing Zhao         messages::internalError(asyncResp->res);
872828252d5SJiaqing Zhao     });
873828252d5SJiaqing Zhao 
874828252d5SJiaqing Zhao     // create a matcher to wait on CSR object
87562598e31SEd Tanous     BMCWEB_LOG_DEBUG("create matcher with path {}", objectPath);
876828252d5SJiaqing Zhao     std::string match("type='signal',"
877828252d5SJiaqing Zhao                       "interface='org.freedesktop.DBus.ObjectManager',"
878828252d5SJiaqing Zhao                       "path='" +
879828252d5SJiaqing Zhao                       objectPath +
880828252d5SJiaqing Zhao                       "',"
881828252d5SJiaqing Zhao                       "member='InterfacesAdded'");
882828252d5SJiaqing Zhao     csrMatcher = std::make_unique<sdbusplus::bus::match_t>(
883828252d5SJiaqing Zhao         *crow::connections::systemBus, match,
884828252d5SJiaqing Zhao         [asyncResp, service, objectPath, certURI](sdbusplus::message_t& m) {
885828252d5SJiaqing Zhao             timeout.cancel();
886828252d5SJiaqing Zhao             if (m.is_method_error())
887828252d5SJiaqing Zhao             {
88862598e31SEd Tanous                 BMCWEB_LOG_ERROR("Dbus method error!!!");
889828252d5SJiaqing Zhao                 messages::internalError(asyncResp->res);
890828252d5SJiaqing Zhao                 return;
891828252d5SJiaqing Zhao             }
892828252d5SJiaqing Zhao 
89380f79a40SMichael Shen             dbus::utility::DBusInterfacesMap interfacesProperties;
894828252d5SJiaqing Zhao 
895828252d5SJiaqing Zhao             sdbusplus::message::object_path csrObjectPath;
896828252d5SJiaqing Zhao             m.read(csrObjectPath, interfacesProperties);
89762598e31SEd Tanous             BMCWEB_LOG_DEBUG("CSR object added{}", csrObjectPath.str);
898828252d5SJiaqing Zhao             for (const auto& interface : interfacesProperties)
899828252d5SJiaqing Zhao             {
900828252d5SJiaqing Zhao                 if (interface.first == "xyz.openbmc_project.Certs.CSR")
901828252d5SJiaqing Zhao                 {
902828252d5SJiaqing Zhao                     getCSR(asyncResp, certURI, service, objectPath,
903828252d5SJiaqing Zhao                            csrObjectPath.str);
904828252d5SJiaqing Zhao                     break;
905828252d5SJiaqing Zhao                 }
906828252d5SJiaqing Zhao             }
907828252d5SJiaqing Zhao         });
908828252d5SJiaqing Zhao     crow::connections::systemBus->async_method_call(
9095e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec, const std::string&) {
910828252d5SJiaqing Zhao             if (ec)
911828252d5SJiaqing Zhao             {
91262598e31SEd Tanous                 BMCWEB_LOG_ERROR("DBUS response error: {}", ec.message());
913828252d5SJiaqing Zhao                 messages::internalError(asyncResp->res);
914828252d5SJiaqing Zhao                 return;
915828252d5SJiaqing Zhao             }
916828252d5SJiaqing Zhao         },
917828252d5SJiaqing Zhao         service, objectPath, "xyz.openbmc_project.Certs.CSR.Create",
918828252d5SJiaqing Zhao         "GenerateCSR", *optAlternativeNames, *optChallengePassword, city,
919828252d5SJiaqing Zhao         commonName, *optContactPerson, country, *optEmail, *optGivenName,
920828252d5SJiaqing Zhao         *optInitials, *optKeyBitLength, *optKeyCurveId, *optKeyPairAlgorithm,
921828252d5SJiaqing Zhao         *optKeyUsage, organization, organizationalUnit, state, *optSurname,
922828252d5SJiaqing Zhao         *optUnstructuredName);
923828252d5SJiaqing Zhao }
924828252d5SJiaqing Zhao 
925828252d5SJiaqing Zhao inline void requestRoutesCertificateService(App& app)
926828252d5SJiaqing Zhao {
927828252d5SJiaqing Zhao     BMCWEB_ROUTE(app, "/redfish/v1/CertificateService/")
928828252d5SJiaqing Zhao         .privileges(redfish::privileges::getCertificateService)
929002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
930828252d5SJiaqing Zhao             std::bind_front(handleCertificateServiceGet, std::ref(app)));
931828252d5SJiaqing Zhao 
932828252d5SJiaqing Zhao     BMCWEB_ROUTE(app, "/redfish/v1/CertificateService/CertificateLocations/")
933828252d5SJiaqing Zhao         .privileges(redfish::privileges::getCertificateLocations)
934828252d5SJiaqing Zhao         .methods(boost::beast::http::verb::get)(
935828252d5SJiaqing Zhao             std::bind_front(handleCertificateLocationsGet, std::ref(app)));
936828252d5SJiaqing Zhao 
937828252d5SJiaqing Zhao     BMCWEB_ROUTE(
938828252d5SJiaqing Zhao         app,
939828252d5SJiaqing Zhao         "/redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate/")
940828252d5SJiaqing Zhao         .privileges(redfish::privileges::postCertificateService)
941828252d5SJiaqing Zhao         .methods(boost::beast::http::verb::post)(
942828252d5SJiaqing Zhao             std::bind_front(handleReplaceCertificateAction, std::ref(app)));
943828252d5SJiaqing Zhao 
944828252d5SJiaqing Zhao     BMCWEB_ROUTE(
945828252d5SJiaqing Zhao         app,
946828252d5SJiaqing Zhao         "/redfish/v1/CertificateService/Actions/CertificateService.GenerateCSR/")
947828252d5SJiaqing Zhao         .privileges(redfish::privileges::postCertificateService)
948828252d5SJiaqing Zhao         .methods(boost::beast::http::verb::post)(
949828252d5SJiaqing Zhao             std::bind_front(handleGenerateCSRAction, std::ref(app)));
950828252d5SJiaqing Zhao } // requestRoutesCertificateService
951828252d5SJiaqing Zhao 
952828252d5SJiaqing Zhao inline void handleHTTPSCertificateCollectionGet(
953828252d5SJiaqing Zhao     App& app, const crow::Request& req,
954253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
955253f11b8SEd Tanous     const std::string& managerId)
956828252d5SJiaqing Zhao {
9573ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
95845ca1b86SEd Tanous     {
95945ca1b86SEd Tanous         return;
96045ca1b86SEd Tanous     }
9611476687dSEd Tanous 
962253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
963253f11b8SEd Tanous     {
964253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
965253f11b8SEd Tanous         return;
966253f11b8SEd Tanous     }
967253f11b8SEd Tanous 
968253f11b8SEd Tanous     asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
969253f11b8SEd Tanous         "/redfish/v1/Managers/{}/NetworkProtocol/HTTPS/Certificates",
970253f11b8SEd Tanous         BMCWEB_REDFISH_MANAGER_URI_NAME);
9711476687dSEd Tanous     asyncResp->res.jsonValue["@odata.type"] =
9721476687dSEd Tanous         "#CertificateCollection.CertificateCollection";
9731476687dSEd Tanous     asyncResp->res.jsonValue["Name"] = "HTTPS Certificates Collection";
9741476687dSEd Tanous     asyncResp->res.jsonValue["Description"] =
9751476687dSEd Tanous         "A Collection of HTTPS certificate instances";
9768d1b46d7Szhanghch05 
977d3f92ce7SJiaqing Zhao     getCertificateList(asyncResp, certs::httpsObjectPath,
978d3f92ce7SJiaqing Zhao                        "/Members"_json_pointer,
979d3f92ce7SJiaqing Zhao                        "/Members@odata.count"_json_pointer);
980828252d5SJiaqing Zhao }
9815968caeeSMarri Devender Rao 
982828252d5SJiaqing Zhao inline void handleHTTPSCertificateCollectionPost(
983828252d5SJiaqing Zhao     App& app, const crow::Request& req,
984253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
985253f11b8SEd Tanous     const std::string& managerId)
986828252d5SJiaqing Zhao {
9873ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
98845ca1b86SEd Tanous     {
98945ca1b86SEd Tanous         return;
99045ca1b86SEd Tanous     }
991253f11b8SEd Tanous 
992253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
993253f11b8SEd Tanous     {
994253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
995253f11b8SEd Tanous         return;
996253f11b8SEd Tanous     }
997253f11b8SEd Tanous 
99862598e31SEd Tanous     BMCWEB_LOG_DEBUG("HTTPSCertificateCollection::doPost");
9998d1b46d7Szhanghch05 
10001476687dSEd Tanous     asyncResp->res.jsonValue["Name"] = "HTTPS Certificate";
10011476687dSEd Tanous     asyncResp->res.jsonValue["Description"] = "HTTPS Certificate";
10025968caeeSMarri Devender Rao 
1003b2896149SEd Tanous     std::string certHttpBody = getCertificateFromReqBody(asyncResp, req);
100458eb238fSKowalski, Kamil 
1005b2896149SEd Tanous     if (certHttpBody.empty())
100658eb238fSKowalski, Kamil     {
100762598e31SEd Tanous         BMCWEB_LOG_ERROR("Cannot get certificate from request body.");
1008a08752f5SZbigniew Kurzynski         messages::unrecognizedRequestBody(asyncResp->res);
100958eb238fSKowalski, Kamil         return;
101058eb238fSKowalski, Kamil     }
101158eb238fSKowalski, Kamil 
10125968caeeSMarri Devender Rao     std::shared_ptr<CertificateFile> certFile =
1013b2896149SEd Tanous         std::make_shared<CertificateFile>(certHttpBody);
10145968caeeSMarri Devender Rao 
10155968caeeSMarri Devender Rao     crow::connections::systemBus->async_method_call(
10165e7e2dc5SEd Tanous         [asyncResp, certFile](const boost::system::error_code& ec,
1017656ec7e3SZbigniew Kurzynski                               const std::string& objectPath) {
10185968caeeSMarri Devender Rao             if (ec)
10195968caeeSMarri Devender Rao             {
102062598e31SEd Tanous                 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
10215968caeeSMarri Devender Rao                 messages::internalError(asyncResp->res);
10225968caeeSMarri Devender Rao                 return;
10235968caeeSMarri Devender Rao             }
1024717b9802SJiaqing Zhao 
1025717b9802SJiaqing Zhao             sdbusplus::message::object_path path(objectPath);
1026717b9802SJiaqing Zhao             std::string certId = path.filename();
1027ef4c65b7SEd Tanous             const boost::urls::url certURL = boost::urls::format(
1028253f11b8SEd Tanous                 "/redfish/v1/Managers/{}/NetworkProtocol/HTTPS/Certificates/{}",
1029253f11b8SEd Tanous                 BMCWEB_REDFISH_MANAGER_URI_NAME, certId);
1030bd79bce8SPatrick Williams             getCertificateProperties(asyncResp, objectPath,
1031bd79bce8SPatrick Williams                                      certs::httpsServiceName, certId, certURL,
1032bd79bce8SPatrick Williams                                      "HTTPS Certificate");
103362598e31SEd Tanous             BMCWEB_LOG_DEBUG("HTTPS certificate install file={}",
103462598e31SEd Tanous                              certFile->getCertFilePath());
10355968caeeSMarri Devender Rao         },
1036828252d5SJiaqing Zhao         certs::httpsServiceName, certs::httpsObjectPath, certs::certInstallIntf,
1037828252d5SJiaqing Zhao         "Install", certFile->getCertFilePath());
1038828252d5SJiaqing Zhao }
10395968caeeSMarri Devender Rao 
1040828252d5SJiaqing Zhao inline void handleHTTPSCertificateGet(
1041828252d5SJiaqing Zhao     App& app, const crow::Request& req,
1042253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1043253f11b8SEd Tanous     const std::string& managerId, const std::string& certId)
10447e860f15SJohn Edward Broadbent {
10453ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
104645ca1b86SEd Tanous     {
104745ca1b86SEd Tanous         return;
104845ca1b86SEd Tanous     }
10497e860f15SJohn Edward Broadbent 
1050253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
1051253f11b8SEd Tanous     {
1052253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
1053253f11b8SEd Tanous         return;
1054253f11b8SEd Tanous     }
1055253f11b8SEd Tanous 
1056253f11b8SEd Tanous     BMCWEB_LOG_DEBUG("HTTPS Certificate ID={}", certId);
1057ef4c65b7SEd Tanous     const boost::urls::url certURL = boost::urls::format(
1058253f11b8SEd Tanous         "/redfish/v1/Managers/{}/NetworkProtocol/HTTPS/Certificates/{}",
1059253f11b8SEd Tanous         BMCWEB_REDFISH_MANAGER_URI_NAME, certId);
1060828252d5SJiaqing Zhao     std::string objPath =
1061253f11b8SEd Tanous         sdbusplus::message::object_path(certs::httpsObjectPath) / certId;
1062253f11b8SEd Tanous     getCertificateProperties(asyncResp, objPath, certs::httpsServiceName,
1063253f11b8SEd Tanous                              certId, certURL, "HTTPS Certificate");
10647e860f15SJohn Edward Broadbent }
106537cce918SMarri Devender Rao 
1066828252d5SJiaqing Zhao inline void requestRoutesHTTPSCertificate(App& app)
106737cce918SMarri Devender Rao {
1068253f11b8SEd Tanous     BMCWEB_ROUTE(
1069253f11b8SEd Tanous         app, "/redfish/v1/Managers/<str>/NetworkProtocol/HTTPS/Certificates/")
1070ed398213SEd Tanous         .privileges(redfish::privileges::getCertificateCollection)
1071828252d5SJiaqing Zhao         .methods(boost::beast::http::verb::get)(std::bind_front(
1072828252d5SJiaqing Zhao             handleHTTPSCertificateCollectionGet, std::ref(app)));
1073828252d5SJiaqing Zhao 
1074253f11b8SEd Tanous     BMCWEB_ROUTE(
1075253f11b8SEd Tanous         app, "/redfish/v1/Managers/<str>/NetworkProtocol/HTTPS/Certificates/")
1076828252d5SJiaqing Zhao         .privileges(redfish::privileges::postCertificateCollection)
1077828252d5SJiaqing Zhao         .methods(boost::beast::http::verb::post)(std::bind_front(
1078828252d5SJiaqing Zhao             handleHTTPSCertificateCollectionPost, std::ref(app)));
1079828252d5SJiaqing Zhao 
1080828252d5SJiaqing Zhao     BMCWEB_ROUTE(
1081828252d5SJiaqing Zhao         app,
1082253f11b8SEd Tanous         "/redfish/v1/Managers/<str>/NetworkProtocol/HTTPS/Certificates/<str>/")
1083828252d5SJiaqing Zhao         .privileges(redfish::privileges::getCertificate)
1084002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1085828252d5SJiaqing Zhao             std::bind_front(handleHTTPSCertificateGet, std::ref(app)));
1086828252d5SJiaqing Zhao }
1087828252d5SJiaqing Zhao 
1088828252d5SJiaqing Zhao inline void handleLDAPCertificateCollectionGet(
1089828252d5SJiaqing Zhao     App& app, const crow::Request& req,
1090828252d5SJiaqing Zhao     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1091828252d5SJiaqing Zhao {
10923ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
109345ca1b86SEd Tanous     {
109445ca1b86SEd Tanous         return;
109545ca1b86SEd Tanous     }
10961476687dSEd Tanous 
10971476687dSEd Tanous     asyncResp->res.jsonValue["@odata.id"] =
10981476687dSEd Tanous         "/redfish/v1/AccountService/LDAP/Certificates";
10991476687dSEd Tanous     asyncResp->res.jsonValue["@odata.type"] =
11001476687dSEd Tanous         "#CertificateCollection.CertificateCollection";
11011476687dSEd Tanous     asyncResp->res.jsonValue["Name"] = "LDAP Certificates Collection";
11021476687dSEd Tanous     asyncResp->res.jsonValue["Description"] =
11031476687dSEd Tanous         "A Collection of LDAP certificate instances";
11048d1b46d7Szhanghch05 
1105d3f92ce7SJiaqing Zhao     getCertificateList(asyncResp, certs::ldapObjectPath,
1106d3f92ce7SJiaqing Zhao                        "/Members"_json_pointer,
1107d3f92ce7SJiaqing Zhao                        "/Members@odata.count"_json_pointer);
1108828252d5SJiaqing Zhao }
110937cce918SMarri Devender Rao 
1110828252d5SJiaqing Zhao inline void handleLDAPCertificateCollectionPost(
1111828252d5SJiaqing Zhao     App& app, const crow::Request& req,
1112828252d5SJiaqing Zhao     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1113828252d5SJiaqing Zhao {
11143ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
111545ca1b86SEd Tanous     {
111645ca1b86SEd Tanous         return;
111745ca1b86SEd Tanous     }
1118b2896149SEd Tanous     std::string certHttpBody = getCertificateFromReqBody(asyncResp, req);
111958eb238fSKowalski, Kamil 
1120b2896149SEd Tanous     if (certHttpBody.empty())
112158eb238fSKowalski, Kamil     {
112262598e31SEd Tanous         BMCWEB_LOG_ERROR("Cannot get certificate from request body.");
1123a08752f5SZbigniew Kurzynski         messages::unrecognizedRequestBody(asyncResp->res);
112458eb238fSKowalski, Kamil         return;
112558eb238fSKowalski, Kamil     }
112658eb238fSKowalski, Kamil 
112758eb238fSKowalski, Kamil     std::shared_ptr<CertificateFile> certFile =
1128b2896149SEd Tanous         std::make_shared<CertificateFile>(certHttpBody);
112958eb238fSKowalski, Kamil 
113037cce918SMarri Devender Rao     crow::connections::systemBus->async_method_call(
11315e7e2dc5SEd Tanous         [asyncResp, certFile](const boost::system::error_code& ec,
1132656ec7e3SZbigniew Kurzynski                               const std::string& objectPath) {
113337cce918SMarri Devender Rao             if (ec)
113437cce918SMarri Devender Rao             {
113562598e31SEd Tanous                 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
113637cce918SMarri Devender Rao                 messages::internalError(asyncResp->res);
113737cce918SMarri Devender Rao                 return;
113837cce918SMarri Devender Rao             }
1139717b9802SJiaqing Zhao 
1140717b9802SJiaqing Zhao             sdbusplus::message::object_path path(objectPath);
1141717b9802SJiaqing Zhao             std::string certId = path.filename();
1142ef4c65b7SEd Tanous             const boost::urls::url certURL = boost::urls::format(
1143ef4c65b7SEd Tanous                 "/redfish/v1/AccountService/LDAP/Certificates/{}", certId);
1144bd79bce8SPatrick Williams             getCertificateProperties(asyncResp, objectPath,
1145bd79bce8SPatrick Williams                                      certs::ldapServiceName, certId, certURL,
1146bd79bce8SPatrick Williams                                      "LDAP Certificate");
114762598e31SEd Tanous             BMCWEB_LOG_DEBUG("LDAP certificate install file={}",
114862598e31SEd Tanous                              certFile->getCertFilePath());
114937cce918SMarri Devender Rao         },
1150828252d5SJiaqing Zhao         certs::ldapServiceName, certs::ldapObjectPath, certs::certInstallIntf,
1151828252d5SJiaqing Zhao         "Install", certFile->getCertFilePath());
1152828252d5SJiaqing Zhao }
115337cce918SMarri Devender Rao 
1154828252d5SJiaqing Zhao inline void handleLDAPCertificateGet(
1155828252d5SJiaqing Zhao     App& app, const crow::Request& req,
1156828252d5SJiaqing Zhao     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id)
115737cce918SMarri Devender Rao {
11583ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
115945ca1b86SEd Tanous     {
116045ca1b86SEd Tanous         return;
116145ca1b86SEd Tanous     }
1162717b9802SJiaqing Zhao 
116362598e31SEd Tanous     BMCWEB_LOG_DEBUG("LDAP Certificate ID={}", id);
1164ef4c65b7SEd Tanous     const boost::urls::url certURL = boost::urls::format(
1165ef4c65b7SEd Tanous         "/redfish/v1/AccountService/LDAP/Certificates/{}", id);
1166717b9802SJiaqing Zhao     std::string objPath =
1167717b9802SJiaqing Zhao         sdbusplus::message::object_path(certs::ldapObjectPath) / id;
1168717b9802SJiaqing Zhao     getCertificateProperties(asyncResp, objPath, certs::ldapServiceName, id,
1169717b9802SJiaqing Zhao                              certURL, "LDAP Certificate");
1170828252d5SJiaqing Zhao }
1171828252d5SJiaqing Zhao 
117299612247SJiaqing Zhao inline void handleLDAPCertificateDelete(
117399612247SJiaqing Zhao     App& app, const crow::Request& req,
117499612247SJiaqing Zhao     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id)
117599612247SJiaqing Zhao {
117699612247SJiaqing Zhao     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
117799612247SJiaqing Zhao     {
117899612247SJiaqing Zhao         return;
117999612247SJiaqing Zhao     }
118099612247SJiaqing Zhao 
118162598e31SEd Tanous     BMCWEB_LOG_DEBUG("Delete LDAP Certificate ID={}", id);
118299612247SJiaqing Zhao     std::string objPath =
118399612247SJiaqing Zhao         sdbusplus::message::object_path(certs::ldapObjectPath) / id;
118499612247SJiaqing Zhao 
118599612247SJiaqing Zhao     deleteCertificate(asyncResp, certs::ldapServiceName, objPath);
118699612247SJiaqing Zhao }
118799612247SJiaqing Zhao 
1188828252d5SJiaqing Zhao inline void requestRoutesLDAPCertificate(App& app)
1189cfcd5f6bSMarri Devender Rao {
1190828252d5SJiaqing Zhao     BMCWEB_ROUTE(app, "/redfish/v1/AccountService/LDAP/Certificates/")
1191828252d5SJiaqing Zhao         .privileges(redfish::privileges::getCertificateCollection)
1192828252d5SJiaqing Zhao         .methods(boost::beast::http::verb::get)(
1193828252d5SJiaqing Zhao             std::bind_front(handleLDAPCertificateCollectionGet, std::ref(app)));
1194828252d5SJiaqing Zhao 
1195828252d5SJiaqing Zhao     BMCWEB_ROUTE(app, "/redfish/v1/AccountService/LDAP/Certificates/")
1196828252d5SJiaqing Zhao         .privileges(redfish::privileges::postCertificateCollection)
1197828252d5SJiaqing Zhao         .methods(boost::beast::http::verb::post)(std::bind_front(
1198828252d5SJiaqing Zhao             handleLDAPCertificateCollectionPost, std::ref(app)));
1199828252d5SJiaqing Zhao 
1200828252d5SJiaqing Zhao     BMCWEB_ROUTE(app, "/redfish/v1/AccountService/LDAP/Certificates/<str>/")
1201ed398213SEd Tanous         .privileges(redfish::privileges::getCertificate)
1202002d39b4SEd Tanous         .methods(boost::beast::http::verb::get)(
1203828252d5SJiaqing Zhao             std::bind_front(handleLDAPCertificateGet, std::ref(app)));
120499612247SJiaqing Zhao 
120599612247SJiaqing Zhao     BMCWEB_ROUTE(app, "/redfish/v1/AccountService/LDAP/Certificates/<str>/")
120699612247SJiaqing Zhao         .privileges(redfish::privileges::deleteCertificate)
120799612247SJiaqing Zhao         .methods(boost::beast::http::verb::delete_)(
120899612247SJiaqing Zhao             std::bind_front(handleLDAPCertificateDelete, std::ref(app)));
1209828252d5SJiaqing Zhao } // requestRoutesLDAPCertificate
1210828252d5SJiaqing Zhao 
1211828252d5SJiaqing Zhao inline void handleTrustStoreCertificateCollectionGet(
1212828252d5SJiaqing Zhao     App& app, const crow::Request& req,
1213253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1214253f11b8SEd Tanous     const std::string& managerId)
1215828252d5SJiaqing Zhao {
12163ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
121745ca1b86SEd Tanous     {
121845ca1b86SEd Tanous         return;
121945ca1b86SEd Tanous     }
12201476687dSEd Tanous 
1221253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
1222253f11b8SEd Tanous     {
1223253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
1224253f11b8SEd Tanous         return;
1225253f11b8SEd Tanous     }
1226253f11b8SEd Tanous 
12271476687dSEd Tanous     asyncResp->res.jsonValue["@odata.id"] =
1228253f11b8SEd Tanous         boost::urls::format("/redfish/v1/Managers/{}/Truststore/Certificates/",
1229253f11b8SEd Tanous                             BMCWEB_REDFISH_MANAGER_URI_NAME);
12301476687dSEd Tanous     asyncResp->res.jsonValue["@odata.type"] =
12311476687dSEd Tanous         "#CertificateCollection.CertificateCollection";
1232002d39b4SEd Tanous     asyncResp->res.jsonValue["Name"] = "TrustStore Certificates Collection";
12331476687dSEd Tanous     asyncResp->res.jsonValue["Description"] =
12341476687dSEd Tanous         "A Collection of TrustStore certificate instances";
12358d1b46d7Szhanghch05 
1236d3f92ce7SJiaqing Zhao     getCertificateList(asyncResp, certs::authorityObjectPath,
1237d3f92ce7SJiaqing Zhao                        "/Members"_json_pointer,
1238d3f92ce7SJiaqing Zhao                        "/Members@odata.count"_json_pointer);
1239828252d5SJiaqing Zhao }
1240cfcd5f6bSMarri Devender Rao 
1241828252d5SJiaqing Zhao inline void handleTrustStoreCertificateCollectionPost(
1242828252d5SJiaqing Zhao     App& app, const crow::Request& req,
1243253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1244253f11b8SEd Tanous     const std::string& managerId)
1245828252d5SJiaqing Zhao {
12463ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
124745ca1b86SEd Tanous     {
124845ca1b86SEd Tanous         return;
124945ca1b86SEd Tanous     }
1250253f11b8SEd Tanous 
1251253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
1252253f11b8SEd Tanous     {
1253253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
1254253f11b8SEd Tanous         return;
1255253f11b8SEd Tanous     }
1256253f11b8SEd Tanous 
1257b2896149SEd Tanous     std::string certHttpBody = getCertificateFromReqBody(asyncResp, req);
1258a08752f5SZbigniew Kurzynski 
1259b2896149SEd Tanous     if (certHttpBody.empty())
1260a08752f5SZbigniew Kurzynski     {
126162598e31SEd Tanous         BMCWEB_LOG_ERROR("Cannot get certificate from request body.");
1262a08752f5SZbigniew Kurzynski         messages::unrecognizedRequestBody(asyncResp->res);
1263a08752f5SZbigniew Kurzynski         return;
1264a08752f5SZbigniew Kurzynski     }
1265a08752f5SZbigniew Kurzynski 
1266a08752f5SZbigniew Kurzynski     std::shared_ptr<CertificateFile> certFile =
1267b2896149SEd Tanous         std::make_shared<CertificateFile>(certHttpBody);
1268cfcd5f6bSMarri Devender Rao     crow::connections::systemBus->async_method_call(
12695e7e2dc5SEd Tanous         [asyncResp, certFile](const boost::system::error_code& ec,
1270656ec7e3SZbigniew Kurzynski                               const std::string& objectPath) {
1271cfcd5f6bSMarri Devender Rao             if (ec)
1272cfcd5f6bSMarri Devender Rao             {
127362598e31SEd Tanous                 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
1274cfcd5f6bSMarri Devender Rao                 messages::internalError(asyncResp->res);
1275cfcd5f6bSMarri Devender Rao                 return;
1276cfcd5f6bSMarri Devender Rao             }
1277656ec7e3SZbigniew Kurzynski 
1278717b9802SJiaqing Zhao             sdbusplus::message::object_path path(objectPath);
1279717b9802SJiaqing Zhao             std::string certId = path.filename();
1280ef4c65b7SEd Tanous             const boost::urls::url certURL = boost::urls::format(
1281253f11b8SEd Tanous                 "/redfish/v1/Managers/{}/Truststore/Certificates/{}",
1282253f11b8SEd Tanous                 BMCWEB_REDFISH_MANAGER_URI_NAME, certId);
1283717b9802SJiaqing Zhao             getCertificateProperties(asyncResp, objectPath,
1284bd79bce8SPatrick Williams                                      certs::authorityServiceName, certId,
1285bd79bce8SPatrick Williams                                      certURL, "TrustStore Certificate");
128662598e31SEd Tanous             BMCWEB_LOG_DEBUG("TrustStore certificate install file={}",
128762598e31SEd Tanous                              certFile->getCertFilePath());
1288cfcd5f6bSMarri Devender Rao         },
1289cfcd5f6bSMarri Devender Rao         certs::authorityServiceName, certs::authorityObjectPath,
12900fda0f12SGeorge Liu         certs::certInstallIntf, "Install", certFile->getCertFilePath());
1291828252d5SJiaqing Zhao }
1292cfcd5f6bSMarri Devender Rao 
1293828252d5SJiaqing Zhao inline void handleTrustStoreCertificateGet(
1294828252d5SJiaqing Zhao     App& app, const crow::Request& req,
1295253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1296253f11b8SEd Tanous     const std::string& managerId, const std::string& certId)
1297cfcd5f6bSMarri Devender Rao {
12983ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
129945ca1b86SEd Tanous     {
130045ca1b86SEd Tanous         return;
130145ca1b86SEd Tanous     }
1302717b9802SJiaqing Zhao 
1303253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
1304253f11b8SEd Tanous     {
1305253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
1306253f11b8SEd Tanous         return;
1307253f11b8SEd Tanous     }
1308253f11b8SEd Tanous 
1309253f11b8SEd Tanous     BMCWEB_LOG_DEBUG("Truststore Certificate ID={}", certId);
1310ef4c65b7SEd Tanous     const boost::urls::url certURL = boost::urls::format(
1311253f11b8SEd Tanous         "/redfish/v1/Managers/{}/Truststore/Certificates/{}",
1312253f11b8SEd Tanous         BMCWEB_REDFISH_MANAGER_URI_NAME, certId);
1313717b9802SJiaqing Zhao     std::string objPath =
1314253f11b8SEd Tanous         sdbusplus::message::object_path(certs::authorityObjectPath) / certId;
1315828252d5SJiaqing Zhao     getCertificateProperties(asyncResp, objPath, certs::authorityServiceName,
1316253f11b8SEd Tanous                              certId, certURL, "TrustStore Certificate");
1317828252d5SJiaqing Zhao }
131807a60299SZbigniew Kurzynski 
1319828252d5SJiaqing Zhao inline void handleTrustStoreCertificateDelete(
1320828252d5SJiaqing Zhao     App& app, const crow::Request& req,
1321253f11b8SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1322253f11b8SEd Tanous     const std::string& managerId, const std::string& certId)
1323828252d5SJiaqing Zhao {
13243ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
132545ca1b86SEd Tanous     {
132645ca1b86SEd Tanous         return;
132745ca1b86SEd Tanous     }
132807a60299SZbigniew Kurzynski 
1329253f11b8SEd Tanous     if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
1330253f11b8SEd Tanous     {
1331253f11b8SEd Tanous         messages::resourceNotFound(asyncResp->res, "Manager", managerId);
1332253f11b8SEd Tanous         return;
1333253f11b8SEd Tanous     }
1334253f11b8SEd Tanous 
1335253f11b8SEd Tanous     BMCWEB_LOG_DEBUG("Delete TrustStore Certificate ID={}", certId);
1336717b9802SJiaqing Zhao     std::string objPath =
1337253f11b8SEd Tanous         sdbusplus::message::object_path(certs::authorityObjectPath) / certId;
133807a60299SZbigniew Kurzynski 
13397a3a8f7aSJiaqing Zhao     deleteCertificate(asyncResp, certs::authorityServiceName, objPath);
1340828252d5SJiaqing Zhao }
1341828252d5SJiaqing Zhao 
1342828252d5SJiaqing Zhao inline void requestRoutesTrustStoreCertificate(App& app)
1343828252d5SJiaqing Zhao {
1344253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/Truststore/Certificates/")
1345828252d5SJiaqing Zhao         .privileges(redfish::privileges::getCertificate)
1346828252d5SJiaqing Zhao         .methods(boost::beast::http::verb::get)(std::bind_front(
1347828252d5SJiaqing Zhao             handleTrustStoreCertificateCollectionGet, std::ref(app)));
1348828252d5SJiaqing Zhao 
1349253f11b8SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/Truststore/Certificates/")
1350828252d5SJiaqing Zhao         .privileges(redfish::privileges::postCertificateCollection)
1351828252d5SJiaqing Zhao         .methods(boost::beast::http::verb::post)(std::bind_front(
1352828252d5SJiaqing Zhao             handleTrustStoreCertificateCollectionPost, std::ref(app)));
1353828252d5SJiaqing Zhao 
1354253f11b8SEd Tanous     BMCWEB_ROUTE(app,
1355253f11b8SEd Tanous                  "/redfish/v1/Managers/<str>/Truststore/Certificates/<str>/")
1356828252d5SJiaqing Zhao         .privileges(redfish::privileges::getCertificate)
1357828252d5SJiaqing Zhao         .methods(boost::beast::http::verb::get)(
1358828252d5SJiaqing Zhao             std::bind_front(handleTrustStoreCertificateGet, std::ref(app)));
1359828252d5SJiaqing Zhao 
1360253f11b8SEd Tanous     BMCWEB_ROUTE(app,
1361253f11b8SEd Tanous                  "/redfish/v1/Managers/<str>/Truststore/Certificates/<str>/")
1362828252d5SJiaqing Zhao         .privileges(redfish::privileges::deleteCertificate)
1363828252d5SJiaqing Zhao         .methods(boost::beast::http::verb::delete_)(
1364828252d5SJiaqing Zhao             std::bind_front(handleTrustStoreCertificateDelete, std::ref(app)));
13657e860f15SJohn Edward Broadbent } // requestRoutesTrustStoreCertificate
13665968caeeSMarri Devender Rao } // namespace redfish
1367