Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support C++ versions before C++17 with boost::filesystem #177

Merged
merged 27 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
38b48cd
support for boost/filesystem.hpp
Matthias-NIDEC Sep 12, 2023
cef629d
Use CMAKE_CXX_STANDARD to decide over the filesystem library selection
Sep 12, 2023
4038f7f
fix on define
Sep 12, 2023
ab60483
Fix related messagelogging when using boost
Sep 12, 2023
5fb3701
Merge branch 'main' into boost-filesystem-support-signed
Matthias-NIDEC Sep 18, 2023
41b24d9
Integrated latest pull
Matthias-NIDEC Sep 20, 2023
578271d
Factored out include to support older c++
Matthias-NIDEC Sep 20, 2023
a7de53e
lib: add `find_package(Boost)`
Dominik-K Sep 20, 2023
eff3cb8
`clang-format` fixes
Dominik-K Sep 20, 2023
6bf3cbf
clang-format 16.0.0 (from Docker-image in GitHub Action)
Dominik-K Sep 20, 2023
9faaac0
Set SDPX format and changed define selection via option
Matthias-NIDEC Sep 21, 2023
b20b170
Fixed header ending
Matthias-NIDEC Sep 21, 2023
6d012c2
cmake: re-add `BOOSTFILESYSTEM`
Dominik-K Sep 21, 2023
6ab07ee
CP implementation: un-doubled `this->logging`
Dominik-K Sep 21, 2023
67890d5
CMakeLists.txt: space-indents instead tabs
Dominik-K Sep 21, 2023
f334351
CP implementation: one `message_log_path` initialisation
Dominik-K Sep 21, 2023
ccf1c58
cmake: verbose message for troubleshooting
Dominik-K Sep 21, 2023
efac291
clang-format fix
Dominik-K Sep 21, 2023
0060a3e
charge_point.cpp: removed obsolete `#include`
Dominik-K Sep 21, 2023
04f50c2
Merge branch 'EVerest:main' into boost-filesystem-support-signed
bWF0dGhpYXMK Sep 25, 2023
463dec6
Merge branch 'EVerest:main' into boost-filesystem-support-signed
bWF0dGhpYXMK Sep 26, 2023
4a08048
Renamed include header and moved the option
Matthias-NIDEC Sep 26, 2023
259ae11
Renamed the include part and moved option
Matthias-NIDEC Sep 27, 2023
f21f332
Merge branch 'EVerest:main' into boost-filesystem-support-signed
bWF0dGhpYXMK Sep 28, 2023
97cc278
Renamed the option to select boost filesystem
Matthias-NIDEC Sep 28, 2023
5e23594
removed unnecessary `#include`
Dominik-K Sep 28, 2023
6395c15
use `LIBOCPP_USE_BOOST_FILESYSTEM` also in macros
Dominik-K Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ option(CMAKE_RUN_CLANG_TIDY "Run clang-tidy" OFF)
option(LIBOCPP_BUILD_EXAMPLES "Build charge_point and central_system binaries." OFF)
option(OCPP_INSTALL "Install the library (shared data might be installed anyway)" ${EVC_MAIN_PROJECT})

if (${CMAKE_CXX_STANDARD} LESS_EQUAL 17)
Dominik-K marked this conversation as resolved.
Show resolved Hide resolved
option(BOOSTFILESYSTEM "Usage of boost/filesystem.hpp instead of std::filesystem" ON)
add_definitions(-DBOOSTFILESYSTEM)
else()
option(BOOSTFILESYSTEM "Usage of boost/filesystem.hpp instead of std::filesystem" OFF)
endif()


# dependencies
find_package(Boost COMPONENTS program_options regex system thread REQUIRED)
find_package(SQLite3 REQUIRED)
Expand Down
78 changes: 44 additions & 34 deletions include/ocpp/common/pki_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#ifndef OCPP_COMMON_PKI_HANDLER
#define OCPP_COMMON_PKI_HANDLER

#include <filesystem>
#ifndef BOOSTFILESYSTEM
<filesystem>
bWF0dGhpYXMK marked this conversation as resolved.
Show resolved Hide resolved
#else
#include <boost/filesystem.hpp>
#endif
#include <memory>
#include <openssl/bio.h>
#include <openssl/err.h>
Expand All @@ -17,6 +21,12 @@

#include <ocpp/common/types.hpp>

#ifndef BOOSTFILESYSTEM
namespace fs = std::filesystem;
#else
namespace fs = boost::filesystem;
#endif

