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

Censor write only variables logging and added a new callback to sanitize any logging that would be passed to the existing message_callback #911

Merged
merged 8 commits into from
Jan 6, 2025
2 changes: 1 addition & 1 deletion include/ocpp/v201/charge_point_callbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct Callbacks {
std::optional<ConfigureNetworkConnectionProfileCallback> configure_network_connection_profile_callback;
std::optional<std::function<void(const ocpp::DateTime& currentTime)>> time_sync_callback;

/// \brief callback to be called to congfigure ocpp message logging
/// \brief callback to be called to configure ocpp message logging
std::optional<std::function<void(const std::string& message, MessageDirection direction)>> ocpp_messages_callback;

///
Expand Down
8 changes: 8 additions & 0 deletions include/ocpp/v201/device_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ class DeviceModel {
}
}

/// \brief Get the mutability for the given component, variable and attribute_enum
/// \param component_id
/// \param variable_id
/// \param attribute_enum
/// \return The mutability of the given component variable, else std::nullopt
std::optional<MutabilityEnum> get_mutability(const Component& component_id, const Variable& variable,
const AttributeEnum& attribute_enum);

/// \brief Sets the variable_id attribute \p value specified by \p component_id , \p variable_id and \p
/// attribute_enum
/// \param component_id
Expand Down
1 change: 0 additions & 1 deletion lib/ocpp/common/websocket/websocket_libwebsockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,6 @@ void WebsocketLibwebsockets::on_conn_message(std::string&& message) {
return;
}

EVLOG_debug << "Received message over TLS websocket polling for process: " << message;
recv_message_queue.push(std::move(message));
}

Expand Down
14 changes: 12 additions & 2 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1820,8 +1820,18 @@ void ChargePoint::handle_variables_changed(const std::map<SetVariableData, SetVa
// iterate over set_variable_results
for (const auto& [set_variable_data, set_variable_result] : set_variable_results) {
if (set_variable_result.attributeStatus == SetVariableStatusEnum::Accepted) {
EVLOG_info << set_variable_data.component.name << ":" << set_variable_data.variable.name << " changed to "
<< set_variable_data.attributeValue.get();
std::optional<MutabilityEnum> mutability =
this->device_model->get_mutability(set_variable_data.component, set_variable_data.variable,
set_variable_data.attributeType.value_or(AttributeEnum::Actual));
// If a nullopt is returned for whatever reason, assume it's write-only to prevent leaking secrets
if (!mutability.has_value() || (mutability.value() == MutabilityEnum::WriteOnly)) {
EVLOG_info << "Write-only " << set_variable_data.component.name << ":"
<< set_variable_data.variable.name << " changed";
} else {
EVLOG_info << set_variable_data.component.name << ":" << set_variable_data.variable.name
<< " changed to " << set_variable_data.attributeValue.get();
}

// handles required behavior specified within OCPP2.0.1 (e.g. reconnect when BasicAuthPassword has changed)
this->handle_variable_changed(set_variable_data);
// notifies libocpp user application that a variable has changed
Expand Down
10 changes: 10 additions & 0 deletions lib/ocpp/v201/device_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ GetVariableStatusEnum DeviceModel::request_value_internal(const Component& compo
return GetVariableStatusEnum::Accepted;
}

std::optional<MutabilityEnum> DeviceModel::get_mutability(const Component& component, const Variable& variable,
const AttributeEnum& attribute_enum) {
const auto attribute = this->device_model->get_variable_attribute(component, variable, attribute_enum);
if (!attribute.has_value()) {
return std::nullopt;
}

return attribute.value().mutability.value();
}

SetVariableStatusEnum DeviceModel::set_value(const Component& component, const Variable& variable,
const AttributeEnum& attribute_enum, const std::string& value,
const std::string& source, bool allow_read_only) {
Expand Down