feat(provenance): enforce trusted Ed25519 package signatures in publish, lockfile, and locked builds
This commit is contained in:
1 parent
21babb8c31
commit
85f2ae274f
21 files changed
+519
-15
No files matched your search
@@ -0,0 +1,65 @@
|
||||
#include <Void/Build/Provenance/Verification.hpp>
|
||||
|
||||
#include <Void/Build/Provenance/Signing.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace Void::Build::Provenance {
|
||||
namespace {
|
||||
|
||||
std::string normalize_hex(std::string_view hex) {
|
||||
std::string normalized{hex};
|
||||
std::ranges::transform(normalized, normalized.begin(), [](char c) {
|
||||
return static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
||||
});
|
||||
return normalized;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string_view trust_decision_name(TrustDecision decision) noexcept {
|
||||
switch (decision) {
|
||||
case TrustDecision::Verified:
|
||||
return "verified";
|
||||
case TrustDecision::Unsigned:
|
||||
return "unsigned";
|
||||
case TrustDecision::UntrustedKey:
|
||||
return "untrusted_key";
|
||||
case TrustDecision::InvalidSignature:
|
||||
return "invalid_signature";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
Void::Result::Result<TrustDecision, Void::Result::Error>
|
||||
verify_trusted_package_signature(std::string_view name, std::string_view version,
|
||||
const PackageSignature &signature,
|
||||
const std::vector<std::string> &trusted_public_keys_hex) {
|
||||
if (trusted_public_keys_hex.empty()) {
|
||||
return TrustDecision::Unsigned;
|
||||
}
|
||||
if (signature.signature.empty() || signature.public_key.empty()) {
|
||||
return TrustDecision::Unsigned;
|
||||
}
|
||||
|
||||
const std::string normalized_key = normalize_hex(signature.public_key);
|
||||
const bool trusted = std::ranges::any_of(trusted_public_keys_hex, [&](const std::string &key) {
|
||||
return normalize_hex(key) == normalized_key;
|
||||
});
|
||||
if (!trusted) {
|
||||
return TrustDecision::UntrustedKey;
|
||||
}
|
||||
|
||||
auto verified =
|
||||
verify_package(name, version, signature.sha256, signature.signature, signature.public_key);
|
||||
if (!verified) {
|
||||
return std::unexpected{verified.error()};
|
||||
}
|
||||
return *verified ? TrustDecision::Verified : TrustDecision::InvalidSignature;
|
||||
}
|
||||
|
||||
} // namespace Void::Build::Provenance
|
||||
Reference in new issue
Block a user