fix(release): derive the public key from either key file

A raw ed25519 private key is 32 bytes and so is its public half, so
'pubkey KEY_FILE' could not tell them apart and printed the private bytes as a
public key. Baking those into a build produces a key no signature can verify
against, and build.rs accepts any 64 hex characters, so the mistake is silent at
build time and shows up on a user's machine as an update check that cannot verify
the manifest.

Anything not named *.pub is now read as the private key it came from and expanded,
so both documented spellings of the command yield the same key.
main
mula.liu 2026-10-26 17:29:59 +08:00
parent 334082cd9b
commit 48b24acc2f
1 changed files with 13 additions and 1 deletions

View File

@ -28,7 +28,19 @@ USAGE = __doc__
def public_hex(path):
key = Ed25519PublicKey.from_public_bytes(path.read_bytes())
"""Hex of the public half of a key file, whichever half was handed over.
A raw ed25519 private key is 32 bytes and so is its public half, so the two
cannot be told apart by content. Baking the private bytes as if they were a
public key produces a key no signature ever verifies against, and the build
accepts it without complaint, so the mistake only surfaces on a user's
machine as "this build cannot verify the manifest". Anything not named
``*.pub`` is therefore read as the private key it came from and expanded.
"""
if path.suffix == ".pub":
key = Ed25519PublicKey.from_public_bytes(path.read_bytes())
else:
key = Ed25519PrivateKey.from_private_bytes(path.read_bytes()).public_key()
return key.public_bytes(
serialization.Encoding.Raw, serialization.PublicFormat.Raw
).hex()