Add extracted tools: CitrineOS, OpenOCPP, ShapeShifter

- CitrineOS core extracted (CSMS OCPP 2.0.1)
- OpenOCPP extracted (firmware OCPP 1.6J/2.0.1)
- ShapeShifter library installed (pip install -e)
- ShapeShifter specification extracted
- EVerest extracted

TODO updated with progress
This commit is contained in:
Eric F
2026-06-08 00:38:27 -04:00
parent 468cfeaa50
commit d398a6ced2
7326 changed files with 1177561 additions and 7 deletions

View File

@@ -0,0 +1,17 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "helpers",
srcs = ["src/helpers.cpp"],
hdrs = ["include/everest/helpers/helpers.hpp",],
copts = ["-std=c++17"],
includes = ["include"],
visibility = ["//visibility:public"],
deps = [
"//lib/everest/tls",
"//types:types_lib",
"@boost.uuid",
"@com_github_fmtlib_fmt//:fmt",
"@com_github_nlohmann_json//:json",
],
)

View File

@@ -0,0 +1,66 @@
# EVerest helper functions
add_library(everest_helpers STATIC)
add_library(everest::helpers ALIAS everest_helpers)
ev_register_library_target(everest_helpers)
target_sources(everest_helpers
PRIVATE
src/helpers.cpp
)
if (EVEREST_CORE_BUILD_TESTING)
target_compile_definitions(everest_helpers PUBLIC EVEREST_COVERAGE_ENABLED)
target_sources(everest_helpers
PRIVATE
src/coverage.cpp
)
endif()
target_include_directories(everest_helpers
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
"$<TARGET_PROPERTY:generate_cpp_files,EVEREST_GENERATED_INCLUDE_DIR>"
)
target_link_libraries(everest_helpers
PRIVATE
Boost::headers
fmt::fmt
nlohmann_json::nlohmann_json
everest::tls
)
set_target_properties(everest_helpers
PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
add_dependencies(everest_helpers generate_cpp_files)
if (BUILD_TESTING)
add_subdirectory(tests)
endif()
if(DISABLE_EDM)
install(
TARGETS
everest_helpers
EXPORT everest-helpers-targets
LIBRARY
)
evc_setup_package(
NAME everest-helpers
EXPORT everest-helpers-targets
NAMESPACE everest
ADDITIONAL_CONTENT
"find_dependency(everest-tls)"
"find_dependency(nlohmann_json)"
"find_dependency(nlohmann_json_schema_validator)"
"find_dependency(fmt)"
)
endif()

View File

@@ -0,0 +1,10 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#pragma once
namespace everest::helpers {
void install_signal_handlers_for_gcov();
}

View File

@@ -0,0 +1,58 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#ifndef everest_helpers_HPP
#define everest_helpers_HPP
#include <algorithm>
#include <cctype>
#include <string>
namespace types::authorization {
struct ProvidedIdToken;
struct IdToken;
} // namespace types::authorization
namespace everest::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);
/// \brief Escapes various HTML characters
/// \returns an escaped version of the provided html
std::string escape_html(const std::string& html);
/// \brief Compares two strings case-insensitively
/// \returns true if the strings are equal, false otherwise
bool is_equal_case_insensitive(const std::string& str1, const std::string& str2);
/// \brief Compares two IdTokens case-insensitively
/// \returns true if the IdTokens are equal, false otherwise
/// \note This function compares the value and type of the IdTokens
bool is_equal_case_insensitive(const types::authorization::IdToken& token1,
const types::authorization::IdToken& token2);
/// \brief Compares two ProvidedIdTokens case-insensitively
/// \returns true if the ProvidedIdTokens are equal, false otherwise
/// \note This function compares the id_token and type of the ProvidedIdTokens
bool is_equal_case_insensitive(const types::authorization::ProvidedIdToken& token1,
const types::authorization::ProvidedIdToken& token2);
/// \brief Provide a UUID
/// \returns a UUID string. This UUID is 36 characters long
std::string get_uuid();
/// \brief Provide a base64 encoded UUID
/// \returns a base64 encoded UUID string. This UUID is 22 characters long
std::string get_base64_uuid();
/// \brief Provide a base64 encoded ID
/// \returns a base64 encoded ID string. This ID is 16 characters long
std::string get_base64_id();
} // namespace everest::helpers
#endif

View File

