Skip to content

Commit a513961

Browse files
authored
Merge pull request #38 from c-jimenez/dev/security_optional_secure_notification
Add configuration key to enable/disable security events notifications
2 parents 72813c1 + a8c8838 commit a513961

File tree

11 files changed

+54
-70
lines changed

11 files changed

+54
-70
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ In the "Owner" column, "S" means that the configuration key behavior is handled
121121
| ChargingScheduleMaxPeriods | S | None |
122122
| ConnectorSwitch3to1PhaseSupported | S | None |
123123
| MaxChargingProfilesInstalled | S | None |
124-
| AdditionalRootCertificateCheck | S | OCPP 1.6 security whitepaper edition 2 configuration key : not implemented yet |
124+
| AdditionalRootCertificateCheck | U | None |
125125
| AuthorizationKey | S | None |
126-
| CertificateSignedMaxChainSize | S | OCPP 1.6 security whitepaper edition 2 configuration key : not implemented yet |
127-
| CertificateStoreMaxLength | S | OCPP 1.6 security whitepaper edition 2 configuration key : not implemented yet |
128-
| CpoName | S | OCPP 1.6 security whitepaper edition 2 configuration key : not implemented yet |
129-
| SecurityProfile | S | OCPP 1.6 security whitepaper edition 2 configuration key : not implemented yet |
126+
| CertificateSignedMaxChainSize | S | None |
127+
| CertificateStoreMaxLength | U | None |
128+
| CpoName | S | None |
129+
| SecurityProfile | S | None |
130130

131131
### OCPP security extensions
132132

@@ -154,6 +154,8 @@ In Charge Point role, it can optionnaly handle the storage of the security event
154154

155155
In Charge Point role, the user application can generate custom security events and defines its criticity so that they are forwarded to the Central System.
156156

157+
In Charge Point role, the notification of security events can be enabled or disabled with the IChargePointConfig::securityEventNotificationEnabled() configuration. This can be usefull to disable them when the Central System does not implement the security extensions.
158+
157159
#### Extended trigger messages
158160

159161
**Open OCPP** support this feature for both Charge Point and Central System roles.

examples/common/config/ChargePointConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class ChargePointConfig : public ocpp::config::IChargePointConfig
125125

126126
// Security
127127

128+
/** @brief Enabled security event notification */
129+
bool securityEventNotificationEnabled() const override { return getBool("SecurityEventNotificationEnabled"); }
128130
/** @brief Maximum number of entries in the security log (0 = no security logs in database) */
129131
unsigned int securityLogMaxEntriesCount() const override { return get<unsigned int>("SecurityLogMaxEntriesCount"); };
130132

examples/quick_start_chargepoint/config/quick_start_chargepoint.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ MeterType=
2929
OperatingVoltage=230
3030
AuthentCacheMaxEntriesCount=1000
3131
LogMaxEntriesCount=2000
32+
SecurityEventNotificationEnabled=true
3233
SecurityLogMaxEntriesCount=1000
3334

3435
[Ocpp]

examples/remote_chargepoint/config/remote_chargepoint.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ MeterType=
2929
OperatingVoltage=230
3030
AuthentCacheMaxEntriesCount=1000
3131
LogMaxEntriesCount=2000
32+
SecurityEventNotificationEnabled=true
3233
SecurityLogMaxEntriesCount=1000
3334

3435
[Ocpp]

examples/security_chargepoint/config/security_chargepoint.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ MeterType=
2929
OperatingVoltage=230
3030
AuthentCacheMaxEntriesCount=1000
3131
LogMaxEntriesCount=2000
32+
SecurityEventNotificationEnabled=true
3233
SecurityLogMaxEntriesCount=1000
3334

3435
[Ocpp]

src/chargepoint/interface/IChargePointConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class IChargePointConfig
118118

119119
// Security
120120

121+
/** @brief Enabled security event notification */
122+
virtual bool securityEventNotificationEnabled() const = 0;
121123
/** @brief Maximum number of entries in the security log (0 = no security logs in database) */
122124
virtual unsigned int securityLogMaxEntriesCount() const = 0;
123125
};

