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

Optionally allow security level 0 connections #856

Merged
merged 5 commits into from
Nov 28, 2024
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
16 changes: 16 additions & 0 deletions config/v201/component_config/standardized/InternalCtrlr.json
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,22 @@
"description": "The flag that indicates if installation of ManufacturerRootCertificate is allowed when security profile is 1.",
"default": true,
"type": "boolean"
},
"AllowSecurityLevelZeroConnections": {
"variable_name": "AllowSecurityLevelZeroConnections",
"characteristics": {
"supportsMonitoring": false,
"dataType": "boolean"
},
"attributes": [
{
"type": "Actual",
"mutability": "ReadOnly"
}
],
"description": "If enabled we allow connections using security level 0. This does pose a security risk and is not allowed according to the OCPP spec",
"default": false,
"type": "boolean"
}
},
"required": [
Expand Down
1 change: 1 addition & 0 deletions include/ocpp/v201/ctrlr_component_variables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ extern const ComponentVariable& ClientCertificateExpireCheckIntervalSeconds;
extern const ComponentVariable& MessageQueueSizeThreshold;
extern const ComponentVariable& MaxMessageSize;
extern const ComponentVariable& ResumeTransactionsOnBoot;
extern const ComponentVariable& AllowSecurityLevelZeroConnections;
extern const ComponentVariable& AlignedDataCtrlrEnabled;
extern const ComponentVariable& AlignedDataCtrlrAvailable;
extern const RequiredComponentVariable& AlignedDataInterval;
Expand Down
28 changes: 23 additions & 5 deletions lib/ocpp/v201/connectivity_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ ConnectivityManager::get_network_connection_profile(const int32_t configuration_

for (const auto& network_profile : this->cached_network_connection_profiles) {
if (network_profile.configurationSlot == configuration_slot) {
if (network_profile.connectionData.securityProfile ==
security::OCPP_1_6_ONLY_UNSECURED_TRANSPORT_WITHOUT_BASIC_AUTHENTICATION) {
throw std::invalid_argument(
"security_profile = " + std::to_string(network_profile.connectionData.securityProfile) +
" not officially allowed in OCPP 2.0.1");
if (!this->device_model
.get_optional_value<bool>(ControllerComponentVariables::AllowSecurityLevelZeroConnections)
.value_or(false) &&
network_profile.connectionData.securityProfile ==
security::OCPP_1_6_ONLY_UNSECURED_TRANSPORT_WITHOUT_BASIC_AUTHENTICATION) {
EVLOG_error << "security_profile 0 not officially allowed in OCPP 2.0.1, skipping profile";
return std::nullopt;
}

return network_profile.connectionData;
Expand Down Expand Up @@ -211,6 +213,11 @@ void ConnectivityManager::try_connect_websocket() {
this->active_network_configuration_priority =
get_priority_from_configuration_slot(configuration_slot_to_set).value();

if (connection_options->security_profile ==
security::OCPP_1_6_ONLY_UNSECURED_TRANSPORT_WITHOUT_BASIC_AUTHENTICATION) {
EVLOG_warning << "Using insecure security profile 0 without authentication";
}

EVLOG_info << "Open websocket with NetworkConfigurationPriority: "
<< this->active_network_configuration_priority + 1 << " which is configurationSlot "
<< configuration_slot_to_set;
Expand Down Expand Up @@ -410,6 +417,17 @@ void ConnectivityManager::cache_network_connection_profiles() {
this->cached_network_connection_profiles =
json::parse(this->device_model.get_value<std::string>(ControllerComponentVariables::NetworkConnectionProfiles));

if (!this->device_model.get_optional_value<bool>(ControllerComponentVariables::AllowSecurityLevelZeroConnections)
.value_or(false) &&
std::none_of(this->cached_network_connection_profiles.begin(), this->cached_network_connection_profiles.end(),
[](const SetNetworkProfileRequest& profile) {
return profile.connectionData.securityProfile !=
security::OCPP_1_6_ONLY_UNSECURED_TRANSPORT_WITHOUT_BASIC_AUTHENTICATION;
})) {
throw std::invalid_argument(
"All profiles configured have security_profile 0 which is not officially allowed in OCPP 2.0.1");
}

for (const std::string& str : ocpp::split_string(
this->device_model.get_value<std::string>(ControllerComponentVariables::NetworkConfigurationPriority),
',')) {
Expand Down
7 changes: 7 additions & 0 deletions lib/ocpp/v201/ctrlr_component_variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ const ComponentVariable& AllowMFRootCertInstallWithUnsecureConnection = {
"AllowMFRootCertInstallWithUnsecureConnection",
}),
};
const ComponentVariable& AllowSecurityLevelZeroConnections = {
ControllerComponents::InternalCtrlr,
std::nullopt,
std::optional<Variable>({
"AllowSecurityLevelZeroConnections",
}),
};
const ComponentVariable& AlignedDataCtrlrEnabled = {
ControllerComponents::AlignedDataCtrlr,
std::nullopt,
Expand Down