@@ -0,0 +1,41 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include <everest/helpers/coverage.hpp>
#include <atomic>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
extern "C" void __gcov_dump();
namespace {
static std::atomic_flag going_to_terminate = ATOMIC_FLAG_INIT;
void terminate_handler(int signal) {
if (going_to_terminate.test_and_set()) {
return;
}
__gcov_dump();
_exit(EXIT_FAILURE);
};
} // namespace
namespace everest::helpers {
void install_signal_handlers_for_gcov() {
struct sigaction action {};
action.sa_handler = &terminate_handler;
// action.sa_mask should be zero, so no blocked signals within the signal handler
// action.sa_flags should be fine with being zero
sigaction(SIGINT, &action, nullptr);
sigaction(SIGTERM, &action, nullptr);
}
} // namespace everest::helpers

View File

@@ -0,0 +1,105 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Pionix GmbH and Contributors to EVerest
#include <everest/helpers/helpers.hpp>
#include <everest/tls/openssl_util.hpp>
#include <unordered_map>
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <fmt/format.h>
#include <generated/types/authorization.hpp>
namespace everest::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;
}
std::string escape_html(const std::string& html) {
std::string escaped_html;
escaped_html.reserve(html.size());
for (const auto& character : html) {
switch (character) {
case '\"':
escaped_html.append("&quot;");
break;
case '\'':
escaped_html.append("&apos;");
break;
case '&':
escaped_html.append("&amp;");
break;
case '<':
escaped_html.append("&lt;");
break;
case '>':
escaped_html.append("&gt;");
break;
default:
escaped_html.push_back(character);
break;
}
}
return escaped_html;
}
bool is_equal_case_insensitive(const std::string& str1, const std::string& str2) {
if (str1.length() != str2.length()) {
return false;
}
return std::equal(str1.begin(), str1.end(), str2.begin(),
[](char a, char b) { return std::tolower(a) == std::tolower(b); });
}
bool is_equal_case_insensitive(const types::authorization::IdToken& token1,
const types::authorization::IdToken& token2) {
return is_equal_case_insensitive(token1.value, token2.value) && token1.type == token2.type;
}
bool is_equal_case_insensitive(const types::authorization::ProvidedIdToken& token1,
const types::authorization::ProvidedIdToken& token2) {
return is_equal_case_insensitive(token1.id_token.value, token2.id_token.value) &&
token1.id_token.type == token2.id_token.type;
}
namespace {
boost::uuids::random_generator& get_rng() {
static thread_local boost::uuids::random_generator rng;
return rng;
}
} // namespace
std::string get_uuid() {
return boost::uuids::to_string(get_rng()()); // 36 characters
}
std::string get_base64_uuid() {
boost::uuids::uuid uuid = get_rng()();
std::string encoded = openssl::base64_encode(uuid.data, uuid.size(), false);
encoded.erase(std::remove(encoded.begin(), encoded.end(), '='), encoded.end()); // remove padding
return encoded; // 22 characters
}
std::string get_base64_id() {
std::array<std::uint8_t, 12> random_bytes;
boost::uuids::uuid uuid = get_rng()();
std::memcpy(random_bytes.data(), uuid.data, random_bytes.size());
std::string encoded = openssl::base64_encode(random_bytes.data(), random_bytes.size(), false);
return encoded; // 16 characters
}
} // namespace everest::helpers

View File

@@ -0,0 +1,17 @@
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::helpers
)
include(GoogleTest)
gtest_discover_tests(${TEST_TARGET_NAME})
ev_register_test_target(${TEST_TARGET_NAME})

View File

@@ -0,0 +1,47 @@
// 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/helpers/helpers.hpp>
using namespace everest::helpers;
using ::testing::StartsWith;
TEST(HelpersTest, redact_token) {
std::string token = "secret token";
auto redacted = redact(token);
EXPECT_THAT(redacted, StartsWith("[redacted] hash: "));
}
TEST(HelpersTest, get_uuid) {
auto uuid1 = get_uuid();
auto uuid2 = get_uuid();
EXPECT_GT(uuid1.length(), 0);
EXPECT_GT(uuid2.length(), 0);
EXPECT_EQ(uuid1.length(), uuid2.length());
EXPECT_NE(uuid1, uuid2);
}
TEST(HelpersTest, get_base64_uuid) {
auto id1 = get_base64_uuid();
auto id2 = get_base64_uuid();
EXPECT_EQ(id1.length(), 22);
EXPECT_EQ(id2.length(), 22);
EXPECT_NE(id1, id2);
}
TEST(HelpersTest, get_base64_id) {
auto id1 = get_base64_id();
auto id2 = get_base64_id();
EXPECT_EQ(id1.length(), 16);
EXPECT_EQ(id2.length(), 16);
EXPECT_NE(id1, id2);
}