feat(provenance): enforce trusted Ed25519 package signatures in publish, lockfile, and locked builds
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s

This commit is contained in:
faumaray committed 2026-12-03 17:57:20 +03:00
1 parent 21babb8c31
commit 85f2ae274f
21 files changed
+519 -15

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ set_target_properties(vbs_core_tests PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
add_test(NAME vbs_core_tests COMMAND "$<TARGET_FILE:vbs_core_tests>" --no-color)
add_executable(vbs_v1_tests FullV1Tests.cpp DaemonTests.cpp SigningTests.cpp)
add_executable(vbs_v1_tests FullV1Tests.cpp DaemonTests.cpp SigningTests.cpp SignatureEnforcementTests.cpp)
target_include_directories(vbs_v1_tests PRIVATE "${PROJECT_BINARY_DIR}/generated")
target_link_libraries(vbs_v1_tests PRIVATE Void::BuildCore Void::Testing)
set_target_properties(vbs_v1_tests PROPERTIES
+78
View File
@@ -2,6 +2,7 @@
#include <Void/Build/Package/Archive.hpp>
#include <Void/Build/Platform/FileOps.hpp>
#include <Void/Build/Platform/ProcessSupervisor.hpp>
#include <Void/Build/Provenance/Signing.hpp>
#include <Void/Build/Registry/HttpServer.hpp>
#include <Void/Build/Registry/RegistryService.hpp>
#include <Void/Build/State/StateStore.hpp>
@@ -140,6 +141,37 @@ VOID_TEST(RegistryTests, registry_rbac_immutability_csrf_xss_web_and_backup_rest
*bytes1);
Void::Testing::expect(pub_ok.has_value() && pub_ok->status == 201);
// Signature metadata is stored and served verbatim (the registry is not a trust authority).
const std::string release_signature(128, 'a');
const std::string release_public_key(64, 'b');
auto signed_pub = send_loopback_http(port, "PUT", "/api/v1/packages/signed-pkg/1.0.0",
{{"Authorization", "Bearer " + *alice_tok},
{"X-Content-SHA256", *sha1},
{"X-Package-Signature", release_signature},
{"X-Package-Public-Key", release_public_key}},
*bytes1);
Void::Testing::expect(signed_pub.has_value() && signed_pub->status == 201);
auto signed_detail = send_loopback_http(port, "GET", "/api/v1/packages/signed-pkg",
{{"Authorization", "Bearer " + *alice_tok}});
Void::Testing::expect(signed_detail.has_value() && signed_detail->status == 200);
if (signed_detail) {
Void::Testing::expect(signed_detail->body.find(release_signature) != std::string::npos);
Void::Testing::expect(signed_detail->body.find(release_public_key) != std::string::npos);
}
auto bad_sig_pub = send_loopback_http(port, "PUT", "/api/v1/packages/bad-sig-pkg/1.0.0",
{{"Authorization", "Bearer " + *alice_tok},
{"X-Content-SHA256", *sha1},
{"X-Package-Signature", std::string(127, 'a')},
{"X-Package-Public-Key", release_public_key}},
*bytes1);
Void::Testing::expect(bad_sig_pub.has_value() && bad_sig_pub->status == 400);
auto half_sig_pub = send_loopback_http(port, "PUT", "/api/v1/packages/half-sig-pkg/1.0.0",
{{"Authorization", "Bearer " + *alice_tok},
{"X-Content-SHA256", *sha1},
{"X-Package-Signature", release_signature}},
*bytes1);
Void::Testing::expect(half_sig_pub.has_value() && half_sig_pub->status == 400);
// Unauthenticated access to private package MUST fail (401)!
auto anon_priv = send_loopback_http(port, "GET", "/api/v1/packages/secret-pkg");
Void::Testing::expect(anon_priv.has_value() && anon_priv->status == 401);
@@ -471,5 +503,51 @@ target_include_directories(hello_pkg PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include
auto run_res = Platform::run_supervised(run_req);
Void::Testing::expect(run_res.has_value() && run_res->succeeded());
// 5. Requiring a trusted key must fail closed for the unsigned locked package.
Platform::ProcessRequest trusted_req = bld_req;
trusted_req.arguments.push_back("--trusted-public-key");
trusted_req.arguments.push_back(std::string(64, 'a'));
auto trusted_res = Platform::run_supervised(trusted_req);
Void::Testing::expect(trusted_res.has_value() && !trusted_res->succeeded());
if (trusted_res) {
Void::Testing::expect(trusted_res->stderr_data.find("not signed by a trusted key") !=
std::string::npos);
}
// 6. With the OpenSSL backend, publish a signed release and require its trusted key.
if (Provenance::signing_available()) {
const auto seed_path = tmp / "publish.seed";
Void::Testing::require(Provenance::generate_signing_seed(seed_path).has_value());
auto public_key = Provenance::public_key_from_seed(seed_path);
Void::Testing::require(public_key.has_value());
(void)Platform::atomic_write_file(
pkg_dir / "src" / "hello.cpp",
"#include \"hello_pkg.hpp\"\nint hello_pkg_value() { return 7; }\n", false);
Platform::ProcessRequest pub3 = pub1;
pub3.arguments[8] = "1.2.0";
pub3.arguments.push_back("--signing-key");
pub3.arguments.push_back(seed_path.string());
auto r3 = Platform::run_supervised(pub3);
Void::Testing::expect(r3.has_value() && r3->succeeded());
Platform::ProcessRequest update_req = deps_req;
update_req.arguments[1] = "update";
auto update_res = Platform::run_supervised(update_req);
Void::Testing::expect(update_res.has_value() && update_res->succeeded());
Platform::ProcessRequest signed_build = bld_req;
signed_build.arguments.push_back("--trusted-public-key");
signed_build.arguments.push_back(*public_key);
auto signed_res = Platform::run_supervised(signed_build);
Void::Testing::expect(signed_res.has_value() && signed_res->succeeded());
Platform::ProcessRequest wrong_key_build = bld_req;
wrong_key_build.arguments.push_back("--trusted-public-key");
wrong_key_build.arguments.push_back(std::string(64, 'a'));
auto wrong_key_res = Platform::run_supervised(wrong_key_build);
Void::Testing::expect(wrong_key_res.has_value() && !wrong_key_res->succeeded());
}
(*svc)->stop_http();
}
+152
View File
@@ -0,0 +1,152 @@
#include <Void/Build/Package/Lockfile.hpp>
#include <Void/Build/Provenance/Signing.hpp>
#include <Void/Build/Provenance/Verification.hpp>
#include <Void/System/TempDir.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <filesystem>
#include <fstream>
#include <string>
#include <vector>
namespace {
using Void::Build::Provenance::signing_available;
using Void::Build::Provenance::TrustDecision;
using Void::Build::Provenance::verify_trusted_package_signature;
constexpr std::string_view kDigest =
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
const std::string kKeyA(64, 'a');
const std::string kKeyB(64, 'b');
const std::string kSignature(128, 'c');
Void::FileSystem::TempDir make_temp_dir() {
auto temp = Void::FileSystem::TempDir::open("vbs_signature_enforcement_");
Void::Testing::require(temp.has_value());
return std::move(*temp);
}
Void::Build::Package::LockfileDocument sample_document(bool signed_entry) {
Void::Build::Package::LockContextRecord context;
context.context_key = "debug:gcc:Linux:x86_64:target";
context.profile_name = "debug";
context.compiler = "gcc";
context.os = "Linux";
context.architecture = "x86_64";
context.machine_role = "target";
context.declaration_fingerprint = "fingerprint";
Void::Build::Package::LockedSourceEntry entry;
entry.alias = "demo";
entry.source_kind = "package";
entry.registry_authority = "http://127.0.0.1:1";
entry.package_name = "demo";
entry.version = "1.0.0";
entry.sha256 = std::string{kDigest};
entry.builder = "native";
if (signed_entry) {
entry.signature = kSignature;
entry.public_key = kKeyA;
}
context.entries.push_back(std::move(entry));
Void::Build::Package::LockfileDocument document;
document.contexts[context.context_key] = std::move(context);
return document;
}
} // namespace
VOID_TEST(SignatureEnforcement, lockfile_signature_fields_roundtrip_and_omit_when_absent) {
using namespace Void::Build::Package;
const auto signed_doc = sample_document(true);
const std::string signed_json = serialize_lockfile(signed_doc);
Void::Testing::expect(signed_json.find("\"signature\"") != std::string::npos);
Void::Testing::expect(signed_json.find("\"public_key\"") != std::string::npos);
auto parsed_signed = parse_lockfile(signed_json);
Void::Testing::require(parsed_signed.has_value());
const auto &signed_entry =
parsed_signed->contexts.at("debug:gcc:Linux:x86_64:target").entries.at(0);
Void::Testing::require(signed_entry.signature.has_value());
Void::Testing::require(signed_entry.public_key.has_value());
Void::Testing::expect_eq(*signed_entry.signature, kSignature);
Void::Testing::expect_eq(*signed_entry.public_key, kKeyA);
Void::Testing::expect_eq(serialize_lockfile(*parsed_signed), signed_json);
const auto unsigned_doc = sample_document(false);
const std::string unsigned_json = serialize_lockfile(unsigned_doc);
Void::Testing::expect(unsigned_json.find("\"signature\"") == std::string::npos);
Void::Testing::expect(unsigned_json.find("\"public_key\"") == std::string::npos);
auto parsed_unsigned = parse_lockfile(unsigned_json);
Void::Testing::require(parsed_unsigned.has_value());
const auto &unsigned_entry =
parsed_unsigned->contexts.at("debug:gcc:Linux:x86_64:target").entries.at(0);
Void::Testing::expect(!unsigned_entry.signature.has_value());
Void::Testing::expect(!unsigned_entry.public_key.has_value());
}
VOID_TEST(SignatureEnforcement, trust_policy_decisions_without_crypto) {
using Void::Build::Provenance::PackageSignature;
const PackageSignature signed_pkg{std::string{kDigest}, kSignature, kKeyA};
auto no_keys = verify_trusted_package_signature("demo", "1.0.0", signed_pkg, {});
Void::Testing::require(no_keys.has_value());
Void::Testing::expect(*no_keys == TrustDecision::Unsigned);
auto missing_signature = verify_trusted_package_signature(
"demo", "1.0.0", PackageSignature{std::string{kDigest}, {}, kKeyA}, {kKeyA});
Void::Testing::require(missing_signature.has_value());
Void::Testing::expect(*missing_signature == TrustDecision::Unsigned);
auto untrusted = verify_trusted_package_signature("demo", "1.0.0", signed_pkg, {kKeyB});
Void::Testing::require(untrusted.has_value());
Void::Testing::expect(*untrusted == TrustDecision::UntrustedKey);
// Case-insensitive trusted-key matching.
std::string upper_key = kKeyA;
for (char &c : upper_key) {
if (c >= 'a' && c <= 'f') {
c = static_cast<char>(c - 'a' + 'A');
}
}
if (!signing_available()) {
auto unavailable =
verify_trusted_package_signature("demo", "1.0.0", signed_pkg, {upper_key});
Void::Testing::expect(!unavailable.has_value());
}
}
VOID_TEST(SignatureEnforcement, trusted_key_accepts_valid_and_rejects_tampered_signature) {
using Void::Build::Provenance::PackageSignature;
if (!signing_available()) {
return;
}
auto temp = make_temp_dir();
const auto seed_path = temp.path() / "signing.seed";
Void::Testing::require(Void::Build::Provenance::generate_signing_seed(seed_path).has_value());
auto public_key = Void::Build::Provenance::public_key_from_seed(seed_path);
Void::Testing::require(public_key.has_value());
auto signature = Void::Build::Provenance::sign_package("demo", "1.0.0", kDigest, seed_path);
Void::Testing::require(signature.has_value());
const PackageSignature valid{std::string{kDigest}, *signature, *public_key};
auto verified = verify_trusted_package_signature("demo", "1.0.0", valid, {*public_key});
Void::Testing::require(verified.has_value());
Void::Testing::expect(*verified == TrustDecision::Verified);
std::string tampered_digest{kDigest};
tampered_digest.back() = tampered_digest.back() == '0' ? '1' : '0';
auto invalid = verify_trusted_package_signature(
"demo", "1.0.0", PackageSignature{tampered_digest, *signature, *public_key}, {*public_key});
Void::Testing::require(invalid.has_value());
Void::Testing::expect(*invalid == TrustDecision::InvalidSignature);
auto malformed = verify_trusted_package_signature(
"demo", "1.0.0", PackageSignature{std::string{kDigest}, "zz", *public_key}, {*public_key});
Void::Testing::expect(!malformed.has_value());
}