Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68d86f76a2 | ||
|
|
cb58236538 |
No files matched your search
@@ -45,16 +45,17 @@ jobs:
|
|||||||
|
|
||||||
- name: Configure
|
- name: Configure
|
||||||
run: |
|
run: |
|
||||||
cmake -S . -B build-release -G Ninja \
|
cmake -S . -B build-relwithdebinfo -G Ninja \
|
||||||
-DCMAKE_BUILD_TYPE=Release \
|
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
||||||
-DBUILD_SHARED_LIBS=ON \
|
-DBUILD_SHARED_LIBS=ON \
|
||||||
-DVOID_ENABLE_TESTING=ON \
|
-DVOID_ENABLE_TESTING=ON \
|
||||||
-DVOID_WARNINGS_AS_ERRORS=ON
|
-DVOID_WARNINGS_AS_ERRORS=ON
|
||||||
|
|
||||||
- name: Build and test
|
- name: Build and test
|
||||||
run: |
|
run: |
|
||||||
cmake --build build-release --parallel
|
cmake --build build-relwithdebinfo --config RelWithDebInfo --parallel
|
||||||
ctest --test-dir build-release --output-on-failure
|
ctest --test-dir build-relwithdebinfo \
|
||||||
|
--build-config RelWithDebInfo --output-on-failure
|
||||||
|
|
||||||
- name: Install and package
|
- name: Install and package
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -63,8 +64,11 @@ jobs:
|
|||||||
version="${GITHUB_REF_NAME#v}"
|
version="${GITHUB_REF_NAME#v}"
|
||||||
package="voidlibrary-${version}-linux-x86_64"
|
package="voidlibrary-${version}-linux-x86_64"
|
||||||
epoch="$(git show -s --format=%ct HEAD)"
|
epoch="$(git show -s --format=%ct HEAD)"
|
||||||
cmake --install build-release \
|
cmake --install build-relwithdebinfo \
|
||||||
|
--config RelWithDebInfo \
|
||||||
--prefix "$PWD/stage/$package"
|
--prefix "$PWD/stage/$package"
|
||||||
|
python3 .release-tools/scripts/verify-relwithdebinfo.py \
|
||||||
|
--root "$PWD/stage/$package"
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
SOURCE_DATE_EPOCH="$epoch" \
|
SOURCE_DATE_EPOCH="$epoch" \
|
||||||
tar --sort=name --mtime="@$epoch" \
|
tar --sort=name --mtime="@$epoch" \
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 4.0.0)
|
cmake_minimum_required(VERSION 4.0.0)
|
||||||
project(Void VERSION 1.0.0 LANGUAGES CXX)
|
project(Void VERSION 1.1.0 LANGUAGES CXX)
|
||||||
if(PROJECT_IS_TOP_LEVEL)
|
if(PROJECT_IS_TOP_LEVEL)
|
||||||
option(BUILD_SHARED_LIBS "Build Void modules as shared libraries" ON)
|
option(BUILD_SHARED_LIBS "Build Void modules as shared libraries" ON)
|
||||||
elseif(NOT DEFINED BUILD_SHARED_LIBS)
|
elseif(NOT DEFINED BUILD_SHARED_LIBS)
|
||||||
|
|||||||
@@ -95,6 +95,13 @@ namespace Void::Plugin
|
|||||||
// publication. A failed validation aborts load/reload
|
// publication. A failed validation aborts load/reload
|
||||||
// transactionally.
|
// transactionally.
|
||||||
std::function<bool(IPlugin&, const PluginInfo&)> instance_validator;
|
std::function<bool(IPlugin&, const PluginInfo&)> instance_validator;
|
||||||
|
// Binary-level contract checked immediately after the shared object
|
||||||
|
// is opened and identified, before configuration, activation, state
|
||||||
|
// transfer, or publication. Hosts can inspect optional exported
|
||||||
|
// symbols through the pinned handle. A rejection is transactional:
|
||||||
|
// initial loads are discarded and reloads keep the current
|
||||||
|
// instance.
|
||||||
|
std::function<bool(const PluginHandle&)> candidate_validator;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Identifies an on_reloaded observer for remove_on_reloaded.
|
// Identifies an on_reloaded observer for remove_on_reloaded.
|
||||||
|
|||||||
@@ -254,6 +254,13 @@ namespace Void::Plugin
|
|||||||
return std::unexpected{inst.error()};
|
return std::unexpected{inst.error()};
|
||||||
}
|
}
|
||||||
std::string name{(*inst)->plugin->name()};
|
std::string name{(*inst)->plugin->name()};
|
||||||
|
if (m_options.candidate_validator &&
|
||||||
|
!m_options.candidate_validator(PluginHandle{*inst})) {
|
||||||
|
Void::Log::warn("Plugin.Manager",
|
||||||
|
"load '{}' aborted: binary validation failed",
|
||||||
|
name);
|
||||||
|
return std::unexpected{LoadError::ActivationFailed};
|
||||||
|
}
|
||||||
if (m_options.config_provider && (*inst)->configure != nullptr) {
|
if (m_options.config_provider && (*inst)->configure != nullptr) {
|
||||||
const std::string config = m_options.config_provider(name);
|
const std::string config = m_options.config_provider(name);
|
||||||
(*inst)->configure((*inst)->plugin, config.c_str());
|
(*inst)->configure((*inst)->plugin, config.c_str());
|
||||||
@@ -425,6 +432,13 @@ namespace Void::Plugin
|
|||||||
name, (*next)->plugin->name());
|
name, (*next)->plugin->name());
|
||||||
return std::unexpected{LoadError::NameMismatch};
|
return std::unexpected{LoadError::NameMismatch};
|
||||||
}
|
}
|
||||||
|
if (m_options.candidate_validator &&
|
||||||
|
!m_options.candidate_validator(PluginHandle{*next})) {
|
||||||
|
Void::Log::warn("Plugin.Manager",
|
||||||
|
"reload '{}' aborted: binary validation failed",
|
||||||
|
name);
|
||||||
|
return std::unexpected{LoadError::ActivationFailed};
|
||||||
|
}
|
||||||
|
|
||||||
if (m_options.config_provider && (*next)->configure != nullptr) {
|
if (m_options.config_provider && (*next)->configure != nullptr) {
|
||||||
const std::string config = m_options.config_provider(name);
|
const std::string config = m_options.config_provider(name);
|
||||||
|
|||||||
+30
-3
@@ -34,6 +34,10 @@ namespace Void::Update
|
|||||||
{
|
{
|
||||||
return value.is_array();
|
return value.is_array();
|
||||||
}
|
}
|
||||||
|
[[nodiscard]] bool is_object(const Json::Value& value) noexcept
|
||||||
|
{
|
||||||
|
return value.is_object();
|
||||||
|
}
|
||||||
[[nodiscard]] bool is_string(const Json::Value& value) noexcept
|
[[nodiscard]] bool is_string(const Json::Value& value) noexcept
|
||||||
{
|
{
|
||||||
return value.is_string();
|
return value.is_string();
|
||||||
@@ -639,10 +643,24 @@ namespace Void::Update
|
|||||||
auto schema =
|
auto schema =
|
||||||
unsigned_number<std::uint32_t>(*envelope, "schemaVersion");
|
unsigned_number<std::uint32_t>(*envelope, "schemaVersion");
|
||||||
auto keyId = string_member(*envelope, "keyId");
|
auto keyId = string_member(*envelope, "keyId");
|
||||||
auto payloadText = string_member(*envelope, "payload");
|
|
||||||
auto signatureText = string_member(*envelope, "signature");
|
auto signatureText = string_member(*envelope, "signature");
|
||||||
if (!schema || !keyId || !payloadText || !signatureText ||
|
if (!schema || !keyId || !signatureText ||
|
||||||
(*schema != 1 && *schema != 2) || !valid_token(*keyId, 256)) {
|
(*schema != 1 && *schema != 2 && *schema != 3) ||
|
||||||
|
!valid_token(*keyId, 256)) {
|
||||||
|
return Void::Result::fail("Update feed: invalid envelope fields");
|
||||||
|
}
|
||||||
|
auto payloadText = string_member(
|
||||||
|
*envelope, *schema == 3 ? "signedPayload" : "payload");
|
||||||
|
const Json::Value* displayedDocument = nullptr;
|
||||||
|
if (*schema == 3) {
|
||||||
|
auto document =
|
||||||
|
member(*envelope, "document", is_object, "an object");
|
||||||
|
if (!document) {
|
||||||
|
return std::unexpected{document.error()};
|
||||||
|
}
|
||||||
|
displayedDocument = *document;
|
||||||
|
}
|
||||||
|
if (!payloadText) {
|
||||||
return Void::Result::fail("Update feed: invalid envelope fields");
|
return Void::Result::fail("Update feed: invalid envelope fields");
|
||||||
}
|
}
|
||||||
const auto key = keys.find(*keyId);
|
const auto key = keys.find(*keyId);
|
||||||
@@ -657,6 +675,15 @@ namespace Void::Update
|
|||||||
return Void::Result::fail(
|
return Void::Result::fail(
|
||||||
"Update feed: invalid or oversized envelope encoding");
|
"Update feed: invalid or oversized envelope encoding");
|
||||||
}
|
}
|
||||||
|
if (*schema == 3) {
|
||||||
|
auto signedDocument = Json::parse(*payload);
|
||||||
|
if (!signedDocument || !signedDocument->is_object() ||
|
||||||
|
displayedDocument == nullptr ||
|
||||||
|
*displayedDocument != *signedDocument) {
|
||||||
|
return Void::Result::fail("Update feed: readable document "
|
||||||
|
"differs from signed payload");
|
||||||
|
}
|
||||||
|
}
|
||||||
const auto signatureBytes =
|
const auto signatureBytes =
|
||||||
std::as_bytes(std::span{signature->data(), signature->size()});
|
std::as_bytes(std::span{signature->data(), signature->size()});
|
||||||
const auto payloadBytes =
|
const auto payloadBytes =
|
||||||
|
|||||||
@@ -61,6 +61,41 @@ Void::Testing::Test manager_unknown_plugin_yields_empty_handle()
|
|||||||
LoadError::UnknownPlugin);
|
LoadError::UnknownPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Void::Testing::Test manager_candidate_validator_rejects_initial_load()
|
||||||
|
{
|
||||||
|
int validations = 0;
|
||||||
|
PluginManager manager{
|
||||||
|
{.candidate_validator = [&](const PluginHandle& candidate) {
|
||||||
|
++validations;
|
||||||
|
Void::Testing::expect(static_cast<bool>(candidate));
|
||||||
|
Void::Testing::expect(candidate.raw_symbol(kInfoSymbol) != nullptr);
|
||||||
|
return false;
|
||||||
|
}}};
|
||||||
|
const auto loaded = manager.load(VOID_STATEFUL_V1_PATH);
|
||||||
|
Void::Testing::expect(!loaded.has_value());
|
||||||
|
Void::Testing::expect(loaded.error() == LoadError::ActivationFailed);
|
||||||
|
Void::Testing::expect_eq(validations, 1);
|
||||||
|
Void::Testing::expect(!manager.acquire("StatefulPlugin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Void::Testing::Test manager_candidate_validator_rejects_reload_transactionally()
|
||||||
|
{
|
||||||
|
bool accept = true;
|
||||||
|
PluginManager manager{
|
||||||
|
{.candidate_validator = [&](const PluginHandle&) { return accept; }}};
|
||||||
|
Void::Testing::require(manager.load(VOID_STATEFUL_V1_PATH).has_value());
|
||||||
|
auto before = manager.acquire("StatefulPlugin");
|
||||||
|
stateful(before)->bump();
|
||||||
|
accept = false;
|
||||||
|
const auto replaced =
|
||||||
|
manager.replace("StatefulPlugin", VOID_STATEFUL_V2_PATH);
|
||||||
|
Void::Testing::expect(!replaced.has_value());
|
||||||
|
Void::Testing::expect(replaced.error() == LoadError::ActivationFailed);
|
||||||
|
auto after = manager.acquire("StatefulPlugin");
|
||||||
|
Void::Testing::expect_eq(stateful(after)->schema_version(), 1);
|
||||||
|
Void::Testing::expect_eq(stateful(after)->counter(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
Void::Testing::Test manager_reload_migrates_v1_state_to_v2()
|
Void::Testing::Test manager_reload_migrates_v1_state_to_v2()
|
||||||
{
|
{
|
||||||
// Copy v1 into a temp path we control, then overwrite with v2 and
|
// Copy v1 into a temp path we control, then overwrite with v2 and
|
||||||
|
|||||||
@@ -101,6 +101,16 @@ namespace
|
|||||||
Void::Encoding::Base64::encode_url(sign(message)));
|
Void::Encoding::Base64::encode_url(sign(message)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string signedReadableEnvelope(std::string_view message)
|
||||||
|
{
|
||||||
|
return std::format(
|
||||||
|
"{{\n \"schemaVersion\": 3,\n \"keyId\": \"test-key\",\n"
|
||||||
|
" \"document\": {},\n \"signedPayload\": \"{}\",\n"
|
||||||
|
" \"signature\": \"{}\"\n}}",
|
||||||
|
message, Void::Encoding::Base64::encode_url(message),
|
||||||
|
Void::Encoding::Base64::encode_url(sign(message)));
|
||||||
|
}
|
||||||
|
|
||||||
constexpr std::string_view componentCatalogPayload = R"json({
|
constexpr std::string_view componentCatalogPayload = R"json({
|
||||||
"schemaVersion": 2,
|
"schemaVersion": 2,
|
||||||
"document": "echoion-component-catalog",
|
"document": "echoion-component-catalog",
|
||||||
@@ -270,6 +280,24 @@ Void::Testing::Test component_feed_verifies_and_resolves_complete_set()
|
|||||||
!Void::Update::validateComponentSet(*catalog, releases).has_value());
|
!Void::Update::validateComponentSet(*catalog, releases).has_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Void::Testing::Test readable_component_envelope_matches_signed_payload()
|
||||||
|
{
|
||||||
|
auto envelope = Void::Update::verifyEnvelope(
|
||||||
|
signedReadableEnvelope(componentCatalogPayload), keyring());
|
||||||
|
Void::Testing::require(envelope.has_value());
|
||||||
|
Void::Testing::expect_eq(envelope->schemaVersion, std::uint32_t{3});
|
||||||
|
Void::Testing::expect_eq(envelope->signedPayload,
|
||||||
|
std::string{componentCatalogPayload});
|
||||||
|
|
||||||
|
auto tampered = signedReadableEnvelope(componentCatalogPayload);
|
||||||
|
const auto position = tampered.find("\"sequence\": 11");
|
||||||
|
Void::Testing::require(position != std::string::npos);
|
||||||
|
tampered.replace(position, std::string{"\"sequence\": 11"}.size(),
|
||||||
|
"\"sequence\": 12");
|
||||||
|
Void::Testing::expect(
|
||||||
|
!Void::Update::verifyEnvelope(tampered, keyring()).has_value());
|
||||||
|
}
|
||||||
|
|
||||||
Void::Testing::Test update_feed_rejects_empty_fractional_timestamp()
|
Void::Testing::Test update_feed_rejects_empty_fractional_timestamp()
|
||||||
{
|
{
|
||||||
std::string malformed{payload};
|
std::string malformed{payload};
|
||||||
|
|||||||
Reference in new issue
Block a user