namespace ocpp {

enum class PkiEnum {
Expand Down Expand Up @@ -51,35 +61,35 @@ using X509_STORE_CTX_ptr = std::unique_ptr<X509_STORE_CTX, decltype(&::X509_STOR
using X509_REQ_ptr = std::unique_ptr<X509_REQ, decltype(&::X509_REQ_free)>;

// 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;
int validIn; // seconds. If > 0 cert is not valid yet
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();
Expand All @@ -100,11 +110,11 @@ struct X509Certificate {
OCSPRequestData getOCSPRequestData();
};
/// \brief loads a X509Certificate from the given \p pat
std::shared_ptr<X509Certificate> loadFromFile(const std::filesystem::path& path);
std::shared_ptr<X509Certificate> loadFromFile(const fs::path& path);
/// \brief loads a X509Certificate from the given \p st
std::shared_ptr<X509Certificate> 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:
Expand All @@ -123,18 +133,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;

Expand All @@ -159,13 +169,13 @@ class PkiHandler {
std::vector<std::shared_ptr<X509Certificate>> 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<std::filesystem::path> getCsmsCaFilePath();
std::optional<fs::path> getCsmsCaFilePath();

/// \brief Returns the number of installed CSMS CA certificates
int getNumberOfCsmsCaCertificates();
Expand All @@ -181,10 +191,10 @@ class PkiHandler {
bool isCaCertificateAlreadyInstalled(const std::shared_ptr<X509Certificate>& 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
Expand Down Expand Up @@ -239,7 +249,7 @@ class PkiHandler {
std::shared_ptr<X509Certificate> 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();
Expand Down
18 changes: 14 additions & 4 deletions include/ocpp/common/schemas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,33 @@
#include <vector>

#include <everest/logging.hpp>
#include <filesystem>
#ifndef BOOSTFILESYSTEM
<filesystem>
#else
#include <boost/filesystem.hpp>
#endif
#include <nlohmann/json-schema.hpp>
#include <nlohmann/json_fwd.hpp>

using json = nlohmann::json;
using json_uri = nlohmann::json_uri;
using json_validator = nlohmann::json_schema::json_validator;

#ifndef BOOSTFILESYSTEM
namespace fs = std::filesystem;
#else
namespace fs = boost::filesystem;
#endif

namespace ocpp {

/// \brief Contains the json schema validation for the libocpp config
class Schemas {
private:
json schema;
std::shared_ptr<json_validator> validator;
std::filesystem::path schemas_path;
std::set<std::filesystem::path> available_schemas_paths;
fs::path schemas_path;
std::set<fs::path> available_schemas_paths;
const static std::vector<std::string> profiles;
const static std::regex date_time_regex;

Expand All @@ -37,7 +47,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
Expand Down
20 changes: 15 additions & 5 deletions include/ocpp/v16/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest
#ifndef OCPP_V16_CHARGE_POINT_HPP
#define OCPP_V16_CHARGE_POINT_HPP
#include <filesystem>
#ifndef BOOSTFILESYSTEM
<filesystem>
#else
#include <boost/filesystem.hpp>
#endif

#include <ocpp/common/cistring.hpp>
#include <ocpp/v16/ocpp_types.hpp>
Expand All @@ -25,6 +29,12 @@
#include <ocpp/v201/messages/SignCertificate.hpp>
#include <ocpp/v201/messages/TriggerMessage.hpp>

#ifndef BOOSTFILESYSTEM
namespace fs = std::filesystem;
#else
namespace fs = boost::filesystem;
#endif

namespace ocpp {
namespace v16 {
class ChargePointImpl;
Expand Down Expand Up @@ -56,10 +66,10 @@ 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();

Expand Down
12 changes: 9 additions & 3 deletions include/ocpp/v16/charge_point_configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@
#include <ocpp/v16/ocpp_types.hpp>
#include <ocpp/v16/types.hpp>

#ifndef BOOSTFILESYSTEM
namespace fs = std::filesystem;
#else
namespace fs = boost::filesystem;
#endif

namespace ocpp {
namespace v16 {

/// \brief contains the configuration of the charge point
class ChargePointConfiguration {
private:
json config;
std::filesystem::path user_config_path;
fs::path user_config_path;

std::set<SupportedFeatureProfiles> supported_feature_profiles;
std::map<Measurand, std::vector<Phase>> supported_measurands;
Expand All @@ -33,8 +39,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();
Expand Down
20 changes: 15 additions & 5 deletions include/ocpp/v16/charge_point_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
#include <chrono>
#include <date/date.h>
#include <date/tz.h>
#include <filesystem>
#ifndef BOOSTFILESYSTEM
<filesystem>
#else
#include <boost/filesystem.hpp>
#endif
#include <future>
#include <iostream>
#include <mutex>
Expand Down Expand Up @@ -78,6 +82,12 @@
#include <ocpp/v201/messages/SignCertificate.hpp>
#include <ocpp/v201/messages/TriggerMessage.hpp>

#ifndef BOOSTFILESYSTEM
namespace fs = std::filesystem;
#else
namespace fs = boost::filesystem;
#endif

namespace ocpp {
namespace v16 {

Expand Down Expand Up @@ -314,10 +324,10 @@ 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() {
}
Expand Down
12 changes: 11 additions & 1 deletion include/ocpp/v16/database_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
#define OCPP_V16_DATABASE_HANDLER_HPP

#include "sqlite3.h"
#include <filesystem>
#ifndef BOOSTFILESYSTEM
<filesystem>
#else
#include <boost/filesystem.hpp>
#endif
#include <fstream>
#include <iostream>

Expand All @@ -14,6 +18,12 @@
#include <ocpp/v16/ocpp_types.hpp>
#include <ocpp/v16/types.hpp>

#ifndef BOOSTFILESYSTEM
namespace fs = std::filesystem;
#else
namespace fs = boost::filesystem;
#endif

namespace ocpp {
namespace v16 {

Expand Down
10 changes: 9 additions & 1 deletion include/ocpp/v201/database_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

#include "sqlite3.h"
#include <deque>
#include <filesystem>
#ifndef BOOSTFILESYSTEM
<filesystem>
#else
#include <boost/filesystem.hpp>
#endif
#include <fstream>
#include <memory>

Expand All @@ -14,7 +18,11 @@

#include <everest/logging.hpp>

#ifndef BOOSTFILESYSTEM
namespace fs = std::filesystem;
#else
namespace fs = boost::filesystem;
#endif

namespace ocpp {
namespace v201 {
Expand Down
Loading