feat(provenance): distribute trusted Ed25519 keys via files, vbs.keys, and environment
This commit is contained in:
1 parent
f5c0c9f09d
commit
ff59f6ff5c
13 files changed
+314
-7
No files matched your search
@@ -1,5 +1,6 @@
|
||||
#include <Void/Build/Package/Lockfile.hpp>
|
||||
#include <Void/Build/Provenance/Signing.hpp>
|
||||
#include <Void/Build/Provenance/TrustedKeys.hpp>
|
||||
#include <Void/Build/Provenance/Verification.hpp>
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
@@ -120,6 +121,61 @@ VOID_TEST(SignatureEnforcement, trust_policy_decisions_without_crypto) {
|
||||
}
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureEnforcement, trusted_key_sources_are_loaded_and_deduplicated) {
|
||||
namespace Provenance = Void::Build::Provenance;
|
||||
auto temp = make_temp_dir();
|
||||
const std::string key_c(64, 'c');
|
||||
const std::string key_d(64, 'd');
|
||||
|
||||
const auto explicit_file = temp.path() / "keys.txt";
|
||||
{
|
||||
std::ofstream out{explicit_file};
|
||||
out << "# trusted maintainers\n" << kKeyA << "\n\n" << kKeyB << "\n" << kKeyA << "\n";
|
||||
}
|
||||
{
|
||||
std::ofstream out{temp.path() / "vbs.keys"};
|
||||
out << kKeyB << "\n" << key_c << "\n";
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::path> files{explicit_file};
|
||||
const std::string environment = key_d + "," + kKeyA;
|
||||
auto loaded = Provenance::load_trusted_keys(files, temp.path(), std::string_view{environment});
|
||||
Void::Testing::require(loaded.has_value());
|
||||
Void::Testing::expect_eq(loaded->size(), std::size_t{4});
|
||||
if (loaded->size() == 4) {
|
||||
Void::Testing::expect((*loaded)[0] == kKeyA);
|
||||
Void::Testing::expect((*loaded)[1] == kKeyB);
|
||||
Void::Testing::expect((*loaded)[2] == key_c);
|
||||
Void::Testing::expect((*loaded)[3] == key_d);
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::path> missing{temp.path() / "missing.keys"};
|
||||
Void::Testing::expect(
|
||||
!Provenance::load_trusted_keys(missing, temp.path(), std::nullopt).has_value());
|
||||
|
||||
const auto invalid_file = temp.path() / "invalid.keys";
|
||||
{
|
||||
std::ofstream out{invalid_file};
|
||||
out << kKeyA << "\nnot-a-key\n";
|
||||
}
|
||||
std::vector<std::filesystem::path> invalid{invalid_file};
|
||||
auto invalid_result = Provenance::load_trusted_keys(invalid, temp.path(), std::nullopt);
|
||||
Void::Testing::expect(!invalid_result.has_value());
|
||||
if (!invalid_result) {
|
||||
Void::Testing::expect(invalid_result.error().message().find("invalid.keys:2") !=
|
||||
std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureEnforcement, normalize_public_key_validates_and_lowercases) {
|
||||
namespace Provenance = Void::Build::Provenance;
|
||||
auto valid = Provenance::normalize_public_key(std::string(64, 'A'));
|
||||
Void::Testing::require(valid.has_value());
|
||||
Void::Testing::expect(*valid == std::string(64, 'a'));
|
||||
Void::Testing::expect(!Provenance::normalize_public_key("abc").has_value());
|
||||
Void::Testing::expect(!Provenance::normalize_public_key(std::string(64, 'z')).has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureEnforcement, trusted_key_accepts_valid_and_rejects_tampered_signature) {
|
||||
using Void::Build::Provenance::PackageSignature;
|
||||
if (!signing_available()) {
|
||||
|
||||
Reference in new issue
Block a user