Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions EXPORTED
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Written by tools/export-public from squatch-dsp at 4ce2afb79bed94dcfadd5e18afb4fa51cf8bd853.
# Written by tools/export-public from squatch-dsp at 08c78d9826b3881618e0e5072a8023466501c6e3 (tools/release-scan, tools/release-signing, tools/test-release-scan, tools/test-release-signing, hosts/tests/test_host_audio.cpp only).
# Do not edit these files here: change them upstream and export again (see the README).
de9ec875a3df8d6488afd6893577bd995198373ca2bd2152887dcc5008504dc2 RESULTS.md
94b7020753515c516163468fd2b55406d1701c7ba032a8683073f6216598a8cc bench/algos.hpp
Expand Down Expand Up @@ -52,7 +52,7 @@ a02486cb10744347717cd51882c7ad6959139443c276532ffc69b454d949d5d6 hosts/common/t
1b4b7b68affbd4395b7d1eb611b01b1220d4d090ab5fbc3ed3a866534a4beba7 hosts/jack/jack_session.hpp
2489d436b9dee2e69eaa0816e8f1b9679eb7150ae8bb9877dc4f678ae4cf1a00 hosts/jack/tone.cpp
601b67e21fab60418bfef5849dbfcefca32568861c90781eac54f9a1049ce70c hosts/jack/tuner_live.cpp
b6cc7da0e324458d7dbfa49f05b29d5d56b3ef9c9eaf0e6f4877fc6227dbe480 hosts/tests/test_host_audio.cpp
1a09177a12b33926ebc06361436777a03f5d718f5a589ac3aaf5bad120ed55d7 hosts/tests/test_host_audio.cpp
8559c84df869cdaa5f4200d8503018fa9ba54208a164f9313bf2e3523676e17b hosts/tests/test_hosts.cpp
0d8c6ad65e5ae06f9c8b1fcabf8270e783812f6d89076d0fab04a88247685a13 hosts/wasm/build.py
22863bba7ba0ee81f6095f6e463926ddf3f545836a2bdd25565f8a63ab91c7c1 hosts/wasm/demo.css
Expand Down Expand Up @@ -98,7 +98,7 @@ cbe66e0adc53dcf976819861a1fc3aeb862ef1c839aa1f5916d1169bdc8630db include/squatc
818c8ee6462a64bff412e3cf2113d0cf92f3a5daefb8088655381e2111e15b54 results/synth.md
2c724991273af88988ec5da7d76717814d829162e6d3680773dfa3eb48025d1b tests/test_core.cpp
ef551ef238d36f01bee7a4006ac35d8fff62f3a6211e25b4db043c80bcd40bed tools/export-public
27be201ebb49c36ae14442a8dd76cef12efeee46ea64e6e222769bc101a30b4a tools/release-scan
414c14c757ea09536eb85c185dcb3962b25aaba4d25b10530b24d2e1749b1c63 tools/release-signing
9942263d376c55df83073aa9cfa635f3a736e0fc9874f043483f68bf3d544b07 tools/test-release-scan
33543123a798b73c5f8eef54d1c0bf898414c711db587133120ab2001579b0cd tools/test-release-signing
62bc2ea583873f1861565ae353901133484f2e969c9d1cf17a5436ee76e28c9e tools/release-scan
d81bdd53b43004b098ececff18b2c4d4962323bd93df3a1f9fd63c49919fb8bb tools/release-signing
6b10083bcd8966fd94664b0838e912d5b3e4c2f80e0781b2188fd5b110e79f37 tools/test-release-scan
38aa6eebe04ef498cc4ab9340d984c80202d21b25c13a315288b581bc57ac643 tools/test-release-signing
4 changes: 2 additions & 2 deletions hosts/tests/test_host_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ void feed(TunerRender& render, std::vector<float>& in, Shape shape, std::vector<
const auto frames = static_cast<uint32_t>(in.size() / shape.in);
for (uint32_t at = 0; at < frames; at += shape.block) {
const uint32_t n = std::min(shape.block, frames - at);
Chunk ic{shape.in, static_cast<uint32_t>(n * shape.in * sizeof(float)), in.data() + static_cast<size_t>(at) * shape.in};
Chunk oc{shape.out, static_cast<uint32_t>(n * shape.out * sizeof(float)), out ? out->data() + static_cast<size_t>(at) * shape.out : nullptr};
Chunk ic{shape.in, static_cast<uint32_t>(static_cast<size_t>(n) * shape.in * sizeof(float)), in.data() + static_cast<size_t>(at) * shape.in};
Chunk oc{shape.out, static_cast<uint32_t>(static_cast<size_t>(n) * shape.out * sizeof(float)), out ? out->data() + static_cast<size_t>(at) * shape.out : nullptr};
render.render({&ic, 1}, {out ? &oc : nullptr, out ? 1u : 0u}, 1000 + at);
}
}
Expand Down
59 changes: 56 additions & 3 deletions tools/release-scan
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ found as well as one in a comment. A .zip is unpacked in memory and scanned memb

