| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 1 | #pragma once | 
|  | 2 |  | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3 | #include <app.hpp> | 
| Iwona Klimaszewska | e6604b1 | 2019-10-23 00:52:55 +0200 | [diff] [blame] | 4 | #include <boost/convert.hpp> | 
|  | 5 | #include <boost/convert/strtol.hpp> | 
| Jiaqing Zhao | 90d2d1e | 2022-04-13 17:01:57 +0800 | [diff] [blame] | 6 | #include <boost/system/linux_error.hpp> | 
| Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 7 | #include <dbus_utility.hpp> | 
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 8 | #include <query.hpp> | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 9 | #include <registries/privilege_registry.hpp> | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 10 |  | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 11 | namespace redfish | 
|  | 12 | { | 
|  | 13 | namespace certs | 
|  | 14 | { | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 15 | constexpr char const* certInstallIntf = "xyz.openbmc_project.Certs.Install"; | 
|  | 16 | constexpr char const* certReplaceIntf = "xyz.openbmc_project.Certs.Replace"; | 
|  | 17 | constexpr char const* objDeleteIntf = "xyz.openbmc_project.Object.Delete"; | 
|  | 18 | constexpr char const* certPropIntf = "xyz.openbmc_project.Certs.Certificate"; | 
|  | 19 | constexpr char const* dbusPropIntf = "org.freedesktop.DBus.Properties"; | 
|  | 20 | constexpr char const* dbusObjManagerIntf = "org.freedesktop.DBus.ObjectManager"; | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 21 | constexpr char const* httpsServiceName = | 
| Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 22 | "xyz.openbmc_project.Certs.Manager.Server.Https"; | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 23 | constexpr char const* ldapServiceName = | 
| Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 24 | "xyz.openbmc_project.Certs.Manager.Client.Ldap"; | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 25 | constexpr char const* authorityServiceName = | 
| Marri Devender Rao | cfcd5f6 | 2019-05-17 08:34:37 -0500 | [diff] [blame] | 26 | "xyz.openbmc_project.Certs.Manager.Authority.Ldap"; | 
| Jiaqing Zhao | c6a8dfb | 2022-06-03 10:44:23 +0800 | [diff] [blame] | 27 | constexpr char const* baseObjectPath = "/xyz/openbmc_project/certs"; | 
|  | 28 | constexpr char const* httpsObjectPath = | 
|  | 29 | "/xyz/openbmc_project/certs/server/https"; | 
|  | 30 | constexpr char const* ldapObjectPath = "/xyz/openbmc_project/certs/client/ldap"; | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 31 | constexpr char const* authorityObjectPath = | 
| Marri Devender Rao | cfcd5f6 | 2019-05-17 08:34:37 -0500 | [diff] [blame] | 32 | "/xyz/openbmc_project/certs/authority/ldap"; | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 33 | } // namespace certs | 
|  | 34 |  | 
|  | 35 | /** | 
|  | 36 | * The Certificate schema defines a Certificate Service which represents the | 
|  | 37 | * actions available to manage certificates and links to where certificates | 
|  | 38 | * are installed. | 
|  | 39 | */ | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 40 |  | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 41 | // TODO: Issue#61 No entries are available for Certificate | 
|  | 42 | // service at https://www.dmtf.org/standards/redfish | 
|  | 43 | // "redfish standard registries". Need to modify after DMTF | 
|  | 44 | // publish Privilege details for certificate service | 
|  | 45 |  | 
|  | 46 | inline void requestRoutesCertificateService(App& app) | 
|  | 47 | { | 
|  | 48 | BMCWEB_ROUTE(app, "/redfish/v1/CertificateService/") | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 49 | .privileges(redfish::privileges::getCertificateService) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 50 | .methods(boost::beast::http::verb::get)( | 
|  | 51 | [&app](const crow::Request& req, | 
|  | 52 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 53 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 54 | { | 
|  | 55 | return; | 
|  | 56 | } | 
| Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 57 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 58 | asyncResp->res.jsonValue["@odata.type"] = | 
|  | 59 | "#CertificateService.v1_0_0.CertificateService"; | 
|  | 60 | asyncResp->res.jsonValue["@odata.id"] = | 
|  | 61 | "/redfish/v1/CertificateService"; | 
|  | 62 | asyncResp->res.jsonValue["Id"] = "CertificateService"; | 
|  | 63 | asyncResp->res.jsonValue["Name"] = "Certificate Service"; | 
|  | 64 | asyncResp->res.jsonValue["Description"] = | 
|  | 65 | "Actions available to manage certificates"; | 
|  | 66 | // /redfish/v1/CertificateService/CertificateLocations is something | 
|  | 67 | // only ConfigureManager can access then only display when the user | 
|  | 68 | // has permissions ConfigureManager | 
|  | 69 | Privileges effectiveUserPrivileges = | 
|  | 70 | redfish::getUserPrivileges(req.userRole); | 
|  | 71 | if (isOperationAllowedWithPrivileges({{"ConfigureManager"}}, | 
|  | 72 | effectiveUserPrivileges)) | 
|  | 73 | { | 
|  | 74 | asyncResp->res.jsonValue["CertificateLocations"]["@odata.id"] = | 
|  | 75 | "/redfish/v1/CertificateService/CertificateLocations"; | 
|  | 76 | } | 
|  | 77 | asyncResp->res | 
|  | 78 | .jsonValue["Actions"]["#CertificateService.ReplaceCertificate"] = { | 
|  | 79 | {"target", | 
|  | 80 | "/redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate"}, | 
|  | 81 | {"CertificateType@Redfish.AllowableValues", {"PEM"}}}; | 
|  | 82 | asyncResp->res | 
|  | 83 | .jsonValue["Actions"]["#CertificateService.GenerateCSR"] = { | 
|  | 84 | {"target", | 
|  | 85 | "/redfish/v1/CertificateService/Actions/CertificateService.GenerateCSR"}}; | 
| Abhishek Patel | 7204878 | 2021-06-02 09:53:24 -0500 | [diff] [blame] | 86 | }); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 87 | } // requestRoutesCertificateService | 
| Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 88 |  | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 89 | /** | 
|  | 90 | * @brief Find the ID specified in the URL | 
|  | 91 | * Finds the numbers specified after the last "/" in the URL and returns. | 
|  | 92 | * @param[in] path URL | 
|  | 93 | * @return -1 on failure and number on success | 
|  | 94 | */ | 
| Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 95 | inline long getIDFromURL(const std::string_view url) | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 96 | { | 
| Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 97 | std::size_t found = url.rfind('/'); | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 98 | if (found == std::string::npos) | 
|  | 99 | { | 
|  | 100 | return -1; | 
|  | 101 | } | 
| Iwona Klimaszewska | e6604b1 | 2019-10-23 00:52:55 +0200 | [diff] [blame] | 102 |  | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 103 | if ((found + 1) < url.length()) | 
|  | 104 | { | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 105 | std::string_view str = url.substr(found + 1); | 
| Iwona Klimaszewska | e6604b1 | 2019-10-23 00:52:55 +0200 | [diff] [blame] | 106 |  | 
|  | 107 | return boost::convert<long>(str, boost::cnv::strtol()).value_or(-1); | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 108 | } | 
| Iwona Klimaszewska | e6604b1 | 2019-10-23 00:52:55 +0200 | [diff] [blame] | 109 |  | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 110 | return -1; | 
|  | 111 | } | 
|  | 112 |  | 
| zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 113 | inline std::string getCertificateFromReqBody( | 
|  | 114 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, | 
|  | 115 | const crow::Request& req) | 
| Kowalski, Kamil | 58eb238 | 2019-08-12 11:54:31 +0200 | [diff] [blame] | 116 | { | 
|  | 117 | nlohmann::json reqJson = nlohmann::json::parse(req.body, nullptr, false); | 
|  | 118 |  | 
|  | 119 | if (reqJson.is_discarded()) | 
|  | 120 | { | 
|  | 121 | // We did not receive JSON request, proceed as it is RAW data | 
|  | 122 | return req.body; | 
|  | 123 | } | 
|  | 124 |  | 
|  | 125 | std::string certificate; | 
|  | 126 | std::optional<std::string> certificateType = "PEM"; | 
|  | 127 |  | 
| Willy Tu | 15ed678 | 2021-12-14 11:03:16 -0800 | [diff] [blame] | 128 | if (!json_util::readJsonPatch(req, asyncResp->res, "CertificateString", | 
|  | 129 | certificate, "CertificateType", | 
|  | 130 | certificateType)) | 
| Kowalski, Kamil | 58eb238 | 2019-08-12 11:54:31 +0200 | [diff] [blame] | 131 | { | 
|  | 132 | BMCWEB_LOG_ERROR << "Required parameters are missing"; | 
|  | 133 | messages::internalError(asyncResp->res); | 
| Ed Tanous | abb93cd | 2021-09-02 14:34:57 -0700 | [diff] [blame] | 134 | return {}; | 
| Kowalski, Kamil | 58eb238 | 2019-08-12 11:54:31 +0200 | [diff] [blame] | 135 | } | 
|  | 136 |  | 
|  | 137 | if (*certificateType != "PEM") | 
|  | 138 | { | 
|  | 139 | messages::propertyValueNotInList(asyncResp->res, *certificateType, | 
|  | 140 | "CertificateType"); | 
| Ed Tanous | abb93cd | 2021-09-02 14:34:57 -0700 | [diff] [blame] | 141 | return {}; | 
| Kowalski, Kamil | 58eb238 | 2019-08-12 11:54:31 +0200 | [diff] [blame] | 142 | } | 
|  | 143 |  | 
|  | 144 | return certificate; | 
|  | 145 | } | 
|  | 146 |  | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 147 | /** | 
|  | 148 | * Class to create a temporary certificate file for uploading to system | 
|  | 149 | */ | 
|  | 150 | class CertificateFile | 
|  | 151 | { | 
|  | 152 | public: | 
|  | 153 | CertificateFile() = delete; | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 154 | CertificateFile(const CertificateFile&) = delete; | 
|  | 155 | CertificateFile& operator=(const CertificateFile&) = delete; | 
|  | 156 | CertificateFile(CertificateFile&&) = delete; | 
|  | 157 | CertificateFile& operator=(CertificateFile&&) = delete; | 
| Ed Tanous | 4e23a44 | 2022-06-06 09:57:26 -0700 | [diff] [blame] | 158 | explicit CertificateFile(const std::string& certString) | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 159 | { | 
| Ed Tanous | 72d52d2 | 2020-10-12 07:46:27 -0700 | [diff] [blame] | 160 | std::array<char, 18> dirTemplate = {'/', 't', 'm', 'p', '/', 'C', | 
| Ed Tanous | 5207438 | 2020-09-28 19:16:18 -0700 | [diff] [blame] | 161 | 'e', 'r', 't', 's', '.', 'X', | 
|  | 162 | 'X', 'X', 'X', 'X', 'X', '\0'}; | 
|  | 163 | char* tempDirectory = mkdtemp(dirTemplate.data()); | 
| Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 164 | if (tempDirectory != nullptr) | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 165 | { | 
|  | 166 | certDirectory = tempDirectory; | 
|  | 167 | certificateFile = certDirectory / "cert.pem"; | 
|  | 168 | std::ofstream out(certificateFile, std::ofstream::out | | 
|  | 169 | std::ofstream::binary | | 
|  | 170 | std::ofstream::trunc); | 
|  | 171 | out << certString; | 
|  | 172 | out.close(); | 
| Ed Tanous | 8cc8ede | 2022-02-28 10:20:59 -0800 | [diff] [blame] | 173 | BMCWEB_LOG_DEBUG << "Creating certificate file" | 
|  | 174 | << certificateFile.string(); | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 175 | } | 
|  | 176 | } | 
|  | 177 | ~CertificateFile() | 
|  | 178 | { | 
|  | 179 | if (std::filesystem::exists(certDirectory)) | 
|  | 180 | { | 
| Ed Tanous | 8cc8ede | 2022-02-28 10:20:59 -0800 | [diff] [blame] | 181 | BMCWEB_LOG_DEBUG << "Removing certificate file" | 
|  | 182 | << certificateFile.string(); | 
| Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 183 | std::error_code ec; | 
|  | 184 | std::filesystem::remove_all(certDirectory, ec); | 
|  | 185 | if (ec) | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 186 | { | 
|  | 187 | BMCWEB_LOG_ERROR << "Failed to remove temp directory" | 
| Ed Tanous | 8cc8ede | 2022-02-28 10:20:59 -0800 | [diff] [blame] | 188 | << certDirectory.string(); | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 189 | } | 
|  | 190 | } | 
|  | 191 | } | 
|  | 192 | std::string getCertFilePath() | 
|  | 193 | { | 
|  | 194 | return certificateFile; | 
|  | 195 | } | 
|  | 196 |  | 
|  | 197 | private: | 
|  | 198 | std::filesystem::path certificateFile; | 
|  | 199 | std::filesystem::path certDirectory; | 
|  | 200 | }; | 
|  | 201 |  | 
| Marri Devender Rao | 3021581 | 2019-03-18 08:59:21 -0500 | [diff] [blame] | 202 | static std::unique_ptr<sdbusplus::bus::match::match> csrMatcher; | 
|  | 203 | /** | 
|  | 204 | * @brief Read data from CSR D-bus object and set to response | 
|  | 205 | * | 
|  | 206 | * @param[in] asyncResp Shared pointer to the response message | 
|  | 207 | * @param[in] certURI Link to certifiate collection URI | 
|  | 208 | * @param[in] service D-Bus service name | 
|  | 209 | * @param[in] certObjPath certificate D-Bus object path | 
|  | 210 | * @param[in] csrObjPath CSR D-Bus object path | 
|  | 211 | * @return None | 
|  | 212 | */ | 
| zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 213 | static void getCSR(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 214 | const std::string& certURI, const std::string& service, | 
|  | 215 | const std::string& certObjPath, | 
|  | 216 | const std::string& csrObjPath) | 
| Marri Devender Rao | 3021581 | 2019-03-18 08:59:21 -0500 | [diff] [blame] | 217 | { | 
|  | 218 | BMCWEB_LOG_DEBUG << "getCSR CertObjectPath" << certObjPath | 
|  | 219 | << " CSRObjectPath=" << csrObjPath | 
|  | 220 | << " service=" << service; | 
|  | 221 | crow::connections::systemBus->async_method_call( | 
|  | 222 | [asyncResp, certURI](const boost::system::error_code ec, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 223 | const std::string& csr) { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 224 | if (ec) | 
|  | 225 | { | 
|  | 226 | BMCWEB_LOG_ERROR << "DBUS response error: " << ec; | 
|  | 227 | messages::internalError(asyncResp->res); | 
|  | 228 | return; | 
|  | 229 | } | 
|  | 230 | if (csr.empty()) | 
|  | 231 | { | 
|  | 232 | BMCWEB_LOG_ERROR << "CSR read is empty"; | 
|  | 233 | messages::internalError(asyncResp->res); | 
|  | 234 | return; | 
|  | 235 | } | 
|  | 236 | asyncResp->res.jsonValue["CSRString"] = csr; | 
|  | 237 | asyncResp->res.jsonValue["CertificateCollection"]["@odata.id"] = | 
|  | 238 | certURI; | 
| Marri Devender Rao | 3021581 | 2019-03-18 08:59:21 -0500 | [diff] [blame] | 239 | }, | 
|  | 240 | service, csrObjPath, "xyz.openbmc_project.Certs.CSR", "CSR"); | 
|  | 241 | } | 
|  | 242 |  | 
|  | 243 | /** | 
|  | 244 | * Action to Generate CSR | 
|  | 245 | */ | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 246 | inline void requestRoutesCertificateActionGenerateCSR(App& app) | 
| Marri Devender Rao | 3021581 | 2019-03-18 08:59:21 -0500 | [diff] [blame] | 247 | { | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 248 | BMCWEB_ROUTE( | 
|  | 249 | app, | 
|  | 250 | "/redfish/v1/CertificateService/Actions/CertificateService.GenerateCSR/") | 
| Abhishek Patel | 5344ab8 | 2021-07-31 17:42:09 -0500 | [diff] [blame] | 251 | .privileges(redfish::privileges::postCertificateService) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 252 | .methods(boost::beast::http::verb::post)( | 
|  | 253 | [&app](const crow::Request& req, | 
|  | 254 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 255 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 256 | { | 
|  | 257 | return; | 
|  | 258 | } | 
|  | 259 | static const int rsaKeyBitLength = 2048; | 
| Marri Devender Rao | 3021581 | 2019-03-18 08:59:21 -0500 | [diff] [blame] | 260 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 261 | // Required parameters | 
|  | 262 | std::string city; | 
|  | 263 | std::string commonName; | 
|  | 264 | std::string country; | 
|  | 265 | std::string organization; | 
|  | 266 | std::string organizationalUnit; | 
|  | 267 | std::string state; | 
|  | 268 | nlohmann::json certificateCollection; | 
| zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 269 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 270 | // Optional parameters | 
|  | 271 | std::optional<std::vector<std::string>> optAlternativeNames = | 
|  | 272 | std::vector<std::string>(); | 
|  | 273 | std::optional<std::string> optContactPerson = ""; | 
|  | 274 | std::optional<std::string> optChallengePassword = ""; | 
|  | 275 | std::optional<std::string> optEmail = ""; | 
|  | 276 | std::optional<std::string> optGivenName = ""; | 
|  | 277 | std::optional<std::string> optInitials = ""; | 
|  | 278 | std::optional<int64_t> optKeyBitLength = rsaKeyBitLength; | 
|  | 279 | std::optional<std::string> optKeyCurveId = "secp384r1"; | 
|  | 280 | std::optional<std::string> optKeyPairAlgorithm = "EC"; | 
|  | 281 | std::optional<std::vector<std::string>> optKeyUsage = | 
|  | 282 | std::vector<std::string>(); | 
|  | 283 | std::optional<std::string> optSurname = ""; | 
|  | 284 | std::optional<std::string> optUnstructuredName = ""; | 
|  | 285 | if (!json_util::readJsonAction( | 
|  | 286 | req, asyncResp->res, "City", city, "CommonName", commonName, | 
|  | 287 | "ContactPerson", optContactPerson, "Country", country, | 
|  | 288 | "Organization", organization, "OrganizationalUnit", | 
|  | 289 | organizationalUnit, "State", state, "CertificateCollection", | 
|  | 290 | certificateCollection, "AlternativeNames", optAlternativeNames, | 
|  | 291 | "ChallengePassword", optChallengePassword, "Email", optEmail, | 
|  | 292 | "GivenName", optGivenName, "Initials", optInitials, | 
|  | 293 | "KeyBitLength", optKeyBitLength, "KeyCurveId", optKeyCurveId, | 
|  | 294 | "KeyPairAlgorithm", optKeyPairAlgorithm, "KeyUsage", | 
|  | 295 | optKeyUsage, "Surname", optSurname, "UnstructuredName", | 
|  | 296 | optUnstructuredName)) | 
|  | 297 | { | 
|  | 298 | return; | 
|  | 299 | } | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 300 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 301 | // bmcweb has no way to store or decode a private key challenge | 
|  | 302 | // password, which will likely cause bmcweb to crash on startup | 
|  | 303 | // if this is not set on a post so not allowing the user to set | 
|  | 304 | // value | 
|  | 305 | if (!optChallengePassword->empty()) | 
|  | 306 | { | 
|  | 307 | messages::actionParameterNotSupported(asyncResp->res, "GenerateCSR", | 
|  | 308 | "ChallengePassword"); | 
|  | 309 | return; | 
|  | 310 | } | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 311 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 312 | std::string certURI; | 
|  | 313 | if (!redfish::json_util::readJson(certificateCollection, asyncResp->res, | 
|  | 314 | "@odata.id", certURI)) | 
|  | 315 | { | 
|  | 316 | return; | 
|  | 317 | } | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 318 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 319 | std::string objectPath; | 
|  | 320 | std::string service; | 
| Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 321 | if (certURI.starts_with( | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 322 | "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates")) | 
|  | 323 | { | 
|  | 324 | objectPath = certs::httpsObjectPath; | 
|  | 325 | service = certs::httpsServiceName; | 
|  | 326 | } | 
| Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 327 | else if (certURI.starts_with( | 
|  | 328 | "/redfish/v1/AccountService/LDAP/Certificates")) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 329 | { | 
|  | 330 | objectPath = certs::ldapObjectPath; | 
|  | 331 | service = certs::ldapServiceName; | 
|  | 332 | } | 
|  | 333 | else | 
|  | 334 | { | 
|  | 335 | messages::actionParameterNotSupported( | 
|  | 336 | asyncResp->res, "CertificateCollection", "GenerateCSR"); | 
|  | 337 | return; | 
|  | 338 | } | 
|  | 339 |  | 
|  | 340 | // supporting only EC and RSA algorithm | 
|  | 341 | if (*optKeyPairAlgorithm != "EC" && *optKeyPairAlgorithm != "RSA") | 
|  | 342 | { | 
|  | 343 | messages::actionParameterNotSupported( | 
|  | 344 | asyncResp->res, "KeyPairAlgorithm", "GenerateCSR"); | 
|  | 345 | return; | 
|  | 346 | } | 
|  | 347 |  | 
|  | 348 | // supporting only 2048 key bit length for RSA algorithm due to | 
|  | 349 | // time consumed in generating private key | 
|  | 350 | if (*optKeyPairAlgorithm == "RSA" && | 
|  | 351 | *optKeyBitLength != rsaKeyBitLength) | 
|  | 352 | { | 
|  | 353 | messages::propertyValueNotInList(asyncResp->res, | 
|  | 354 | std::to_string(*optKeyBitLength), | 
|  | 355 | "KeyBitLength"); | 
|  | 356 | return; | 
|  | 357 | } | 
|  | 358 |  | 
|  | 359 | // validate KeyUsage supporting only 1 type based on URL | 
| Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 360 | if (certURI.starts_with( | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 361 | "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates")) | 
|  | 362 | { | 
|  | 363 | if (optKeyUsage->empty()) | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 364 | { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 365 | optKeyUsage->push_back("ServerAuthentication"); | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 366 | } | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 367 | else if (optKeyUsage->size() == 1) | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 368 | { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 369 | if ((*optKeyUsage)[0] != "ServerAuthentication") | 
|  | 370 | { | 
|  | 371 | messages::propertyValueNotInList( | 
|  | 372 | asyncResp->res, (*optKeyUsage)[0], "KeyUsage"); | 
|  | 373 | return; | 
|  | 374 | } | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 375 | } | 
|  | 376 | else | 
|  | 377 | { | 
|  | 378 | messages::actionParameterNotSupported( | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 379 | asyncResp->res, "KeyUsage", "GenerateCSR"); | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 380 | return; | 
|  | 381 | } | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 382 | } | 
| Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 383 | else if (certURI.starts_with( | 
|  | 384 | "/redfish/v1/AccountService/LDAP/Certificates")) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 385 | { | 
|  | 386 | if (optKeyUsage->empty()) | 
|  | 387 | { | 
|  | 388 | optKeyUsage->push_back("ClientAuthentication"); | 
|  | 389 | } | 
|  | 390 | else if (optKeyUsage->size() == 1) | 
|  | 391 | { | 
|  | 392 | if ((*optKeyUsage)[0] != "ClientAuthentication") | 
|  | 393 | { | 
|  | 394 | messages::propertyValueNotInList( | 
|  | 395 | asyncResp->res, (*optKeyUsage)[0], "KeyUsage"); | 
|  | 396 | return; | 
|  | 397 | } | 
|  | 398 | } | 
|  | 399 | else | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 400 | { | 
|  | 401 | messages::actionParameterNotSupported( | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 402 | asyncResp->res, "KeyUsage", "GenerateCSR"); | 
|  | 403 | return; | 
|  | 404 | } | 
|  | 405 | } | 
|  | 406 |  | 
|  | 407 | // Only allow one CSR matcher at a time so setting retry | 
|  | 408 | // time-out and timer expiry to 10 seconds for now. | 
|  | 409 | static const int timeOut = 10; | 
|  | 410 | if (csrMatcher) | 
|  | 411 | { | 
|  | 412 | messages::serviceTemporarilyUnavailable(asyncResp->res, | 
|  | 413 | std::to_string(timeOut)); | 
|  | 414 | return; | 
|  | 415 | } | 
|  | 416 |  | 
|  | 417 | // Make this static so it survives outside this method | 
|  | 418 | static boost::asio::steady_timer timeout(*req.ioService); | 
|  | 419 | timeout.expires_after(std::chrono::seconds(timeOut)); | 
|  | 420 | timeout.async_wait([asyncResp](const boost::system::error_code& ec) { | 
|  | 421 | csrMatcher = nullptr; | 
|  | 422 | if (ec) | 
|  | 423 | { | 
|  | 424 | // operation_aborted is expected if timer is canceled | 
|  | 425 | // before completion. | 
|  | 426 | if (ec != boost::asio::error::operation_aborted) | 
|  | 427 | { | 
|  | 428 | BMCWEB_LOG_ERROR << "Async_wait failed " << ec; | 
|  | 429 | } | 
|  | 430 | return; | 
|  | 431 | } | 
|  | 432 | BMCWEB_LOG_ERROR << "Timed out waiting for Generating CSR"; | 
|  | 433 | messages::internalError(asyncResp->res); | 
|  | 434 | }); | 
|  | 435 |  | 
|  | 436 | // create a matcher to wait on CSR object | 
|  | 437 | BMCWEB_LOG_DEBUG << "create matcher with path " << objectPath; | 
|  | 438 | std::string match("type='signal'," | 
|  | 439 | "interface='org.freedesktop.DBus.ObjectManager'," | 
|  | 440 | "path='" + | 
|  | 441 | objectPath + | 
|  | 442 | "'," | 
|  | 443 | "member='InterfacesAdded'"); | 
|  | 444 | csrMatcher = std::make_unique<sdbusplus::bus::match::match>( | 
|  | 445 | *crow::connections::systemBus, match, | 
|  | 446 | [asyncResp, service, objectPath, | 
|  | 447 | certURI](sdbusplus::message::message& m) { | 
|  | 448 | timeout.cancel(); | 
|  | 449 | if (m.is_method_error()) | 
|  | 450 | { | 
|  | 451 | BMCWEB_LOG_ERROR << "Dbus method error!!!"; | 
|  | 452 | messages::internalError(asyncResp->res); | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 453 | return; | 
|  | 454 | } | 
|  | 455 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 456 | dbus::utility::DBusInteracesMap interfacesProperties; | 
|  | 457 |  | 
|  | 458 | sdbusplus::message::object_path csrObjectPath; | 
|  | 459 | m.read(csrObjectPath, interfacesProperties); | 
|  | 460 | BMCWEB_LOG_DEBUG << "CSR object added" << csrObjectPath.str; | 
| Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 461 | for (const auto& interface : interfacesProperties) | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 462 | { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 463 | if (interface.first == "xyz.openbmc_project.Certs.CSR") | 
|  | 464 | { | 
|  | 465 | getCSR(asyncResp, certURI, service, objectPath, | 
|  | 466 | csrObjectPath.str); | 
|  | 467 | break; | 
|  | 468 | } | 
|  | 469 | } | 
|  | 470 | }); | 
|  | 471 | crow::connections::systemBus->async_method_call( | 
|  | 472 | [asyncResp](const boost::system::error_code ec, | 
|  | 473 | const std::string&) { | 
|  | 474 | if (ec) | 
|  | 475 | { | 
|  | 476 | BMCWEB_LOG_ERROR << "DBUS response error: " << ec.message(); | 
|  | 477 | messages::internalError(asyncResp->res); | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 478 | return; | 
|  | 479 | } | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 480 | }, | 
|  | 481 | service, objectPath, "xyz.openbmc_project.Certs.CSR.Create", | 
|  | 482 | "GenerateCSR", *optAlternativeNames, *optChallengePassword, city, | 
|  | 483 | commonName, *optContactPerson, country, *optEmail, *optGivenName, | 
|  | 484 | *optInitials, *optKeyBitLength, *optKeyCurveId, | 
|  | 485 | *optKeyPairAlgorithm, *optKeyUsage, organization, | 
|  | 486 | organizationalUnit, state, *optSurname, *optUnstructuredName); | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 487 | }); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 488 | } // requestRoutesCertificateActionGenerateCSR | 
| Marri Devender Rao | 3021581 | 2019-03-18 08:59:21 -0500 | [diff] [blame] | 489 |  | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 490 | /** | 
| Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 491 | * @brief Parse and update Certificate Issue/Subject property | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 492 | * | 
|  | 493 | * @param[in] asyncResp Shared pointer to the response message | 
|  | 494 | * @param[in] str  Issuer/Subject value in key=value pairs | 
|  | 495 | * @param[in] type Issuer/Subject | 
|  | 496 | * @return None | 
|  | 497 | */ | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 498 | static void updateCertIssuerOrSubject(nlohmann::json& out, | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 499 | const std::string_view value) | 
|  | 500 | { | 
|  | 501 | // example: O=openbmc-project.xyz,CN=localhost | 
|  | 502 | std::string_view::iterator i = value.begin(); | 
|  | 503 | while (i != value.end()) | 
|  | 504 | { | 
|  | 505 | std::string_view::iterator tokenBegin = i; | 
|  | 506 | while (i != value.end() && *i != '=') | 
|  | 507 | { | 
| Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 508 | ++i; | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 509 | } | 
|  | 510 | if (i == value.end()) | 
|  | 511 | { | 
|  | 512 | break; | 
|  | 513 | } | 
| Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 514 | const std::string_view key(tokenBegin, | 
|  | 515 | static_cast<size_t>(i - tokenBegin)); | 
| Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 516 | ++i; | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 517 | tokenBegin = i; | 
|  | 518 | while (i != value.end() && *i != ',') | 
|  | 519 | { | 
| Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 520 | ++i; | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 521 | } | 
| Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 522 | const std::string_view val(tokenBegin, | 
|  | 523 | static_cast<size_t>(i - tokenBegin)); | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 524 | if (key == "L") | 
|  | 525 | { | 
|  | 526 | out["City"] = val; | 
|  | 527 | } | 
|  | 528 | else if (key == "CN") | 
|  | 529 | { | 
|  | 530 | out["CommonName"] = val; | 
|  | 531 | } | 
|  | 532 | else if (key == "C") | 
|  | 533 | { | 
|  | 534 | out["Country"] = val; | 
|  | 535 | } | 
|  | 536 | else if (key == "O") | 
|  | 537 | { | 
|  | 538 | out["Organization"] = val; | 
|  | 539 | } | 
|  | 540 | else if (key == "OU") | 
|  | 541 | { | 
|  | 542 | out["OrganizationalUnit"] = val; | 
|  | 543 | } | 
|  | 544 | else if (key == "ST") | 
|  | 545 | { | 
|  | 546 | out["State"] = val; | 
|  | 547 | } | 
|  | 548 | // skip comma character | 
|  | 549 | if (i != value.end()) | 
|  | 550 | { | 
| Manojkiran Eda | 17a897d | 2020-09-12 15:31:58 +0530 | [diff] [blame] | 551 | ++i; | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 552 | } | 
|  | 553 | } | 
|  | 554 | } | 
|  | 555 |  | 
|  | 556 | /** | 
| Jiaqing Zhao | d3f92ce | 2022-06-03 11:46:12 +0800 | [diff] [blame] | 557 | * @brief Retrieve the installed certificate list | 
|  | 558 | * | 
|  | 559 | * @param[in] asyncResp Shared pointer to the response message | 
|  | 560 | * @param[in] basePath DBus object path to search | 
|  | 561 | * @param[in] listPtr Json pointer to the list in asyncResp | 
|  | 562 | * @param[in] countPtr Json pointer to the count in asyncResp | 
|  | 563 | * @return None | 
|  | 564 | */ | 
|  | 565 | static void | 
|  | 566 | getCertificateList(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, | 
|  | 567 | const std::string& basePath, | 
|  | 568 | const nlohmann::json::json_pointer& listPtr, | 
|  | 569 | const nlohmann::json::json_pointer& countPtr) | 
|  | 570 | { | 
|  | 571 | crow::connections::systemBus->async_method_call( | 
|  | 572 | [asyncResp, listPtr, countPtr]( | 
|  | 573 | const boost::system::error_code ec, | 
|  | 574 | const dbus::utility::MapperGetSubTreePathsResponse& certPaths) { | 
|  | 575 | if (ec) | 
|  | 576 | { | 
|  | 577 | BMCWEB_LOG_ERROR << "Certificate collection query failed: " << ec; | 
|  | 578 | messages::internalError(asyncResp->res); | 
|  | 579 | return; | 
|  | 580 | } | 
|  | 581 |  | 
|  | 582 | nlohmann::json& links = asyncResp->res.jsonValue[listPtr]; | 
|  | 583 | links = nlohmann::json::array(); | 
|  | 584 | for (const auto& certPath : certPaths) | 
|  | 585 | { | 
|  | 586 | sdbusplus::message::object_path objPath(certPath); | 
|  | 587 | std::string certId = objPath.filename(); | 
|  | 588 | if (certId.empty()) | 
|  | 589 | { | 
|  | 590 | BMCWEB_LOG_ERROR << "Invalid certificate objPath " << certPath; | 
|  | 591 | continue; | 
|  | 592 | } | 
|  | 593 |  | 
|  | 594 | boost::urls::url certURL; | 
|  | 595 | if (objPath.parent_path() == certs::httpsObjectPath) | 
|  | 596 | { | 
|  | 597 | certURL = crow::utility::urlFromPieces( | 
|  | 598 | "redfish", "v1", "Managers", "bmc", "NetworkProtocol", | 
|  | 599 | "HTTPS", "Certificates", certId); | 
|  | 600 | } | 
|  | 601 | else if (objPath.parent_path() == certs::ldapObjectPath) | 
|  | 602 | { | 
|  | 603 | certURL = crow::utility::urlFromPieces("redfish", "v1", | 
|  | 604 | "AccountService", "LDAP", | 
|  | 605 | "Certificates", certId); | 
|  | 606 | } | 
|  | 607 | else if (objPath.parent_path() == certs::authorityObjectPath) | 
|  | 608 | { | 
|  | 609 | certURL = crow::utility::urlFromPieces( | 
|  | 610 | "redfish", "v1", "Managers", "bmc", "Truststore", | 
|  | 611 | "Certificates", certId); | 
|  | 612 | } | 
|  | 613 | else | 
|  | 614 | { | 
|  | 615 | continue; | 
|  | 616 | } | 
|  | 617 |  | 
|  | 618 | nlohmann::json::object_t link; | 
|  | 619 | link["@odata.id"] = certURL; | 
|  | 620 | links.emplace_back(std::move(link)); | 
|  | 621 | } | 
|  | 622 |  | 
|  | 623 | asyncResp->res.jsonValue[countPtr] = links.size(); | 
|  | 624 | }, | 
|  | 625 | "xyz.openbmc_project.ObjectMapper", | 
|  | 626 | "/xyz/openbmc_project/object_mapper", | 
|  | 627 | "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", basePath, 0, | 
|  | 628 | std::array<const char*, 1>{certs::certPropIntf}); | 
|  | 629 | } | 
|  | 630 |  | 
|  | 631 | /** | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 632 | * @brief Retrieve the certificates properties and append to the response | 
|  | 633 | * message | 
|  | 634 | * | 
|  | 635 | * @param[in] asyncResp Shared pointer to the response message | 
|  | 636 | * @param[in] objectPath  Path of the D-Bus service object | 
|  | 637 | * @param[in] certId  Id of the certificate | 
|  | 638 | * @param[in] certURL  URL of the certificate object | 
|  | 639 | * @param[in] name  name of the certificate | 
|  | 640 | * @return None | 
|  | 641 | */ | 
|  | 642 | static void getCertificateProperties( | 
| zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 643 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, | 
|  | 644 | const std::string& objectPath, const std::string& service, long certId, | 
|  | 645 | const std::string& certURL, const std::string& name) | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 646 | { | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 647 | BMCWEB_LOG_DEBUG << "getCertificateProperties Path=" << objectPath | 
|  | 648 | << " certId=" << certId << " certURl=" << certURL; | 
|  | 649 | crow::connections::systemBus->async_method_call( | 
| Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 650 | [asyncResp, certURL, certId, | 
|  | 651 | name](const boost::system::error_code ec, | 
|  | 652 | const dbus::utility::DBusPropertiesMap& properties) { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 653 | if (ec) | 
|  | 654 | { | 
|  | 655 | BMCWEB_LOG_ERROR << "DBUS response error: " << ec; | 
|  | 656 | messages::resourceNotFound(asyncResp->res, name, | 
|  | 657 | std::to_string(certId)); | 
|  | 658 | return; | 
|  | 659 | } | 
|  | 660 | asyncResp->res.jsonValue["@odata.id"] = certURL; | 
|  | 661 | asyncResp->res.jsonValue["@odata.type"] = | 
|  | 662 | "#Certificate.v1_0_0.Certificate"; | 
|  | 663 | asyncResp->res.jsonValue["Id"] = std::to_string(certId); | 
|  | 664 | asyncResp->res.jsonValue["Name"] = name; | 
|  | 665 | asyncResp->res.jsonValue["Description"] = name; | 
|  | 666 | for (const auto& property : properties) | 
|  | 667 | { | 
|  | 668 | if (property.first == "CertificateString") | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 669 | { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 670 | asyncResp->res.jsonValue["CertificateString"] = ""; | 
|  | 671 | const std::string* value = | 
|  | 672 | std::get_if<std::string>(&property.second); | 
|  | 673 | if (value != nullptr) | 
|  | 674 | { | 
|  | 675 | asyncResp->res.jsonValue["CertificateString"] = *value; | 
|  | 676 | } | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 677 | } | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 678 | else if (property.first == "KeyUsage") | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 679 | { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 680 | nlohmann::json& keyUsage = asyncResp->res.jsonValue["KeyUsage"]; | 
|  | 681 | keyUsage = nlohmann::json::array(); | 
|  | 682 | const std::vector<std::string>* value = | 
|  | 683 | std::get_if<std::vector<std::string>>(&property.second); | 
|  | 684 | if (value != nullptr) | 
| Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 685 | { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 686 | for (const std::string& usage : *value) | 
| Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 687 | { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 688 | keyUsage.push_back(usage); | 
| Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 689 | } | 
|  | 690 | } | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 691 | } | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 692 | else if (property.first == "Issuer") | 
|  | 693 | { | 
|  | 694 | const std::string* value = | 
|  | 695 | std::get_if<std::string>(&property.second); | 
|  | 696 | if (value != nullptr) | 
|  | 697 | { | 
|  | 698 | updateCertIssuerOrSubject( | 
|  | 699 | asyncResp->res.jsonValue["Issuer"], *value); | 
|  | 700 | } | 
|  | 701 | } | 
|  | 702 | else if (property.first == "Subject") | 
|  | 703 | { | 
|  | 704 | const std::string* value = | 
|  | 705 | std::get_if<std::string>(&property.second); | 
|  | 706 | if (value != nullptr) | 
|  | 707 | { | 
|  | 708 | updateCertIssuerOrSubject( | 
|  | 709 | asyncResp->res.jsonValue["Subject"], *value); | 
|  | 710 | } | 
|  | 711 | } | 
|  | 712 | else if (property.first == "ValidNotAfter") | 
|  | 713 | { | 
|  | 714 | const uint64_t* value = std::get_if<uint64_t>(&property.second); | 
|  | 715 | if (value != nullptr) | 
|  | 716 | { | 
|  | 717 | asyncResp->res.jsonValue["ValidNotAfter"] = | 
|  | 718 | crow::utility::getDateTimeUint(*value); | 
|  | 719 | } | 
|  | 720 | } | 
|  | 721 | else if (property.first == "ValidNotBefore") | 
|  | 722 | { | 
|  | 723 | const uint64_t* value = std::get_if<uint64_t>(&property.second); | 
|  | 724 | if (value != nullptr) | 
|  | 725 | { | 
|  | 726 | asyncResp->res.jsonValue["ValidNotBefore"] = | 
|  | 727 | crow::utility::getDateTimeUint(*value); | 
|  | 728 | } | 
|  | 729 | } | 
|  | 730 | } | 
|  | 731 | asyncResp->res.addHeader("Location", certURL); | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 732 | }, | 
| Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 733 | service, objectPath, certs::dbusPropIntf, "GetAll", | 
|  | 734 | certs::certPropIntf); | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 735 | } | 
|  | 736 |  | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 737 | /** | 
|  | 738 | * Action to replace an existing certificate | 
|  | 739 | */ | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 740 | inline void requestRoutesCertificateActionsReplaceCertificate(App& app) | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 741 | { | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 742 | BMCWEB_ROUTE( | 
|  | 743 | app, | 
|  | 744 | "/redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate/") | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 745 | .privileges(redfish::privileges::postCertificateService) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 746 | .methods(boost::beast::http::verb::post)( | 
|  | 747 | [&app](const crow::Request& req, | 
|  | 748 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 749 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 750 | { | 
|  | 751 | return; | 
|  | 752 | } | 
|  | 753 | std::string certificate; | 
|  | 754 | nlohmann::json certificateUri; | 
|  | 755 | std::optional<std::string> certificateType = "PEM"; | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 756 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 757 | if (!json_util::readJsonAction(req, asyncResp->res, "CertificateString", | 
|  | 758 | certificate, "CertificateUri", | 
|  | 759 | certificateUri, "CertificateType", | 
|  | 760 | certificateType)) | 
|  | 761 | { | 
|  | 762 | BMCWEB_LOG_ERROR << "Required parameters are missing"; | 
|  | 763 | messages::internalError(asyncResp->res); | 
|  | 764 | return; | 
|  | 765 | } | 
|  | 766 |  | 
|  | 767 | if (!certificateType) | 
|  | 768 | { | 
|  | 769 | // should never happen, but it never hurts to be paranoid. | 
|  | 770 | return; | 
|  | 771 | } | 
|  | 772 | if (certificateType != "PEM") | 
|  | 773 | { | 
|  | 774 | messages::actionParameterNotSupported( | 
|  | 775 | asyncResp->res, "CertificateType", "ReplaceCertificate"); | 
|  | 776 | return; | 
|  | 777 | } | 
|  | 778 |  | 
|  | 779 | std::string certURI; | 
|  | 780 | if (!redfish::json_util::readJson(certificateUri, asyncResp->res, | 
|  | 781 | "@odata.id", certURI)) | 
|  | 782 | { | 
|  | 783 | messages::actionParameterMissing( | 
|  | 784 | asyncResp->res, "ReplaceCertificate", "CertificateUri"); | 
|  | 785 | return; | 
|  | 786 | } | 
|  | 787 |  | 
|  | 788 | BMCWEB_LOG_INFO << "Certificate URI to replace" << certURI; | 
|  | 789 | long id = getIDFromURL(certURI); | 
|  | 790 | if (id < 0) | 
|  | 791 | { | 
|  | 792 | messages::actionParameterValueFormatError(asyncResp->res, certURI, | 
|  | 793 | "CertificateUri", | 
|  | 794 | "ReplaceCertificate"); | 
|  | 795 | return; | 
|  | 796 | } | 
|  | 797 | std::string objectPath; | 
|  | 798 | std::string name; | 
|  | 799 | std::string service; | 
| Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 800 | if (certURI.starts_with( | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 801 | "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/")) | 
|  | 802 | { | 
|  | 803 | objectPath = | 
|  | 804 | std::string(certs::httpsObjectPath) + "/" + std::to_string(id); | 
|  | 805 | name = "HTTPS certificate"; | 
|  | 806 | service = certs::httpsServiceName; | 
|  | 807 | } | 
| Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 808 | else if (certURI.starts_with( | 
|  | 809 | "/redfish/v1/AccountService/LDAP/Certificates/")) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 810 | { | 
|  | 811 | objectPath = | 
|  | 812 | std::string(certs::ldapObjectPath) + "/" + std::to_string(id); | 
|  | 813 | name = "LDAP certificate"; | 
|  | 814 | service = certs::ldapServiceName; | 
|  | 815 | } | 
| Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 816 | else if (certURI.starts_with( | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 817 | "/redfish/v1/Managers/bmc/Truststore/Certificates/")) | 
|  | 818 | { | 
|  | 819 | objectPath = std::string(certs::authorityObjectPath) + "/" + | 
|  | 820 | std::to_string(id); | 
|  | 821 | name = "TrustStore certificate"; | 
|  | 822 | service = certs::authorityServiceName; | 
|  | 823 | } | 
|  | 824 | else | 
|  | 825 | { | 
|  | 826 | messages::actionParameterNotSupported( | 
|  | 827 | asyncResp->res, "CertificateUri", "ReplaceCertificate"); | 
|  | 828 | return; | 
|  | 829 | } | 
|  | 830 |  | 
|  | 831 | std::shared_ptr<CertificateFile> certFile = | 
|  | 832 | std::make_shared<CertificateFile>(certificate); | 
|  | 833 | crow::connections::systemBus->async_method_call( | 
|  | 834 | [asyncResp, certFile, objectPath, service, certURI, id, | 
|  | 835 | name](const boost::system::error_code ec) { | 
|  | 836 | if (ec) | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 837 | { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 838 | BMCWEB_LOG_ERROR << "DBUS response error: " << ec; | 
|  | 839 | if (ec.value() == | 
|  | 840 | boost::system::linux_error::bad_request_descriptor) | 
|  | 841 | { | 
|  | 842 | messages::resourceNotFound(asyncResp->res, name, | 
|  | 843 | std::to_string(id)); | 
|  | 844 | return; | 
|  | 845 | } | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 846 | messages::internalError(asyncResp->res); | 
|  | 847 | return; | 
|  | 848 | } | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 849 | getCertificateProperties(asyncResp, objectPath, service, id, | 
|  | 850 | certURI, name); | 
|  | 851 | BMCWEB_LOG_DEBUG << "HTTPS certificate install file=" | 
|  | 852 | << certFile->getCertFilePath(); | 
|  | 853 | }, | 
|  | 854 | service, objectPath, certs::certReplaceIntf, "Replace", | 
|  | 855 | certFile->getCertFilePath()); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 856 | }); | 
|  | 857 | } // requestRoutesCertificateActionsReplaceCertificate | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 858 |  | 
|  | 859 | /** | 
|  | 860 | * Certificate resource describes a certificate used to prove the identity | 
|  | 861 | * of a component, account or service. | 
|  | 862 | */ | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 863 |  | 
|  | 864 | inline void requestRoutesHTTPSCertificate(App& app) | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 865 | { | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 866 | BMCWEB_ROUTE( | 
|  | 867 | app, | 
|  | 868 | "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/<str>/") | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 869 | .privileges(redfish::privileges::getCertificate) | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 870 | .methods( | 
|  | 871 | boost::beast::http::verb:: | 
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 872 | get)([&app](const crow::Request& req, | 
|  | 873 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, | 
|  | 874 | const std::string& param) -> void { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 875 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 876 | { | 
|  | 877 | return; | 
|  | 878 | } | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 879 | if (param.empty()) | 
|  | 880 | { | 
|  | 881 | messages::internalError(asyncResp->res); | 
|  | 882 | return; | 
|  | 883 | } | 
|  | 884 | long id = getIDFromURL(req.url); | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 885 |  | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 886 | BMCWEB_LOG_DEBUG << "HTTPSCertificate::doGet ID=" | 
|  | 887 | << std::to_string(id); | 
|  | 888 | std::string certURL = | 
|  | 889 | "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/" + | 
|  | 890 | std::to_string(id); | 
|  | 891 | std::string objectPath = certs::httpsObjectPath; | 
|  | 892 | objectPath += "/"; | 
|  | 893 | objectPath += std::to_string(id); | 
|  | 894 | getCertificateProperties(asyncResp, objectPath, | 
|  | 895 | certs::httpsServiceName, id, certURL, | 
|  | 896 | "HTTPS Certificate"); | 
|  | 897 | }); | 
|  | 898 | } | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 899 |  | 
|  | 900 | /** | 
|  | 901 | * Collection of HTTPS certificates | 
|  | 902 | */ | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 903 | inline void requestRoutesHTTPSCertificateCollection(App& app) | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 904 | { | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 905 | BMCWEB_ROUTE(app, | 
|  | 906 | "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/") | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 907 | .privileges(redfish::privileges::getCertificateCollection) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 908 | .methods(boost::beast::http::verb::get)( | 
|  | 909 | [&app](const crow::Request& req, | 
|  | 910 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 911 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 912 | { | 
|  | 913 | return; | 
|  | 914 | } | 
|  | 915 |  | 
|  | 916 | asyncResp->res.jsonValue["@odata.id"] = | 
|  | 917 | "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates"; | 
|  | 918 | asyncResp->res.jsonValue["@odata.type"] = | 
|  | 919 | "#CertificateCollection.CertificateCollection"; | 
|  | 920 | asyncResp->res.jsonValue["Name"] = "HTTPS Certificates Collection"; | 
|  | 921 | asyncResp->res.jsonValue["Description"] = | 
|  | 922 | "A Collection of HTTPS certificate instances"; | 
|  | 923 |  | 
| Jiaqing Zhao | d3f92ce | 2022-06-03 11:46:12 +0800 | [diff] [blame] | 924 | getCertificateList(asyncResp, certs::httpsObjectPath, | 
|  | 925 | "/Members"_json_pointer, | 
|  | 926 | "/Members@odata.count"_json_pointer); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 927 | }); | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 928 |  | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 929 | BMCWEB_ROUTE(app, | 
|  | 930 | "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/") | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 931 | .privileges(redfish::privileges::postCertificateCollection) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 932 | .methods(boost::beast::http::verb::post)( | 
|  | 933 | [&app](const crow::Request& req, | 
|  | 934 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 935 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 936 | { | 
|  | 937 | return; | 
|  | 938 | } | 
|  | 939 | BMCWEB_LOG_DEBUG << "HTTPSCertificateCollection::doPost"; | 
|  | 940 |  | 
|  | 941 | asyncResp->res.jsonValue["Name"] = "HTTPS Certificate"; | 
|  | 942 | asyncResp->res.jsonValue["Description"] = "HTTPS Certificate"; | 
|  | 943 |  | 
|  | 944 | std::string certFileBody = getCertificateFromReqBody(asyncResp, req); | 
|  | 945 |  | 
|  | 946 | if (certFileBody.empty()) | 
|  | 947 | { | 
|  | 948 | BMCWEB_LOG_ERROR << "Cannot get certificate from request body."; | 
|  | 949 | messages::unrecognizedRequestBody(asyncResp->res); | 
|  | 950 | return; | 
|  | 951 | } | 
|  | 952 |  | 
|  | 953 | std::shared_ptr<CertificateFile> certFile = | 
|  | 954 | std::make_shared<CertificateFile>(certFileBody); | 
|  | 955 |  | 
|  | 956 | crow::connections::systemBus->async_method_call( | 
|  | 957 | [asyncResp, certFile](const boost::system::error_code ec, | 
|  | 958 | const std::string& objectPath) { | 
|  | 959 | if (ec) | 
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 960 | { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 961 | BMCWEB_LOG_ERROR << "DBUS response error: " << ec; | 
|  | 962 | messages::internalError(asyncResp->res); | 
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 963 | return; | 
|  | 964 | } | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 965 | long certId = getIDFromURL(objectPath); | 
|  | 966 | if (certId < 0) | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 967 | { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 968 | BMCWEB_LOG_ERROR << "Invalid objectPath value" << objectPath; | 
|  | 969 | messages::internalError(asyncResp->res); | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 970 | return; | 
|  | 971 | } | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 972 | std::string certURL = | 
|  | 973 | "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/" + | 
|  | 974 | std::to_string(certId); | 
|  | 975 | getCertificateProperties(asyncResp, objectPath, | 
|  | 976 | certs::httpsServiceName, certId, certURL, | 
|  | 977 | "HTTPS Certificate"); | 
|  | 978 | BMCWEB_LOG_DEBUG << "HTTPS certificate install file=" | 
|  | 979 | << certFile->getCertFilePath(); | 
|  | 980 | }, | 
|  | 981 | certs::httpsServiceName, certs::httpsObjectPath, | 
|  | 982 | certs::certInstallIntf, "Install", certFile->getCertFilePath()); | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 983 | }); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 984 | } // requestRoutesHTTPSCertificateCollection | 
|  | 985 |  | 
|  | 986 | /** | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 987 | * The certificate location schema defines a resource that an administrator | 
|  | 988 | * can use in order to locate all certificates installed on a given service. | 
|  | 989 | */ | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 990 | inline void requestRoutesCertificateLocations(App& app) | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 991 | { | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 992 | BMCWEB_ROUTE(app, "/redfish/v1/CertificateService/CertificateLocations/") | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 993 | .privileges(redfish::privileges::getCertificateLocations) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 994 | .methods(boost::beast::http::verb::get)( | 
|  | 995 | [&app](const crow::Request& req, | 
|  | 996 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 997 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 998 | { | 
|  | 999 | return; | 
|  | 1000 | } | 
|  | 1001 | asyncResp->res.jsonValue["@odata.id"] = | 
|  | 1002 | "/redfish/v1/CertificateService/CertificateLocations"; | 
|  | 1003 | asyncResp->res.jsonValue["@odata.type"] = | 
|  | 1004 | "#CertificateLocations.v1_0_0.CertificateLocations"; | 
|  | 1005 | asyncResp->res.jsonValue["Name"] = "Certificate Locations"; | 
|  | 1006 | asyncResp->res.jsonValue["Id"] = "CertificateLocations"; | 
|  | 1007 | asyncResp->res.jsonValue["Description"] = | 
|  | 1008 | "Defines a resource that an administrator can use in order to " | 
|  | 1009 | "locate all certificates installed on a given service"; | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 1010 |  | 
| Jiaqing Zhao | d3f92ce | 2022-06-03 11:46:12 +0800 | [diff] [blame] | 1011 | getCertificateList(asyncResp, certs::baseObjectPath, | 
|  | 1012 | "/Links/Certificates"_json_pointer, | 
|  | 1013 | "/Links/Certificates@odata.count"_json_pointer); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1014 | }); | 
|  | 1015 | } | 
|  | 1016 | // requestRoutesCertificateLocations | 
| Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 1017 |  | 
|  | 1018 | /** | 
|  | 1019 | * Collection of LDAP certificates | 
|  | 1020 | */ | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1021 | inline void requestRoutesLDAPCertificateCollection(App& app) | 
| Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 1022 | { | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1023 | BMCWEB_ROUTE(app, "/redfish/v1/AccountService/LDAP/Certificates/") | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1024 | .privileges(redfish::privileges::getCertificateCollection) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1025 | .methods(boost::beast::http::verb::get)( | 
|  | 1026 | [&app](const crow::Request& req, | 
|  | 1027 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1028 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1029 | { | 
|  | 1030 | return; | 
|  | 1031 | } | 
|  | 1032 |  | 
|  | 1033 | asyncResp->res.jsonValue["@odata.id"] = | 
|  | 1034 | "/redfish/v1/AccountService/LDAP/Certificates"; | 
|  | 1035 | asyncResp->res.jsonValue["@odata.type"] = | 
|  | 1036 | "#CertificateCollection.CertificateCollection"; | 
|  | 1037 | asyncResp->res.jsonValue["Name"] = "LDAP Certificates Collection"; | 
|  | 1038 | asyncResp->res.jsonValue["Description"] = | 
|  | 1039 | "A Collection of LDAP certificate instances"; | 
|  | 1040 |  | 
| Jiaqing Zhao | d3f92ce | 2022-06-03 11:46:12 +0800 | [diff] [blame] | 1041 | getCertificateList(asyncResp, certs::ldapObjectPath, | 
|  | 1042 | "/Members"_json_pointer, | 
|  | 1043 | "/Members@odata.count"_json_pointer); | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1044 | }); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1045 |  | 
|  | 1046 | BMCWEB_ROUTE(app, "/redfish/v1/AccountService/LDAP/Certificates/") | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1047 | .privileges(redfish::privileges::postCertificateCollection) | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1048 | .methods(boost::beast::http::verb::post)( | 
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1049 | [&app](const crow::Request& req, | 
|  | 1050 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1051 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1052 | { | 
|  | 1053 | return; | 
|  | 1054 | } | 
|  | 1055 | std::string certFileBody = getCertificateFromReqBody(asyncResp, req); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1056 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1057 | if (certFileBody.empty()) | 
|  | 1058 | { | 
|  | 1059 | BMCWEB_LOG_ERROR << "Cannot get certificate from request body."; | 
|  | 1060 | messages::unrecognizedRequestBody(asyncResp->res); | 
|  | 1061 | return; | 
|  | 1062 | } | 
| Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 1063 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1064 | std::shared_ptr<CertificateFile> certFile = | 
|  | 1065 | std::make_shared<CertificateFile>(certFileBody); | 
| zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1066 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1067 | crow::connections::systemBus->async_method_call( | 
|  | 1068 | [asyncResp, certFile](const boost::system::error_code ec, | 
|  | 1069 | const std::string& objectPath) { | 
|  | 1070 | if (ec) | 
|  | 1071 | { | 
|  | 1072 | BMCWEB_LOG_ERROR << "DBUS response error: " << ec; | 
|  | 1073 | messages::internalError(asyncResp->res); | 
|  | 1074 | return; | 
|  | 1075 | } | 
|  | 1076 | long certId = getIDFromURL(objectPath); | 
|  | 1077 | if (certId < 0) | 
|  | 1078 | { | 
|  | 1079 | BMCWEB_LOG_ERROR << "Invalid objectPath value" << objectPath; | 
|  | 1080 | messages::internalError(asyncResp->res); | 
|  | 1081 | return; | 
|  | 1082 | } | 
|  | 1083 | std::string certURL = | 
|  | 1084 | "/redfish/v1/AccountService/LDAP/Certificates/" + | 
|  | 1085 | std::to_string(certId); | 
|  | 1086 | getCertificateProperties(asyncResp, objectPath, | 
|  | 1087 | certs::ldapServiceName, certId, certURL, | 
|  | 1088 | "LDAP Certificate"); | 
|  | 1089 | BMCWEB_LOG_DEBUG << "LDAP certificate install file=" | 
|  | 1090 | << certFile->getCertFilePath(); | 
|  | 1091 | }, | 
|  | 1092 | certs::ldapServiceName, certs::ldapObjectPath, | 
|  | 1093 | certs::certInstallIntf, "Install", certFile->getCertFilePath()); | 
|  | 1094 | }); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1095 | } // requestRoutesLDAPCertificateCollection | 
| Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 1096 |  | 
|  | 1097 | /** | 
|  | 1098 | * Certificate resource describes a certificate used to prove the identity | 
|  | 1099 | * of a component, account or service. | 
|  | 1100 | */ | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1101 | inline void requestRoutesLDAPCertificate(App& app) | 
| Marri Devender Rao | 37cce91 | 2019-02-20 01:05:22 -0600 | [diff] [blame] | 1102 | { | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1103 | BMCWEB_ROUTE(app, "/redfish/v1/AccountService/LDAP/Certificates/<str>/") | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1104 | .privileges(redfish::privileges::getCertificate) | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1105 | .methods(boost::beast::http::verb::get)( | 
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1106 | [&app](const crow::Request& req, | 
|  | 1107 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, | 
|  | 1108 | const std::string&) { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1109 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1110 | { | 
|  | 1111 | return; | 
|  | 1112 | } | 
|  | 1113 | long id = getIDFromURL(req.url); | 
|  | 1114 | if (id < 0) | 
|  | 1115 | { | 
|  | 1116 | BMCWEB_LOG_ERROR << "Invalid url value" << req.url; | 
|  | 1117 | messages::internalError(asyncResp->res); | 
|  | 1118 | return; | 
|  | 1119 | } | 
|  | 1120 | BMCWEB_LOG_DEBUG << "LDAP Certificate ID=" << std::to_string(id); | 
|  | 1121 | std::string certURL = "/redfish/v1/AccountService/LDAP/Certificates/" + | 
|  | 1122 | std::to_string(id); | 
|  | 1123 | std::string objectPath = certs::ldapObjectPath; | 
|  | 1124 | objectPath += "/"; | 
|  | 1125 | objectPath += std::to_string(id); | 
|  | 1126 | getCertificateProperties(asyncResp, objectPath, certs::ldapServiceName, | 
|  | 1127 | id, certURL, "LDAP Certificate"); | 
|  | 1128 | }); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1129 | } // requestRoutesLDAPCertificate | 
| Marri Devender Rao | cfcd5f6 | 2019-05-17 08:34:37 -0500 | [diff] [blame] | 1130 | /** | 
|  | 1131 | * Collection of TrustStoreCertificate certificates | 
|  | 1132 | */ | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1133 | inline void requestRoutesTrustStoreCertificateCollection(App& app) | 
| Marri Devender Rao | cfcd5f6 | 2019-05-17 08:34:37 -0500 | [diff] [blame] | 1134 | { | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1135 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Truststore/Certificates/") | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1136 | .privileges(redfish::privileges::getCertificate) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1137 | .methods(boost::beast::http::verb::get)( | 
|  | 1138 | [&app](const crow::Request& req, | 
|  | 1139 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1140 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1141 | { | 
|  | 1142 | return; | 
|  | 1143 | } | 
|  | 1144 |  | 
|  | 1145 | asyncResp->res.jsonValue["@odata.id"] = | 
|  | 1146 | "/redfish/v1/Managers/bmc/Truststore/Certificates/"; | 
|  | 1147 | asyncResp->res.jsonValue["@odata.type"] = | 
|  | 1148 | "#CertificateCollection.CertificateCollection"; | 
|  | 1149 | asyncResp->res.jsonValue["Name"] = "TrustStore Certificates Collection"; | 
|  | 1150 | asyncResp->res.jsonValue["Description"] = | 
|  | 1151 | "A Collection of TrustStore certificate instances"; | 
|  | 1152 |  | 
| Jiaqing Zhao | d3f92ce | 2022-06-03 11:46:12 +0800 | [diff] [blame] | 1153 | getCertificateList(asyncResp, certs::authorityObjectPath, | 
|  | 1154 | "/Members"_json_pointer, | 
|  | 1155 | "/Members@odata.count"_json_pointer); | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1156 | }); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1157 |  | 
|  | 1158 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Truststore/Certificates/") | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1159 | .privileges(redfish::privileges::postCertificateCollection) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1160 | .methods(boost::beast::http::verb::post)( | 
|  | 1161 | [&app](const crow::Request& req, | 
|  | 1162 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1163 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1164 | { | 
|  | 1165 | return; | 
|  | 1166 | } | 
|  | 1167 | std::string certFileBody = getCertificateFromReqBody(asyncResp, req); | 
|  | 1168 |  | 
|  | 1169 | if (certFileBody.empty()) | 
|  | 1170 | { | 
|  | 1171 | BMCWEB_LOG_ERROR << "Cannot get certificate from request body."; | 
|  | 1172 | messages::unrecognizedRequestBody(asyncResp->res); | 
|  | 1173 | return; | 
|  | 1174 | } | 
|  | 1175 |  | 
|  | 1176 | std::shared_ptr<CertificateFile> certFile = | 
|  | 1177 | std::make_shared<CertificateFile>(certFileBody); | 
|  | 1178 | crow::connections::systemBus->async_method_call( | 
|  | 1179 | [asyncResp, certFile](const boost::system::error_code ec, | 
|  | 1180 | const std::string& objectPath) { | 
|  | 1181 | if (ec) | 
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1182 | { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1183 | BMCWEB_LOG_ERROR << "DBUS response error: " << ec; | 
|  | 1184 | messages::internalError(asyncResp->res); | 
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1185 | return; | 
|  | 1186 | } | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1187 | long certId = getIDFromURL(objectPath); | 
|  | 1188 | if (certId < 0) | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1189 | { | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1190 | BMCWEB_LOG_ERROR << "Invalid objectPath value" << objectPath; | 
|  | 1191 | messages::internalError(asyncResp->res); | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1192 | return; | 
|  | 1193 | } | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1194 | std::string certURL = | 
|  | 1195 | "/redfish/v1/Managers/bmc/Truststore/Certificates/" + | 
|  | 1196 | std::to_string(certId); | 
| Marri Devender Rao | cfcd5f6 | 2019-05-17 08:34:37 -0500 | [diff] [blame] | 1197 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1198 | getCertificateProperties(asyncResp, objectPath, | 
|  | 1199 | certs::authorityServiceName, certId, | 
|  | 1200 | certURL, "TrustStore Certificate"); | 
|  | 1201 | BMCWEB_LOG_DEBUG << "TrustStore certificate install file=" | 
|  | 1202 | << certFile->getCertFilePath(); | 
|  | 1203 | }, | 
|  | 1204 | certs::authorityServiceName, certs::authorityObjectPath, | 
|  | 1205 | certs::certInstallIntf, "Install", certFile->getCertFilePath()); | 
| George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 1206 | }); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1207 | } // requestRoutesTrustStoreCertificateCollection | 
| Marri Devender Rao | cfcd5f6 | 2019-05-17 08:34:37 -0500 | [diff] [blame] | 1208 |  | 
|  | 1209 | /** | 
|  | 1210 | * Certificate resource describes a certificate used to prove the identity | 
|  | 1211 | * of a component, account or service. | 
|  | 1212 | */ | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1213 | inline void requestRoutesTrustStoreCertificate(App& app) | 
| Marri Devender Rao | cfcd5f6 | 2019-05-17 08:34:37 -0500 | [diff] [blame] | 1214 | { | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1215 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Truststore/Certificates/<str>/") | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1216 | .privileges(redfish::privileges::getCertificate) | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1217 | .methods(boost::beast::http::verb::get)( | 
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1218 | [&app](const crow::Request& req, | 
|  | 1219 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, | 
|  | 1220 | const std::string&) { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1221 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1222 | { | 
|  | 1223 | return; | 
|  | 1224 | } | 
|  | 1225 | long id = getIDFromURL(req.url); | 
|  | 1226 | if (id < 0) | 
|  | 1227 | { | 
|  | 1228 | BMCWEB_LOG_ERROR << "Invalid url value" << req.url; | 
|  | 1229 | messages::internalError(asyncResp->res); | 
|  | 1230 | return; | 
|  | 1231 | } | 
|  | 1232 | BMCWEB_LOG_DEBUG << "TrustStoreCertificate::doGet ID=" | 
|  | 1233 | << std::to_string(id); | 
|  | 1234 | std::string certURL = | 
|  | 1235 | "/redfish/v1/Managers/bmc/Truststore/Certificates/" + | 
|  | 1236 | std::to_string(id); | 
|  | 1237 | std::string objectPath = certs::authorityObjectPath; | 
|  | 1238 | objectPath += "/"; | 
|  | 1239 | objectPath += std::to_string(id); | 
|  | 1240 | getCertificateProperties(asyncResp, objectPath, | 
|  | 1241 | certs::authorityServiceName, id, certURL, | 
|  | 1242 | "TrustStore Certificate"); | 
|  | 1243 | }); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1244 |  | 
|  | 1245 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Truststore/Certificates/<str>/") | 
| Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1246 | .privileges(redfish::privileges::deleteCertificate) | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1247 | .methods(boost::beast::http::verb::delete_)( | 
| Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1248 | [&app](const crow::Request& req, | 
|  | 1249 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, | 
|  | 1250 | const std::string& param) { | 
| Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 1251 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1252 | { | 
|  | 1253 | return; | 
|  | 1254 | } | 
|  | 1255 | if (param.empty()) | 
|  | 1256 | { | 
|  | 1257 | messages::internalError(asyncResp->res); | 
|  | 1258 | return; | 
|  | 1259 | } | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1260 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1261 | long id = getIDFromURL(req.url); | 
|  | 1262 | if (id < 0) | 
|  | 1263 | { | 
|  | 1264 | BMCWEB_LOG_ERROR << "Invalid url value: " << req.url; | 
|  | 1265 | messages::resourceNotFound(asyncResp->res, "TrustStore Certificate", | 
|  | 1266 | std::string(req.url)); | 
|  | 1267 | return; | 
|  | 1268 | } | 
|  | 1269 | BMCWEB_LOG_DEBUG << "TrustStoreCertificate::doDelete ID=" | 
|  | 1270 | << std::to_string(id); | 
|  | 1271 | std::string certPath = certs::authorityObjectPath; | 
|  | 1272 | certPath += "/"; | 
|  | 1273 | certPath += std::to_string(id); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1274 |  | 
| Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1275 | crow::connections::systemBus->async_method_call( | 
|  | 1276 | [asyncResp, id](const boost::system::error_code ec) { | 
|  | 1277 | if (ec) | 
|  | 1278 | { | 
|  | 1279 | messages::resourceNotFound(asyncResp->res, | 
|  | 1280 | "TrustStore Certificate", | 
|  | 1281 | std::to_string(id)); | 
|  | 1282 | return; | 
|  | 1283 | } | 
|  | 1284 | BMCWEB_LOG_INFO << "Certificate deleted"; | 
|  | 1285 | asyncResp->res.result(boost::beast::http::status::no_content); | 
|  | 1286 | }, | 
|  | 1287 | certs::authorityServiceName, certPath, certs::objDeleteIntf, | 
|  | 1288 | "Delete"); | 
|  | 1289 | }); | 
| John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1290 | } // requestRoutesTrustStoreCertificate | 
| Marri Devender Rao | 5968cae | 2019-01-21 10:27:12 -0600 | [diff] [blame] | 1291 | } // namespace redfish |