src/chargepoint/security/SecurityManager.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ SecurityManager::SecurityManager(const ocpp::config::IChargePointConfig&
7373
GenericMessageHandler<GetInstalledCertificateIdsReq, GetInstalledCertificateIdsConf>(GET_INSTALLED_CERTIFICATE_IDS_ACTION,
7474
messages_converter),
7575
GenericMessageHandler<InstallCertificateReq, InstallCertificateConf>(INSTALL_CERTIFICATE_ACTION, messages_converter),
76+
m_stack_config(stack_config),
7677
m_ocpp_config(ocpp_config),
7778
m_events_handler(events_handler),
7879
m_worker_pool(worker_pool),
@@ -197,32 +198,35 @@ bool SecurityManager::logSecurityEvent(const std::string& type, const std::strin
197198
{
198199
LOG_WARNING << "Security Event : type = " << type << ", message = " << message;
199200

200-
SecurityEventNotificationReq request;
201-
request.type.assign(type);
202-
request.timestamp = timestamp;
203-
if (!message.empty())
201+
if (m_stack_config.securityEventNotificationEnabled())
204202
{
205-
request.techInfo.value().assign(message);
206-
}
203+
SecurityEventNotificationReq request;
204+
request.type.assign(type);
205+
request.timestamp = timestamp;
206+
if (!message.empty())
207+
{
208+
request.techInfo.value().assign(message);
209+
}
207210

208-
if (m_msg_sender)
209-
{
210-
// Stack is started, try to send the notification
211-
SecurityEventNotificationConf response;
212-
if (m_msg_sender->call(SECURITY_EVENT_NOTIFICATION_ACTION, request, response, &m_requests_fifo) == CallResult::Failed)
211+
if (m_msg_sender)
213212
{
214-
ret = false;
213+
// Stack is started, try to send the notification
214+
SecurityEventNotificationConf response;
215+
if (m_msg_sender->call(SECURITY_EVENT_NOTIFICATION_ACTION, request, response, &m_requests_fifo) == CallResult::Failed)
216+
{
217+
ret = false;
218+
}
215219
}
216-
}
217-
else
218-
{
219-
// Stack is not started, queue the notification
220-
rapidjson::Document payload;
221-
payload.Parse("{}");
222-
m_security_event_req_converter.setAllocator(&payload.GetAllocator());
223-
if (m_security_event_req_converter.toJson(request, payload))
220+
else
224221
{
225-
m_requests_fifo.push(0, SECURITY_EVENT_NOTIFICATION_ACTION, payload);
222+
// Stack is not started, queue the notification
223+
rapidjson::Document payload;
224+
payload.Parse("{}");
225+
m_security_event_req_converter.setAllocator(&payload.GetAllocator());
226+
if (m_security_event_req_converter.toJson(request, payload))
227+
{
228+
m_requests_fifo.push(0, SECURITY_EVENT_NOTIFICATION_ACTION, payload);
229+
}
226230
}
227231
}
228232
}

src/chargepoint/security/SecurityManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ class SecurityManager
159159
std::string& error_message) override;
160160

161161
private:
162+
/** @brief Stack configuration */
163+
const ocpp::config::IChargePointConfig& m_stack_config;
162164
/** @brief Standard OCPP configuration */
163165
ocpp::config::IOcppConfig& m_ocpp_config;
164166
/** @brief User defined events handler */

src/tools/x509/X509Document.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ time_t X509Document::convertAsn1Time(const void* pasn1_time)
109109
const ASN1_TIME* asn1_time = reinterpret_cast<const ASN1_TIME*>(pasn1_time);
110110
struct tm tm;
111111
ASN1_TIME_to_tm(asn1_time, &tm);
112-
return mktime(&tm);
112+
time_t timestamp = mktime(&tm);
113+
timestamp += tm.tm_gmtoff;
114+
timestamp -= (tm.tm_isdst * 3600);
115+
return timestamp;
113116
}
114117

115118
/** @brief Convert a string in ASN1_STRING format to a standard string representation */

tests/tools/test_workerthreadpool.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ TEST_SUITE("WorkerThreadPool class test suite")
2828
{
2929
WorkerThreadPool worker_thread_pool(3);
3030

31+
std::mutex jobs_done_mutex;
3132
unsigned int jobs_done = 0;
3233

3334
std::mutex end_job1_mutex;
@@ -43,9 +44,10 @@ TEST_SUITE("WorkerThreadPool class test suite")
4344
worker_thread_pool.run<void>(job1);
4445
Waiter<void> waiter1 = worker_thread_pool.run<void>(job1);
4546

46-
auto job2 = [&jobs_done]
47+
auto job2 = [&jobs_done, &jobs_done_mutex]
4748
{
4849
std::this_thread::sleep_for(std::chrono::milliseconds(25u));
50+
std::lock_guard<std::mutex> lock(jobs_done_mutex);
4951
jobs_done++;
5052
};
5153
worker_thread_pool.run<void>(job2);

0 commit comments

Comments
 (0)