Private patterns (code names, lineage) live in tools/release-scan.private, which is not published; the
public script carries only generic ones. The export guard checks the source for them before every export.
The owner's private terms (name, usernames, emails, domains, home paths) live outside every repo, in the
privacy scanner (squatch-privacy, in the owner's bin directory). When that scanner is on this machine, every file name, text
file, binary string and UTF-16 string is checked against it too, and a hit is reported as
"owner private term #N" with the file, never with the text. It is not there in CI, so the check runs locally,
before a release is tagged. If the scanner is there and cannot load, the scan fails (exit 2).

Allowlist (default tools/release-scan.allow, next to this script): one `path-glob regex` per line,
`#` comments. A hit is forgiven only when its file matches the glob AND its line matches the regex,
Expand All @@ -22,7 +27,10 @@ Exit 0 clean, 1 findings, 2 broken scanner or bad usage. Standard library only.
"""
import argparse
import fnmatch
import importlib.machinery
import importlib.util
import io
import os
import re
import sys
import tempfile
Expand All @@ -35,7 +43,7 @@ HERE = Path(__file__).resolve().parent
# regex per line, stays in the development tree and is read when it is present.
LINEAGE = r"/Users/[A-Za-z]|/home/[a-z]|\b192\.168\.|~/\.secrets"
# Other people's marks: allowed only in a sentence the allowlist names.
TRADEMARKS = r"\bRATs?\b|TS-?808|Tube ?Screamer|\bKlon\b|Centaur|\bProCo\b|Ibanez"
TRADEMARKS = r"\bRATs?\b|TS-?808|Tube[ _-]?Screamer|\bTS[ _-]?Drive\b|\bKlon\b|Centaur|\bProCo\b|Ibanez"
SECRETS = (
r"\bgh[pousr]_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{30,}|\bAKIA[0-9A-Z]{16}\b"
r"|-----BEGIN [A-Z ]*PRIVATE KEY-----|\bxox[baprs]-[A-Za-z0-9-]{10,}"
Expand All @@ -47,8 +55,28 @@ if PRIVATE.is_file():
RULES = [(re.compile(LINEAGE, re.I), "private lineage, infrastructure or path"),
(re.compile(TRADEMARKS, re.I), "a trademark"),
(re.compile(SECRETS), "a credential")]
PRIVACY = Path(os.environ.get("RELEASE_SCAN_PRIVACY") or Path.home() / "bin" / "squatch-privacy")


def load_privacy(path=PRIVACY):
"""The owner's private-term scanner, or None where it does not exist (CI). Never prints a term."""
if not Path(path).is_file():
return None
os.environ.setdefault("SQ_PRIV_REEXEC", "1") # never re-exec this script under another python
loader = importlib.machinery.SourceFileLoader("squatch_privacy", str(path))
mod = importlib.util.module_from_spec(importlib.util.spec_from_loader("squatch_privacy", loader))
loader.exec_module(mod)
sc = mod.Scanner([]) # strict: every class of term
if not sc.terms:
raise RuntimeError("the private term list is empty")
return sc


PRIV = None # set by main() (and by tests); scan_lines asks it about every line and every file name
# Rules that are case-sensitive in spirit are kept loose on purpose: a false hit is reviewed, a miss ships.
STRINGS = re.compile(rb"[\x20-\x7e]{5,}")
U16LE = re.compile(rb"(?:[\x20-\x7e]\x00){5,}")
U16BE = re.compile(rb"(?:\x00[\x20-\x7e]){5,}")
SKIP_DIRS = {".git", "node_modules", "build", "__pycache__"}
SKIP_FILES = {"release-scan", "release-scan.allow", "release-scan.private", "test-release-scan"}
MEDIA = {".png", ".jpg", ".jpeg", ".gif", ".ico", ".webp", ".woff", ".woff2", ".wav", ".f32", ".mp3"}
Expand All @@ -67,12 +95,29 @@ def load_allow(path):

def lines_of(data):
if b"\x00" in data[:8192]:
return [m.group().decode("ascii") for m in STRINGS.finditer(data)]
runs = [m.group().decode("ascii") for m in STRINGS.finditer(data)]
if PRIV is not None: # UTF-16 text (certificate subjects, Windows/Apple metadata)
runs += [m.group().decode("utf-16le") for m in U16LE.finditer(data)]
runs += [m.group().decode("utf-16be") for m in U16BE.finditer(data)]
return runs
return data.decode("utf-8", errors="replace").splitlines()


def private_hits(name, lines):
out = []
if PRIV is None:
return out
seen = set()
for n, line in [(0, name)] + list(enumerate(lines, 1)):
for lab, _cls in PRIV.scan(line):
if (lab, n) not in seen:
seen.add((lab, n))
out.append(f"{name}:{n or 'file name'}: owner private {lab}")
return out


def scan_lines(name, lines, allow):
hits = []
hits = private_hits(name, lines)
for n, line in enumerate(lines, 1):
for rx, why in RULES:
m = rx.search(line)
Expand Down Expand Up @@ -122,6 +167,14 @@ def main(argv):
ap.add_argument("paths", nargs="+")
ap.add_argument("--allow", default=str(HERE / "release-scan.allow"))
args = ap.parse_args(argv)
global PRIV
try:
PRIV = load_privacy()
except Exception as e: # fail closed: a scanner that exists must work
print(f"release-scan: the private-term scanner is present but cannot load ({type(e).__name__}); not scanning", file=sys.stderr)
return 2
if PRIV is None:
print("release-scan: no private-term scanner on this machine; the owner's terms were not checked", file=sys.stderr)
if not self_check():
print("release-scan: the negative controls were not caught; the scanner is broken", file=sys.stderr)
return 2
Expand Down
2 changes: 2 additions & 0 deletions tools/release-signing
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ def pkg(a):
"--install-location", a.install_location, unsigned])
run(["productsign", "--timestamp", "--keychain", KEYCHAIN, "--sign", identity("Installer"), unsigned, a.out])
run(["pkgutil", "--check-signature", a.out])
# The unsigned intermediate sits beside the output, so it would ship with the release (v0.2.1 did): remove it.
unsigned.unlink(missing_ok=True)
return 0


