Publish VCC Plus OSS source distribution for 3.6.2 build 60
This commit is contained in:
commit
c652a5276d
1192 files changed
+272368
No files matched your search
@@ -0,0 +1,46 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Optional signed-policy fixture: compile once, copy, and sign the peers with
|
||||
// their edition's bundle identifiers and a contributor-supplied signing identity.
|
||||
// Supply the matching publisher team through VCC_TEST_COMPANION_TEAM_ID; this is
|
||||
// separate from the default ad-hoc app build and needs no maintainer credentials.
|
||||
import Foundation
|
||||
|
||||
@main struct SignedTransportPeer {
|
||||
static func main() async throws {
|
||||
let teamID = (ProcessInfo.processInfo.environment["VCC_TEST_COMPANION_TEAM_ID"] ?? "")
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !teamID.isEmpty else { throw CompanionTransport.Failure.untrustedPeer }
|
||||
let args = Array(CommandLine.arguments.dropFirst())
|
||||
guard args.count == 2 else { throw CompanionTransport.Failure.malformedFrame }
|
||||
if args[0] == "validate" {
|
||||
do {
|
||||
try CompanionTransport.validateApplication(at: URL(fileURLWithPath: args[1]),
|
||||
permittedBundleIDs: ["com.brianholman.vccplus.oss.mac"], teamID: teamID)
|
||||
print("PASS production application validation")
|
||||
} catch {
|
||||
print("DENIED application validation: \(error.localizedDescription)")
|
||||
exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
var configuration = CompanionTransport.Configuration.production
|
||||
configuration.teamID = teamID
|
||||
configuration.directory = URL(fileURLWithPath: args[1])
|
||||
configuration.timeout = 10
|
||||
if args[0] == "server" {
|
||||
let server = try CompanionTransport.Server(configuration: configuration) { method, payload in
|
||||
guard method == "signedEcho" else { throw CompanionTransport.Failure.malformedFrame }
|
||||
return payload
|
||||
}
|
||||
print("READY")
|
||||
fflush(stdout)
|
||||
try await Task.sleep(nanoseconds: 10_000_000_000)
|
||||
server.stop()
|
||||
} else {
|
||||
let input = Data("signed companion payload".utf8)
|
||||
let output = try await CompanionTransport.Client(configuration: configuration).request(method: "signedEcho", payload: input)
|
||||
guard output == input else { throw CompanionTransport.Failure.malformedFrame }
|
||||
print("PASS production same-team/bundle authentication and binary round-trip")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Standalone authored IPC fixtures. Compile with -D VCC_COMPANION_TESTING.
|
||||
import Foundation
|
||||
import Darwin
|
||||
|
||||
@main struct TransportChecks {
|
||||
actor Flag {
|
||||
var started = false
|
||||
var cancelled = false
|
||||
func start() { started = true }
|
||||
func cancel() { cancelled = true }
|
||||
}
|
||||
static func require(_ condition: Bool, _ message: String) throws {
|
||||
if !condition { throw NSError(domain: "TransportCheck", code: 1, userInfo: [NSLocalizedDescriptionKey: message]) }
|
||||
}
|
||||
static func configuration(_ root: URL, name: String = "fixture.sock", timeout: TimeInterval = 3) -> CompanionTransport.Configuration {
|
||||
var config = CompanionTransport.Configuration(directory: root)
|
||||
config.socketName = name; config.timeout = timeout; config.allowUnsignedTestPeers = true
|
||||
return config
|
||||
}
|
||||
static func fixtureSocket(_ path: String, listening: Bool = false) throws -> Int32 {
|
||||
let fd = socket(AF_UNIX, SOCK_STREAM, 0)
|
||||
guard fd >= 0 else { throw POSIXError(.EIO) }
|
||||
var address = sockaddr_un(); address.sun_family = sa_family_t(AF_UNIX)
|
||||
address.sun_len = UInt8(MemoryLayout<sockaddr_un>.size)
|
||||
let bytes = Array(path.utf8CString)
|
||||
guard bytes.count <= MemoryLayout.size(ofValue: address.sun_path) else { close(fd); throw POSIXError(.ENAMETOOLONG) }
|
||||
withUnsafeMutableBytes(of: &address.sun_path) { target in bytes.withUnsafeBytes { target.copyBytes(from: $0) } }
|
||||
let rc = withUnsafePointer(to: &address) { $0.withMemoryRebound(to: sockaddr.self, capacity: 1) { bind(fd, $0, socklen_t(MemoryLayout<sockaddr_un>.size)) } }
|
||||
guard rc == 0, chmod(path, 0o600) == 0 else { close(fd); throw POSIXError(.EIO) }
|
||||
if listening { guard listen(fd, 2) == 0 else { close(fd); throw POSIXError(.EIO) } }
|
||||
return fd
|
||||
}
|
||||
static func main() async throws {
|
||||
let root = URL(fileURLWithPath: "/private/tmp/vcc-ipc-" + UUID().uuidString)
|
||||
defer { try? FileManager.default.removeItem(at: root) }
|
||||
let config = configuration(root)
|
||||
let server = try CompanionTransport.Server(configuration: config) { method, payload in
|
||||
if method == "error" { throw CompanionTransport.Failure.remote("Authored remote error") }
|
||||
return payload
|
||||
}
|
||||
defer { server.stop() }
|
||||
let client = CompanionTransport.Client(configuration: config)
|
||||
let bytes = Data((0..<(1024 * 1024)).map { UInt8($0 & 255) })
|
||||
let echoed = try await client.request(method: "echo", payload: bytes)
|
||||
try require(echoed == bytes, "Binary round-trip differs")
|
||||
print("PASS binary round-trip")
|
||||
try await withThrowingTaskGroup(of: Void.self) { group in
|
||||
for n in 0..<4 {
|
||||
group.addTask {
|
||||
let expected = Data("request-\(n)".utf8)
|
||||
let actual = try await client.request(method: "echo", payload: expected)
|
||||
try require(actual == expected, "Concurrent response crossed request identities")
|
||||
}
|
||||
}
|
||||
try await group.waitForAll()
|
||||
}
|
||||
print("PASS concurrent request identities")
|
||||
do { _ = try await client.request(method: "error"); throw POSIXError(.EIO) }
|
||||
catch CompanionTransport.Failure.remote(let message) { try require(message == "Authored remote error", "Remote error differs") }
|
||||
print("PASS remote errors")
|
||||
do { _ = try CompanionTransport.Server(configuration: config) { _, p in p }; throw POSIXError(.EIO) }
|
||||
catch CompanionTransport.Failure.busy { }
|
||||
try require(try await client.request(method: "echo") == Data(), "Duplicate listener disrupted live endpoint")
|
||||
print("PASS duplicate listener preserves running service")
|
||||
var second = config; second.socketName = "second.sock"
|
||||
let other = try CompanionTransport.Server(configuration: second) { _, _ in Data("other".utf8) }
|
||||
try require(try await CompanionTransport.Client(configuration: second).request(method: "echo") == Data("other".utf8), "Second endpoint failed")
|
||||
other.stop()
|
||||
try require(try await client.request(method: "echo") == Data(), "Second endpoint stopped first service")
|
||||
print("PASS independent app endpoints")
|
||||
var signedOnly = config; signedOnly.allowUnsignedTestPeers = false
|
||||
do { _ = try await CompanionTransport.Client(configuration: signedOnly).request(method: "echo"); throw POSIXError(.EIO) }
|
||||
catch CompanionTransport.Failure.untrustedPeer { }
|
||||
print("PASS unsigned peer rejected by production policy")
|
||||
do {
|
||||
try CompanionTransport.validateApplication(at: URL(fileURLWithPath: CommandLine.arguments[0]),
|
||||
permittedBundleIDs: ["com.brianholman.vccplus.oss.mac"])
|
||||
throw POSIXError(.EIO)
|
||||
} catch CompanionTransport.Failure.untrustedPeer { }
|
||||
print("PASS unsigned application rejected before launch")
|
||||
do { _ = try await client.request(method: "echo", payload: Data(count: CompanionTransport.maximumPayloadBytes + 1)); throw POSIXError(.EIO) }
|
||||
catch CompanionTransport.Failure.tooLarge { }
|
||||
print("PASS oversized payload rejected")
|
||||
let flag = Flag()
|
||||
var waiting = config; waiting.socketName = "waiting.sock"
|
||||
let slow = try CompanionTransport.Server(configuration: waiting) { _, _ in
|
||||
await flag.start()
|
||||
do { try await Task.sleep(nanoseconds: 10_000_000_000) }
|
||||
catch { await flag.cancel(); throw error }
|
||||
return Data()
|
||||
}
|
||||
let task = Task { try await CompanionTransport.Client(configuration: waiting).request(method: "wait") }
|
||||
for _ in 0..<40 {
|
||||
if await flag.started { break }
|
||||
try await Task.sleep(nanoseconds: 25_000_000)
|
||||
}
|
||||
try require(await flag.started, "Handler did not start")
|
||||
task.cancel()
|
||||
do { _ = try await task.value; throw POSIXError(.EIO) } catch is CancellationError { }
|
||||
for _ in 0..<40 {
|
||||
if await flag.cancelled { break }
|
||||
try await Task.sleep(nanoseconds: 25_000_000)
|
||||
}
|
||||
try require(await flag.cancelled, "Client cancellation did not reach handler")
|
||||
slow.stop()
|
||||
print("PASS cancellation propagates to server work")
|
||||
var stale = config; stale.socketName = "stale.sock"
|
||||
close(try fixtureSocket(stale.socketPath))
|
||||
let recovered = try CompanionTransport.Server(configuration: stale) { _, p in p }
|
||||
recovered.stop()
|
||||
print("PASS owned stale socket recovery")
|
||||
var active = config; active.socketName = "active.sock"
|
||||
let foreign = try fixtureSocket(active.socketPath, listening: true)
|
||||
do { _ = try CompanionTransport.Server(configuration: active) { _, p in p }; throw POSIXError(.EIO) }
|
||||
catch CompanionTransport.Failure.busy { }
|
||||
var activeInfo = stat(); try require(lstat(active.socketPath, &activeInfo) == 0, "Live foreign socket removed")
|
||||
close(foreign); unlink(active.socketPath)
|
||||
print("PASS live foreign socket preserved")
|
||||
var unsafe = config; unsafe.socketName = "unsafe.sock"
|
||||
let target = root.appendingPathComponent("retained.txt")
|
||||
try Data("retained".utf8).write(to: target)
|
||||
try FileManager.default.createSymbolicLink(atPath: unsafe.socketPath, withDestinationPath: target.path)
|
||||
do { _ = try CompanionTransport.Server(configuration: unsafe) { _, p in p }; throw POSIXError(.EIO) }
|
||||
catch CompanionTransport.Failure.unsafeEndpoint { }
|
||||
try require(try Data(contentsOf: target) == Data("retained".utf8), "Symlink target changed")
|
||||
print("PASS symlink endpoint refused without modifying target")
|
||||
var replaced = config; replaced.socketName = "replaced.sock"
|
||||
let old = try CompanionTransport.Server(configuration: replaced) { _, p in p }
|
||||
unlink(replaced.socketPath)
|
||||
let replacement = try fixtureSocket(replaced.socketPath)
|
||||
old.stop()
|
||||
var replacementInfo = stat()
|
||||
try require(lstat(replaced.socketPath, &replacementInfo) == 0, "Replaced socket removed during stop")
|
||||
close(replacement); unlink(replaced.socketPath)
|
||||
print("PASS stop preserves replaced endpoint")
|
||||
var timing = config; timing.socketName = "timeout.sock"; timing.timeout = 0.2
|
||||
let hung = try CompanionTransport.Server(configuration: timing) { _, _ in
|
||||
try await Task.sleep(nanoseconds: 10_000_000_000); return Data()
|
||||
}
|
||||
do { _ = try await CompanionTransport.Client(configuration: timing).request(method: "wait"); throw POSIXError(.EIO) }
|
||||
catch CompanionTransport.Failure.timedOut { }
|
||||
hung.stop()
|
||||
print("PASS bounded operation deadline")
|
||||
server.stop()
|
||||
do { _ = try await client.request(method: "echo"); throw POSIXError(.EIO) }
|
||||
catch CompanionTransport.Failure.unavailable { }
|
||||
print("PASS stopped service unavailable")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Foundation-only executable: the runner places it in authored fixture bundles.
|
||||
import Foundation
|
||||
import Darwin
|
||||
|
||||
@main struct ValidationChecks {
|
||||
static func require(_ value: Bool, _ message: String) throws {
|
||||
guard value else { throw NSError(domain: "CompanionValidationChecks", code: 1, userInfo: [NSLocalizedDescriptionKey: message]) }
|
||||
}
|
||||
static func main() throws {
|
||||
let args = CommandLine.arguments
|
||||
let expectingEnabled = args.contains("--expect-enabled")
|
||||
if CompanionValidation.enabled != expectingEnabled {
|
||||
print("DIAGNOSTIC bundle=\(Bundle.main.bundleIdentifier ?? "nil") url=\(Bundle.main.bundleURL.path)")
|
||||
if let index = args.firstIndex(of: "--companion-validation-root"), args.indices.contains(index + 1) {
|
||||
let supplied = URL(fileURLWithPath: args[index + 1], isDirectory: true).standardizedFileURL
|
||||
var info = stat()
|
||||
let rc = lstat(supplied.path, &info)
|
||||
print("DIAGNOSTIC supplied=\(supplied.path) resolved=\(supplied.resolvingSymlinksInPath().path) lstat=\(rc) uid=\(info.st_uid)/\(geteuid()) mode=\(String(info.st_mode, radix: 8))")
|
||||
}
|
||||
do { _ = try CompanionValidation.configuration(forVCCPlus: true) }
|
||||
catch { print("DIAGNOSTIC \(error)") }
|
||||
fflush(stdout)
|
||||
}
|
||||
try require(CompanionValidation.enabled == expectingEnabled, "Unexpected validation availability")
|
||||
if expectingEnabled {
|
||||
let supplied = args[args.firstIndex(of: "--companion-validation-root")! + 1]
|
||||
let canonical = URL(fileURLWithPath: supplied).standardizedFileURL.resolvingSymlinksInPath()
|
||||
try require(CompanionValidation.root == canonical, "Validation root differs")
|
||||
let vcc = try CompanionValidation.configuration(forVCCPlus: true)
|
||||
let dw = try CompanionValidation.configuration(forVCCPlus: false)
|
||||
try require(vcc.directory == canonical && dw.directory == canonical, "Fixture escaped isolated root")
|
||||
try require(vcc.socketPath != dw.socketPath, "Fixture endpoints collide")
|
||||
try require(vcc.expectedServerBundleIDs == [CompanionValidation.vccPlusBundleID] &&
|
||||
vcc.expectedClientBundleIDs == [CompanionValidation.driveWireBundleID], "Wrong VCC fixture peer identities")
|
||||
try require(dw.expectedServerBundleIDs == [CompanionValidation.driveWireBundleID] &&
|
||||
dw.expectedClientBundleIDs == [CompanionValidation.vccPlusBundleID], "Wrong DriveWire fixture peer identities")
|
||||
try require(vcc.teamID.isEmpty && dw.teamID.isEmpty, "Authored fixture unexpectedly configured publisher trust")
|
||||
print("DIAGNOSTIC no publisher team is configured; signed companion authentication fails closed")
|
||||
do {
|
||||
try CompanionTransport.validateApplication(at: Bundle.main.bundleURL, permittedBundleIDs: [CompanionValidation.vccPlusBundleID])
|
||||
throw NSError(domain: "CompanionValidationChecks", code: 3, userInfo: [NSLocalizedDescriptionKey: "Unconfigured trust accepted a companion"])
|
||||
} catch CompanionTransport.Failure.untrustedPeer { }
|
||||
} else {
|
||||
try require(CompanionValidation.root == nil && CompanionValidation.vccApplicationURL == nil, "Disabled validation exposed fixture values")
|
||||
let fixtureIdentity = [CompanionValidation.vccPlusBundleID, CompanionValidation.driveWireBundleID].contains(Bundle.main.bundleIdentifier ?? "")
|
||||
if CompanionValidation.requested || fixtureIdentity {
|
||||
do {
|
||||
_ = try CompanionValidation.configuration(forVCCPlus: true)
|
||||
throw NSError(domain: "CompanionValidationChecks", code: 2, userInfo: [NSLocalizedDescriptionKey: "Invalid fixture fell through to production"])
|
||||
} catch CompanionTransport.Failure.unsafeEndpoint { }
|
||||
catch CompanionTransport.Failure.untrustedPeer { }
|
||||
} else {
|
||||
let config = try CompanionValidation.configuration(forVCCPlus: true)
|
||||
try require(config.socketPath == CompanionTransport.Configuration.production.socketPath, "Normal launch endpoint changed")
|
||||
}
|
||||
}
|
||||
print("PASS \(Bundle.main.bundleIdentifier ?? "unbundled") enabled=\(CompanionValidation.enabled) requested=\(CompanionValidation.requested)")
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
#!/bin/zsh
|
||||
set -euo pipefail
|
||||
repo_dir="${0:A:h:h:h:h}"
|
||||
check_dir="$(mktemp -d /private/tmp/vcc-transport-checks.XXXXXX)"
|
||||
trap 'rm -rf "$check_dir"' EXIT
|
||||
export DEVELOPER_DIR="${DEVELOPER_DIR:-/Applications/Xcode.app/Contents/Developer}"
|
||||
xcrun swiftc -swift-version 6 -strict-concurrency=complete \
|
||||
-module-cache-path "$check_dir/module-cache" -D VCC_COMPANION_TESTING -parse-as-library \
|
||||
"$repo_dir/platforms/macos/Companion/CompanionTransport.swift" \
|
||||
"$repo_dir/tests/macos/companion/TransportChecks.swift" -o "$check_dir/checks"
|
||||
"$check_dir/checks"
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Authored Foundation-only bundle fixtures; no NSApplication, UI, sockets or personal data."""
|
||||
from pathlib import Path
|
||||
import os, plistlib, shutil, subprocess, tempfile
|
||||
|
||||
repo = Path(__file__).resolve().parents[3]
|
||||
with tempfile.TemporaryDirectory(prefix="vcc-cv-", dir="/private/tmp") as folder:
|
||||
work = Path(folder)
|
||||
env = dict(os.environ, DEVELOPER_DIR=os.environ.get("DEVELOPER_DIR", "/Applications/Xcode.app/Contents/Developer"))
|
||||
def compile(name, debug):
|
||||
target = work / name
|
||||
command = ["xcrun", "swiftc", "-swift-version", "6", "-strict-concurrency=complete", "-module-cache-path", str(work / "module-cache"), "-parse-as-library"]
|
||||
if debug: command += ["-D", "DEBUG"]
|
||||
command += [str(repo / "platforms/macos/Companion/CompanionTransport.swift"),
|
||||
str(repo / "platforms/macos/Companion/CompanionValidation.swift"),
|
||||
str(repo / "tests/macos/companion/ValidationChecks.swift"), "-o", str(target)]
|
||||
subprocess.run(command, env=env, check=True)
|
||||
return target
|
||||
debug, release = compile("debug", True), compile("release", False)
|
||||
def bundle(name, identifier, executable=debug):
|
||||
root = work / (name + ".app")
|
||||
contents = root / "Contents"
|
||||
(contents / "MacOS").mkdir(parents=True)
|
||||
(contents / "Info.plist").write_bytes(plistlib.dumps({"CFBundleIdentifier": identifier, "CFBundleExecutable": "check", "CFBundlePackageType": "APPL"}))
|
||||
shutil.copyfile(executable, contents / "MacOS/check")
|
||||
(contents / "MacOS/check").chmod(0o700)
|
||||
return root
|
||||
vcc = bundle("VCC", "com.brianholman.vccplus.oss.mac.uitesting")
|
||||
dw = bundle("DriveWire", "com.brianholman.vccplus.oss.drivewire.companionpreview")
|
||||
production = bundle("Production", "com.brianholman.vccplus.oss.mac")
|
||||
rel = bundle("Release", "com.brianholman.vccplus.oss.mac.uitesting", release)
|
||||
private = work / "private"; private.mkdir(mode=0o700)
|
||||
public = work / "public"; public.mkdir(mode=0o755)
|
||||
symlink = work / "linked"; symlink.symlink_to(private)
|
||||
base = ["--companion-validation-root", str(private)]
|
||||
def run(app, args): subprocess.run([str(app / "Contents/MacOS/check")] + args, check=True)
|
||||
run(vcc, base + ["--expect-enabled"])
|
||||
run(dw, base + ["--expect-enabled", "--companion-validation-peer", str(vcc)])
|
||||
run(vcc, [])
|
||||
run(production, [])
|
||||
run(production, base)
|
||||
run(rel, base)
|
||||
run(vcc, ["--companion-validation-root", str(public)])
|
||||
run(vcc, ["--companion-validation-root", str(symlink)])
|
||||
run(vcc, ["--companion-validation-root"])
|
||||
run(vcc, base + base)
|
||||
run(dw, base + ["--companion-validation-peer", str(production)])
|
||||
Reference in new issue
Block a user