diff --git a/.gitignore b/.gitignore index 2674aa109..fe793897e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *build* *vscode +.cache/ workspace.yaml CMakeLists.txt.user !doc/build-with-fetchcontent diff --git a/include/ocpp/common/pki_handler.hpp b/include/ocpp/common/pki_handler.hpp index 0502fadb9..d951633f8 100644 --- a/include/ocpp/common/pki_handler.hpp +++ b/include/ocpp/common/pki_handler.hpp @@ -3,8 +3,8 @@ #ifndef OCPP_COMMON_PKI_HANDLER #define OCPP_COMMON_PKI_HANDLER -#include #include +#include #include #include #include @@ -51,21 +51,21 @@ using X509_STORE_CTX_ptr = std::unique_ptr; // filenames of ca certificates -const std::filesystem::path CSMS_ROOT_CA("CSMS_ROOT_CA.pem"); -const std::filesystem::path CSMS_ROOT_CA_BACKUP("CSMS_ROOT_CA_BACKUP.pem"); +const fs::path CSMS_ROOT_CA("CSMS_ROOT_CA.pem"); +const fs::path CSMS_ROOT_CA_BACKUP("CSMS_ROOT_CA_BACKUP.pem"); // filenames of leaf certificates, csrs and private keys -const std::filesystem::path CSMS_LEAF("CSMS_LEAF.pem"); -const std::filesystem::path CSMS_LEAF_KEY("CSMS_LEAF.key"); -const std::filesystem::path CSMS_LEAF_KEY_BACKUP("CSMS_LEAF_BACKUP.key"); -const std::filesystem::path CSMS_CSR("CSMS_CSR.pem"); -const std::filesystem::path V2G_LEAF("SECC_LEAF.pem"); // SECC_LEAF in ISO15118 -const std::filesystem::path V2G_LEAF_KEY("SECC_LEAF.key"); -const std::filesystem::path V2G_LEAF_KEY_BACKUP("SECC_LEAF_BACKUP.key"); -const std::filesystem::path V2G_CSR("SECC_CSR.pem"); +const fs::path CSMS_LEAF("CSMS_LEAF.pem"); +const fs::path CSMS_LEAF_KEY("CSMS_LEAF.key"); +const fs::path CSMS_LEAF_KEY_BACKUP("CSMS_LEAF_BACKUP.key"); +const fs::path CSMS_CSR("CSMS_CSR.pem"); +const fs::path V2G_LEAF("SECC_LEAF.pem"); // SECC_LEAF in ISO15118 +const fs::path V2G_LEAF_KEY("SECC_LEAF.key"); +const fs::path V2G_LEAF_KEY_BACKUP("SECC_LEAF_BACKUP.key"); +const fs::path V2G_CSR("SECC_CSR.pem"); struct X509Certificate { - std::filesystem::path path; + fs::path path; X509* x509; std::string str; CertificateType type; @@ -73,13 +73,13 @@ struct X509Certificate { int validTo; // seconds. If < 0 cert has expired X509Certificate(){}; - X509Certificate(std::filesystem::path path, X509* x509, std::string str); + X509Certificate(fs::path path, X509* x509, std::string str); ~X509Certificate(); /// \brief writes the X509 certificate to the path set bool write(); /// \brief writes the X509 certificate to the given \p path - bool write(const std::filesystem::path& path); + bool write(const fs::path& path); /// \brief Gets CN of certificate std::string getCommonName(); @@ -100,11 +100,11 @@ struct X509Certificate { OCSPRequestData getOCSPRequestData(); }; /// \brief loads a X509Certificate from the given \p pat -std::shared_ptr loadFromFile(const std::filesystem::path& path); +std::shared_ptr loadFromFile(const fs::path& path); /// \brief loads a X509Certificate from the given \p st std::shared_ptr loadFromString(std::string& str); /// \brief reads a file from the given \p path to a strin -std::string readFileToString(const std::filesystem::path& path); +std::string readFileToString(const fs::path& path); /// \brief Handler for verifying, installing, deleting and managing certificates and security related operations. /// Requires CA files to be located inside the following directory structure according to their use: @@ -123,18 +123,18 @@ std::string readFileToString(const std::filesystem::path& path); class PkiHandler { private: - std::filesystem::path certsPath; - std::filesystem::path caPath; - std::filesystem::path caCsmsPath; - std::filesystem::path caCsoPath; - std::filesystem::path caCpsPath; - std::filesystem::path caMfPath; - std::filesystem::path caMoPath; - std::filesystem::path caOemPath; - std::filesystem::path caV2gPath; - - std::filesystem::path clientCsmsPath; - std::filesystem::path clientCsoPath; + fs::path certsPath; + fs::path caPath; + fs::path caCsmsPath; + fs::path caCsoPath; + fs::path caCpsPath; + fs::path caMfPath; + fs::path caMoPath; + fs::path caOemPath; + fs::path caV2gPath; + + fs::path clientCsmsPath; + fs::path clientCsoPath; bool useRootCaFallback; @@ -159,13 +159,13 @@ class PkiHandler { std::vector> getCertificatesFromChain(const std::string& certChain); /// \brief Returns the path where the ca certificates of the given \p pki are located - std::filesystem::path getCaPath(const PkiEnum& pki); + fs::path getCaPath(const PkiEnum& pki); /// \brief Executes "openssl rehash" for the given \p caPath - void execOpenSSLRehash(const std::filesystem::path caPath); + void execOpenSSLRehash(const fs::path caPath); /// \brief Returns the file path of the CSMS root CA file - std::optional getCsmsCaFilePath(); + std::optional getCsmsCaFilePath(); /// \brief Returns the number of installed CSMS CA certificates int getNumberOfCsmsCaCertificates(); @@ -181,10 +181,10 @@ class PkiHandler { bool isCaCertificateAlreadyInstalled(const std::shared_ptr& certificate); public: - explicit PkiHandler(const std::filesystem::path& certsPath, const bool multipleCsmsCaNotAllowed); + explicit PkiHandler(const fs::path& certsPath, const bool multipleCsmsCaNotAllowed); /// \brief Returns the path where the certificates are located - std::filesystem::path getCaCsmsPath(); + fs::path getCaCsmsPath(); /// \brief Verifies the given \p certificate and the \p charge_box_serial_number using the /// CentralSystemRootCertificate This method verifies the certificate chain, the signature, and the period when the @@ -239,7 +239,7 @@ class PkiHandler { std::shared_ptr getLeafCertificate(const CertificateSigningUseEnum& certificate_signing_use); /// \brief Get the leaf private key of the given \p certificate_signing_use - std::filesystem::path getLeafPrivateKeyPath(const CertificateSigningUseEnum& certificate_signing_use); + fs::path getLeafPrivateKeyPath(const CertificateSigningUseEnum& certificate_signing_use); /// \brief Removes a fallback central system root certificate if present void removeCentralSystemFallbackCa(); diff --git a/include/ocpp/common/schemas.hpp b/include/ocpp/common/schemas.hpp index 65a901d7e..becbf7dac 100644 --- a/include/ocpp/common/schemas.hpp +++ b/include/ocpp/common/schemas.hpp @@ -9,9 +9,9 @@ #include #include -#include #include #include +#include using json = nlohmann::json; using json_uri = nlohmann::json_uri; @@ -24,8 +24,8 @@ class Schemas { private: json schema; std::shared_ptr validator; - std::filesystem::path schemas_path; - std::set available_schemas_paths; + fs::path schemas_path; + std::set available_schemas_paths; const static std::vector profiles; const static std::regex date_time_regex; @@ -37,7 +37,7 @@ class Schemas { public: /// \brief Creates a new Schemas object looking for the root schema file in relation to the provided \p main_dir - explicit Schemas(std::filesystem::path schemas_path); + explicit Schemas(fs::path schemas_path); /// \brief Provides the config schema /// \returns the config schema as as json object diff --git a/include/ocpp/common/sqlite_statement.hpp b/include/ocpp/common/sqlite_statement.hpp index 4e4dc2831..6a6ec7d5e 100644 --- a/include/ocpp/common/sqlite_statement.hpp +++ b/include/ocpp/common/sqlite_statement.hpp @@ -4,7 +4,6 @@ #ifndef SQLITE_STATEMENT_HPP #define SQLITE_STATEMENT_HPP -#include #include #include @@ -103,4 +102,4 @@ class SQLiteStatement { } // namespace ocpp -#endif // DEVICE_MODEL_STORAGE_SQLITE_HPP \ No newline at end of file +#endif // DEVICE_MODEL_STORAGE_SQLITE_HPP diff --git a/include/ocpp/common/support_older_cpp_versions.hpp b/include/ocpp/common/support_older_cpp_versions.hpp new file mode 100644 index 000000000..1c651d60d --- /dev/null +++ b/include/ocpp/common/support_older_cpp_versions.hpp @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest + +#ifndef OCPP_COMMON_SUPPORT_OLDER_CPP_VERSIONS_HPP_ +#define OCPP_COMMON_SUPPORT_OLDER_CPP_VERSIONS_HPP_ + +#ifndef LIBOCPP_USE_BOOST_FILESYSTEM +#include +#else +#include +#endif + +#ifndef LIBOCPP_USE_BOOST_FILESYSTEM +namespace fs = std::filesystem; +#else +namespace fs = boost::filesystem; +#endif + +#endif /* OCPP_COMMON_SUPPORT_OLDER_CPP_VERSIONS_HPP_ */ diff --git a/include/ocpp/v16/charge_point.hpp b/include/ocpp/v16/charge_point.hpp index 9ffb4ffe0..70a5c94d8 100644 --- a/include/ocpp/v16/charge_point.hpp +++ b/include/ocpp/v16/charge_point.hpp @@ -2,9 +2,9 @@ // Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest #ifndef OCPP_V16_CHARGE_POINT_HPP #define OCPP_V16_CHARGE_POINT_HPP -#include #include +#include #include #include @@ -57,10 +57,9 @@ class ChargePoint { /// \param certs_path this points to the directory where certificates used by libocpp are located, these are used /// for the "Improved security for OCPP 1.6-J" whitepaper (eg. Security Profile 3 TLS with Client Side Certificates) /// as well as for Plug & Charge. - explicit ChargePoint(const std::string& config, const std::filesystem::path& share_path, - const std::filesystem::path& user_config_path, const std::filesystem::path& database_path, - const std::filesystem::path& sql_init_path, const std::filesystem::path& message_log_path, - const std::filesystem::path& certs_path); + explicit ChargePoint(const std::string& config, const fs::path& share_path, const fs::path& user_config_path, + const fs::path& database_path, const fs::path& sql_init_path, const fs::path& message_log_path, + const fs::path& certs_path); ~ChargePoint(); diff --git a/include/ocpp/v16/charge_point_configuration.hpp b/include/ocpp/v16/charge_point_configuration.hpp index cdb707efb..2512904a0 100644 --- a/include/ocpp/v16/charge_point_configuration.hpp +++ b/include/ocpp/v16/charge_point_configuration.hpp @@ -5,6 +5,7 @@ #include +#include #include #include @@ -16,7 +17,7 @@ class ChargePointConfiguration { private: json config; json custom_schema; - std::filesystem::path user_config_path; + fs::path user_config_path; std::set supported_feature_profiles; std::map> supported_measurands; @@ -34,8 +35,8 @@ class ChargePointConfiguration { bool isConnectorPhaseRotationValid(std::string str); public: - ChargePointConfiguration(const std::string& config, const std::filesystem::path& ocpp_main_path, - const std::filesystem::path& user_config_path); + ChargePointConfiguration(const std::string& config, const fs::path& ocpp_main_path, + const fs::path& user_config_path); // Internal config options std::string getChargePointId(); diff --git a/include/ocpp/v16/charge_point_impl.hpp b/include/ocpp/v16/charge_point_impl.hpp index 47258706a..d9a4f33f3 100644 --- a/include/ocpp/v16/charge_point_impl.hpp +++ b/include/ocpp/v16/charge_point_impl.hpp @@ -6,10 +6,10 @@ #include #include #include -#include #include #include #include +#include #include #include @@ -317,10 +317,9 @@ class ChargePointImpl : ocpp::ChargingStationBase { /// \param certs_path this points to the directory where certificates used by libocpp are located, these are used /// for the "Improved security for OCPP 1.6-J" whitepaper (eg. Security Profile 3 TLS with Client Side Certificates) /// as well as for Plug & Charge. - explicit ChargePointImpl(const std::string& config, const std::filesystem::path& share_path, - const std::filesystem::path& user_config_path, const std::filesystem::path& database_path, - const std::filesystem::path& sql_init_path, const std::filesystem::path& message_log_path, - const std::filesystem::path& certs_path); + explicit ChargePointImpl(const std::string& config, const fs::path& share_path, const fs::path& user_config_path, + const fs::path& database_path, const fs::path& sql_init_path, + const fs::path& message_log_path, const fs::path& certs_path); ~ChargePointImpl() { } diff --git a/include/ocpp/v16/database_handler.hpp b/include/ocpp/v16/database_handler.hpp index 58299f5ec..f55e04123 100644 --- a/include/ocpp/v16/database_handler.hpp +++ b/include/ocpp/v16/database_handler.hpp @@ -4,12 +4,12 @@ #define OCPP_V16_DATABASE_HANDLER_HPP #include "sqlite3.h" -#include #include #include #include #include +#include #include #include #include @@ -40,16 +40,15 @@ struct TransactionEntry { /// \brief This class handles the connection and operations of the SQLite database class DatabaseHandler : public ocpp::common::DatabaseHandlerBase { private: - std::filesystem::path db_path; // directory where the database file is located - std::filesystem::path init_script_path; // full path of init sql script + fs::path db_path; // directory where the database file is located + fs::path init_script_path; // full path of init sql script void run_sql_init(); bool clear_table(const std::string& table_name); void init_connector_table(int32_t number_of_connectors); public: - DatabaseHandler(const std::string& chargepoint_id, const std::filesystem::path& database_path, - const std::filesystem::path& init_script_path); + DatabaseHandler(const std::string& chargepoint_id, const fs::path& database_path, const fs::path& init_script_path); ~DatabaseHandler(); /// \brief Opens the database connection, runs initialization script and initializes the CONNECTORS and diff --git a/include/ocpp/v201/database_handler.hpp b/include/ocpp/v201/database_handler.hpp index 436d4dd89..94d11f79b 100644 --- a/include/ocpp/v201/database_handler.hpp +++ b/include/ocpp/v201/database_handler.hpp @@ -5,17 +5,15 @@ #include "sqlite3.h" #include -#include #include #include +#include #include #include #include -namespace fs = std::filesystem; - namespace ocpp { namespace v201 { diff --git a/include/ocpp/v201/device_model_storage.hpp b/include/ocpp/v201/device_model_storage.hpp index cce54f48f..df1222cad 100644 --- a/include/ocpp/v201/device_model_storage.hpp +++ b/include/ocpp/v201/device_model_storage.hpp @@ -4,9 +4,9 @@ #ifndef OCPP_V201_DEVICE_MODEL_STORAGE_HPP #define OCPP_V201_DEVICE_MODEL_STORAGE_HPP -#include #include #include +#include #include #include diff --git a/include/ocpp/v201/device_model_storage_sqlite.hpp b/include/ocpp/v201/device_model_storage_sqlite.hpp index c736376c5..8725ecaa7 100644 --- a/include/ocpp/v201/device_model_storage_sqlite.hpp +++ b/include/ocpp/v201/device_model_storage_sqlite.hpp @@ -4,10 +4,8 @@ #ifndef DEVICE_MODEL_STORAGE_SQLITE_HPP #define DEVICE_MODEL_STORAGE_SQLITE_HPP -#include -#include - #include +#include namespace ocpp { namespace v201 { @@ -24,7 +22,7 @@ class DeviceModelStorageSqlite : public DeviceModelStorage { public: /// \brief Opens SQLite connection at given \p db_path /// \param db_path path to database - explicit DeviceModelStorageSqlite(const std::filesystem::path& db_path); + explicit DeviceModelStorageSqlite(const fs::path& db_path); std::map> get_device_model() final; diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 588bd2a36..fa3f4464f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -40,6 +40,7 @@ add_subdirectory(ocpp/common/websocket) add_subdirectory(ocpp/v16/messages) add_subdirectory(ocpp/v201/messages) +option(LIBOCPP_USE_BOOST_FILESYSTEM "Usage of boost/filesystem.hpp instead of std::filesystem" OFF) target_include_directories(ocpp PUBLIC @@ -74,7 +75,7 @@ endif() ############# # End logging configuration ############# - + target_link_libraries(ocpp PUBLIC everest::timer @@ -90,6 +91,18 @@ target_link_libraries(ocpp date::date-tz ) +if(LIBOCPP_USE_BOOST_FILESYSTEM) + find_package(Boost REQUIRED COMPONENTS filesystem) + target_link_libraries(ocpp + PRIVATE + Boost::filesystem + ) + target_compile_definitions(log + PRIVATE + LIBOCPP_USE_BOOST_FILESYSTEM + ) +endif() + # FIXME (aw): right now nlohmann_json and boost::optional don't compile # with gcc 10.x and C++11/14, so we need to publish the # C++17 standard diff --git a/lib/ocpp/common/pki_handler.cpp b/lib/ocpp/common/pki_handler.cpp index b4c769a5e..5b7c08afe 100644 --- a/lib/ocpp/common/pki_handler.cpp +++ b/lib/ocpp/common/pki_handler.cpp @@ -10,7 +10,7 @@ namespace ocpp { -X509Certificate::X509Certificate(std::filesystem::path path, X509* x509, std::string str) { +X509Certificate::X509Certificate(fs::path path, X509* x509, std::string str) { this->path = path; this->x509 = x509; this->str = str; @@ -139,7 +139,7 @@ CertificateType getRootCertificateTypeFromPki(const PkiEnum& pki) { } } -std::shared_ptr loadFromFile(const std::filesystem::path& path) { +std::shared_ptr loadFromFile(const fs::path& path) { try { X509* x509; std::string fileStr; @@ -196,8 +196,7 @@ std::shared_ptr loadFromString(const std::string& str) { return cert; } -PkiHandler::PkiHandler(const std::filesystem::path& certsPath, const bool multipleCsmsCaNotAllowed) : - certsPath(certsPath) { +PkiHandler::PkiHandler(const fs::path& certsPath, const bool multipleCsmsCaNotAllowed) : certsPath(certsPath) { this->caPath = this->certsPath / "ca"; this->caCsmsPath = this->caPath / "csms"; @@ -228,7 +227,7 @@ PkiHandler::PkiHandler(const std::filesystem::path& certsPath, const bool multip std::vector pkis = {PkiEnum::CSO, PkiEnum::CSMS, PkiEnum::MF, PkiEnum::MO, PkiEnum::OEM, PkiEnum::V2G}; for (const auto& pki : pkis) { const auto caPath = this->getCaPath(pki); - if (std::filesystem::exists(caPath)) { + if (fs::exists(caPath)) { this->execOpenSSLRehash(caPath); } else { EVLOG_warning << "Certificate directory does not exist: " << caPath; @@ -236,13 +235,13 @@ PkiHandler::PkiHandler(const std::filesystem::path& certsPath, const bool multip } } -std::filesystem::path PkiHandler::getCaCsmsPath() { +fs::path PkiHandler::getCaCsmsPath() { return this->caCsmsPath; } int PkiHandler::getNumberOfCsmsCaCertificates() { int fileCounter = 0; - for (const auto& entry : std::filesystem::directory_iterator(this->caCsmsPath)) { + for (const auto& entry : fs::directory_iterator(this->caCsmsPath)) { if (entry.path().extension().string() == ".pem") { fileCounter++; } @@ -309,7 +308,7 @@ void PkiHandler::writeClientCertificate(const std::string& certificateChain, } else { auto leafCert = certificates.at(0); std::string newPath; - std::filesystem::path leafPath; + fs::path leafPath; if (certificate_use == CertificateSigningUseEnum::ChargingStationCertificate) { leafPath = this->clientCsmsPath / CSMS_LEAF; @@ -317,7 +316,7 @@ void PkiHandler::writeClientCertificate(const std::string& certificateChain, leafPath = this->clientCsoPath / V2G_LEAF; } - if (std::filesystem::exists(leafPath)) { + if (fs::exists(leafPath)) { const auto oldLeafPath = leafPath.parent_path() / (leafPath.filename().string().substr(0, leafPath.filename().string().find_last_of(".")) + @@ -341,8 +340,8 @@ std::string PkiHandler::generateCsr(const CertificateSigningUseEnum& certificate EC_KEY* ecKey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); X509_NAME* x509Name = X509_REQ_get_subject_name(x509ReqPtr.get()); - std::filesystem::path csrFile; - std::filesystem::path privateKeyFile; + fs::path csrFile; + fs::path privateKeyFile; // FIXME(piet): This just overrides the private key and in case no valid certificate will be delivered by a future // CertificateSigned.req from CSMS for this CSR the private key is lost @@ -453,19 +452,19 @@ std::string PkiHandler::generateCsr(const CertificateSigningUseEnum& certificate } bool PkiHandler::isCentralSystemRootCertificateInstalled() { - return !std::filesystem::is_empty(this->getCaPath(PkiEnum::CSMS)); + return !fs::is_empty(this->getCaPath(PkiEnum::CSMS)); } bool PkiHandler::isV2GRootCertificateInstalled() { - return !std::filesystem::is_empty(this->getCaPath(PkiEnum::V2G)); + return !fs::is_empty(this->getCaPath(PkiEnum::V2G)); } bool PkiHandler::isManufacturerRootCertificateInstalled() { - return !std::filesystem::is_empty(this->getCaPath(PkiEnum::MF)); + return !fs::is_empty(this->getCaPath(PkiEnum::MF)); } bool PkiHandler::isCsmsLeafCertificateInstalled() { - return std::filesystem::exists(this->clientCsmsPath / CSMS_LEAF); + return fs::exists(this->clientCsmsPath / CSMS_LEAF); } std::optional> @@ -561,7 +560,7 @@ DeleteCertificateResult PkiHandler::deleteRootCertificate(CertificateHashDataTyp return DeleteCertificateResult::Failed; } found = true; - if (!std::filesystem::remove(cert->path)) { + if (!fs::remove(cert->path)) { removeFailed = true; } } @@ -652,7 +651,7 @@ PkiHandler::getLeafCertificate(const CertificateSigningUseEnum& certificate_sign std::shared_ptr cert = nullptr; int validIn = INT_MIN; - std::filesystem::path leafPath; + fs::path leafPath; if (certificate_signing_use == CertificateSigningUseEnum::ChargingStationCertificate) { leafPath = this->clientCsmsPath / CSMS_LEAF; } else { @@ -660,7 +659,7 @@ PkiHandler::getLeafCertificate(const CertificateSigningUseEnum& certificate_sign } // TODO(piet): Client certificate could be V2G_LEAF or CSMS_LEAF, possibly only one cert is set - for (const auto& dirEntry : std::filesystem::directory_iterator(leafPath.parent_path())) { + for (const auto& dirEntry : fs::directory_iterator(leafPath.parent_path())) { if (dirEntry.path().string().find(leafPath.filename().c_str()) != std::string::npos) { std::shared_ptr c = loadFromFile(dirEntry.path()); if (c != nullptr && c->validIn < 0 && c->validIn > validIn) { @@ -671,7 +670,7 @@ PkiHandler::getLeafCertificate(const CertificateSigningUseEnum& certificate_sign return cert; } -std::filesystem::path PkiHandler::getLeafPrivateKeyPath(const CertificateSigningUseEnum& certificate_signing_use) { +fs::path PkiHandler::getLeafPrivateKeyPath(const CertificateSigningUseEnum& certificate_signing_use) { if (certificate_signing_use == CertificateSigningUseEnum::ChargingStationCertificate) { return this->clientCsmsPath / CSMS_LEAF_KEY; } else { @@ -684,9 +683,9 @@ void PkiHandler::removeCentralSystemFallbackCa() { } void PkiHandler::useCsmsFallbackRoot() { - if (std::filesystem::exists(this->caCsmsPath / CSMS_ROOT_CA_BACKUP)) { + if (fs::exists(this->caCsmsPath / CSMS_ROOT_CA_BACKUP)) { std::remove((this->caCsmsPath / CSMS_ROOT_CA).c_str()); // remove recently installed ca - std::filesystem::path new_path = this->caCsmsPath / CSMS_ROOT_CA; + fs::path new_path = this->caCsmsPath / CSMS_ROOT_CA; std::rename((this->caCsmsPath / CSMS_ROOT_CA_BACKUP).c_str(), new_path.c_str()); this->execOpenSSLRehash(this->caCsmsPath); } else { @@ -719,8 +718,8 @@ void PkiHandler::updateOcspCache(const OCSPRequestData& ocspRequestData, const s cert->getSerialNumber() == ocspRequestData.serialNumber) { EVLOG_info << "Writing OCSP Response to filesystem"; const auto ocspPath = cert->path.parent_path() / "ocsp"; - if (!std::filesystem::exists(ocspPath)) { - std::filesystem::create_directories(ocspPath); + if (!fs::exists(ocspPath)) { + fs::create_directories(ocspPath); } const auto ocspFilePath = ocspPath / cert->path.filename().replace_extension(".ocsp.der"); std::ofstream fs(ocspFilePath.string()); @@ -886,7 +885,7 @@ bool PkiHandler::isCaCertificateAlreadyInstalled(const std::shared_ptrcaCsmsPath; @@ -907,10 +906,10 @@ std::filesystem::path PkiHandler::getCaPath(const PkiEnum& pki) { } } -void PkiHandler::execOpenSSLRehash(const std::filesystem::path caPath) { - for (const auto& entry : std::filesystem::directory_iterator(caPath)) { - if (std::filesystem::is_symlink(entry.path())) { - std::filesystem::remove(entry.path()); +void PkiHandler::execOpenSSLRehash(const fs::path caPath) { + for (const auto& entry : fs::directory_iterator(caPath)) { + if (fs::is_symlink(entry.path())) { + fs::remove(entry.path()); } } @@ -920,9 +919,9 @@ void PkiHandler::execOpenSSLRehash(const std::filesystem::path caPath) { } } -std::optional PkiHandler::getCsmsCaFilePath() { - std::optional csmsCaFilePath; - for (const auto& entry : std::filesystem::directory_iterator(this->caCsmsPath)) { +std::optional PkiHandler::getCsmsCaFilePath() { + std::optional csmsCaFilePath; + for (const auto& entry : fs::directory_iterator(this->caCsmsPath)) { if (entry.path().extension().string() == ".pem") { csmsCaFilePath.emplace(entry.path()); } @@ -937,8 +936,8 @@ PkiHandler::getCaCertificates(const PkiEnum& pki, const CertificateType& type, c const auto caPath = this->getCaPath(pki); - if (std::filesystem::exists(caPath)) { - for (const auto& dirEntry : std::filesystem::directory_iterator(caPath)) { + if (fs::exists(caPath)) { + for (const auto& dirEntry : fs::directory_iterator(caPath)) { if (dirEntry.path().extension().string() != ".ocsp" and (includeSymlinks or dirEntry.path().extension().string() == ".pem")) { auto cert = loadFromFile(dirEntry.path()); diff --git a/lib/ocpp/common/schemas.cpp b/lib/ocpp/common/schemas.cpp index b7efa8de0..5cb7c8d22 100644 --- a/lib/ocpp/common/schemas.cpp +++ b/lib/ocpp/common/schemas.cpp @@ -9,12 +9,12 @@ namespace ocpp { -Schemas::Schemas(std::filesystem::path schemas_path) : schemas_path(schemas_path) { - if (!std::filesystem::exists(this->schemas_path) || !std::filesystem::is_directory(this->schemas_path)) { +Schemas::Schemas(fs::path schemas_path) : schemas_path(schemas_path) { + if (!fs::exists(this->schemas_path) || !fs::is_directory(this->schemas_path)) { EVLOG_error << this->schemas_path << " does not exist"; // FIXME(kai): exception? } else { - for (auto file : std::filesystem::directory_iterator(this->schemas_path)) { + for (auto file : fs::directory_iterator(this->schemas_path)) { available_schemas_paths.insert(file.path()); } this->load_root_schema(); @@ -22,9 +22,9 @@ Schemas::Schemas(std::filesystem::path schemas_path) : schemas_path(schemas_path } void Schemas::load_root_schema() { - std::filesystem::path config_schema_path = this->schemas_path / "Config.json"; + fs::path config_schema_path = this->schemas_path / "Config.json"; - EVLOG_debug << "parsing root schema file: " << std::filesystem::canonical(config_schema_path); + EVLOG_debug << "parsing root schema file: " << fs::canonical(config_schema_path); std::ifstream ifs(config_schema_path.c_str()); std::string schema_file((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); @@ -59,7 +59,7 @@ void Schemas::loader(const json_uri& uri, json& schema) { location.erase(0, 1); } - std::filesystem::path schema_path = this->schemas_path / std::filesystem::path(location); + fs::path schema_path = this->schemas_path / fs::path(location); if (available_schemas_paths.count(schema_path) != 0) { std::ifstream ifs(schema_path.string().c_str()); std::string schema_file((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); diff --git a/lib/ocpp/common/websocket/websocket_tls.cpp b/lib/ocpp/common/websocket/websocket_tls.cpp index abc376a41..ab1d6894c 100644 --- a/lib/ocpp/common/websocket/websocket_tls.cpp +++ b/lib/ocpp/common/websocket/websocket_tls.cpp @@ -306,7 +306,7 @@ void WebsocketTLS::on_fail_tls(tls_client* c, websocketpp::connection_hdl hdl) { // TODO(piet): Trigger SecurityEvent in case InvalidCentralSystemCertificate - if (std::filesystem::exists(this->pki_handler->getCaCsmsPath() / CSMS_ROOT_CA_BACKUP)) { + if (fs::exists(this->pki_handler->getCaCsmsPath() / CSMS_ROOT_CA_BACKUP)) { // if a fallback ca exists, we move back to it and delete the new ca certificate EVLOG_warning << "Connection with new CA was not successful - Falling back to old CA"; this->pki_handler->useCsmsFallbackRoot(); diff --git a/lib/ocpp/v16/charge_point.cpp b/lib/ocpp/v16/charge_point.cpp index 9be4c2710..4eca07e62 100644 --- a/lib/ocpp/v16/charge_point.cpp +++ b/lib/ocpp/v16/charge_point.cpp @@ -10,10 +10,9 @@ namespace ocpp { namespace v16 { -ChargePoint::ChargePoint(const std::string& config, const std::filesystem::path& share_path, - const std::filesystem::path& user_config_path, const std::filesystem::path& database_path, - const std::filesystem::path& sql_init_path, const std::filesystem::path& message_log_path, - const std::filesystem::path& certs_path) { +ChargePoint::ChargePoint(const std::string& config, const fs::path& share_path, const fs::path& user_config_path, + const fs::path& database_path, const fs::path& sql_init_path, const fs::path& message_log_path, + const fs::path& certs_path) { this->charge_point = std::make_unique(config, share_path, user_config_path, database_path, sql_init_path, message_log_path, certs_path); } diff --git a/lib/ocpp/v16/charge_point_configuration.cpp b/lib/ocpp/v16/charge_point_configuration.cpp index a1ce141b9..b58fada32 100644 --- a/lib/ocpp/v16/charge_point_configuration.cpp +++ b/lib/ocpp/v16/charge_point_configuration.cpp @@ -15,12 +15,11 @@ namespace ocpp { namespace v16 { -ChargePointConfiguration::ChargePointConfiguration(const std::string& config, - const std::filesystem::path& ocpp_main_path, - const std::filesystem::path& user_config_path) { +ChargePointConfiguration::ChargePointConfiguration(const std::string& config, const fs::path& ocpp_main_path, + const fs::path& user_config_path) { this->user_config_path = user_config_path; - if (!std::filesystem::exists(this->user_config_path)) { + if (!fs::exists(this->user_config_path)) { EVLOG_critical << "User config file does not exist"; throw std::runtime_error("User config file does not exist"); } @@ -32,7 +31,7 @@ ChargePointConfiguration::ChargePointConfiguration(const std::string& config, try { this->config = json::parse(config); const auto custom_schema_path = schemas_path / "Custom.json"; - if (std::filesystem::exists(custom_schema_path)) { + if (fs::exists(custom_schema_path)) { std::ifstream ifs(custom_schema_path.c_str()); std::string custom_schema_file((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); this->custom_schema = json::parse(custom_schema_file); @@ -178,7 +177,7 @@ ChargePointConfiguration::ChargePointConfiguration(const std::string& config, } json ChargePointConfiguration::get_user_config() { - if (std::filesystem::exists(this->user_config_path)) { + if (fs::exists(this->user_config_path)) { // reading from and overriding to existing user config std::fstream ifs(user_config_path.c_str()); std::string user_config_file((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); diff --git a/lib/ocpp/v16/charge_point_impl.cpp b/lib/ocpp/v16/charge_point_impl.cpp index 84464785b..0afd975da 100644 --- a/lib/ocpp/v16/charge_point_impl.cpp +++ b/lib/ocpp/v16/charge_point_impl.cpp @@ -19,11 +19,10 @@ const auto V2G_CERTIFICATE_TIMER_INTERVAL = std::chrono::hours(12); const auto INITIAL_CERTIFICATE_REQUESTS_DELAY = std::chrono::seconds(60); const auto WEBSOCKET_INIT_DELAY = std::chrono::seconds(2); -ChargePointImpl::ChargePointImpl(const std::string& config, const std::filesystem::path& share_path, - const std::filesystem::path& user_config_path, - const std::filesystem::path& database_path, const std::filesystem::path& sql_init_path, - const std::filesystem::path& message_log_path, - const std::filesystem::path& certs_path) : +ChargePointImpl::ChargePointImpl(const std::string& config, const fs::path& share_path, + const fs::path& user_config_path, const fs::path& database_path, + const fs::path& sql_init_path, const fs::path& message_log_path, + const fs::path& certs_path) : ocpp::ChargingStationBase(), boot_notification_callerror(false), initialized(false), @@ -32,7 +31,7 @@ ChargePointImpl::ChargePointImpl(const std::string& config, const std::filesyste diagnostics_status(DiagnosticsStatus::Idle), firmware_status(FirmwareStatus::Idle), log_status(UploadLogStatusEnumType::Idle), - message_log_path(message_log_path), + message_log_path(message_log_path.string()), // .string() for compatibility with boost::filesystem switch_security_profile_callback(nullptr) { this->configuration = std::make_shared(config, share_path, user_config_path); this->pki_handler = std::make_shared( @@ -57,7 +56,7 @@ ChargePointImpl::ChargePointImpl(const std::string& config, const std::filesyste bool session_logging = std::find(log_formats.begin(), log_formats.end(), "session_logging") != log_formats.end(); this->logging = std::make_shared( - this->configuration->getLogMessages(), message_log_path, DateTime().to_rfc3339(), log_to_console, + this->configuration->getLogMessages(), this->message_log_path, DateTime().to_rfc3339(), log_to_console, detailed_log_to_console, log_to_file, log_to_html, session_logging); this->boot_notification_timer = diff --git a/lib/ocpp/v16/database_handler.cpp b/lib/ocpp/v16/database_handler.cpp index 7aebfca79..50e615aeb 100644 --- a/lib/ocpp/v16/database_handler.cpp +++ b/lib/ocpp/v16/database_handler.cpp @@ -9,12 +9,12 @@ namespace ocpp { namespace v16 { -DatabaseHandler::DatabaseHandler(const std::string& chargepoint_id, const std::filesystem::path& database_path, - const std::filesystem::path& init_script_path) : +DatabaseHandler::DatabaseHandler(const std::string& chargepoint_id, const fs::path& database_path, + const fs::path& init_script_path) : ocpp::common::DatabaseHandlerBase() { const auto sqlite_db_filename = chargepoint_id + ".db"; - if (!std::filesystem::exists(database_path)) { - std::filesystem::create_directories(database_path); + if (!fs::exists(database_path)) { + fs::create_directories(database_path); } this->db_path = database_path / sqlite_db_filename; this->init_script_path = init_script_path; diff --git a/lib/ocpp/v201/database_handler.cpp b/lib/ocpp/v201/database_handler.cpp index 58876bcbd..6b4e5cbc0 100644 --- a/lib/ocpp/v201/database_handler.cpp +++ b/lib/ocpp/v201/database_handler.cpp @@ -7,8 +7,6 @@ #include #include -namespace fs = std::filesystem; - namespace ocpp { namespace v201 { diff --git a/lib/ocpp/v201/device_model_storage_sqlite.cpp b/lib/ocpp/v201/device_model_storage_sqlite.cpp index b5405bf94..f1dc4d5fb 100644 --- a/lib/ocpp/v201/device_model_storage_sqlite.cpp +++ b/lib/ocpp/v201/device_model_storage_sqlite.cpp @@ -9,7 +9,7 @@ namespace ocpp { namespace v201 { -DeviceModelStorageSqlite::DeviceModelStorageSqlite(const std::filesystem::path& db_path) { +DeviceModelStorageSqlite::DeviceModelStorageSqlite(const fs::path& db_path) { if (sqlite3_open(db_path.c_str(), &this->db) != SQLITE_OK) { EVLOG_error << "Could not open database at provided path: " << db_path; EVLOG_AND_THROW(std::runtime_error("Could not open device model database at provided path.")); diff --git a/src/charge_point.cpp b/src/charge_point.cpp index 330dbbd9b..3c5aa779f 100644 --- a/src/charge_point.cpp +++ b/src/charge_point.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -55,12 +54,12 @@ int main(int argc, char* argv[]) { } const auto database_path = "/tmp/ocpp"; - const auto share_path = std::filesystem::path(maindir) / "share" / "everest" / "modules" / "OCPP"; + const auto share_path = fs::path(maindir) / "share" / "everest" / "modules" / "OCPP"; // initialize logging as early as possible auto logging_config = share_path / "logging.ini"; if (vm.count("logconf") != 0) { - logging_config = std::filesystem::path(vm["logconf"].as()); + logging_config = fs::path(vm["logconf"].as()); } Everest::Logging::init(logging_config.string(), "charge_point"); @@ -69,8 +68,8 @@ int main(int argc, char* argv[]) { conf = vm["conf"].as(); } - std::filesystem::path config_path = share_path / conf; - if (!std::filesystem::exists(config_path)) { + fs::path config_path = share_path / conf; + if (!fs::exists(config_path)) { EVLOG_error << "Could not find config at: " << config_path; return 1; } @@ -79,9 +78,9 @@ int main(int argc, char* argv[]) { auto json_config = json::parse(config_file); json_config["Internal"]["LogMessagesFormat"][0] = "console_detailed"; - auto user_config_path = std::filesystem::path("/tmp") / "user_config.json"; + auto user_config_path = fs::path("/tmp") / "user_config.json"; - if (std::filesystem::exists(user_config_path)) { + if (fs::exists(user_config_path)) { std::ifstream ifs(user_config_path.c_str()); std::string user_config_file((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); auto user_config = json::parse(user_config_file); @@ -93,17 +92,16 @@ int main(int argc, char* argv[]) { fs.close(); } - const std::filesystem::path sql_init_path = share_path / "init.sql"; + const fs::path sql_init_path = share_path / "init.sql"; // create the cso_path - const std::filesystem::path cso_path = "/tmp/client/cso"; - if (!std::filesystem::exists(cso_path)) { - std::filesystem::create_directories(cso_path); + const fs::path cso_path = "/tmp/client/cso"; + if (!fs::exists(cso_path)) { + fs::create_directories(cso_path); } - charge_point = - new ocpp::v16::ChargePoint(json_config.dump(), share_path, user_config_path, database_path, sql_init_path, - std::filesystem::path("/tmp"), std::filesystem::path("/tmp")); + charge_point = new ocpp::v16::ChargePoint(json_config.dump(), share_path, user_config_path, database_path, + sql_init_path, fs::path("/tmp"), fs::path("/tmp")); /************************************** START REGISTERING CALLBACKS **************************************/