verify: no Latest/ in the aux repo; Go's source tree is cross-platform
Tools makes Latest/ for the main repository only, and upstream's aux repository has none either, so verify no longer requires it there. The Go toolchain in aux ships ELF test data and race-detector objects for every platform under /usr/local/go<N>/src/; that tree is exempt from the aarch64 check, nothing else of the Go packages is. The first real 26.1.11 mirror now verifies clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
90dd8bb200
commit
0342256eb9
3 changed files with 94 additions and 23 deletions
10
RELEASE.md
10
RELEASE.md
|
|
@ -358,10 +358,14 @@ python3 mirror/gwmirror.py verify --url https://opnsense.karsttech.com --series
|
|||
|
||||
**`verify --root`** checks, for each `<ABI>/<series>`:
|
||||
- the catalogue signatures, and that both catalogues agree;
|
||||
- every package's path, ABI, size, sha256 and `Latest/` signature;
|
||||
- every package's path, ABI, size and sha256, and in the main repository
|
||||
its `Latest/` signature (tools makes `Latest/` for the main repository
|
||||
only; upstream's aux repository has none either);
|
||||
- the set and image signatures against `keys/fingerprints`;
|
||||
- that every ELF inside every package and set is aarch64 (firmware
|
||||
directories excepted);
|
||||
- that every ELF inside every package and set is aarch64. Firmware
|
||||
directories are excepted, and so is the Go toolchain's source tree
|
||||
(`/usr/local/go<N>/src/`, in the aux repository), which ships test data
|
||||
and race-detector objects for every platform.
|
||||
- that every name can be stored on the SMB share (see "Names on disk").
|
||||
|
||||
Nothing is extracted to disk while verifying.
|
||||
|
|
|
|||
|
|
@ -40,8 +40,10 @@ import urllib.request
|
|||
ARCH = "aarch64"
|
||||
EM_AARCH64 = 183
|
||||
ELF_NAMES = {3: "i386", 40: "arm", 62: "x86-64", 183: "aarch64", 243: "riscv"}
|
||||
# Firmware for other processors may legitimately be an ELF of another machine.
|
||||
ELF_ARCH_EXEMPT = re.compile(r"(^|/)(boot/firmware|firmware)/")
|
||||
# Firmware for other processors may legitimately be an ELF of another machine, and so
|
||||
# may the Go toolchain's source tree (lang/go*): test data and the race detector's
|
||||
# objects for every platform.
|
||||
ELF_ARCH_EXEMPT = re.compile(r"(^|/)(boot/firmware|firmware)/|^/?usr/local/go[0-9]+/src/")
|
||||
|
||||
MAX_SIG = 64 * 1024 # a .sig file (SIGNATURE/CERT/END)
|
||||
MAX_META = 64 * 1024 # meta.conf
|
||||
|
|
@ -513,8 +515,12 @@ def parse_packages(data_doc, manifests_doc, rel):
|
|||
return from_data
|
||||
|
||||
|
||||
def verify_repo(source, prefix, abi, trust, report, deep, elf):
|
||||
"""Verify a pkg repository; return its {name: version} catalogue."""
|
||||
def verify_repo(source, prefix, abi, trust, report, deep, elf, latest=True):
|
||||
"""Verify a pkg repository; return its {name: version} catalogue.
|
||||
|
||||
With latest, each package also needs its signed Latest/<name>.pkg, which tools
|
||||
makes for the main repository only (pkg bootstrap and opnsense-update fetch
|
||||
from there); the aux repository has none, upstream's neither."""
|
||||
try:
|
||||
meta = parse_meta(source.read(join(prefix, "meta.conf"), MAX_META))
|
||||
manifests = read_catalogue_doc(source, prefix, meta["manifests_archive"],
|
||||
|
|
@ -544,20 +550,21 @@ def verify_repo(source, prefix, abi, trust, report, deep, elf):
|
|||
raise VerifyError(f"{name}: bad checksum field")
|
||||
if source.size(where) != p.get("pkgsize"):
|
||||
raise VerifyError(f"{where}: size differs from catalogue")
|
||||
latest = join(prefix, f"Latest/{name}.pkg")
|
||||
if source.size(latest) != p["pkgsize"]:
|
||||
raise VerifyError(f"{latest}: size differs from catalogue")
|
||||
sig, cert = read_sig(source, latest + ".sig")
|
||||
trust.verify_digest(p["sum"], sig, cert)
|
||||
link = join(prefix, f"Latest/{name}.pkg")
|
||||
if latest:
|
||||
if source.size(link) != p["pkgsize"]:
|
||||
raise VerifyError(f"{link}: size differs from catalogue")
|
||||
sig, cert = read_sig(source, link + ".sig")
|
||||
trust.verify_digest(p["sum"], sig, cert)
|
||||
if deep:
|
||||
with source.open(where) as f:
|
||||
digest, _ = sha256_stream(f, MAX_UNPACKED)
|
||||
if digest != p["sum"]:
|
||||
raise VerifyError(f"{where}: sha256 differs from catalogue")
|
||||
if not source.same_file(where, latest):
|
||||
with source.open(latest) as f:
|
||||
if latest and not source.same_file(where, link):
|
||||
with source.open(link) as f:
|
||||
if sha256_stream(f, MAX_UNPACKED)[0] != p["sum"]:
|
||||
raise VerifyError(f"{latest}: sha256 differs from catalogue")
|
||||
raise VerifyError(f"{link}: sha256 differs from catalogue")
|
||||
if elf:
|
||||
with source.open(where) as f:
|
||||
scan_tar_elf(f, where, report)
|
||||
|
|
@ -623,7 +630,7 @@ def verify_series(source, series_dir, trust, upstream, report, deep, device, url
|
|||
for name in ("changelog.txz", "bogons.txz"):
|
||||
verify_signed_file(source, f"{sets}/{name}", upstream, report, deep=True)
|
||||
if source.exists(f"{series_dir}/aux/meta.conf"):
|
||||
verify_repo(source, f"{series_dir}/aux", abi, trust, report, deep, elf)
|
||||
verify_repo(source, f"{series_dir}/aux", abi, trust, report, deep, elf, latest=False)
|
||||
|
||||
|
||||
def verify_upgrade_set(source, rel, trust, report):
|
||||
|
|
|
|||
|
|
@ -89,10 +89,12 @@ def write_pkg(path, name, version, files):
|
|||
tf.addfile(ti, io.BytesIO(data))
|
||||
|
||||
|
||||
def write_repo(keys, root, packages, abi=ABI, key="good"):
|
||||
"""A pkg repository: All/, Latest/ (+.sig), meta.conf, signed catalogues."""
|
||||
def write_repo(keys, root, packages, abi=ABI, key="good", latest=True):
|
||||
"""A pkg repository: All/, Latest/ (+.sig; tools makes it for the main repo
|
||||
only), meta.conf, signed catalogues."""
|
||||
os.makedirs(os.path.join(root, "All"), exist_ok=True)
|
||||
os.makedirs(os.path.join(root, "Latest"), exist_ok=True)
|
||||
if latest:
|
||||
os.makedirs(os.path.join(root, "Latest"), exist_ok=True)
|
||||
entries = []
|
||||
for name, version, files in packages:
|
||||
rel = f"All/{name}-{version}.pkg"
|
||||
|
|
@ -100,9 +102,10 @@ def write_repo(keys, root, packages, abi=ABI, key="good"):
|
|||
write_pkg(path, name, version, files)
|
||||
with open(path, "rb") as f:
|
||||
data = f.read()
|
||||
latest = os.path.join(root, "Latest", f"{name}.pkg")
|
||||
os.symlink(f"../{rel}", latest)
|
||||
keys.sig_file(latest, key)
|
||||
if latest:
|
||||
link = os.path.join(root, "Latest", f"{name}.pkg")
|
||||
os.symlink(f"../{rel}", link)
|
||||
keys.sig_file(link, key)
|
||||
entries.append({"name": name, "origin": f"x/{name}", "version": version, "abi": abi,
|
||||
"sum": hashlib.sha256(data).hexdigest(), "pkgsize": len(data),
|
||||
"path": rel, "repopath": rel})
|
||||
|
|
@ -159,7 +162,8 @@ def make_build(keys, out, version=VERSION, abi=ABI, packages=None, image=True, a
|
|||
if aux:
|
||||
aux_tar = os.path.join(sets, f"aux-{version}-aarch64.tar")
|
||||
with tempfile.TemporaryDirectory() as auxrepo:
|
||||
write_repo(keys, auxrepo, [("rust", "1.90.0", [("/usr/local/bin/rustc", elf(g.EM_AARCH64))])], abi)
|
||||
write_repo(keys, auxrepo, [("rust", "1.90.0", [("/usr/local/bin/rustc", elf(g.EM_AARCH64))])], abi,
|
||||
latest=False)
|
||||
with tarfile.open(aux_tar, "w:") as tf:
|
||||
tf.add(auxrepo, arcname=".")
|
||||
keys.sig_file(aux_tar)
|
||||
|
|
@ -390,6 +394,23 @@ class VerifyRootTest(Base):
|
|||
code, text = self.verify()
|
||||
self.assertNotIn("wifi.bin", text)
|
||||
|
||||
def test_go_source_tree_exempt(self):
|
||||
go = [("/usr/local/go126/src/runtime/race/race_linux_amd64.syso", elf(62)),
|
||||
("/usr/local/go126/src/debug/elf/testdata/gcc-386-freebsd-exec", elf(3)),
|
||||
("/usr/local/go126/bin/go", elf(g.EM_AARCH64))]
|
||||
self.staged(packages=GOOD_PACKAGES + [("go126", "1.26.4", go)])
|
||||
code, text = self.verify()
|
||||
self.assertEqual(code, 0, text)
|
||||
|
||||
def test_go_exemption_is_only_the_source_tree(self):
|
||||
for path in ("/usr/local/go126/bin/go", "/usr/local/go126/srcx/a", "/usr/local/gopher/src/a",
|
||||
"/usr/local/go/src/a", "/usr/local/bin/go126/src/a", "/usr/local/go126/pkg/tool/link"):
|
||||
with self.subTest(path):
|
||||
shutil.rmtree(self.mirror, ignore_errors=True)
|
||||
shutil.rmtree(os.path.join(self.tmp, "out"), ignore_errors=True)
|
||||
self.staged(packages=GOOD_PACKAGES + [("go126", "1.26.4", [(path, elf(62))])])
|
||||
self.assertFails(f"{path} is x86-64 ELF")
|
||||
|
||||
def test_path_traversal_in_catalogue(self):
|
||||
d = self.staged()
|
||||
entries = [{"name": "evil", "version": "1", "abi": ABI, "sum": "0" * 64, "pkgsize": 1,
|
||||
|
|
@ -410,6 +431,45 @@ class VerifyRootTest(Base):
|
|||
os.symlink("/etc/passwd", latest)
|
||||
self.assertFails("resolves outside the mirror")
|
||||
|
||||
def test_aux_without_latest(self):
|
||||
# tools makes no Latest/ for the aux repository (nor does upstream's have one)
|
||||
d = self.staged()
|
||||
self.assertFalse(os.path.exists(os.path.join(d, "aux-repo", "Latest")))
|
||||
code, text = self.verify()
|
||||
self.assertEqual(code, 0, text)
|
||||
self.assertIn("aux: 1 packages", text)
|
||||
|
||||
def test_main_repo_needs_latest(self):
|
||||
d = self.staged()
|
||||
os.unlink(os.path.join(d, "latest", "Latest", "opnsense.pkg"))
|
||||
self.assertFails("Latest/opnsense.pkg")
|
||||
|
||||
def test_unsigned_aux_catalogue(self):
|
||||
# what tools' sign step left before finish signed the aux catalogue (2026-11-22)
|
||||
d = self.staged()
|
||||
aux = os.path.join(d, "aux-repo")
|
||||
for archive in ("packagesite", "data"):
|
||||
path = os.path.join(aux, f"{archive}.pkg")
|
||||
with tarfile.open(path) as tf:
|
||||
doc = [m for m in tf.getmembers() if not m.name.endswith((".sig", ".pub"))][0]
|
||||
body = tf.extractfile(doc).read()
|
||||
with tarfile.open(path, "w:zst") as tf:
|
||||
ti = tarfile.TarInfo(doc.name)
|
||||
ti.size = len(body)
|
||||
tf.addfile(ti, io.BytesIO(body))
|
||||
shutil.copyfile(path, os.path.join(aux, f"{archive}.tzst"))
|
||||
self.assertFails("aux/packagesite.pkg: unexpected members")
|
||||
|
||||
def test_tampered_aux_package(self):
|
||||
d = self.staged()
|
||||
pkg = os.path.join(d, "aux-repo", "All", "rust-1.90.0.pkg")
|
||||
with open(pkg, "r+b") as f:
|
||||
f.seek(-1, os.SEEK_END)
|
||||
last = f.read(1)
|
||||
f.seek(-1, os.SEEK_END)
|
||||
f.write(bytes([last[0] ^ 1]))
|
||||
self.assertFails("sha256 differs from catalogue")
|
||||
|
||||
def test_wrong_abi_in_catalogue(self):
|
||||
self.staged()
|
||||
bad = os.path.join(self.tmp, "bad")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue