Skip to content

Commit

Permalink
Merge branch 'main' into feature/ev-api
Browse files Browse the repository at this point in the history
  • Loading branch information
hikinggrass authored Dec 10, 2024
2 parents 5879dd3 + 7771a02 commit a89c6c3
Show file tree
Hide file tree
Showing 50 changed files with 1,096 additions and 377 deletions.
10 changes: 5 additions & 5 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
/modules/simulation/ @SebaLukas @pietfried @hikinggrass
/modules/SlacSimulator/ @SebaLukas @pietfried @corneliusclaussen @MarzellT
/modules/rust_examples/ @SirVer @dorezyuk
**/Cargo.toml @SirVer @dorezyuk
**/Cargo.lock @SirVer @dorezyuk
**/Cargo.toml @SirVer @dorezyuk @pietfried @hikinggrass
**/Cargo.lock @SirVer @dorezyuk @pietfried @hikinggrass


# Rust & Bazel
*.rs @SirVer @dorezyuk
*.bazel @SirVer @dorezyuk
*.bzl @SirVer @dorezyuk
*.rs @SirVer @dorezyuk @pietfried @hikinggrass
*.bazel @SirVer @dorezyuk @pietfried @hikinggrass
*.bzl @SirVer @dorezyuk @pietfried @hikinggrass

# third-party/bazel
/third-party/bazel/deps_versions.bzl @pietfried @hikinggrass @corneliusclaussen @SebaLukas @a-w50 @SirVer @dorezyuk
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16)

