47 lines
2.3 KiB
Swift
47 lines
2.3 KiB
Swift
// 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")
|
|
}
|
|
}
|
|
}
|