use new sdbus++ camelcase for CSR.
Change I17a8d7479556596a3cf252b3f4eae9c8df547189 will change
how sdbus++ generates names which start with an acronym.
Prepare for this by keying off the SDBUSPP_NEW_CAMELCASE
define to use the new format.
Changes:
cSR() -> csr()
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I9adb628d7d064af9f65d37aebe99e06532690163
diff --git a/bmc-vmi-ca/ca_cert_entry.hpp b/bmc-vmi-ca/ca_cert_entry.hpp
index 245a5cc..ad7ffce 100644
--- a/bmc-vmi-ca/ca_cert_entry.hpp
+++ b/bmc-vmi-ca/ca_cert_entry.hpp
@@ -50,7 +50,11 @@
bus(bus), id(entryId), manager(manager)
{
+#ifdef SDBUSPP_NEW_CAMELCASE
+ this->csr(csr);
+#else
cSR(csr);
+#endif
clientCertificate(cert);
// Emit deferred signal.
diff --git a/csr.cpp b/csr.cpp
index 1850935..556f09a 100644
--- a/csr.cpp
+++ b/csr.cpp
@@ -1,81 +1,85 @@
-#include "config.h"
-
-#include "csr.hpp"
-
-#include <openssl/pem.h>
-
-#include <filesystem>
-#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/elog.hpp>
-#include <xyz/openbmc_project/Certs/error.hpp>
-#include <xyz/openbmc_project/Common/error.hpp>
-
-namespace phosphor
-{
-namespace certs
-{
-
-using X509_REQ_Ptr = std::unique_ptr<X509_REQ, decltype(&::X509_REQ_free)>;
-using BIO_Ptr = std::unique_ptr<BIO, decltype(&::BIO_free_all)>;
-using InternalFailure =
- sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
-using namespace phosphor::logging;
-namespace fs = std::filesystem;
-
-CSR::CSR(sdbusplus::bus::bus& bus, const char* path,
- CertInstallPath&& installPath, const Status& status) :
- CSRIface(bus, path, true),
- bus(bus), objectPath(path), certInstallPath(std::move(installPath)),
- csrStatus(status)
-{
- // Emit deferred signal.
- this->emit_object_added();
-}
-
-std::string CSR::cSR()
-{
- if (csrStatus == Status::FAILURE)
- {
- log<level::ERR>("Failure in Generating CSR");
- elog<InternalFailure>();
- }
- fs::path csrFilePath = certInstallPath;
- csrFilePath = csrFilePath.parent_path() / CSR_FILE_NAME;
- if (!fs::exists(csrFilePath))
- {
- log<level::ERR>("CSR file doesn't exists",
- entry("FILENAME=%s", csrFilePath.c_str()));
- elog<InternalFailure>();
- }
-
- FILE* fp = std::fopen(csrFilePath.c_str(), "r");
- X509_REQ_Ptr x509Req(PEM_read_X509_REQ(fp, NULL, NULL, NULL),
- ::X509_REQ_free);
- if (x509Req == NULL || fp == NULL)
- {
- if (fp != NULL)
- {
- std::fclose(fp);
- }
- log<level::ERR>("ERROR occured while reading CSR file",
- entry("FILENAME=%s", csrFilePath.c_str()));
- elog<InternalFailure>();
- }
- std::fclose(fp);
-
- BIO_Ptr bio(BIO_new(BIO_s_mem()), ::BIO_free_all);
- int ret = PEM_write_bio_X509_REQ(bio.get(), x509Req.get());
- if (ret <= 0)
- {
- log<level::ERR>("Error occured while calling PEM_write_bio_X509_REQ");
- elog<InternalFailure>();
- }
-
- BUF_MEM* mem = NULL;
- BIO_get_mem_ptr(bio.get(), &mem);
- std::string pem(mem->data, mem->length);
- return pem;
-}
-
-} // namespace certs
-} // namespace phosphor
+#include "config.h"
+
+#include "csr.hpp"
+
+#include <openssl/pem.h>
+
+#include <filesystem>
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <xyz/openbmc_project/Certs/error.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
+
+namespace phosphor
+{
+namespace certs
+{
+
+using X509_REQ_Ptr = std::unique_ptr<X509_REQ, decltype(&::X509_REQ_free)>;
+using BIO_Ptr = std::unique_ptr<BIO, decltype(&::BIO_free_all)>;
+using InternalFailure =
+ sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
+using namespace phosphor::logging;
+namespace fs = std::filesystem;
+
+CSR::CSR(sdbusplus::bus::bus& bus, const char* path,
+ CertInstallPath&& installPath, const Status& status) :
+ CSRIface(bus, path, true),
+ bus(bus), objectPath(path), certInstallPath(std::move(installPath)),
+ csrStatus(status)
+{
+ // Emit deferred signal.
+ this->emit_object_added();
+}
+
+#ifdef SDBUSPP_NEW_CAMELCASE
+std::string CSR::csr()
+#else
+std::string CSR::cSR()
+#endif
+{
+ if (csrStatus == Status::FAILURE)
+ {
+ log<level::ERR>("Failure in Generating CSR");
+ elog<InternalFailure>();
+ }
+ fs::path csrFilePath = certInstallPath;
+ csrFilePath = csrFilePath.parent_path() / CSR_FILE_NAME;
+ if (!fs::exists(csrFilePath))
+ {
+ log<level::ERR>("CSR file doesn't exists",
+ entry("FILENAME=%s", csrFilePath.c_str()));
+ elog<InternalFailure>();
+ }
+
+ FILE* fp = std::fopen(csrFilePath.c_str(), "r");
+ X509_REQ_Ptr x509Req(PEM_read_X509_REQ(fp, NULL, NULL, NULL),
+ ::X509_REQ_free);
+ if (x509Req == NULL || fp == NULL)
+ {
+ if (fp != NULL)
+ {
+ std::fclose(fp);
+ }
+ log<level::ERR>("ERROR occured while reading CSR file",
+ entry("FILENAME=%s", csrFilePath.c_str()));
+ elog<InternalFailure>();
+ }
+ std::fclose(fp);
+
+ BIO_Ptr bio(BIO_new(BIO_s_mem()), ::BIO_free_all);
+ int ret = PEM_write_bio_X509_REQ(bio.get(), x509Req.get());
+ if (ret <= 0)
+ {
+ log<level::ERR>("Error occured while calling PEM_write_bio_X509_REQ");
+ elog<InternalFailure>();
+ }
+
+ BUF_MEM* mem = NULL;
+ BIO_get_mem_ptr(bio.get(), &mem);
+ std::string pem(mem->data, mem->length);
+ return pem;
+}
+
+} // namespace certs
+} // namespace phosphor
diff --git a/csr.hpp b/csr.hpp
index 728cfef..45ebf00 100644
--- a/csr.hpp
+++ b/csr.hpp
@@ -39,7 +39,11 @@
CertInstallPath&& installPath, const Status& status);
/** @brief Return CSR
*/
+#ifdef SDBUSPP_NEW_CAMELCASE
+ std::string csr() override;
+#else
std::string cSR() override;
+#endif
private:
/** @brief sdbusplus handler */
diff --git a/test/certs_manager_test.cpp b/test/certs_manager_test.cpp
index b971bed..6244359 100644
--- a/test/certs_manager_test.cpp
+++ b/test/certs_manager_test.cpp
@@ -146,7 +146,7 @@
MainApp(phosphor::certs::Manager* manager,
phosphor::certs::CSR* csr = nullptr) :
manager(manager),
- csr(csr)
+ csr_(csr)
{
}
void install(std::string& path)
@@ -176,12 +176,19 @@
keyCurveId, keyPairAlgorithm, keyUsage, organization,
organizationalUnit, state, surname, unstructuredName));
}
+#ifdef SDBUSPP_NEW_CAMELCASE
+ std::string csr()
+ {
+ return (csr_->csr());
+ }
+#else
std::string cSR()
{
- return (csr->cSR());
+ return (csr_->cSR());
}
+#endif
phosphor::certs::Manager* manager;
- phosphor::certs::CSR* csr;
+ phosphor::certs::CSR* csr_;
};
/** @brief Check if server install routine is invoked for server setup
@@ -896,7 +903,11 @@
{
try
{
+#ifdef SDBUSPP_NEW_CAMELCASE
+ csrData = csr.csr();
+#else
csrData = csr.cSR();
+#endif
}
catch (const InternalFailure& e)
{
@@ -908,7 +919,11 @@
sleep(10);
EXPECT_TRUE(fs::exists(CSRPath));
EXPECT_TRUE(fs::exists(privateKeyPath));
+#ifdef SDBUSPP_NEW_CAMELCASE
+ csrData = csr.csr();
+#else
csrData = csr.cSR();
+#endif
ASSERT_NE("", csrData.c_str());
}