fix(security): verify an ed25519 signature on the bootstrap archive (F5)

The chain-bootstrap download was authenticated only by a same-origin SHA-256,
which anyone who can replace the archive (CDN/server compromise or a TLS break)
can also replace. The RCE half of the original report is already closed — extract
skips every *.conf/wallet*/.dat entry, so DRAGONX.conf/blocknotify can't be
overwritten — but the archive itself was unauthenticated.

Verify a detached ed25519 signature over the published .sha256 file (the archive
is multi-GB; its checksum already binds the bytes, so signing the small checksum
authenticates the whole download) against a pinned key. A present-but-invalid
signature always fails closed; a missing one is gated by
kBootstrapRequireSignature (false until bootstrap.dragonx.is publishes .sig
files, then flip to true). Adds scripts/sign-bootstrap-release.sh; the secret key
stays offline.

Also adds regression tests: testBootstrapSignatureInterop (known-answer verify
against the pinned key, fails closed on tamper/wrong-key — F5) and
testEphemeralPortPick (F13).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 11:52:57 -06:00
co-authored by Claude Opus 4.8
parent 5ffb083855
commit b79a62b24b
4 changed files with 209 additions and 0 deletions
+43
View File
@@ -14680,6 +14680,47 @@ void testDaemonSignatureInterop()
EXPECT_FALSE(verifyXmrigSignature(msg, sigB64, std::string(kXmrigSignaturePublicKeyBase64)));
}
void testBootstrapSignatureInterop()
{
using namespace dragonx::util;
// F5 — known answer from scripts/sign-bootstrap-release.sh (OpenSSL ed25519) over the published
// "<sha256> DRAGONX.zip\n" checksum file, verified with libsodium against the key pinned in
// bootstrap.h. The wallet signs the small checksum (not the multi-GB archive), so this is the exact
// byte string the signer signs and the verifier checks. Proves the pinned bootstrap key matches the
// signing key and that a tampered checksum / wrong key fails closed.
const std::string content =
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 DRAGONX.zip\n";
const std::string sigB64 =
"MXcbt9SBbiScAXknsf3vfBDp7pXXC9Ii0Jx3RT03Tssps/LJmxgNyFu2onK7T2VLq8bhaudoyxt0C2cLxyTUAg==";
const std::string pin = Bootstrap::kBootstrapSignaturePublicKeyBase64;
EXPECT_TRUE(verifyXmrigSignature(content, sigB64, pin));
EXPECT_TRUE(verifyXmrigSignature(content, " " + sigB64 + "\n", pin)); // trailing newline tolerated
// Fails closed on a tampered checksum, a different checksum, or the wrong pinned key.
EXPECT_FALSE(verifyXmrigSignature(content + "x", sigB64, pin));
EXPECT_FALSE(verifyXmrigSignature(
"0000000000000000000000000000000000000000000000000000000000000000 DRAGONX.zip\n", sigB64, pin));
EXPECT_FALSE(verifyXmrigSignature(content, sigB64, std::string(kXmrigSignaturePublicKeyBase64)));
// The pinned key must be valid base64 for a 32-byte ed25519 public key.
EXPECT_TRUE(sodium_init() >= 0);
unsigned char pk[crypto_sign_PUBLICKEYBYTES];
std::size_t n = 0; const char* end = nullptr;
EXPECT_EQ(sodium_base642bin(pk, sizeof(pk), pin.data(), pin.size(), " \t\r\n", &n, &end,
sodium_base64_VARIANT_ORIGINAL), 0);
EXPECT_EQ(n, static_cast<std::size_t>(crypto_sign_PUBLICKEYBYTES));
}
// F13 — the migrate-to-seed port picker must hand out an OS-assigned free port via a real bind(), not a
// guessable fixed-range number, so a local co-tenant can't pre-squat the port the isolated node will take.
void testEphemeralPortPick()
{
using dragonx::daemon::EmbeddedDaemon;
const int a = EmbeddedDaemon::pickEphemeralPort();
EXPECT_TRUE(a > 1024); // a real ephemeral port, not 0/low/fixed
EXPECT_FALSE(EmbeddedDaemon::tcpPortInUse(a)); // nothing is LISTENing on a port just handed out free
const int b = EmbeddedDaemon::pickEphemeralPort();
EXPECT_TRUE(b > 1024);
}
void testDaemonReleaseListParsing()
{
using namespace dragonx::util;
@@ -20545,6 +20586,8 @@ int main()
testDaemonSignatureAssetSelection();
testDaemonPinnedKeyValidity();
testDaemonSignatureInterop();
testBootstrapSignatureInterop();
testEphemeralPortPick();
testDaemonReleaseListParsing();
testLiteServerHostParsing();
testLiteOfficialServerDetection();