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

Integrates the security module in the Evse15118D20 module #1030

Merged
merged 8 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions config/config-sil-dc-d20.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ active_modules:
module: Evse15118D20
config_module:
device: auto
connections:
security:
- module_id: evse_security
implementation_id: main
iso15118_car:
module: PyEvJosev
config_module:
Expand Down
4 changes: 4 additions & 0 deletions config/config-sil-dc-isomux-tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ active_modules:
device: lo
tls_negotiation_strategy: ACCEPT_CLIENT_OFFER
enable_sdp_server: false
connections:
security:
- module_id: evse_security
implementation_id: main
iso_mux:
module: IsoMux
config_module:
Expand Down
4 changes: 4 additions & 0 deletions config/config-sil-dc-isomux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ active_modules:
device: lo
tls_negotiation_strategy: ACCEPT_CLIENT_OFFER
enable_sdp_server: false
connections:
security:
- module_id: evse_security
implementation_id: main
iso_mux:
module: IsoMux
config_module:
Expand Down
2 changes: 1 addition & 1 deletion dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ libcbv2g:
# libiso15118
libiso15118:
git: https://github.com/EVerest/libiso15118.git
git_tag: v0.3.0
git_tag: v0.4.0
cmake_condition: "EVEREST_DEPENDENCY_ENABLED_LIBISO15118"

# LEM DCBM 400/600 module
Expand Down
10 changes: 7 additions & 3 deletions modules/Evse15118D20/Evse15118D20.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// headers for provided interface implementations
#include <generated/interfaces/ISO15118_charger/Implementation.hpp>

// headers for required interface implementations
#include <generated/interfaces/evse_security/Interface.hpp>

// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
// insert your custom include headers here
// ev@4bf81b14-a215-475c-a1d3-0a484ae48918:v1
Expand All @@ -24,7 +27,6 @@ struct Conf {
std::string certificate_path;
std::string logging_path;
std::string tls_negotiation_strategy;
std::string private_key_password;
bool enable_ssl_logging;
bool enable_tls_key_logging;
bool enable_sdp_server;
Expand All @@ -36,10 +38,12 @@ struct Conf {
class Evse15118D20 : public Everest::ModuleBase {
public:
Evse15118D20() = delete;
Evse15118D20(const ModuleInfo& info, std::unique_ptr<ISO15118_chargerImplBase> p_charger, Conf& config) :
ModuleBase(info), p_charger(std::move(p_charger)), config(config){};
Evse15118D20(const ModuleInfo& info, std::unique_ptr<ISO15118_chargerImplBase> p_charger,
std::unique_ptr<evse_securityIntf> r_security, Conf& config) :
ModuleBase(info), p_charger(std::move(p_charger)), r_security(std::move(r_security)), config(config){};

const std::unique_ptr<ISO15118_chargerImplBase> p_charger;
const std::unique_ptr<evse_securityIntf> r_security;
const Conf& config;

// ev@1fce4c5e-0ab8-41bb-90f7-14277703d2ac:v1
Expand Down
41 changes: 24 additions & 17 deletions modules/Evse15118D20/charger/ISO15118_chargerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ namespace dt = iso15118::message_20::datatypes;

namespace {

std::filesystem::path construct_cert_path(const std::filesystem::path& initial_path, const std::string& config_path) {
if (config_path.empty()) {
return initial_path;
}

if (config_path.front() == '/') {
return config_path;
} else {
return initial_path / config_path;
}
}

iso15118::config::TlsNegotiationStrategy convert_tls_negotiation_strategy(const std::string& strategy) {
using Strategy = iso15118::config::TlsNegotiationStrategy;
if (strategy == "ACCEPT_CLIENT_OFFER") {
Expand Down Expand Up @@ -154,7 +142,6 @@ void ISO15118_chargerImpl::init() {
}

void ISO15118_chargerImpl::ready() {

while (true) {
if (setup_steps_done.all()) {
break;
Expand All @@ -164,13 +151,33 @@ void ISO15118_chargerImpl::ready() {

const auto session_logger = std::make_unique<SessionLogger>(mod->config.logging_path);

const auto default_cert_path = mod->info.paths.etc / "certs";
const auto cert_path = construct_cert_path(default_cert_path, mod->config.certificate_path);
// Obtain certificate location from the security module
const auto certificate_response = mod->r_security->call_get_leaf_certificate_info(
types::evse_security::LeafCertificateType::V2G, types::evse_security::EncodingFormat::PEM, false);

if (certificate_response.status != types::evse_security::GetCertificateInfoStatus::Accepted or
!certificate_response.info.has_value()) {
EVLOG_AND_THROW(Everest::EverestConfigError("V2G certificate not found"));
}

const auto& certificate_info = certificate_response.info.value();
std::string path_chain;

if (certificate_info.certificate.has_value()) {
path_chain = certificate_info.certificate.value();
} else if (certificate_info.certificate_single.has_value()) {
path_chain = certificate_info.certificate_single.value();
} else {
EVLOG_AND_THROW(Everest::EverestConfigError("V2G certificate not found"));
}

const iso15118::TbdConfig tbd_config = {
{
iso15118::config::CertificateBackend::EVEREST_LAYOUT,
cert_path.string(),
mod->config.private_key_password,
{},
path_chain,
certificate_info.key,
certificate_info.password,
mod->config.enable_ssl_logging,
mod->config.enable_tls_key_logging,
},
Expand Down
10 changes: 5 additions & 5 deletions modules/Evse15118D20/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ config:
- ACCEPT_CLIENT_OFFER
- ENFORCE_TLS
- ENFORCE_NO_TLS
default: ACCEPT_CLIENT_OFFER
private_key_password:
description: Password for private key files (USE ONLY FOR TESTING)
type: string
default: "123456"
default: ACCEPT_CLIENT_OFFER
enable_ssl_logging:
description: Verbosely log the ssl/tls connection
type: boolean
Expand Down Expand Up @@ -62,6 +58,10 @@ provides:
interface: ISO15118_charger
description: >-
This interface provides limited access to iso15118-20
requires:
security:
interface: evse_security

enable_external_mqtt: false
metadata:
license: https://opensource.org/licenses/Apache-2.0
Expand Down