Skip to content

Commit

Permalink
Move certificate stuff of iso15118 to security functional block. (#959)
Browse files Browse the repository at this point in the history
Signed-off-by: Maaike Zijderveld, iolar <git.mail@iolar.nl>
  • Loading branch information
maaikez authored Jan 30, 2025
1 parent 1fa8fa0 commit e7d9de1
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 249 deletions.
20 changes: 1 addition & 19 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,22 @@
#include <ocpp/v201/types.hpp>
#include <ocpp/v201/utils.hpp>

#include "ocpp/v201/messages/Get15118EVCertificate.hpp"
#include <ocpp/v201/messages/Authorize.hpp>
#include <ocpp/v201/messages/BootNotification.hpp>
#include <ocpp/v201/messages/ClearChargingProfile.hpp>
#include <ocpp/v201/messages/ClearVariableMonitoring.hpp>
#include <ocpp/v201/messages/CostUpdated.hpp>
#include <ocpp/v201/messages/CustomerInformation.hpp>
#include <ocpp/v201/messages/DataTransfer.hpp>
#include <ocpp/v201/messages/DeleteCertificate.hpp>
#include <ocpp/v201/messages/Get15118EVCertificate.hpp>
#include <ocpp/v201/messages/GetBaseReport.hpp>
#include <ocpp/v201/messages/GetChargingProfiles.hpp>
#include <ocpp/v201/messages/GetCompositeSchedule.hpp>
#include <ocpp/v201/messages/GetInstalledCertificateIds.hpp>
#include <ocpp/v201/messages/GetLog.hpp>
#include <ocpp/v201/messages/GetMonitoringReport.hpp>
#include <ocpp/v201/messages/GetReport.hpp>
#include <ocpp/v201/messages/GetTransactionStatus.hpp>
#include <ocpp/v201/messages/GetVariables.hpp>
#include <ocpp/v201/messages/InstallCertificate.hpp>
#include <ocpp/v201/messages/MeterValues.hpp>
#include <ocpp/v201/messages/NotifyCustomerInformation.hpp>
#include <ocpp/v201/messages/NotifyEvent.hpp>
Expand Down Expand Up @@ -380,8 +377,6 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa

// timers
Everest::SteadyTimer boot_notification_timer;
Everest::SteadyTimer client_certificate_expiration_check_timer;
Everest::SteadyTimer v2g_certificate_expiration_check_timer;
ClockAlignedTimer aligned_meter_values_timer;

// states
Expand Down Expand Up @@ -436,9 +431,6 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa

// internal helper functions
void initialize(const std::map<int32_t, int32_t>& evse_connector_structure, const std::string& message_log_path);
void init_certificate_expiration_check_timers();
void scheduled_check_client_certificate_expiration();
void scheduled_check_v2g_certificate_expiration();
void websocket_connected_callback(const int configuration_slot,
const NetworkConnectionProfile& network_connection_profile);
void websocket_disconnected_callback(const int configuration_slot,
Expand Down Expand Up @@ -633,11 +625,6 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
// Functional Block L: Firmware management
void handle_firmware_update_req(Call<UpdateFirmwareRequest> call);

// Functional Block M: ISO 15118 Certificate Management
void handle_get_installed_certificate_ids_req(Call<GetInstalledCertificateIdsRequest> call);
void handle_install_certificate_req(Call<InstallCertificateRequest> call);
void handle_delete_certificate_req(Call<DeleteCertificateRequest> call);

// Functional Block N: Diagnostics
void handle_get_log_req(Call<GetLogRequest> call);
void handle_customer_information_req(Call<CustomerInformationRequest> call);
Expand Down Expand Up @@ -665,11 +652,6 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
};
}

/// \brief Helper function to determine if a certificate installation should be allowed
/// \param cert_type is the certificate type to be checked
/// \return true if it should be allowed
bool should_allow_certificate_install(InstallCertificateUseEnum cert_type) const;

protected:
std::shared_ptr<SmartChargingHandlerInterface> smart_charging_handler;

Expand Down
31 changes: 31 additions & 0 deletions include/ocpp/v201/functional_blocks/security.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <ocpp/v201/ocsp_updater.hpp>

#include <ocpp/v201/messages/CertificateSigned.hpp>
#include <ocpp/v201/messages/DeleteCertificate.hpp>
#include <ocpp/v201/messages/Get15118EVCertificate.hpp>
#include <ocpp/v201/messages/GetInstalledCertificateIds.hpp>
#include <ocpp/v201/messages/InstallCertificate.hpp>
#include <ocpp/v201/messages/SignCertificate.hpp>

namespace ocpp::v201 {
Expand All @@ -28,6 +32,11 @@ class SecurityInterface : public MessageHandlerInterface {
virtual void sign_certificate_req(const ocpp::CertificateSigningUseEnum& certificate_signing_use,
const bool initiated_by_trigger_message = false) = 0;
virtual void stop_certificate_signed_timer() = 0;
virtual void init_certificate_expiration_check_timers() = 0;
virtual void stop_certificate_expiration_check_timers() = 0;

virtual Get15118EVCertificateResponse
on_get_15118_ev_certificate_request(const Get15118EVCertificateRequest& request) = 0;
};

class Security : public SecurityInterface {
Expand All @@ -38,6 +47,10 @@ class Security : public SecurityInterface {
virtual ~Security();
void handle_message(const EnhancedMessage<MessageType>& message) override;
virtual void stop_certificate_signed_timer() override;
void init_certificate_expiration_check_timers() override;
void stop_certificate_expiration_check_timers() override;
Get15118EVCertificateResponse
on_get_15118_ev_certificate_request(const Get15118EVCertificateRequest& request) override;

private: // Members
MessageDispatcherInterface<MessageType>& message_dispatcher;
Expand All @@ -52,6 +65,8 @@ class Security : public SecurityInterface {
int csr_attempt;
std::optional<ocpp::CertificateSigningUseEnum> awaited_certificate_signing_use_enum;
Everest::SteadyTimer certificate_signed_timer;
Everest::SteadyTimer client_certificate_expiration_check_timer;
Everest::SteadyTimer v2g_certificate_expiration_check_timer;

private: // Functions
/* OCPP message requests */
Expand All @@ -63,7 +78,23 @@ class Security : public SecurityInterface {
const bool initiated_by_trigger_message = false) override;

/* OCPP message handlers */

// Functional Block A: Security
void handle_certificate_signed_req(Call<CertificateSignedRequest> call);
void handle_sign_certificate_response(CallResult<SignCertificateResponse> call_result);

// Functional Block M: ISO 15118 Certificate Management
void handle_get_installed_certificate_ids_req(Call<GetInstalledCertificateIdsRequest> call);
void handle_install_certificate_req(Call<InstallCertificateRequest> call);
void handle_delete_certificate_req(Call<DeleteCertificateRequest> call);

// Internal helper functions

/// \brief Helper function to determine if a certificate installation should be allowed
/// \param cert_type is the certificate type to be checked
/// \return true if it should be allowed
bool should_allow_certificate_install(InstallCertificateUseEnum cert_type) const;
void scheduled_check_client_certificate_expiration();
void scheduled_check_v2g_certificate_expiration();
};
} // namespace ocpp::v201
Loading

0 comments on commit e7d9de1

Please sign in to comment.