Files

53 lines
1.7 KiB
Python

"""Sign a release archive and produce the manifest signature field.
Workflow (offline, on the machine holding the private key):
python packaging/sign_manifest.py --package dist/Bx.zip \
--key ..\\signing\\yiyezhqiu-release-private-key.pem
Prints the base64 Ed25519 signature over the archive bytes. Paste it into
``update-manifest.template.json``'s ``signature`` field (stable channel
manifests must carry it; the client refuses unsigned stable updates).
NEVER copy the private key into the repository or the release package.
"""
from __future__ import annotations
import argparse
import base64
import sys
from pathlib import Path
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="Sign an update archive")
parser.add_argument("--package", type=Path, required=True)
parser.add_argument("--key", type=Path, required=True)
return parser
def main(argv: list[str] | None = None) -> int:
options = build_parser().parse_args(argv)
try:
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric.ed25519 import (
Ed25519PrivateKey,
)
except ImportError:
print("cryptography is required: pip install cryptography", file=sys.stderr)
return 2
key_pem = options.key.read_bytes()
private_key = serialization.load_pem_private_key(key_pem, password=None)
if not isinstance(private_key, Ed25519PrivateKey):
print("the key file is not an Ed25519 private key", file=sys.stderr)
return 2
signature = private_key.sign(options.package.read_bytes())
print(base64.b64encode(signature).decode("ascii"))
return 0
if __name__ == "__main__":
raise SystemExit(main())