Skip to content

Commit

Permalink
Merge branch 'main' into feature/PN7160TokenProv-extLib
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Burandt <[email protected]>
  • Loading branch information
cburandt committed Dec 19, 2024
2 parents 8d9ed54 + d8db948 commit 45245f2
Show file tree
Hide file tree
Showing 85 changed files with 5,808 additions and 601 deletions.
10 changes: 5 additions & 5 deletions .github/CODEOWNERS
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
8 changes: 4 additions & 4 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.19.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: c66383782a32827920af80314165843deed63c98
cmake_condition: "EVEREST_DEPENDENCY_ENABLED_LIBOCPP"
# Josev
Josev:
Expand All @@ -86,7 +86,7 @@ ext-mbedtls:
# everest-testing and ev-dev-tools
everest-utils:
git: https://github.com/EVerest/everest-utils.git
git_tag: v0.4.3
git_tag: v0.4.4
# linux_libnfc-nci for RFID
libnfc-nci:
git: https://github.com/EVerest/linux_libnfc-nci.git
Expand Down
5 changes: 3 additions & 2 deletions interfaces/evse_manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ cmds:
arguments:
reservation_id:
description: >-
The reservation id (should be added to the TransactionStarted
event)
The reservation id (should be added to the TransactionStarted event). Set this to a negative value if there is
no specific reservation id for this evse but the evse should still move to a Reserved state because of total
global reservations.
type: integer
result:
description: Returns true if the EVSE accepted the reservation, else false.
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
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -104,7 +105,7 @@ void Auth::ready() {
[this](const std::optional<int32_t> evse_id, const int32_t reservation_id, const ReservationEndReason reason,
const bool send_reservation_update) {
// Only call the evse manager to cancel the reservation if it was for a specific evse
if (evse_id.has_value()) {
if (evse_id.has_value() && evse_id.value() > 0) {
EVLOG_debug << "Call evse manager to cancel the reservation with evse id " << evse_id.value();
this->r_evse_manager.at(evse_id.value() - 1)->call_cancel_reservation();
}
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: 7 additions & 7 deletions modules/Auth/include/AuthHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,10 @@ class AuthHandler {

std::map<int, std::unique_ptr<EVSEContext>> evses;

std::mutex timer_mutex;
std::list<int> plug_in_queue;
std::mutex plug_in_queue_mutex;
std::mutex plug_in_mutex;
std::set<std::string> tokens_in_process;
std::mutex token_in_process_mutex;
std::condition_variable cv;
std::recursive_mutex evse_mutex;
std::mutex event_mutex;

// callbacks
std::function<void(const int evse_index, const ProvidedIdToken& provided_token,
Expand Down Expand Up @@ -268,14 +264,18 @@ class AuthHandler {
*/
int select_evse(const std::vector<int>& selected_evses);

void lock_plug_in_mutex(const std::vector<int>& evse_ids);
void unlock_plug_in_mutex(const std::vector<int>& evse_ids);
int get_latest_plugin(const std::vector<int>& evse_ids);
void notify_evse(int evse_id, const ProvidedIdToken& provided_token, const ValidationResult& validation_result);
Identifier get_identifier(const ValidationResult& validation_result, const std::string& id_token,
const AuthorizationType& type);
void submit_event_for_connector(const int32_t evse_id, const int32_t connector_id,
const ConnectorEvent connector_event);
/**
* @brief Check reservations: if there are as many reservations as evse's, all should be set to reserved.
*
* This will check the reservation status of the evse's and send the statusses to the evse manager.
*/
void check_evse_reserved_and_send_updates();
};

} // namespace module
Expand Down
11 changes: 8 additions & 3 deletions modules/Auth/include/Connector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ struct EVSEContext {
}

EVSEContext(int evse_id, int evse_index, const std::vector<Connector>& connectors) :
evse_id(evse_id), evse_index(evse_index), transaction_active(false), connectors(connectors), plugged_in(false) {
evse_id(evse_id),
evse_index(evse_index),
transaction_active(false),
connectors(connectors),
plugged_in(false),
plug_in_timeout(false) {
}

int32_t evse_id;
Expand All @@ -77,9 +82,9 @@ struct EVSEContext {
std::optional<Identifier> identifier = std::nullopt;
std::vector<Connector> connectors;
Everest::SteadyTimer timeout_timer;
std::mutex plug_in_mutex;
std::mutex event_mutex;
bool plugged_in;
bool plug_in_timeout; // indicates no authorization received within connection_timeout. Replug is required for this
// EVSE to get authorization and start a transaction

bool is_available();
bool is_unavailable();
Expand Down
Loading

0 comments on commit 45245f2

Please sign in to comment.