mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-21 10:45:53 +03:00
Compare commits
1 Commits
@@ -6,8 +6,6 @@ on:
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
env:
|
||||
XTL_CI: "1"
|
||||
jobs:
|
||||
build-linux:
|
||||
strategy:
|
||||
@@ -24,7 +22,7 @@ jobs:
|
||||
uses: actions/checkout@v6
|
||||
- name: Build and test
|
||||
run: |
|
||||
docker compose run --build -e XTL_CI=1 xtool bash -c \
|
||||
docker compose run --build xtool bash -c \
|
||||
"swift build --product xtool && .build/debug/xtool --help && swift test"
|
||||
build-macos:
|
||||
runs-on: macos-26
|
||||
|
||||
@@ -3,9 +3,6 @@ on:
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
env:
|
||||
XTL_CI: "1"
|
||||
|
||||
jobs:
|
||||
build-linux:
|
||||
strategy:
|
||||
@@ -26,7 +23,6 @@ jobs:
|
||||
run: |
|
||||
docker compose run --build \
|
||||
-e XTOOL_VERSION=${{ github.ref_name }} \
|
||||
-e XTL_CI=1 \
|
||||
--rm xtool Linux/build.sh
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v7
|
||||
@@ -92,8 +88,6 @@ jobs:
|
||||
id-token: write # for signing attestations and cache entries with GitHub OIDC
|
||||
packages: write # to push built images to GitHub Container Registry
|
||||
with:
|
||||
build-args: |
|
||||
XTL_CI=1
|
||||
output: image
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
@@ -101,8 +95,3 @@ jobs:
|
||||
ghcr.io/xtool-org/xtool
|
||||
meta-tags: |
|
||||
type=semver,pattern={{version}}
|
||||
secrets:
|
||||
registry-auths: |
|
||||
- registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
# About
|
||||
|
||||
xtool is a cross-platform replacement for Xcode (including build system, provisioning, deployment).
|
||||
|
||||
The `xtool` CLI supports macOS, Linux, WSL. The lower-level XKit (provisioning and device interaction) library additionally supports iOS.
|
||||
|
||||
## Development
|
||||
|
||||
- The majority of the code is in the Swift Package. You can use `swift build` / `swift test` / etc for iteration.
|
||||
- Caveat: on macOS, xtool is distributed as an app bundle (allows entitlements like Keychain). To build the Mac app, use `make mac`. You can then invoke the CLI at `./macOS/Build/xtool`.
|
||||
- Make sure to run `make lint` (swiftlint) when you're done
|
||||
|
||||
## Conventions
|
||||
|
||||
- Use modern Swift 6. Strict concurrency is enabled.
|
||||
- Use swift-dependencies for Dependency Injection. Passing dependencies around as arguments is an anti-pattern.
|
||||
@@ -100,8 +100,6 @@ CMD [ "/bin/bash" ]
|
||||
|
||||
FROM build-xtool-base AS build-xtool
|
||||
|
||||
ARG XTL_CI
|
||||
|
||||
ADD Package.swift Package.resolved /xtool/
|
||||
RUN swift package resolve
|
||||
|
||||
|
||||
+8
-23
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:6.2
|
||||
// swift-tools-version:6.0
|
||||
|
||||
import PackageDescription
|
||||
|
||||
@@ -19,14 +19,6 @@ let cSettings: [CSetting] = [
|
||||
.define("_GNU_SOURCE", .when(platforms: [.linux])),
|
||||
]
|
||||
|
||||
let swiftSettings: [SwiftSetting] = {
|
||||
var settings: [SwiftSetting] = []
|
||||
if Context.environment["XTL_CI"] == "1" {
|
||||
settings.append(.treatAllWarnings(as: .error))
|
||||
}
|
||||
return settings
|
||||
}()
|
||||
|
||||
let package = Package(
|
||||
name: "xtool",
|
||||
platforms: [
|
||||
@@ -98,8 +90,7 @@ let package = Package(
|
||||
dependencies: [
|
||||
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
|
||||
],
|
||||
exclude: ["openapi-generator-config.yaml", "patch.js"],
|
||||
swiftSettings: swiftSettings,
|
||||
exclude: ["openapi-generator-config.yaml", "patch.js"]
|
||||
),
|
||||
// common utilities shared across xtool targets
|
||||
.target(
|
||||
@@ -111,8 +102,7 @@ let package = Package(
|
||||
package: "swift-subprocess",
|
||||
condition: .when(platforms: [.linux, .macOS])
|
||||
),
|
||||
],
|
||||
swiftSettings: swiftSettings,
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "XKit",
|
||||
@@ -151,16 +141,14 @@ let package = Package(
|
||||
condition: .when(platforms: [.linux])
|
||||
),
|
||||
],
|
||||
cSettings: cSettings,
|
||||
swiftSettings: swiftSettings,
|
||||
cSettings: cSettings
|
||||
),
|
||||
.testTarget(
|
||||
name: "XToolTests",
|
||||
dependencies: [
|
||||
"XKit",
|
||||
"XToolSupport",
|
||||
],
|
||||
swiftSettings: swiftSettings,
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "XToolSupport",
|
||||
@@ -174,8 +162,7 @@ let package = Package(
|
||||
.product(name: "Version", package: "Version"),
|
||||
.product(name: "libunxip", package: "unxip"),
|
||||
],
|
||||
cSettings: cSettings,
|
||||
swiftSettings: swiftSettings,
|
||||
cSettings: cSettings
|
||||
),
|
||||
.target(
|
||||
name: "PackLib",
|
||||
@@ -183,8 +170,7 @@ let package = Package(
|
||||
"XUtils",
|
||||
.product(name: "Yams", package: "Yams"),
|
||||
.product(name: "XcodeGenKit", package: "XcodeGen", condition: .when(platforms: [.macOS])),
|
||||
],
|
||||
swiftSettings: swiftSettings,
|
||||
]
|
||||
),
|
||||
.executableTarget(
|
||||
name: "xtool",
|
||||
@@ -193,8 +179,7 @@ let package = Package(
|
||||
"XKit",
|
||||
"XToolSupport",
|
||||
],
|
||||
cSettings: cSettings,
|
||||
swiftSettings: swiftSettings,
|
||||
cSettings: cSettings
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
@@ -140,10 +140,12 @@ public struct DeveloperAPIXcodeAuthMiddleware: ClientMiddleware {
|
||||
|
||||
// Xcode-specific
|
||||
request.headerFields[.userAgent] = "Xcode"
|
||||
request.headerFields[.init(DeviceInfo.xcodeVersionKey)!] = DeviceInfo.xcodeVersion
|
||||
request.headerFields[.init(DeviceInfo.xcodeVersionKey)!] = "16.2 (16C5031c)"
|
||||
|
||||
// MobileMe identity
|
||||
request.headerFields[.init(DeviceInfo.clientInfoKey)!] = deviceInfo.clientInfo.clientString
|
||||
request.headerFields[.init(DeviceInfo.clientInfoKey)!] = """
|
||||
<VirtualMac2,1> <macOS;15.1.1;24B91> <com.apple.AuthKit/1 (com.apple.dt.Xcode/23505)>
|
||||
""" // deviceInfo.clientInfo.clientString
|
||||
request.headerFields[.init(DeviceInfo.deviceIDKey)!] = deviceInfo.deviceID
|
||||
|
||||
// GrandSlam authentication
|
||||
|
||||
@@ -14,19 +14,29 @@ public struct DeviceInfo: Codable, Sendable {
|
||||
/// `X-Xcode-Version`
|
||||
static let xcodeVersionKey = "X-Xcode-Version"
|
||||
/// Not included in `dictionary`
|
||||
public static let xcodeVersion = "26.5 (17F42)"
|
||||
public static let xcodeVersion = "14.2 (14C18)"
|
||||
|
||||
public struct ClientInfo: Codable {
|
||||
public static let macOSVersion = "14.3.1"
|
||||
public static let macOSBuild = "23D60"
|
||||
|
||||
public static let authKitVersion = "1"
|
||||
public static let akdVersion = "1.0"
|
||||
public static let cfNetworkVersion = "978.0.7"
|
||||
public static let darwinVersion = "18.7.0"
|
||||
|
||||
public let modelID: String // e.g. MacBookPro11,5
|
||||
|
||||
// TODO: Do we need to replace com.apple.akd with com.apple.dt.Xcode? See AltStore
|
||||
var clientString: String {
|
||||
"""
|
||||
<\(modelID)> <macOS;26.6;25G72> <com.apple.AuthKit/1 (com.apple.dt.Xcode/26.0)>
|
||||
<\(modelID)> <Mac OS X;\(Self.macOSVersion);\(Self.macOSBuild)> \
|
||||
<com.apple.AuthKit/\(Self.authKitVersion) (com.apple.akd/\(Self.akdVersion))>
|
||||
"""
|
||||
}
|
||||
|
||||
var userAgent: String {
|
||||
"AuthKit/1 (Macintosh; OS X 26.6) (com.apple.dt.Xcode/26.0)"
|
||||
"akd/\(Self.akdVersion) CFNetwork/\(Self.cfNetworkVersion) Darwin/\(Self.darwinVersion)"
|
||||
}
|
||||
|
||||
public init(modelID: String) {
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
#if false
|
||||
|
||||
// For reference: https://github.com/xtool-org/xtool/issues/196
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Creates a socket connected to `ip` on `port`.
|
||||
|
||||
@@ -41,11 +41,7 @@ struct GrandSlamClient: Sendable {
|
||||
}
|
||||
request.configure(request: &httpRequest, deviceInfo: deviceInfo, anisetteData: anisetteData)
|
||||
|
||||
// GrandSlam doesn't seem to like reused (keep-alive) connections so create a
|
||||
// new one for each request. cf https://github.com/rileytestut/AltSign/pull/52
|
||||
let resp = try await httpClient.withEphemeralClient {
|
||||
try await $0.makeRequest(httpRequest, body: body)
|
||||
}
|
||||
let resp = try await httpClient.makeRequest(httpRequest, body: body)
|
||||
return try R.Decoder.decode(data: resp.body)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,31 +18,23 @@ import OpenAPIAsyncHTTPClient
|
||||
import Dependencies
|
||||
|
||||
extension HTTPClientDependencyKey: DependencyKey {
|
||||
public static let liveValue: HTTPClientProtocol = Client()
|
||||
}
|
||||
|
||||
private struct Client: HTTPClientProtocol {
|
||||
private static let tlsConfiguration: TLSConfiguration = {
|
||||
public static let liveValue: HTTPClientProtocol = {
|
||||
// if ssl cert parsing fails we're screwed so we might as well force try
|
||||
// swiftlint:disable:next force_try
|
||||
let appleRootCA = try! NIOSSLCertificate(bytes: Array(appleRootPEM.utf8), format: .pem)
|
||||
var tlsConfiguration: TLSConfiguration = .makeClientConfiguration()
|
||||
tlsConfiguration.additionalTrustRoots = [.certificates([appleRootCA])]
|
||||
return tlsConfiguration
|
||||
}()
|
||||
|
||||
var client: HTTPClient
|
||||
|
||||
init() {
|
||||
var config = HTTPClient.Configuration(
|
||||
tlsConfiguration: Self.tlsConfiguration,
|
||||
tlsConfiguration: tlsConfiguration,
|
||||
decompression: .enabled(limit: .none)
|
||||
)
|
||||
config.timeout.connect = .seconds(60)
|
||||
self.client = HTTPClient(configuration: config)
|
||||
}
|
||||
return HTTPClient(configuration: config)
|
||||
}()
|
||||
}
|
||||
|
||||
func makeWebSocket(url: URL) async throws -> any WebSocketSession {
|
||||
extension HTTPClient: HTTPClientProtocol {
|
||||
public func makeWebSocket(url: URL) async throws -> any WebSocketSession {
|
||||
let (stream, continuation) = AsyncStream.makeStream(of: WebSocketSessionWrapper.self)
|
||||
async let value = stream.first(where: { _ in true })
|
||||
// must be after the `async let` so that we finish if connect throws
|
||||
@@ -50,7 +42,7 @@ private struct Client: HTTPClientProtocol {
|
||||
// we can't use the async overload because we need to immediately subscribe
|
||||
// to onText/onBinary in the same EventLoop tick that the WebSocket is created.
|
||||
// This is also why we create the SessionWrapper inside the closure.
|
||||
let future = WebSocket.connect(to: url, on: client.eventLoopGroup) {
|
||||
let future = WebSocket.connect(to: url, on: eventLoopGroup) {
|
||||
continuation.yield(WebSocketSessionWrapper(webSocket: $0))
|
||||
}
|
||||
try await future.get()
|
||||
@@ -64,17 +56,8 @@ private struct Client: HTTPClientProtocol {
|
||||
case connectFailed
|
||||
}
|
||||
|
||||
var asOpenAPITransport: any ClientTransport {
|
||||
AsyncHTTPClientTransport(configuration: .init(client: client))
|
||||
}
|
||||
|
||||
func withEphemeralClient<T>(
|
||||
perform: (any HTTPClientProtocol) async throws -> T
|
||||
) async throws -> T {
|
||||
let ephemeralClient = Client()
|
||||
let result = await Result { try await perform(ephemeralClient) }
|
||||
try? await ephemeralClient.client.shutdown()
|
||||
return try result.get()
|
||||
public var asOpenAPITransport: any ClientTransport {
|
||||
AsyncHTTPClientTransport(configuration: .init(client: self))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,6 @@ public protocol HTTPClientProtocol: Sendable {
|
||||
var asOpenAPITransport: ClientTransport { get }
|
||||
|
||||
func makeWebSocket(url: URL) async throws -> WebSocketSession
|
||||
|
||||
func withEphemeralClient<T>(
|
||||
perform: (any HTTPClientProtocol) async throws -> T
|
||||
) async throws -> T
|
||||
}
|
||||
|
||||
extension HTTPClientProtocol {
|
||||
@@ -45,72 +41,28 @@ extension HTTPClientProtocol {
|
||||
public func makeRequest(
|
||||
_ request: HTTPRequest,
|
||||
body: Data? = nil,
|
||||
requireHTTPSuccess: Bool = true,
|
||||
onProgress: @isolated(any) (Double?) -> Void = { _ in }
|
||||
) async throws -> (response: HTTPResponse, body: Data) {
|
||||
await onProgress(0)
|
||||
let (response, responseBody) = try await send(request, body: body.map { HTTPBody($0) })
|
||||
guard !requireHTTPSuccess || ![.clientError, .serverError].contains(response.status.kind) else {
|
||||
let errorBody = (try? await responseBody.collect()) ?? Data()
|
||||
throw HTTPResponseError(
|
||||
method: request.method,
|
||||
url: "\(request.scheme ?? "https")://\(request.authority ?? "")\(request.path ?? "")",
|
||||
status: response.status,
|
||||
// we don't use `decoding:as:` because we want to validate the UTF8
|
||||
body: String(data: errorBody, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
)
|
||||
let (response, body) = try await send(request, body: body.map { HTTPBody($0) })
|
||||
guard let body else {
|
||||
return (response, Data())
|
||||
}
|
||||
return (response, try await responseBody.collect(onProgress: onProgress))
|
||||
}
|
||||
}
|
||||
|
||||
extension HTTPBody? {
|
||||
fileprivate func collect(
|
||||
onProgress: @isolated(any) (Double?) -> Void = { _ in }
|
||||
) async throws -> Data {
|
||||
try await self?.collect(onProgress: onProgress) ?? Data()
|
||||
}
|
||||
}
|
||||
|
||||
extension HTTPBody {
|
||||
fileprivate func collect(
|
||||
onProgress: @isolated(any) (Double?) -> Void
|
||||
) async throws -> Data {
|
||||
switch self.length {
|
||||
switch body.length {
|
||||
case .unknown:
|
||||
return try await self.reduce(into: Data()) { $0 += $1 }
|
||||
return (response, try await body.reduce(into: Data()) { $0 += $1 })
|
||||
case .known(let length):
|
||||
var data = Data(capacity: Int(length))
|
||||
let total = Double(length)
|
||||
for try await chunk in self {
|
||||
for try await chunk in body {
|
||||
data += chunk
|
||||
await onProgress(Swift.min(Double(data.count) / total, 1))
|
||||
await onProgress(min(Double(data.count) / total, 1))
|
||||
}
|
||||
return data
|
||||
return (response, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct HTTPResponseError: Error, LocalizedError, Sendable, CustomStringConvertible {
|
||||
public let method: HTTPRequest.Method
|
||||
public let url: String
|
||||
public let status: HTTPResponse.Status
|
||||
public let body: String?
|
||||
|
||||
public var description: String {
|
||||
var description = "\(method.rawValue) \(url) failed: HTTP \(status.code)"
|
||||
if !status.reasonPhrase.isEmpty {
|
||||
description += " \(status.reasonPhrase)"
|
||||
}
|
||||
if let body, !body.isEmpty {
|
||||
description += ". Details:\n\(body)"
|
||||
}
|
||||
return description
|
||||
}
|
||||
|
||||
public var errorDescription: String? { description }
|
||||
}
|
||||
|
||||
private struct UnimplementedHTTPClient: HTTPClientProtocol, ClientTransport {
|
||||
public var asOpenAPITransport: ClientTransport { self }
|
||||
|
||||
@@ -132,12 +84,6 @@ private struct UnimplementedHTTPClient: HTTPClientProtocol, ClientTransport {
|
||||
return try closure()
|
||||
}
|
||||
|
||||
func withEphemeralClient<T>(
|
||||
perform: (any HTTPClientProtocol) async throws -> T
|
||||
) async throws -> T {
|
||||
try await perform(self)
|
||||
}
|
||||
|
||||
public func makeWebSocket(url: URL) async throws -> any WebSocketSession {
|
||||
let closure: (URL) async throws -> any WebSocketSession = unimplemented()
|
||||
return try await closure(url)
|
||||
|
||||
@@ -56,15 +56,6 @@ private struct Client: HTTPClientProtocol {
|
||||
URLSessionTransport(configuration: .init(session: session))
|
||||
}
|
||||
|
||||
func withEphemeralClient<T>(
|
||||
perform: (any HTTPClientProtocol) async throws -> T
|
||||
) async throws -> T {
|
||||
let ephemeralClient = Client()
|
||||
let result = await Result { try await perform(ephemeralClient) }
|
||||
ephemeralClient.session.finishTasksAndInvalidate()
|
||||
return try result.get()
|
||||
}
|
||||
|
||||
public func makeWebSocket(url: URL) async throws -> any WebSocketSession {
|
||||
let task = session.webSocketTask(with: url)
|
||||
let (event, eventContinuation) = AsyncStream<URLSessionWebSocketTask.CloseCode?>.makeStream()
|
||||
|
||||
@@ -22,7 +22,7 @@ struct DSTeamsListCommand: AsyncParsableCommand {
|
||||
func run() async throws {
|
||||
let token = try AuthToken.saved()
|
||||
|
||||
guard case let .xcode(authData) = token.authData() else {
|
||||
guard case let .xcode(authData) = try token.authData() else {
|
||||
throw Console.Error("This command requires password-based authentication")
|
||||
}
|
||||
let client = DeveloperServicesClient(authData: authData)
|
||||
|
||||
@@ -8,7 +8,7 @@ import Dependencies
|
||||
enum XToolMain {
|
||||
static func main() async throws {
|
||||
prepareDependencies { _ in
|
||||
// TODO: Improve persistence mechanism
|
||||
#warning("Improve persistence mechanism")
|
||||
// for Windows, we could use dpapi.h or wincred.h.
|
||||
// for Linux, maybe use libsecret?
|
||||
// see https://github.com/atom/node-keytar
|
||||
|
||||
Reference in New Issue
Block a user