Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Make the update feed with every release, and check it

Țugui Dragoș74391a51290c
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index e9560e12..80600160 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -341,11 +341,21 @@ not signed with Peel's Developer ID, the hardened runtime, and a secure timestam
x86_64 slices, or has its class data unsigned, in which Sparkle carries its XPC services, in which a language is
missing, or which `syspolicy_check distribution` says macOS would not open.
+Last, it makes `appcast.xml`, the update feed every copy of Peel reads from the latest release: Sparkle's
+`generate_appcast` offers the disk image at the release's download address, signs it and the feed with the update key
+in the Keychain, marks the update critical, so Sparkle's window offers no Skip This Version, and embeds the changelog's
+entry for the version as Markdown release notes. `Scripts/check_appcast.swift` then refuses a feed that offers more
+than this one update, another version, build, or minimum macOS than the app's, a hardware requirement (which keeps an
+update from every Mac without that processor), another address or length, a disk image or a feed whose signature the
+app's own `SUPublicEDKey` doesn't verify, or no release notes. `generate_appcast` leaves the disk image unsigned, with
+only a warning, when the app inside names another key, and such a feed would fail every update.
+
Before it runs, the version is set by hand in each of the project's targets: `MARKETING_VERSION`, and
`CURRENT_PROJECT_VERSION`, the build every program carries, written as the year, month, and day it was set (261013),
with the release's entry in CHANGELOG.md. The script needs a Developer ID Application certificate in the keychain, a
notary profile stored once with `xcrun notarytool store-credentials` (it uses the one named Peel unless given another),
-and uv (`brew install uv`), and it refuses to start without uv.
+the update key in the Keychain under the account peel, made once with Sparkle's `generate_keys --account peel`, and
+uv (`brew install uv`), and it refuses to start without uv.
A Release build of every program has pointer authentication (`ENABLE_POINTER_AUTHENTICATION`, an arm64e slice
beside arm64 and x86_64), and the helper the rest of Enhanced Security too. Xcode gives the Swift packages only the
diff --git a/Scripts/check_appcast.swift b/Scripts/check_appcast.swift
new file mode 100644
index 00000000..cee35179
--- /dev/null
+++ b/Scripts/check_appcast.swift
@@ -0,0 +1,132 @@
+// Checks the update feed a release makes before it is published: every copy of Peel reads the feed of the latest
+// release, so a feed that is wrong reaches all of them.
+//
+// Usage: swift Scripts/check_appcast.swift <appcast.xml> <Peel.app> <disk image> <download URL prefix>
+// Prints what the feed offers, or each reason it is refused, and then exits 1.
+import CryptoKit
+import Foundation
+
+let arguments = Array(CommandLine.arguments.dropFirst())
+guard arguments.count == 4 else {
+ print("usage: swift check_appcast.swift <appcast.xml> <Peel.app> <disk image> <download URL prefix>")
+ exit(64)
+}
+let image = URL(filePath: arguments[2])
+let download = arguments[3] + image.lastPathComponent
+
+guard let info = NSDictionary(contentsOf: URL(filePath: arguments[1]).appending(path: "Contents/Info.plist")),
+ let version = info["CFBundleShortVersionString"] as? String,
+ let build = info["CFBundleVersion"] as? String,
+ let minimum = info["LSMinimumSystemVersion"] as? String,
+ let key = (info["SUPublicEDKey"] as? String).flatMap({ Data(base64Encoded: $0) })
+ .flatMap({ try? Curve25519.Signing.PublicKey(rawRepresentation: $0) })
+else {
+ print("REFUSED: \(arguments[1]) names no version, build, minimum macOS, or public key")
+ exit(1)
+}
+guard let feed = try? Data(contentsOf: URL(filePath: arguments[0])), let disk = try? Data(contentsOf: image) else {
+ print("REFUSED: \(arguments[0]) or \(arguments[2]) can't be read")
+ exit(1)
+}
+
+func verifies(_ signature: String?, _ data: Data) -> Bool {
+ signature.flatMap { Data(base64Encoded: $0) }.map { key.isValidSignature($0, for: data) } ?? false
+}
+
+var refusals: [String] = []
+
+// Sparkle checks the signature over every byte before the feed's signature block (SPUExtractSignedFeed.m).
+if let block = feed.range(of: Data("<!-- sparkle-signatures:\n".utf8), options: .backwards) {
+ let signed = feed[..<block.lowerBound]
+ var fields: [String: String] = [:]
+ for line in String(decoding: feed[block.upperBound...], as: UTF8.self).split(separator: "\n") {
+ let parts = line.split(separator: ":", maxSplits: 1)
+ if parts.count == 2 { fields[String(parts[0])] = parts[1].trimmingCharacters(in: .whitespaces) }
+ }
+ if fields["length"] != String(signed.count) { refusals.append("its signature doesn't cover the whole feed") }
+ if !verifies(fields["edSignature"], Data(signed)) {
+ refusals.append("its signature doesn't verify with the public key in Peel")
+ }
+} else {
+ refusals.append("it isn't signed, and Peel takes only a signed feed")
+}
+
+/// The elements directly inside each item, with their text and attributes, named as the feed writes them
+/// (`sparkle:version`). An enclosure inside `sparkle:deltas` is a delta's, not the update's.
+final class Items: NSObject, XMLParserDelegate {
+ var all: [[String: (text: String, attributes: [String: String])]] = []
+ private var current: [String: (text: String, attributes: [String: String])]?
+ private var depth = 0
+ private var attributes: [String: String] = [:]
+ private var text = ""
+
+ func parser(_ parser: XMLParser, didStartElement name: String, namespaceURI: String?, qualifiedName: String?,
+ attributes: [String: String]) {
+ if name == "item" {
+ current = [:]
+ depth = 0
+ } else if current != nil {
+ depth += 1
+ }
+ self.attributes = attributes
+ text = ""
+ }
+
+ func parser(_ parser: XMLParser, foundCharacters string: String) { text += string }
+
+ func parser(_ parser: XMLParser, foundCDATA block: Data) { text += String(decoding: block, as: UTF8.self) }
+
+ func parser(_ parser: XMLParser, didEndElement name: String, namespaceURI: String?, qualifiedName: String?) {
+ if name == "item", let item = current {
+ all.append(item)
+ current = nil
+ } else if current != nil {
+ if depth == 1 { current?[name] = (text.trimmingCharacters(in: .whitespacesAndNewlines), attributes) }
+ depth -= 1
+ }
+ text = ""
+ }
+}
+
+let items = Items()
+let parser = XMLParser(data: feed)
+parser.delegate = items
+if !parser.parse() { refusals.append("it isn't valid XML") }
+if items.all.count != 1 { refusals.append("it offers \(items.all.count) updates rather than this one") }
+if let item = items.all.first {
+ func text(_ name: String) -> String { item[name]?.text ?? "nothing" }
+ if text("sparkle:version") != build { refusals.append("its build is \(text("sparkle:version")), not \(build)") }
+ if text("sparkle:shortVersionString") != version {
+ refusals.append("its version is \(text("sparkle:shortVersionString")), not \(version)")
+ }
+ if text("sparkle:minimumSystemVersion") != minimum {
+ refusals.append("it asks for macOS \(text("sparkle:minimumSystemVersion")), while Peel runs on \(minimum)")
+ }
+ // Critical from any version, so Sparkle's window offers neither Skip This Version nor Remind Me Later.
+ if item["sparkle:criticalUpdate"].map({ $0.attributes["sparkle:version"] != nil }) ?? true {
+ refusals.append("it isn't critical from every version")
+ }
+ // Sparkle offers an update with a hardware requirement to no Mac that lacks it.
+ if let requirement = item["sparkle:hardwareRequirements"] {
+ refusals.append("it is offered only to Macs with \(requirement.text)")
+ }
+ let enclosure = item["enclosure"]?.attributes ?? [:]
+ if enclosure["url"] != download {
+ refusals.append("it downloads \(enclosure["url"] ?? "nothing"), not \(download)")
+ }
+ if enclosure["length"] != String(disk.count) { refusals.append("its length isn't the disk image's") }
+ if !verifies(enclosure["sparkle:edSignature"], disk) {
+ refusals.append("the disk image's signature doesn't verify with the public key in Peel")
+ }
+ if item["description"]?.attributes["sparkle:format"] != "markdown" || text("description").isEmpty {
+ refusals.append("it carries no release notes in Markdown")
+ }
+}
+
+if refusals.isEmpty {
+ print("The feed offers Peel \(version) (\(build)) to every Mac on macOS \(minimum) or later, critical,")
+ print("from \(download), with its release notes, signed with the key in Peel.")
+} else {
+ for refusal in refusals { print("REFUSED: the feed: \(refusal).") }
+ exit(1)
+}
diff --git a/Scripts/release.sh b/Scripts/release.sh
index a8f32d5d..f51fde02 100755
--- a/Scripts/release.sh
+++ b/Scripts/release.sh
@@ -1,6 +1,6 @@
#!/bin/zsh
# Tests, builds, signs, notarizes, and checks a release of Peel from a committed tree, then prints the paths and
-# SHA-256 checksums of its disk image, for people, and its zip, for Homebrew.
+# SHA-256 checksums of its disk image, for people, and its zip, for Homebrew, and the path of its update feed.
#
# Signing uses Xcode's `archive` and `exportArchive`, which do what notarization requires: they add a secure
# timestamp and remove the `com.apple.security.get-task-allow` entitlement. Nothing is sent to Apple's notary
@@ -8,8 +8,9 @@
#
# Requires a Developer ID Application certificate in the keychain and a notary profile, stored once with
# xcrun notarytool store-credentials Peel --apple-id <you> --team-id 6R6J264YA2
-# which prompts for the app-specific password, so the password stays out of the shell history, and uv
-# (`brew install uv`), which runs dmgbuild for the disk image's window.
+# which prompts for the app-specific password, so the password stays out of the shell history, uv
+# (`brew install uv`), which runs dmgbuild for the disk image's window, and the update key in the Keychain under the
+# account peel, made once with Sparkle's `generate_keys --account peel`.
#
# Usage: zsh Scripts/release.sh [notary-profile] (default profile: Peel)
set -euo pipefail
@@ -216,9 +217,33 @@ xcrun stapler staple "$image"
xcrun stapler validate "$image"
spctl -a -vvv -t open --context context:primary-signature "$image"
+echo "== The update feed"
+# Every copy of Peel reads appcast.xml from the latest release. It offers the disk image, signed with the key in the
+# Keychain, whose prompt is the person's to answer; every update is critical, so Sparkle offers no Skip This Version;
+# and its release notes are the changelog's entry, which Sparkle shows as Markdown, GitHub's alerts made bold lines.
+feed="$build/feed"
+download="https://github.com/TuguiDragos/Peel/releases/download/v$version/"
+mkdir -p "$feed"
+cp "$image" "$feed/"
+awk -v heading="## $version (" '
+ index($0, heading) == 1 { found = 1; next }
+ found && /^## / { exit }
+ found && /^> \[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]$/ {
+ kind = substr($0, 5, length($0) - 5)
+ $0 = "> **" substr(kind, 1, 1) tolower(substr(kind, 2)) "**"
+ }
+ found && (started || NF) { started = 1; lines[++count] = $0; if (NF) last = count }
+ END { for (line = 1; line <= last; line++) print lines[line] }
+' CHANGELOG.md > "$feed/Peel-$version.md"
+[ -s "$feed/Peel-$version.md" ] || { echo "REFUSED: CHANGELOG.md has no entry for $version"; exit 1; }
+build/SparkleBuild/Build/Products/Release/generate_appcast --account peel --critical-update-version "" \
+ --embed-release-notes --download-url-prefix "$download" "$feed"
+swift Scripts/check_appcast.swift "$feed/appcast.xml" "$app" "$image" "$download"
+
echo "== Made"
echo "Peel $version ($build_number)"
for made in "$image" "$final"; do
echo "$made"
shasum -a 256 "$made"
done
+echo "$feed/appcast.xml"