carlos / platform Public

bootstrap-box fix round 2: build pubkey DER in python, not dash-unsafe printf '\\x'

CRITICAL: the inner script runs under /bin/sh = dash on the Debian fleet.
dash's printf does not honour \x hex escapes, so
printf '\x30\x2a...' emitted literal text, pub.der was garbage, openssl pkey
failed, and bootstrap failed closed even for a genuine signed binary — would
brick every new-box bootstrap. Build the 12-byte Ed25519 SPKI header + raw key
in python3 (already a hard dep) instead. No new dependency; verification logic
unchanged. Scanned the rest of the inner script for bashisms (none; pipefail is
honoured by Debian 13 dash). Re-ran the mocked-aws fail-closed test UNDER dash:
genuine=exit0 installs; mismatch/forged/missing=exit1 no install. Both copies
byte-identical.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude Opus (hunt fix) pushed by claude agent, operated by paul@keymail.dev fb86a680dc88e3a5a48e941e22c00ce73c08f33d parent 0829b17
2 files changed, +24 −2
  • infra-proposed/carloku-infra/bootstrap-box.sh +12 −1
  • infra-proposed/platform-infra/bootstrap-box.sh +12 −1
diff --git a/infra-proposed/carloku-infra/bootstrap-box.sh b/infra-proposed/carloku-infra/bootstrap-box.sh
index d4c15f65f..2b5a4e8d9 100644
--- a/infra-proposed/carloku-infra/bootstrap-box.sh
+++ b/infra-proposed/carloku-infra/bootstrap-box.sh
@@ -72,7 +72,18 @@ aws s3 cp s3://$depbucket/control/system/router/stable.json "\$vdir/pointer.json
# Reconstruct the root public key PEM from the raw 32-byte key already in hand.
printf '%s' '$pub' | base64 -d > "\$vdir/pub.raw"
[ "\$(wc -c < "\$vdir/pub.raw")" -eq 32 ] || { echo "bootstrap verify: CARLOS_RELEASE_PUBKEY is not a 32-byte Ed25519 key" >&2; exit 1; }
-{ printf '\x30\x2a\x30\x05\x06\x03\x2b\x65\x70\x03\x21\x00'; cat "\$vdir/pub.raw"; } > "\$vdir/pub.der"
+# Build the DER SubjectPublicKeyInfo (12-byte Ed25519 SPKI header + the 32-byte
+# raw key) in python. NOT shell printf: the box runs this under /bin/sh = dash,
+# whose printf does not honour \x hex escapes (it would emit the literal text),
+# so the DER would be garbage and verification would fail closed on a GENUINE
+# binary. python3 is already required above, so this adds no new dependency.
+python3 - "\$vdir/pub.raw" "\$vdir/pub.der" <<'PY' || { echo "bootstrap verify: cannot build the release pubkey DER" >&2; exit 1; }
+import sys
+raw = open(sys.argv[1], "rb").read()
+if len(raw) != 32:
+ sys.exit("release pubkey is not 32 bytes")
+open(sys.argv[2], "wb").write(b"\x30\x2a\x30\x05\x06\x03\x2b\x65\x70\x03\x21\x00" + raw)
+PY
openssl pkey -pubin -inform DER -in "\$vdir/pub.der" -out "\$vdir/pub.pem" 2>/dev/null || { echo "bootstrap verify: cannot load the release pubkey" >&2; exit 1; }
# Split the signed wrapper into the EXACT base64 payload string and the signature.
# (This only extracts; the signature over that exact string is the gate below.)
diff --git a/infra-proposed/platform-infra/bootstrap-box.sh b/infra-proposed/platform-infra/bootstrap-box.sh
index d4c15f65f..2b5a4e8d9 100644
--- a/infra-proposed/platform-infra/bootstrap-box.sh
+++ b/infra-proposed/platform-infra/bootstrap-box.sh
@@ -72,7 +72,18 @@ aws s3 cp s3://$depbucket/control/system/router/stable.json "\$vdir/pointer.json
# Reconstruct the root public key PEM from the raw 32-byte key already in hand.
printf '%s' '$pub' | base64 -d > "\$vdir/pub.raw"
[ "\$(wc -c < "\$vdir/pub.raw")" -eq 32 ] || { echo "bootstrap verify: CARLOS_RELEASE_PUBKEY is not a 32-byte Ed25519 key" >&2; exit 1; }
-{ printf '\x30\x2a\x30\x05\x06\x03\x2b\x65\x70\x03\x21\x00'; cat "\$vdir/pub.raw"; } > "\$vdir/pub.der"
+# Build the DER SubjectPublicKeyInfo (12-byte Ed25519 SPKI header + the 32-byte
+# raw key) in python. NOT shell printf: the box runs this under /bin/sh = dash,
+# whose printf does not honour \x hex escapes (it would emit the literal text),
+# so the DER would be garbage and verification would fail closed on a GENUINE
+# binary. python3 is already required above, so this adds no new dependency.
+python3 - "\$vdir/pub.raw" "\$vdir/pub.der" <<'PY' || { echo "bootstrap verify: cannot build the release pubkey DER" >&2; exit 1; }
+import sys
+raw = open(sys.argv[1], "rb").read()
+if len(raw) != 32:
+ sys.exit("release pubkey is not 32 bytes")
+open(sys.argv[2], "wb").write(b"\x30\x2a\x30\x05\x06\x03\x2b\x65\x70\x03\x21\x00" + raw)
+PY
openssl pkey -pubin -inform DER -in "\$vdir/pub.der" -out "\$vdir/pub.pem" 2>/dev/null || { echo "bootstrap verify: cannot load the release pubkey" >&2; exit 1; }
# Split the signed wrapper into the EXACT base64 payload string and the signature.
# (This only extracts; the signature over that exact string is the gate below.)