feat(install): sign installer archives with Ed25519 and checksums
This commit is contained in:
1 parent
9509c0691e
commit
b55aca328a
8 files changed
+122
-10
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <Void/Build/Package/Archive.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Provenance/Signing.hpp>
|
||||
#include <Void/Build/Util/Json.hpp>
|
||||
#include <Void/Build/Util/Sha256.hpp>
|
||||
#include <Void/Core/Scope.hpp>
|
||||
@@ -591,19 +592,13 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build
|
||||
if (auto zipped = write_stored_zip(*options.archive_path, archive_entries); !zipped) {
|
||||
return std::unexpected{zipped.error()};
|
||||
}
|
||||
report.archive_path = *options.archive_path;
|
||||
return report;
|
||||
}
|
||||
if (options.archive_format == "deb") {
|
||||
} else if (options.archive_format == "deb") {
|
||||
if (auto packed = write_deb_package(*options.archive_path, options, graph,
|
||||
archive_entries);
|
||||
!packed) {
|
||||
return std::unexpected{packed.error()};
|
||||
}
|
||||
report.archive_path = *options.archive_path;
|
||||
return report;
|
||||
}
|
||||
|
||||
} else {
|
||||
const bool archive_as_script = options.archive_format == "sh";
|
||||
const auto archive_target = archive_as_script
|
||||
? stage_root / "installer-payload.tar"
|
||||
@@ -659,7 +654,48 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build
|
||||
return std::unexpected{written.error()};
|
||||
}
|
||||
}
|
||||
}
|
||||
report.archive_path = *options.archive_path;
|
||||
|
||||
// Optional detached signature and checksums over the final archive bytes.
|
||||
if (options.signing_seed_path) {
|
||||
auto bytes = Void::FileSystem::read_file(*options.archive_path);
|
||||
if (!bytes) {
|
||||
return std::unexpected{bytes.error()};
|
||||
}
|
||||
report.archive_sha256 = Util::sha256_hex(*bytes);
|
||||
report.checksum_path = options.archive_path->string() + ".sha256";
|
||||
if (auto written = Platform::atomic_write_file(
|
||||
*report.checksum_path,
|
||||
report.archive_sha256 + " " + options.archive_path->filename().string() + "\n",
|
||||
true);
|
||||
!written) {
|
||||
return std::unexpected{written.error()};
|
||||
}
|
||||
|
||||
auto signature = Provenance::sign_message(
|
||||
std::as_bytes(std::span<const char>{bytes->data(), bytes->size()}),
|
||||
*options.signing_seed_path);
|
||||
if (!signature) {
|
||||
return std::unexpected{signature.error()};
|
||||
}
|
||||
auto public_key = Provenance::public_key_from_seed(*options.signing_seed_path);
|
||||
if (!public_key) {
|
||||
return std::unexpected{public_key.error()};
|
||||
}
|
||||
report.signature_path = options.archive_path->string() + ".sig";
|
||||
if (auto written = Platform::atomic_write_file(*report.signature_path,
|
||||
*signature + "\n", true);
|
||||
!written) {
|
||||
return std::unexpected{written.error()};
|
||||
}
|
||||
report.public_key_path = options.archive_path->string() + ".pub";
|
||||
if (auto written = Platform::atomic_write_file(*report.public_key_path,
|
||||
*public_key + "\n", true);
|
||||
!written) {
|
||||
return std::unexpected{written.error()};
|
||||
}
|
||||
}
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user