diff --git a/scripts/sign-bootstrap-release.sh b/scripts/sign-bootstrap-release.sh index 60e173c..d697998 100755 --- a/scripts/sign-bootstrap-release.sh +++ b/scripts/sign-bootstrap-release.sh @@ -3,7 +3,7 @@ # # The bootstrap archive (DRAGONX.zip) can be multiple GB, so the wallet does NOT sign the archive bytes. # Instead it verifies a detached ed25519 signature over the published "DRAGONX.zip.sha256" FILE, against a -# public key pinned in src/util/bootstrap.h (kBootstrapSignaturePublicKeyBase64). The SHA-256 file already +# public keys pinned in src/util/bootstrap.h (kBootstrapSignaturePublicKeysBase64). The SHA-256 file already # binds the archive bytes (the wallet computes and matches the archive's hash first), so signing the small # checksum authenticates the whole download cheaply. # @@ -58,7 +58,7 @@ case "$cmd" in echo "secret key : $prefix.ed25519.key (KEEP OFFLINE, mode 600)" echo "public key : $prefix.ed25519.pub.b64" echo - echo "Pin this in src/util/bootstrap.h (kBootstrapSignaturePublicKeyBase64):" + echo "Pin this in src/util/bootstrap.h (kBootstrapSignaturePublicKeysBase64):" echo " $pub" ;; @@ -84,15 +84,15 @@ case "$cmd" in [ -f "$key" ] || die "no such key: $key" [ -f "$zip" ] || die "no such archive: $zip" - # Warn if this key does not match the public key pinned in the wallet (it would then reject every - # signature made with it — expected only when deliberately rotating the pinned key). - pinned="$(grep -oE '"[A-Za-z0-9+/]{43}="' "$PROJECT_ROOT/src/util/bootstrap.h" 2>/dev/null | head -1 | tr -d '"')" + # Warn if this key is not one of the public keys pinned in the wallet (it would then reject every + # signature made with it — expected only when deliberately rotating the pinned keys). + pinned="$(grep -oE '"[A-Za-z0-9+/]{43}="' "$PROJECT_ROOT/src/util/bootstrap.h" 2>/dev/null | tr -d '"')" mine="$(pubkey_b64 "$key")" - if [ -n "$pinned" ] && [ "$pinned" != "$mine" ]; then - echo "WARNING: this key's public key does not match the one pinned in bootstrap.h:" >&2 + if [ -n "$pinned" ] && ! printf '%s\n' "$pinned" | grep -qxF "$mine"; then + echo "WARNING: this key's public key is not pinned in bootstrap.h:" >&2 echo " signing key -> $mine" >&2 - echo " pinned key -> $pinned" >&2 - echo " The wallet will REJECT these signatures unless you are rotating the pinned key." >&2 + echo " pinned keys -> $(echo $pinned)" >&2 + echo " The wallet will REJECT these signatures unless you are rotating the pinned keys." >&2 echo >&2 fi diff --git a/src/util/bootstrap.cpp b/src/util/bootstrap.cpp index df08c1a..c6426ef 100644 --- a/src/util/bootstrap.cpp +++ b/src/util/bootstrap.cpp @@ -1162,14 +1162,19 @@ bool Bootstrap::verifyChecksums(const std::string& zipPath, const std::string& b return true; } -bool Bootstrap::verifyArchiveSignature(const std::string& sha256Content, const std::string& baseUrl) { - const std::string pubKey = kBootstrapSignaturePublicKeyBase64 ? kBootstrapSignaturePublicKeyBase64 : ""; +bool Bootstrap::signatureMatchesPinnedKey(const std::string& sha256Content, const std::string& sigFileContent) { + for (const char* pubKey : kBootstrapSignaturePublicKeysBase64) { + if (util::verifyXmrigSignature(sha256Content, sigFileContent, pubKey)) return true; + } + return false; +} +bool Bootstrap::verifyArchiveSignature(const std::string& sha256Content, const std::string& baseUrl) { HttpGetOptions opt; opt.cancel = &cancel_requested_; const std::string sig = httpGetString(baseUrl + "/" + kZipName + ".sha256.sig", "[bootstrap]", opt); if (cancel_requested_) return false; - if (sig.empty() || pubKey.empty()) { + if (sig.empty()) { if (kBootstrapRequireSignature) { DEBUG_LOGF("[Bootstrap] No ed25519 signature published - refusing (signature required)\n"); setProgress(State::Failed, "Verification failed: the bootstrap is not signed. " @@ -1182,13 +1187,13 @@ bool Bootstrap::verifyArchiveSignature(const std::string& sha256Content, const s // Verify over the EXACT .sha256 bytes the signer signed (not the parsed hash). A present-but-invalid // signature is always fatal — it means the checksum we just trusted was not issued by us. - if (!util::verifyXmrigSignature(sha256Content, sig, pubKey)) { + if (!signatureMatchesPinnedKey(sha256Content, sig)) { DEBUG_LOGF("[Bootstrap] ed25519 signature MISMATCH - refusing\n"); - setProgress(State::Failed, "Verification failed: the bootstrap signature did not match the pinned " + setProgress(State::Failed, "Verification failed: the bootstrap signature did not match any pinned " "release key. Refusing to install."); return false; // fail CLOSED; archive is KEPT } - DEBUG_LOGF("[Bootstrap] ed25519 signature verified against the pinned key\n"); + DEBUG_LOGF("[Bootstrap] ed25519 signature verified against a pinned key\n"); return true; } diff --git a/src/util/bootstrap.h b/src/util/bootstrap.h index bafaddc..67547e2 100644 --- a/src/util/bootstrap.h +++ b/src/util/bootstrap.h @@ -78,14 +78,22 @@ public: // F5 — authenticity of the bootstrap archive. A same-origin SHA-256 only proves transport integrity: // whoever can replace the archive (CDN/server compromise, or a TLS break) can replace its .sha256 too. // So we additionally verify a detached ed25519 signature, over the published .sha256 file (not the - // multi-GB archive — the checksum already binds the archive bytes), against the key pinned here. A - // signature that is PRESENT but invalid is always fatal. A MISSING signature is fatal only when - // kBootstrapRequireSignature is true; until bootstrap.dragonx.is publishes per-archive - // ".sha256.sig" files, it stays false (SHA-256 over verified TLS still applies) — flip it to true - // once signatures are published to fully close the archive-substitution gap. Sign with - // scripts/sign-bootstrap-release.sh; the secret key stays offline. - static constexpr const char* kBootstrapSignaturePublicKeyBase64 = - "CbyBk7GAw9PFU3OEWoXdm6FfxdpIX3LMy4b4EnurJDM="; + // multi-GB archive — the checksum already binds the archive bytes), against the keys pinned here. A + // signature that is PRESENT but matches none of them is always fatal. A MISSING signature is fatal only + // when kBootstrapRequireSignature is true; flip it to true once every served bootstrap publishes a + // ".sha256.sig", to fully close the archive-substitution gap. + // + // A signature is accepted if it verifies against ANY pinned key: + // [0] the automated builder-signer box, which builds, verifies and signs each weekly bootstrap. Its + // secret key never leaves that host and can only sign a well-formed " DRAGONX.zip" line. + // [1] the offline backup key, held off-line by the operator. It signs by hand + // (scripts/sign-bootstrap-release.sh) if the automated key is lost or must be revoked, so a + // bootstrap can still be published while a wallet release drops the bad key. + // Changing this list requires a wallet release, so keep two keys pinned at all times. + static constexpr const char* kBootstrapSignaturePublicKeysBase64[] = { + "GHgDNfZV+CSGEsDYYustJXuo909nbHIGUlcCsF33olY=", // automated signer (hot) + "MZi/rTuQFSI1CJxEDKNK3JUa9gNkHb2f71ZIK6wqeRk=", // offline backup (cold) + }; static constexpr bool kBootstrapRequireSignature = false; /// Start the bootstrap process on a background thread. @@ -195,6 +203,10 @@ private: /// invalid signature, or on a missing signature when kBootstrapRequireSignature is true. bool verifyArchiveSignature(const std::string& sha256Content, const std::string& baseUrl); + /// True if sigFileContent (base64 ed25519 signature, as published in ".sha256.sig") verifies over + /// the exact sha256Content bytes against any key in kBootstrapSignaturePublicKeysBase64. No network. + static bool signatureMatchesPinnedKey(const std::string& sha256Content, const std::string& sigFileContent); + struct RemoteInfo { bool transportOk = false; long httpCode = 0; long long size = -1; }; /// HEAD the remote file. transportOk=false on any curl error; size=-1 when absent. RemoteInfo getRemoteFileSize(const std::string& url); diff --git a/tests/test_phase4.cpp b/tests/test_phase4.cpp index ca3c8c4..5b50a34 100644 --- a/tests/test_phase4.cpp +++ b/tests/test_phase4.cpp @@ -14716,30 +14716,43 @@ void testDaemonSignatureInterop() void testBootstrapSignatureInterop() { using namespace dragonx::util; - // F5 — known answer from scripts/sign-bootstrap-release.sh (OpenSSL ed25519) over the published - // " 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. + // F5 — known answer: a REAL weekly bootstrap checksum signed by the automated signer box + // (drgx-sign-checksum, OpenSSL ed25519, 2026-11-20 dry run at height 3449343), verified here with + // libsodium against the pinned keys. This is the exact byte string the signer signs and the wallet + // checks (" DRAGONX.zip\n"), so it closes the OpenSSL<->libsodium interop loop and proves + // pinned key [0] matches the signer's secret key. const std::string content = - "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 DRAGONX.zip\n"; + "25ad8b708465e3eefe5425e145924a23e9035df7b4493ef8b28533928275ee01 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)); + "KWFrVunRSgg5NQXLsobea8LmGHftg3yWr/S2xETpQZs9ir/UOS4D9KSnenphvz8pO9sy9cH1H+CBlKg42N3WDA=="; + const std::string hot = Bootstrap::kBootstrapSignaturePublicKeysBase64[0]; + const std::string cold = Bootstrap::kBootstrapSignaturePublicKeysBase64[1]; + EXPECT_TRUE(verifyXmrigSignature(content, sigB64, hot)); + EXPECT_TRUE(Bootstrap::signatureMatchesPinnedKey(content, sigB64)); + EXPECT_TRUE(Bootstrap::signatureMatchesPinnedKey(content, sigB64 + "\n")); // as published: trailing newline + // Fails closed on a tampered checksum, a different checksum, a garbage signature, or the wrong key. + EXPECT_FALSE(Bootstrap::signatureMatchesPinnedKey(content + "x", sigB64)); + EXPECT_FALSE(Bootstrap::signatureMatchesPinnedKey( + "0000000000000000000000000000000000000000000000000000000000000000 DRAGONX.zip\n", sigB64)); + EXPECT_FALSE(Bootstrap::signatureMatchesPinnedKey(content, "not a signature")); + EXPECT_FALSE(Bootstrap::signatureMatchesPinnedKey(content, "")); + EXPECT_FALSE(verifyXmrigSignature(content, sigB64, cold)); // the hot key's signature is not the cold key's EXPECT_FALSE(verifyXmrigSignature(content, sigB64, std::string(kXmrigSignaturePublicKeyBase64))); - // The pinned key must be valid base64 for a 32-byte ed25519 public key. + // The retired single key (no secret half on record) must no longer be pinned. + for (const char* k : Bootstrap::kBootstrapSignaturePublicKeysBase64) + EXPECT_TRUE(std::string(k) != "CbyBk7GAw9PFU3OEWoXdm6FfxdpIX3LMy4b4EnurJDM="); + // Two distinct pinned keys, each valid base64 for a 32-byte ed25519 public key. + EXPECT_EQ(sizeof(Bootstrap::kBootstrapSignaturePublicKeysBase64) / sizeof(const char*), static_cast(2)); + EXPECT_TRUE(hot != cold); 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(crypto_sign_PUBLICKEYBYTES)); + for (const char* k : Bootstrap::kBootstrapSignaturePublicKeysBase64) { + const std::string pin = k; + 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(crypto_sign_PUBLICKEYBYTES)); + } } // F13 — the migrate-to-seed port picker must hand out an OS-assigned free port via a real bind(), not a