Expand Down
58 changes: 58 additions & 0 deletions tools/test-release-scan
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ same tree with one planted problem fails. Run: tools/test-release-scan"""
import importlib.machinery
import importlib.util
import io
import os
import sys
import tempfile
import unittest
Expand Down Expand Up @@ -53,6 +54,11 @@ class Scan(unittest.TestCase):
found = hits({"plugins.zip": buf.getvalue()})
self.assertTrue(found and "plugins.zip!Plugin.clap" in found[0])

def test_the_old_pedal_label_and_hyphenated_trademark_are_found(self):
self.assertTrue(hits({"a.json": '{"label": "' + "TS" + ' Drive"}'}))
self.assertTrue(hits({"a.md": "Tube-" + "screamer-style overdrive"}))
self.assertEqual(hits({"a.md": "results drive the loop; Trail Drive"}), [])

def test_a_broken_scanner_is_refused(self):
saved = scan.RULES
scan.RULES = []
Expand All @@ -63,5 +69,57 @@ class Scan(unittest.TestCase):
self.assertTrue(scan.self_check())


FAKE = "zq" + "fake" + "term" + "xv"
SCANNER = Path.home() / "bin" / "squatch-privacy"


@unittest.skipUnless(SCANNER.is_file(), "the owner's private-term scanner exists only on the owner's machine")
class OwnerTerms(unittest.TestCase):
"""The owner's private terms are never in this repo: the scan reuses the scanner outside it. These tests point it at
a scratch list holding a made-up term and plant that term everywhere a real one could hide."""

def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
(Path(self.tmp.name) / "terms").write_text(f"name|word|{FAKE}\n")
self.old_dir = os.environ.get("SQUATCH_PRIVACY_DIR")
os.environ["SQUATCH_PRIVACY_DIR"] = self.tmp.name
self.saved = scan.PRIV
scan.PRIV = scan.load_privacy()

def tearDown(self):
scan.PRIV = self.saved
if self.old_dir is None:
os.environ.pop("SQUATCH_PRIVACY_DIR", None)
else:
os.environ["SQUATCH_PRIVACY_DIR"] = self.old_dir
self.tmp.cleanup()

def test_a_planted_term_is_found_in_text_a_name_a_binary_utf16_and_a_zip(self):
buf = io.BytesIO()
with zipfile.ZipFile(buf, "w") as z:
z.writestr("Plugin/info.txt", f"Developer ID: {FAKE}")
found = hits({
"about.html": f"by {FAKE}",
f"{FAKE}.txt": "x",
"b.bin": b"\x00\x01 ok " + FAKE.encode() + b" tail \x00",
"u.dat": b"\x00\x01" + f"Signed {FAKE} here".encode("utf-16le"),
"p.zip": buf.getvalue(),
})
text = "\n".join(found)
for part in ("about.html", "file name", "b.bin", "u.dat", "p.zip!Plugin/info.txt"):
self.assertIn(part, text, text)
self.assertIn("term #1", text)
self.assertNotIn(FAKE, text.replace(f"{FAKE}.txt", ""), "the term was printed")

def test_a_clean_tree_passes_and_a_missing_term_list_is_refused(self):
self.assertEqual(hits({"a.txt": "Squatch Stack"}), [])
(Path(self.tmp.name) / "terms").write_text("# nothing\n")
with self.assertRaises(Exception):
scan.load_privacy()

def test_without_the_scanner_the_scan_still_runs_and_says_so(self):
self.assertIsNone(scan.load_privacy(Path(self.tmp.name) / "no-such-scanner"))


if __name__ == "__main__":
unittest.main(verbosity=1)
19 changes: 19 additions & 0 deletions tools/test-release-signing
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,24 @@ class Notarize(unittest.TestCase):
rs.run = real


class Pkg(unittest.TestCase):
def test_the_unsigned_intermediate_is_removed_so_it_never_ships(self):
import types
with tempfile.TemporaryDirectory() as d:
out = Path(d) / "x.pkg"
real_run, real_id, rs.DRY = rs.run, rs.identity, False
def fake(cmd, **kw): # pkgbuild writes its last argument; productsign writes its last argument
if cmd[0] in ("pkgbuild", "productsign"):
Path(str(cmd[-1])).write_bytes(b"pkg")
return ""
rs.run, rs.identity = fake, (lambda kind: "Developer ID Installer: Test")
try:
rs.pkg(types.SimpleNamespace(root=d, identifier="cc.squatch.x", version="1", install_location="/", out=str(out)))
finally:
rs.run, rs.identity = real_run, real_id
self.assertTrue(out.exists())
self.assertFalse(out.with_suffix(".unsigned.pkg").exists())


if __name__ == "__main__":
unittest.main(verbosity=1)
Loading