project(everest-core
VERSION 2024.10.0
VERSION 2024.11.0
DESCRIPTION "The open operating system for e-mobility charging stations"
LANGUAGES CXX C
)
Expand Down
6 changes: 3 additions & 3 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
---
everest-framework:
git: https://github.com/EVerest/everest-framework.git
git_tag: v0.18.0
git_tag: v0.18.1
options: [
"BUILD_TESTING OFF",
"everest-framework_USE_PYTHON_VENV ${PROJECT_NAME}_USE_PYTHON_VENV",
Expand Down Expand Up @@ -61,13 +61,13 @@ libcurl:
# of libocpp and would otherwise be overwritten by the version used there
libevse-security:
git: https://github.com/EVerest/libevse-security.git
git_tag: v0.9.1
git_tag: v0.9.2
cmake_condition: "EVEREST_DEPENDENCY_ENABLED_LIBEVSE_SECURITY"

# OCPP
libocpp:
git: https://github.com/EVerest/libocpp.git
git_tag: 9836ac4766e99a79555adb15c3001c8704f8b7a7
git_tag: 2f005e04460149f71a223e381733b2e2471abdc0
cmake_condition: "EVEREST_DEPENDENCY_ENABLED_LIBOCPP"
# Josev
Josev:
Expand Down
10 changes: 10 additions & 0 deletions interfaces/evse_security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ cmds:
result:
description: The path of the CA bundle file
type: string
get_verify_location:
description: Command to get the file path of the CA root directory that can be used for verification. Will also invoke c_rehash for that directory
arguments:
certificate_type:
description: Specifies that CA certificate type
type: string
$ref: /evse_security#/CaCertificateType
result:
description: The path of the CA certificates directory
type: string
get_leaf_expiry_days_count:
description: >-
Command to get the days count until the given leaf certificate expires.
Expand Down
1 change: 1 addition & 0 deletions lib/staging/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_subdirectory(can_dpm1000)
add_subdirectory(external_energy_limits)
add_subdirectory(helpers)
add_subdirectory(util)

if(EVEREST_DEPENDENCY_ENABLED_LIBEVSE_SECURITY)
Expand Down
13 changes: 13 additions & 0 deletions lib/staging/helpers/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cc_library(
name = "helpers",
srcs = ["lib/helpers.cpp"],
hdrs = ["include/everest/staging/helpers/helpers.hpp"],
copts = ["-std=c++17"],
visibility = ["//visibility:public"],
includes = ["include"],
deps = [
"@com_github_fmtlib_fmt//:fmt",
"@com_github_nlohmann_json//:json",
"//types:types_lib",
],
)
28 changes: 28 additions & 0 deletions lib/staging/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# EVerest helper functions

add_library(everest_staging_helpers STATIC)
add_library(everest::staging::helpers ALIAS everest_staging_helpers)

target_sources(everest_staging_helpers
PRIVATE
lib/helpers.cpp
)

target_include_directories(everest_staging_helpers
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
"$<TARGET_PROPERTY:generate_cpp_files,EVEREST_GENERATED_INCLUDE_DIR>"
$<INSTALL_INTERFACE:include>
)

target_link_libraries(everest_staging_helpers
PRIVATE
fmt::fmt
nlohmann_json::nlohmann_json
)

add_dependencies(everest_staging_helpers generate_cpp_files)

if (BUILD_TESTING)
add_subdirectory(tests)
endif()
23 changes: 23 additions & 0 deletions lib/staging/helpers/include/everest/staging/helpers/helpers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest

#ifndef EVEREST_STAGING_HELPERS_HPP
#define EVEREST_STAGING_HELPERS_HPP

#include <string>

namespace types::authorization {
struct ProvidedIdToken;
}

namespace everest::staging::helpers {

/// \brief Redacts a provided \p token by hashing it
/// \returns a hashed version of the provided token
std::string redact(const std::string& token);

types::authorization::ProvidedIdToken redact(const types::authorization::ProvidedIdToken& token);

} // namespace everest::staging::helpers

#endif
27 changes: 27 additions & 0 deletions lib/staging/helpers/lib/helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest

#include <everest/staging/helpers/helpers.hpp>

#include <unordered_map>

#include <fmt/format.h>

#include <generated/types/authorization.hpp>

namespace everest::staging::helpers {
std::string redact(const std::string& token) {
auto hash = std::hash<std::string>{}(token);
return fmt::format("[redacted] hash: {:X}", hash);
}

types::authorization::ProvidedIdToken redact(const types::authorization::ProvidedIdToken& token) {
types::authorization::ProvidedIdToken redacted_token = token;
redacted_token.id_token.value = redact(redacted_token.id_token.value);
if (redacted_token.parent_id_token.has_value()) {
auto& parent_id_token = redacted_token.parent_id_token.value();
parent_id_token.value = redact(parent_id_token.value);
}
return redacted_token;
}
} // namespace everest::staging::helpers
15 changes: 15 additions & 0 deletions lib/staging/helpers/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(TEST_TARGET_NAME ${PROJECT_NAME}_helpers_tests)

add_executable(${TEST_TARGET_NAME}
helpers_test.cpp
)

target_link_libraries(${TEST_TARGET_NAME}
PRIVATE
GTest::gmock_main
GTest::gtest_main
everest::staging::helpers
)

include(GoogleTest)
gtest_discover_tests(${TEST_TARGET_NAME})
19 changes: 19 additions & 0 deletions lib/staging/helpers/tests/helpers_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <iostream>

#include <everest/staging/helpers/helpers.hpp>

using namespace everest::staging::helpers;
using ::testing::StartsWith;

TEST(HelpersTest, redact_token) {
std::string token = "secret token";

auto redacted = redact(token);

EXPECT_THAT(redacted, StartsWith("[redacted] hash: "));
}
4 changes: 4 additions & 0 deletions lib/staging/ocpp/evse_security_ocpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ std::string EvseSecurity::get_verify_file(const ocpp::CaCertificateType& certifi
return this->r_security.call_get_verify_file(conversions::from_ocpp(certificate_type));
}

std::string EvseSecurity::get_verify_location(const ocpp::CaCertificateType& certificate_type) {
return this->r_security.call_get_verify_location(conversions::from_ocpp(certificate_type));
}

int EvseSecurity::get_leaf_expiry_days_count(const ocpp::CertificateSigningUseEnum& certificate_type) {
return this->r_security.call_get_leaf_expiry_days_count(conversions::from_ocpp(certificate_type));
}
Expand Down
1 change: 1 addition & 0 deletions lib/staging/ocpp/evse_security_ocpp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class EvseSecurity : public ocpp::EvseSecurity {
bool include_ocsp) override;
bool update_certificate_links(const ocpp::CertificateSigningUseEnum& certificate_type) override;
std::string get_verify_file(const ocpp::CaCertificateType& certificate_type) override;
std::string get_verify_location(const ocpp::CaCertificateType& certificate_type) override;
int get_leaf_expiry_days_count(const ocpp::CertificateSigningUseEnum& certificate_type) override;
};

Expand Down
1 change: 1 addition & 0 deletions modules/Auth/Auth.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include <everest/staging/helpers/helpers.hpp>

#include <utility>

Expand Down
1 change: 1 addition & 0 deletions modules/Auth/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cc_library(
"@com_github_HowardHinnant_date//:date",
"//types:types_lib",
"//interfaces:interfaces_lib",
"//lib/staging/helpers",
],
# See https://github.com/HowardHinnant/date/issues/324
local_defines = [
Expand Down
1 change: 1 addition & 0 deletions modules/Auth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ target_link_libraries(${MODULE_NAME}
date::date
date::date-tz
everest::timer
everest::staging::helpers
)
# ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1

Expand Down
14 changes: 9 additions & 5 deletions modules/Auth/lib/AuthHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <AuthHandler.hpp>

#include <everest/logging.hpp>
#include <everest/staging/helpers/helpers.hpp>
#include <generated/interfaces/kvs/Interface.hpp>

namespace module {
Expand Down Expand Up @@ -73,7 +74,7 @@ TokenHandlingResult AuthHandler::on_token(const ProvidedIdToken& provided_token)
TokenHandlingResult result;

// check if token is already currently processed
EVLOG_info << "Received new token: " << provided_token;
EVLOG_info << "Received new token: " << everest::staging::helpers::redact(provided_token);
this->token_in_process_mutex.lock();
const auto referenced_evses = this->get_referenced_evses(provided_token);

Expand All @@ -86,7 +87,8 @@ TokenHandlingResult AuthHandler::on_token(const ProvidedIdToken& provided_token)
this->unlock_plug_in_mutex(referenced_evses);
} else {
// do nothing if token is currently processed
EVLOG_info << "Received token " << provided_token.id_token.value << " repeatedly while still processing it";
EVLOG_info << "Received token " << everest::staging::helpers::redact(provided_token.id_token.value)
<< " repeatedly while still processing it";
this->token_in_process_mutex.unlock();
result = TokenHandlingResult::ALREADY_IN_PROCESS;
}
Expand All @@ -113,7 +115,7 @@ TokenHandlingResult AuthHandler::on_token(const ProvidedIdToken& provided_token)
this->tokens_in_process.erase(provided_token.id_token.value);
}

EVLOG_info << "Result for token: " << provided_token.id_token.value << ": "
EVLOG_info << "Result for token: " << everest::staging::helpers::redact(provided_token.id_token.value) << ": "
<< conversions::token_handling_result_to_string(result);
return result;
}
Expand Down Expand Up @@ -276,7 +278,8 @@ TokenHandlingResult AuthHandler::handle_token(const ProvidedIdToken& provided_to
- compare referenced_evses against the evses listed in the validation_result
*/
int evse_id = this->select_evse(referenced_evses); // might block
EVLOG_debug << "Selected evse#" << evse_id << " for token: " << provided_token.id_token.value;
EVLOG_debug << "Selected evse#" << evse_id
<< " for token: " << everest::staging::helpers::redact(provided_token.id_token.value);
if (evse_id != -1) { // indicates timeout of evse selection
std::optional<std::string> parent_id_token;
if (validation_result.parent_id_token.has_value()) {
Expand Down Expand Up @@ -312,7 +315,8 @@ TokenHandlingResult AuthHandler::handle_token(const ProvidedIdToken& provided_to
this->notify_evse(evse_id, provided_token, validation_result);
} else {
// in this case we dont need / cannot notify an evse, because no evse was selected
EVLOG_info << "Timeout while selecting evse for provided token: " << provided_token;
EVLOG_info << "Timeout while selecting evse for provided token: "
<< everest::staging::helpers::redact(provided_token);
return TokenHandlingResult::TIMEOUT;
}
}
Expand Down
1 change: 1 addition & 0 deletions modules/Auth/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ PRIVATE
date::date
date::date-tz
everest::framework
everest::staging::helpers
)

# needs c++ 14
Expand Down
5 changes: 3 additions & 2 deletions modules/Auth/lib/ReservationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <Connector.hpp>

#include <everest/logging.hpp>
#include <everest/staging/helpers/helpers.hpp>
#include <generated/interfaces/kvs/Interface.hpp>
#include <utils/date.hpp>

Expand Down Expand Up @@ -338,8 +339,8 @@ std::optional<int32_t> ReservationHandler::matches_reserved_identifier(const std
const std::optional<uint32_t> evse_id,
std::optional<std::string> parent_id_token) {
EVLOG_debug << "Matches reserved identifier for evse id " << (evse_id.has_value() ? evse_id.value() : 9999)
<< " and id token " << id_token << " and parent id token "
<< (parent_id_token.has_value() ? parent_id_token.value() : "-");
<< " and id token " << everest::staging::helpers::redact(id_token) << " and parent id token "
<< (parent_id_token.has_value() ? everest::staging::helpers::redact(parent_id_token.value()) : "-");

std::lock_guard<std::recursive_mutex> lock(this->reservation_mutex);

Expand Down
1 change: 1 addition & 0 deletions modules/Auth/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ target_link_libraries(${TEST_TARGET_NAME} PRIVATE
${CMAKE_DL_LIBS}
everest::log
everest::framework
everest::staging::helpers
pthread
nlohmann_json::nlohmann_json
date::date
Expand Down
1 change: 1 addition & 0 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ev_add_module(DummyV2G)
ev_add_module(MicroMegaWattBSP)
ev_add_module(DPM1000)
ev_add_module(OCPPExtensionExample)
ev_add_module(DummyBankSessionTokenProvider)
ev_add_module(DummyTokenValidator)
ev_add_module(DummyTokenProvider)
ev_add_module(DummyTokenProviderManual)
Expand Down
Loading

0 comments on commit a89c6c3

Please sign in to comment.