mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-21 02:41:46 +03:00
Compare commits
155 Commits
@@ -1,20 +0,0 @@
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Build
|
||||
run: |
|
||||
docker compose run --build --rm supersign -c Linux/build.sh
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
draft: true
|
||||
files: |
|
||||
Linux/packages/Supersign.AppImage
|
||||
@@ -0,0 +1,39 @@
|
||||
on:
|
||||
- push
|
||||
jobs:
|
||||
build-linux:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
host:
|
||||
- runner: ubuntu-24.04
|
||||
arch: x86_64
|
||||
- runner: ubuntu-24.04-arm
|
||||
arch: aarch64
|
||||
runs-on: ${{ matrix.host.runner }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Build
|
||||
run: |
|
||||
docker compose run --build --rm xtool swift build --product xtool
|
||||
build-macos:
|
||||
runs-on: macos-15
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Build
|
||||
run: |
|
||||
swift build --product xtool
|
||||
build-ios:
|
||||
runs-on: macos-15
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Build
|
||||
run: |
|
||||
set -o pipefail \
|
||||
&& xcodebuild build \
|
||||
-skipMacroValidation -skipPackagePluginValidation \
|
||||
-scheme XKit -destination generic/platform=iOS \
|
||||
| xcbeautify
|
||||
@@ -0,0 +1,77 @@
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-linux:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
host:
|
||||
- runner: ubuntu-24.04
|
||||
arch: x86_64
|
||||
- runner: ubuntu-24.04-arm
|
||||
arch: aarch64
|
||||
runs-on: ${{ matrix.host.runner }}
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Build
|
||||
run: |
|
||||
docker compose run --build --rm xtool Linux/build.sh
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: xtool-${{ matrix.host.arch }}
|
||||
path: |
|
||||
Linux/packages/xtool-${{ matrix.host.arch }}.AppImage
|
||||
Linux/packages/xtool-${{ matrix.host.arch }}.AppImage.zsync
|
||||
build-mac:
|
||||
runs-on: macos-15
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Ruby
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
working-directory: macOS
|
||||
bundler-cache: true
|
||||
- name: Build
|
||||
env:
|
||||
APP_STORE_CONNECT_API_KEY_KEY_ID: ${{ secrets.APP_STORE_CONNECT_API_KEY_KEY_ID }}
|
||||
APP_STORE_CONNECT_API_KEY_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_API_KEY_ISSUER_ID }}
|
||||
APP_STORE_CONNECT_API_KEY_KEY: ${{ secrets.APP_STORE_CONNECT_API_KEY_KEY }}
|
||||
IDENTITY_P12: ${{ secrets.IDENTITY_P12 }}
|
||||
DEVELOPMENT_TEAM: ${{ secrets.DEVELOPMENT_TEAM }}
|
||||
run: |
|
||||
cd macOS
|
||||
bundle exec fastlane package
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: xtool-mac
|
||||
path: |
|
||||
macOS/Build/Output/xtool.app.zip
|
||||
macOS/Build/Output/xtool.app.dSYM.zip
|
||||
release:
|
||||
needs: [build-linux, build-mac]
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
contents: write
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Download artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: xtool-*
|
||||
path: output
|
||||
- name: Create and publish release
|
||||
run: |
|
||||
TAG="${GITHUB_REF##*/}-${GITHUB_SHA:0:7}"
|
||||
gh release create "$TAG" --draft --title "Draft Release"
|
||||
gh release upload "$TAG" output/**/*.{AppImage,AppImage.zsync,app.zip,app.dSYM.zip}
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
/Tests/SupersignTests/config/*
|
||||
!/Tests/SupersignTests/config/config-template.json
|
||||
/Tests/XKitTests/config/*
|
||||
!/Tests/XKitTests/config/config-template.json
|
||||
*.ipa
|
||||
.DS_Store
|
||||
/.build
|
||||
@@ -9,5 +9,6 @@ DerivedData/
|
||||
.swiftpm/configuration/registries.json
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
.netrc
|
||||
.docc-build
|
||||
|
||||
/openapi.json
|
||||
/openapi
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
version: 1
|
||||
builder:
|
||||
configs:
|
||||
- scheme: xtool
|
||||
platform: macosSpm
|
||||
documentation_targets:
|
||||
- xtool
|
||||
- scheme: xtool
|
||||
platform: macosXcodebuild
|
||||
- scheme: xtool
|
||||
platform: linux
|
||||
image: kabiroberai/xtool-dev:latest
|
||||
- scheme: XKit
|
||||
platform: ios
|
||||
@@ -1,67 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1410"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Supersign"
|
||||
BuildableName = "Supersign"
|
||||
BlueprintName = "Supersign"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Supersign"
|
||||
BuildableName = "Supersign"
|
||||
BlueprintName = "Supersign"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
+44
-49
@@ -1,7 +1,7 @@
|
||||
# Note: We use 20.04 since AppImage recommends building on the
|
||||
# Note: We use 22.04 since AppImage recommends building on the
|
||||
# oldest configuration that you support
|
||||
|
||||
FROM ubuntu:focal AS limd-build
|
||||
FROM swift:6.1-jammy AS build-base
|
||||
|
||||
RUN apt-get update \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||
@@ -16,78 +16,73 @@ RUN apt-get update \
|
||||
pkg-config \
|
||||
libxml2 \
|
||||
curl libcurl4-openssl-dev \
|
||||
zip unzip \
|
||||
liblzma-dev zlib1g-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN mkdir /prefix
|
||||
|
||||
RUN curl -fsS https://dlang.org/install.sh | bash -s ldc
|
||||
FROM build-base AS build-limd
|
||||
|
||||
RUN git clone https://github.com/libimobiledevice/libplist.git \
|
||||
&& cd libplist \
|
||||
RUN mkdir -p /prefix
|
||||
|
||||
ADD --keep-git-dir=true https://github.com/libimobiledevice/libplist.git#2.6.0 /libplist
|
||||
|
||||
RUN cd libplist \
|
||||
&& ./autogen.sh --prefix /usr --without-cython \
|
||||
&& make \
|
||||
&& make install \
|
||||
&& make install DESTDIR=/prefix \
|
||||
&& cd .. \
|
||||
&& rm -rf libplist
|
||||
&& make install DESTDIR=/prefix
|
||||
|
||||
RUN git clone https://github.com/libimobiledevice/libimobiledevice-glue.git \
|
||||
&& cd libimobiledevice-glue \
|
||||
ADD --keep-git-dir=true https://github.com/libimobiledevice/libimobiledevice-glue.git#1.3.1 /libimobiledevice-glue
|
||||
|
||||
RUN cd libimobiledevice-glue \
|
||||
&& ./autogen.sh --prefix /usr \
|
||||
&& make \
|
||||
&& make install \
|
||||
&& make install DESTDIR=/prefix \
|
||||
&& cd .. \
|
||||
&& rm -rf libimobiledevice-glue
|
||||
&& make install DESTDIR=/prefix
|
||||
|
||||
RUN git clone https://github.com/libimobiledevice/libusbmuxd.git \
|
||||
&& cd libusbmuxd \
|
||||
ADD --keep-git-dir=true https://github.com/libimobiledevice/libusbmuxd.git#2.1.0 /libusbmuxd
|
||||
|
||||
RUN cd libusbmuxd \
|
||||
&& ./autogen.sh --prefix /usr \
|
||||
&& make \
|
||||
&& make install \
|
||||
&& make install DESTDIR=/prefix \
|
||||
&& cd .. \
|
||||
&& rm -rf libusbmuxd
|
||||
&& make install DESTDIR=/prefix
|
||||
|
||||
RUN git clone https://github.com/libimobiledevice/libtatsu.git \
|
||||
&& cd libtatsu \
|
||||
ADD --keep-git-dir=true https://github.com/libimobiledevice/libtatsu.git#1.0.4 /libtatsu
|
||||
|
||||
RUN cd libtatsu \
|
||||
&& ./autogen.sh --prefix /usr \
|
||||
&& make \
|
||||
&& make install \
|
||||
&& make install DESTDIR=/prefix \
|
||||
&& cd .. \
|
||||
&& rm -rf libtatsu
|
||||
&& make install DESTDIR=/prefix
|
||||
|
||||
RUN git clone https://github.com/libimobiledevice/libimobiledevice.git \
|
||||
&& cd libimobiledevice \
|
||||
&& ./autogen.sh --prefix /usr --without-cython --enable-debug \
|
||||
ADD --keep-git-dir=true https://github.com/libimobiledevice/libimobiledevice.git#master /libimobiledevice
|
||||
|
||||
RUN cd libimobiledevice \
|
||||
&& ./autogen.sh --prefix /usr --without-cython \
|
||||
&& make \
|
||||
&& make install \
|
||||
&& make install DESTDIR=/prefix \
|
||||
&& cd .. \
|
||||
&& rm -rf libimobiledevice
|
||||
&& make install DESTDIR=/prefix
|
||||
|
||||
ADD https://api.github.com/repos/SuperchargeApp/SupersetteD/git/refs/heads/main Supersette-version.json
|
||||
|
||||
RUN git clone https://github.com/SuperchargeApp/SupersetteD.git \
|
||||
&& cd SupersetteD \
|
||||
FROM build-base AS build-xadi
|
||||
|
||||
RUN mkdir -p /prefix/usr/lib
|
||||
|
||||
RUN curl -fsS https://dlang.org/install.sh | bash -s ldc
|
||||
|
||||
ADD https://github.com/xtool-org/xadi.git#main /xadi
|
||||
|
||||
RUN cd xadi \
|
||||
&& /bin/bash -c 'source $(/root/dlang/install.sh ldc -a) && dub build --build=release' \
|
||||
&& cp -r bin/libsupersette.so /prefix/usr/lib/libsupersette.so \
|
||||
&& cd .. \
|
||||
&& rm -rf SupersetteD
|
||||
|
||||
FROM swift:6.0-focal
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
libssl-dev \
|
||||
ca-certificates \
|
||||
zip unzip \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
&& cp -r bin/libxadi.so /prefix/usr/lib/libxadi.so
|
||||
|
||||
|
||||
COPY --from=limd-build /prefix/usr /usr
|
||||
FROM build-base
|
||||
|
||||
COPY --from=build-limd /prefix/usr /usr
|
||||
COPY --from=build-xadi /prefix/usr /usr
|
||||
|
||||
# Docker doesn't support FUSE
|
||||
ENV APPIMAGE_EXTRACT_AND_RUN=1
|
||||
@@ -97,6 +92,6 @@ ENV APPIMAGE_EXTRACT_AND_RUN=1
|
||||
# socat -dd TCP-LISTEN:27015,range=127.0.0.1/32,reuseaddr,fork UNIX-CLIENT:/var/run/usbmuxd
|
||||
ENV USBMUXD_SOCKET_ADDRESS=host.docker.internal:27015
|
||||
|
||||
WORKDIR /Supersign
|
||||
WORKDIR /xtool
|
||||
|
||||
ENTRYPOINT [ "/bin/bash" ]
|
||||
CMD [ "/bin/bash" ]
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
# Supersign + Linux = <3
|
||||
# xtool + Linux = <3
|
||||
|
||||
Supersign currently uses AppImage to build its Linux CLI. It is possible to build and run the AppImage on a native Linux host, as well as through Docker (natively or through Docker Desktop on macOS).
|
||||
xtool currently uses AppImage to build its Linux CLI. It is possible to build and run the AppImage on a native Linux host, as well as through Docker (natively or through Docker Desktop on macOS).
|
||||
|
||||
## Setup
|
||||
|
||||
@@ -10,9 +10,9 @@ Make sure `usbmuxd` is installed on your host machine. On macOS, `usbmuxd` is pr
|
||||
|
||||
You can build and run a container with standard Docker Compose commands, for example:
|
||||
```
|
||||
docker compose run --rm supersign
|
||||
docker compose run --rm xtool
|
||||
```
|
||||
This will spawn a shell inside the container. The Supersign root directory will be bind-mounted at `/Supersign`.
|
||||
This will spawn a shell inside the container. The xtool root directory will be bind-mounted at `/xtool`.
|
||||
|
||||
To actually access iOS devices from inside Docker, you'll also need to forward the host's `usbmuxd` to a port which the Docker container's libusbmuxd will connect to. Keep this command running on your host machine:
|
||||
```
|
||||
@@ -21,4 +21,4 @@ socat -dd TCP-LISTEN:27015,range=127.0.0.1/32,reuseaddr,fork UNIX-CLIENT:/var/ru
|
||||
|
||||
## Building
|
||||
|
||||
Simply run `./build.sh` in this directory. This will output an AppImage to `packages/Supersign.AppImage`, which can directly be invoked.
|
||||
Simply run `./build.sh` in this directory. This will output an AppImage to `packages/xtool.AppImage`, which can directly be invoked.
|
||||
|
||||
+15
-10
@@ -5,8 +5,8 @@ shopt -s nullglob
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
# installer version
|
||||
export LINUXDEPLOY_OUTPUT_VERSION="1.0.0"
|
||||
# release version
|
||||
export LINUXDEPLOY_OUTPUT_VERSION="latest"
|
||||
|
||||
if ! command -v fusermount &>/dev/null; then
|
||||
# Docker doesn't support FUSE
|
||||
@@ -16,11 +16,12 @@ fi
|
||||
rm -rf staging/tmp
|
||||
mkdir -p staging/tmp staging/linuxdeploy
|
||||
|
||||
swift build --package-path .. -c release --product SupersignCLI --static-swift-stdlib
|
||||
swift build --package-path .. -c release --product xtool --static-swift-stdlib
|
||||
bin="$(swift build --package-path .. -c release --show-bin-path)"
|
||||
strip "${bin}/SupersignCLI"
|
||||
strip "${bin}/xtool"
|
||||
|
||||
curr_git_info="$(curl -fsSL https://api.github.com/repos/linuxdeploy/linuxdeploy/git/refs/tags/continuous)"
|
||||
curr_arch="$(uname -m)"
|
||||
|
||||
if [[ -f staging/linuxdeploy/git.json ]]; then
|
||||
if ! cmp -s staging/linuxdeploy/git.json <(echo "$curr_git_info"); then
|
||||
@@ -33,7 +34,7 @@ else
|
||||
fi
|
||||
|
||||
if [[ ! -f staging/linuxdeploy/linuxdeploy.AppImage ]]; then
|
||||
curl -fsSL "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-$(arch).AppImage" \
|
||||
curl -fsSL "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-${curr_arch}.AppImage" \
|
||||
-o staging/linuxdeploy/linuxdeploy.AppImage
|
||||
chmod +x staging/linuxdeploy/linuxdeploy.AppImage
|
||||
echo "$curr_git_info" > staging/linuxdeploy/git.json
|
||||
@@ -42,14 +43,18 @@ fi
|
||||
mkdir -p staging/tmp/AppDir/usr/bin
|
||||
find "${bin}"/ -name '*.resources' -print0 | xargs -0 -I {} cp -a {} "${PWD}/staging/tmp/AppDir/usr/bin/"
|
||||
|
||||
LDAI_OUTPUT="staging/tmp/Supersign.AppImage" ./staging/linuxdeploy/linuxdeploy.AppImage \
|
||||
env \
|
||||
LDAI_OUTPUT="staging/tmp/xtool.AppImage" \
|
||||
LDAI_UPDATE_INFORMATION="gh-releases-zsync|xtool-org|xtool|latest|xtool-${curr_arch}.AppImage.zsync" \
|
||||
./staging/linuxdeploy/linuxdeploy.AppImage \
|
||||
--appdir staging/tmp/AppDir \
|
||||
--output appimage \
|
||||
-e "${bin}/SupersignCLI" \
|
||||
-d Supersign.desktop \
|
||||
-i Supersign.png
|
||||
-e "${bin}/xtool" \
|
||||
-d xtool.desktop \
|
||||
-i xtool.png
|
||||
mkdir -p packages
|
||||
mv -f staging/tmp/Supersign.AppImage packages/Supersign.AppImage
|
||||
mv -f staging/tmp/xtool.AppImage "packages/xtool-${curr_arch}.AppImage"
|
||||
mv -f ./xtool.AppImage.zsync "packages/xtool-${curr_arch}.AppImage.zsync"
|
||||
|
||||
rm -rf staging/tmp
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
[Desktop Entry]
|
||||
Version=1.0
|
||||
Type=Application
|
||||
Name=Supersign
|
||||
Name=xtool
|
||||
Categories=Development;
|
||||
Exec=SupersignCLI
|
||||
Icon=Supersign
|
||||
Exec=xtool
|
||||
Icon=xtool
|
||||
# TODO: remove
|
||||
Terminal=true
|
||||
|
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 119 KiB |
@@ -2,9 +2,9 @@ SPEC_URL = https://developer.apple.com/sample-code/app-store-connect/app-store-c
|
||||
|
||||
.PHONY: api update-api
|
||||
|
||||
api: openapi.json
|
||||
api: openapi/openapi.json
|
||||
swift run swift-openapi-generator generate \
|
||||
openapi.json \
|
||||
openapi/openapi.json \
|
||||
--config Sources/DeveloperAPI/openapi-generator-config.yaml \
|
||||
--output-directory Sources/DeveloperAPI/Generated
|
||||
for file in Sources/DeveloperAPI/Generated/*.swift; do \
|
||||
@@ -14,5 +14,9 @@ api: openapi.json
|
||||
update-api:
|
||||
@+$(MAKE) -B api
|
||||
|
||||
openapi.json:
|
||||
curl -fsSL "$(SPEC_URL)" | bsdtar -xOf- > openapi.json
|
||||
openapi/openapi.json: openapi/base.json Sources/DeveloperAPI/openapi-overlay.yaml
|
||||
npx --yes bump-cli overlay openapi/base.json Sources/DeveloperAPI/openapi-overlay.yaml > openapi/openapi.json
|
||||
|
||||
openapi/base.json:
|
||||
@mkdir -p openapi
|
||||
curl -fsSL "$(SPEC_URL)" | bsdtar -xOf- > openapi/base.json
|
||||
|
||||
+148
-76
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"originHash" : "093c707d9a59dbc3862fcc4682cd2a725695bec85446dcc453245f6ec0363481",
|
||||
"originHash" : "6980154be7e8da0aace058cc72033471d7d9573fa77fdbf53972129e4cd1d0a2",
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "aexml",
|
||||
@@ -15,8 +15,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/swift-server/async-http-client.git",
|
||||
"state" : {
|
||||
"revision" : "0a9b72369b9d87ab155ef585ef50700a34abf070",
|
||||
"version" : "1.23.1"
|
||||
"revision" : "333f51104b75d1a5b94cb3b99e4c58a3b442c9f7",
|
||||
"version" : "1.25.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -24,8 +24,17 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/attaswift/BigInt",
|
||||
"state" : {
|
||||
"revision" : "a7ee11486233ba45f5ceee0b8cb3d6629ed450ef",
|
||||
"version" : "5.5.0"
|
||||
"revision" : "114343a705df4725dfe7ab8a2a326b8883cfd79c",
|
||||
"version" : "5.5.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "combine-schedulers",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/pointfreeco/combine-schedulers",
|
||||
"state" : {
|
||||
"revision" : "5928286acce13def418ec36d05a001a9641086f2",
|
||||
"version" : "1.0.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -42,8 +51,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/mattpolzin/OpenAPIKit",
|
||||
"state" : {
|
||||
"revision" : "5b5ee49624dda5b3e3b85aff184f44a007862fb7",
|
||||
"version" : "3.3.0"
|
||||
"revision" : "da7d3a5ddff0dd8e5e9fdb5585d186d645bcc21b",
|
||||
"version" : "3.5.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -60,8 +69,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/onevcat/Rainbow.git",
|
||||
"state" : {
|
||||
"revision" : "e0dada9cd44e3fa7ec3b867e49a8ddbf543e3df3",
|
||||
"version" : "4.0.1"
|
||||
"revision" : "0c627a4f8a39ef37eadec1ceec02e4a7f55561ac",
|
||||
"version" : "4.1.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -73,22 +82,13 @@
|
||||
"version" : "0.10.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "superchargecore",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/SuperchargeApp/SuperchargeCore",
|
||||
"state" : {
|
||||
"revision" : "e409f42fd5736fac149c8288eba69c50e7eac5c2",
|
||||
"version" : "1.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-algorithms",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-algorithms.git",
|
||||
"state" : {
|
||||
"revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42",
|
||||
"version" : "1.2.0"
|
||||
"revision" : "87e50f483c54e6efd60e885f7f5aa946cee68023",
|
||||
"version" : "1.2.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -105,8 +105,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-asn1.git",
|
||||
"state" : {
|
||||
"revision" : "7faebca1ea4f9aaf0cda1cef7c43aecd2311ddf6",
|
||||
"version" : "1.3.0"
|
||||
"revision" : "a54383ada6cecde007d374f58f864e29370ba5c3",
|
||||
"version" : "1.3.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -123,8 +123,17 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-certificates",
|
||||
"state" : {
|
||||
"revision" : "1fbb6ef21f1525ed5faf4c95207b9c11bea27e94",
|
||||
"version" : "1.6.1"
|
||||
"revision" : "999fd70c7803da89f3904d635a6815a2a7cd7585",
|
||||
"version" : "1.10.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-clocks",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/pointfreeco/swift-clocks",
|
||||
"state" : {
|
||||
"revision" : "cc46202b53476d64e824e0b6612da09d84ffde8e",
|
||||
"version" : "1.0.6"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -139,10 +148,10 @@
|
||||
{
|
||||
"identity" : "swift-concurrency-extras",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/pointfreeco/swift-concurrency-extras.git",
|
||||
"location" : "https://github.com/pointfreeco/swift-concurrency-extras",
|
||||
"state" : {
|
||||
"revision" : "163409ef7dae9d960b87f34b51587b6609a76c1f",
|
||||
"version" : "1.3.0"
|
||||
"revision" : "82a4ae7170d98d8538ec77238b7eb8e7199ef2e8",
|
||||
"version" : "1.3.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -150,8 +159,44 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-crypto",
|
||||
"state" : {
|
||||
"revision" : "06dc63c6d8da54ee11ceb268cde1fa68161afc96",
|
||||
"version" : "3.9.1"
|
||||
"revision" : "e8d6eba1fef23ae5b359c46b03f7d94be2f41fed",
|
||||
"version" : "3.12.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-dependencies",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/pointfreeco/swift-dependencies",
|
||||
"state" : {
|
||||
"revision" : "4c90d6b2b9bf0911af87b103bb40f41771891596",
|
||||
"version" : "1.9.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-docc-plugin",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-docc-plugin",
|
||||
"state" : {
|
||||
"revision" : "85e4bb4e1cd62cec64a4b8e769dcefdf0c5b9d64",
|
||||
"version" : "1.4.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-docc-symbolkit",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/swiftlang/swift-docc-symbolkit",
|
||||
"state" : {
|
||||
"revision" : "b45d1f2ed151d057b54504d653e0da5552844e34",
|
||||
"version" : "1.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-http-structured-headers",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-http-structured-headers.git",
|
||||
"state" : {
|
||||
"revision" : "f280fc7676b9940ff2c6598642751ea333c6544f",
|
||||
"version" : "1.2.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -159,8 +204,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-http-types",
|
||||
"state" : {
|
||||
"revision" : "ef18d829e8b92d731ad27bb81583edd2094d1ce3",
|
||||
"version" : "1.3.1"
|
||||
"revision" : "a0a57e949a8903563aba4615869310c0ebf14c03",
|
||||
"version" : "1.4.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -168,17 +213,17 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-log.git",
|
||||
"state" : {
|
||||
"revision" : "9cb486020ebf03bfa5b5df985387a14a98744537",
|
||||
"version" : "1.6.1"
|
||||
"revision" : "3d8596ed08bd13520157f0355e35caed215ffbfa",
|
||||
"version" : "1.6.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-nio",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-nio.git",
|
||||
"location" : "https://github.com/apple/swift-nio",
|
||||
"state" : {
|
||||
"revision" : "914081701062b11e3bb9e21accc379822621995e",
|
||||
"version" : "2.76.1"
|
||||
"revision" : "0f54d58bb5db9e064f332e8524150de379d1e51c",
|
||||
"version" : "2.82.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -186,8 +231,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-nio-extras.git",
|
||||
"state" : {
|
||||
"revision" : "2e9746cfc57554f70b650b021b6ae4738abef3e6",
|
||||
"version" : "1.24.1"
|
||||
"revision" : "f1f6f772198bee35d99dd145f1513d8581a54f2c",
|
||||
"version" : "1.26.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -195,8 +240,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-nio-http2.git",
|
||||
"state" : {
|
||||
"revision" : "eaa71bb6ae082eee5a07407b1ad0cbd8f48f9dca",
|
||||
"version" : "1.34.1"
|
||||
"revision" : "4281466512f63d1bd530e33f4aa6993ee7864be0",
|
||||
"version" : "1.36.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -204,8 +249,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-nio-ssl.git",
|
||||
"state" : {
|
||||
"revision" : "c7e95421334b1068490b5d41314a50e70bab23d1",
|
||||
"version" : "2.29.0"
|
||||
"revision" : "6df102a39c8da5fdc2eae29a0f63546d660866fc",
|
||||
"version" : "2.30.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -213,8 +258,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-nio-transport-services.git",
|
||||
"state" : {
|
||||
"revision" : "bbd5e63cf949b7db0c9edaf7a21e141c52afe214",
|
||||
"version" : "1.23.0"
|
||||
"revision" : "cd1e89816d345d2523b11c55654570acd5cd4c56",
|
||||
"version" : "1.24.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -222,8 +267,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-numerics.git",
|
||||
"state" : {
|
||||
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
|
||||
"version" : "1.0.2"
|
||||
"revision" : "e0ec0f5f3af6f3e4d5e7a19d2af26b481acb6ba8",
|
||||
"version" : "1.0.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -231,8 +276,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/swift-server/swift-openapi-async-http-client",
|
||||
"state" : {
|
||||
"revision" : "abfe558a66992ef1e896a577010f957915f30591",
|
||||
"version" : "1.0.0"
|
||||
"revision" : "915aeff168625b0f88a5810ee7ab8e9c00af671b",
|
||||
"version" : "1.1.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -240,8 +285,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-openapi-generator",
|
||||
"state" : {
|
||||
"revision" : "e971af5c5374e4ea83c20d0ad0a0df2cc84d39ad",
|
||||
"version" : "1.5.0"
|
||||
"revision" : "02cab48b66b4b412013827c2938adaf0eb67dc8d",
|
||||
"version" : "1.7.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -249,8 +294,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-openapi-runtime",
|
||||
"state" : {
|
||||
"revision" : "5e119a3d52dde0229312ed586be99c666c6b6f64",
|
||||
"version" : "1.7.0"
|
||||
"revision" : "8f33cc5dfe81169fb167da73584b9c72c3e8bc23",
|
||||
"version" : "1.8.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -258,17 +303,26 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-openapi-urlsession",
|
||||
"state" : {
|
||||
"revision" : "9bf4c712ad7989d6a91dbe68748b8829a50837e4",
|
||||
"version" : "1.0.2"
|
||||
"revision" : "6fac6f7c428d5feea2639b5f5c8b06ddfb79434b",
|
||||
"version" : "1.1.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-syntax",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/swiftlang/swift-syntax",
|
||||
"state" : {
|
||||
"revision" : "f99ae8aa18f0cf0d53481901f88a0991dc3bd4a2",
|
||||
"version" : "601.0.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-system",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-system.git",
|
||||
"location" : "https://github.com/apple/swift-system",
|
||||
"state" : {
|
||||
"revision" : "c8a44d836fe7913603e246acab7c528c2e780168",
|
||||
"version" : "1.4.0"
|
||||
"revision" : "a34201439c74b53f0fd71ef11741af7e7caf01e1",
|
||||
"version" : "1.4.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -281,21 +335,21 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swiftpack",
|
||||
"identity" : "swiftymobiledevice",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/kabiroberai/swiftpack",
|
||||
"location" : "https://github.com/xtool-org/SwiftyMobileDevice",
|
||||
"state" : {
|
||||
"revision" : "3610144c5fd3b1a50c323476ac7f42cebb9780bc",
|
||||
"version" : "1.0.1"
|
||||
"revision" : "5ee5f680d065519dd6ac56c96435a7db0d599ade",
|
||||
"version" : "1.4.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swiftymobiledevice",
|
||||
"identity" : "unxip",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/SuperchargeApp/SwiftyMobileDevice",
|
||||
"location" : "https://github.com/saagarjha/unxip",
|
||||
"state" : {
|
||||
"revision" : "954fff0438c181b64c0ab5dac5428486cc0cb6e0",
|
||||
"version" : "1.3.0"
|
||||
"revision" : "d6f0009109f7502f8f5b3f23dcd5b43cf5b29b32",
|
||||
"version" : "3.1.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -312,8 +366,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/vapor/websocket-kit.git",
|
||||
"state" : {
|
||||
"revision" : "4232d34efa49f633ba61afde365d3896fc7f8740",
|
||||
"version" : "2.15.0"
|
||||
"revision" : "014ccd52891b8c098d7e1033d5e72ed76fef7a86",
|
||||
"version" : "2.16.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -321,8 +375,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/yonaskolb/XcodeGen",
|
||||
"state" : {
|
||||
"revision" : "82c6ab9bbd5b6075fc0887d897733fc0c4ffc9ab",
|
||||
"version" : "2.42.0"
|
||||
"revision" : "7193eb447a6f60061f069e07bc1efd32d73c0e19",
|
||||
"version" : "2.43.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -330,8 +384,26 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/tuist/XcodeProj.git",
|
||||
"state" : {
|
||||
"revision" : "447c159b0c5fb047a024fd8d942d4a76cf47dde0",
|
||||
"version" : "8.16.0"
|
||||
"revision" : "dc3b87a4e69f9cd06c6cb16199f5d0472e57ef6b",
|
||||
"version" : "8.24.3"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "xctest-dynamic-overlay",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
|
||||
"state" : {
|
||||
"revision" : "39de59b2d47f7ef3ca88a039dff3084688fe27f4",
|
||||
"version" : "1.5.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "xtool-core",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/xtool-org/xtool-core",
|
||||
"state" : {
|
||||
"revision" : "63c644eef014f7faff53daaebe8bad37c31fbbe5",
|
||||
"version" : "1.3.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -339,17 +411,17 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/jpsim/Yams",
|
||||
"state" : {
|
||||
"revision" : "3036ba9d69cf1fd04d433527bc339dc0dc75433d",
|
||||
"version" : "5.1.3"
|
||||
"revision" : "b4b8042411dc7bbb696300a34a4bf3ba1b7ad19b",
|
||||
"version" : "5.3.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "zsign",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/kabiroberai/zsign",
|
||||
"location" : "https://github.com/xtool-org/zsign",
|
||||
"state" : {
|
||||
"revision" : "c3fea016227f595cd51f037450650a2ff362f7db",
|
||||
"version" : "1.3.0"
|
||||
"revision" : "e9853fd3be36ea1a61fa9d4b7f71f4b4d8244369",
|
||||
"version" : "1.4.0"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
+62
-32
@@ -7,52 +7,62 @@ let cSettings: [CSetting] = [
|
||||
]
|
||||
|
||||
let package = Package(
|
||||
name: "Supersign",
|
||||
name: "xtool",
|
||||
platforms: [
|
||||
.iOS(.v15),
|
||||
.macOS(.v12),
|
||||
],
|
||||
products: [
|
||||
.library(
|
||||
name: "Supersign",
|
||||
targets: ["Supersign"]
|
||||
name: "XKit",
|
||||
targets: ["XKit"]
|
||||
),
|
||||
.library(
|
||||
name: "SupersignCLISupport",
|
||||
targets: ["SupersignCLISupport"]
|
||||
name: "XToolSupport",
|
||||
targets: ["XToolSupport"]
|
||||
),
|
||||
.executable(
|
||||
name: "SupersignCLI",
|
||||
targets: ["SupersignCLI"]
|
||||
name: "xtool",
|
||||
targets: ["xtool"]
|
||||
),
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/SuperchargeApp/SuperchargeCore", .upToNextMinor(from: "1.2.0")),
|
||||
.package(url: "https://github.com/SuperchargeApp/SwiftyMobileDevice", .upToNextMinor(from: "1.3.0")),
|
||||
.package(url: "https://github.com/kabiroberai/swiftpack", .upToNextMinor(from: "1.0.1")),
|
||||
.package(url: "https://github.com/kabiroberai/zsign", .upToNextMinor(from: "1.3.0")),
|
||||
.package(url: "https://github.com/xtool-org/xtool-core", .upToNextMinor(from: "1.3.0")),
|
||||
.package(url: "https://github.com/xtool-org/SwiftyMobileDevice", .upToNextMinor(from: "1.4.0")),
|
||||
.package(url: "https://github.com/xtool-org/zsign", .upToNextMinor(from: "1.4.0")),
|
||||
|
||||
.package(url: "https://github.com/apple/swift-system", from: "1.4.0"),
|
||||
.package(url: "https://github.com/apple/swift-http-types", from: "1.3.1"),
|
||||
.package(url: "https://github.com/apple/swift-certificates", from: "1.0.0"),
|
||||
.package(url: "https://github.com/apple/swift-crypto", from: "3.9.1"),
|
||||
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
|
||||
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
|
||||
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.6.0"),
|
||||
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
|
||||
.package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
|
||||
.package(url: "https://github.com/apple/swift-nio", from: "2.77.0"),
|
||||
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
|
||||
|
||||
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.23.0"),
|
||||
.package(url: "https://github.com/swift-server/swift-openapi-async-http-client", from: "1.0.0"),
|
||||
.package(url: "https://github.com/vapor/websocket-kit.git", from: "2.15.0"),
|
||||
|
||||
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.3.0"),
|
||||
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.6.2"),
|
||||
|
||||
.package(url: "https://github.com/attaswift/BigInt", from: "5.5.0"),
|
||||
.package(url: "https://github.com/mxcl/Version", from: "2.1.0"),
|
||||
.package(url: "https://github.com/jpsim/Yams", from: "5.1.3"),
|
||||
.package(url: "https://github.com/saagarjha/unxip", from: "3.1.0"),
|
||||
|
||||
// TODO: just depend on tuist/XcodeProj instead
|
||||
.package(url: "https://github.com/yonaskolb/XcodeGen", from: "2.43.0"),
|
||||
],
|
||||
targets: [
|
||||
.systemLibrary(name: "CSupersette"),
|
||||
.systemLibrary(name: "XADI"),
|
||||
.target(
|
||||
name: "CSupersign",
|
||||
name: "CXKit",
|
||||
dependencies: [
|
||||
.product(name: "OpenSSL", package: "SuperchargeCore")
|
||||
.product(name: "OpenSSL", package: "xtool-core")
|
||||
],
|
||||
cSettings: cSettings
|
||||
),
|
||||
@@ -61,24 +71,27 @@ let package = Package(
|
||||
dependencies: [
|
||||
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
|
||||
],
|
||||
exclude: ["openapi-generator-config.yaml"]
|
||||
exclude: ["openapi-generator-config.yaml", "openapi-overlay.yaml"]
|
||||
),
|
||||
.target(
|
||||
name: "Supersign",
|
||||
name: "XKit",
|
||||
dependencies: [
|
||||
"DeveloperAPI",
|
||||
"CSupersign",
|
||||
.byName(name: "CSupersette", condition: .when(platforms: [.linux])),
|
||||
"CXKit",
|
||||
.byName(name: "XADI", condition: .when(platforms: [.linux])),
|
||||
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
|
||||
.product(name: "Dependencies", package: "swift-dependencies"),
|
||||
.product(name: "SwiftyMobileDevice", package: "SwiftyMobileDevice"),
|
||||
.product(name: "Zupersign", package: "zsign"),
|
||||
.product(name: "SignerSupport", package: "SuperchargeCore"),
|
||||
.product(name: "ProtoCodable", package: "SuperchargeCore"),
|
||||
.product(name: "Superutils", package: "SuperchargeCore"),
|
||||
.product(name: "SignerSupport", package: "xtool-core"),
|
||||
.product(name: "ProtoCodable", package: "xtool-core"),
|
||||
.product(name: "Superutils", package: "xtool-core"),
|
||||
.product(name: "Crypto", package: "swift-crypto"),
|
||||
.product(name: "_CryptoExtras", package: "swift-crypto"),
|
||||
.product(name: "X509", package: "swift-certificates"),
|
||||
.product(name: "BigInt", package: "BigInt"),
|
||||
.product(name: "HTTPTypes", package: "swift-http-types"),
|
||||
.product(name: "HTTPTypesFoundation", package: "swift-http-types"),
|
||||
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
|
||||
.product(
|
||||
name: "OpenAPIAsyncHTTPClient",
|
||||
@@ -99,10 +112,16 @@ let package = Package(
|
||||
cSettings: cSettings
|
||||
),
|
||||
.testTarget(
|
||||
name: "SupersignTests",
|
||||
name: "XToolTests",
|
||||
dependencies: [
|
||||
"Supersign",
|
||||
.product(name: "SuperutilsTestSupport", package: "SuperchargeCore")
|
||||
"XToolSupport",
|
||||
]
|
||||
),
|
||||
.testTarget(
|
||||
name: "XKitTests",
|
||||
dependencies: [
|
||||
"XKit",
|
||||
.product(name: "SuperutilsTestSupport", package: "xtool-core")
|
||||
],
|
||||
exclude: [
|
||||
"config/config-template.json",
|
||||
@@ -113,21 +132,32 @@ let package = Package(
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "SupersignCLISupport",
|
||||
name: "XToolSupport",
|
||||
dependencies: [
|
||||
"SwiftyMobileDevice",
|
||||
"Supersign",
|
||||
.product(name: "PackLib", package: "swiftpack"),
|
||||
.product(name: "ArgumentParser", package: "swift-argument-parser")
|
||||
"XKit",
|
||||
"PackLib",
|
||||
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
||||
.product(name: "SystemPackage", package: "swift-system"),
|
||||
.product(name: "NIOPosix", package: "swift-nio"),
|
||||
.product(name: "Version", package: "Version"),
|
||||
.product(name: "libunxip", package: "unxip"),
|
||||
],
|
||||
cSettings: cSettings
|
||||
),
|
||||
.target(
|
||||
name: "PackLib",
|
||||
dependencies: [
|
||||
.product(name: "Yams", package: "Yams"),
|
||||
.product(name: "XcodeGenKit", package: "XcodeGen", condition: .when(platforms: [.macOS])),
|
||||
]
|
||||
),
|
||||
.executableTarget(
|
||||
name: "SupersignCLI",
|
||||
name: "xtool",
|
||||
dependencies: [
|
||||
"SwiftyMobileDevice",
|
||||
"Supersign",
|
||||
"SupersignCLISupport",
|
||||
"XKit",
|
||||
"XToolSupport",
|
||||
],
|
||||
cSettings: cSettings
|
||||
),
|
||||
|
||||
@@ -1,43 +1,67 @@
|
||||
# Supersign
|
||||
# xtool
|
||||
|
||||
An all-in-one tool/library for sideloading iOS apps and talking to Apple Developer Services. Supports macOS and Linux.
|
||||
Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, and macOS.
|
||||
|
||||
## Prerequisites
|
||||
## Overview
|
||||
|
||||
- Supersign works out of the box on macOS.
|
||||
- On Linux, you'll need the development packages of [libimobiledevice](https://github.com/libimobiledevice/libimobiledevice) + its dependencies.
|
||||
- Alternatively, we provide a Dockerfile that does this for you. See [Linux/README.md](/Linux/README.md).
|
||||
xtool is a cross-platform (Linux/WSL/macOS) tool that replicates Xcode functionality with open standards.
|
||||
|
||||
## Installation (CLI)
|
||||
✅ Build a SwiftPM package into an iOS app
|
||||
|
||||
✅ Sign and install iOS apps
|
||||
|
||||
✅ Interact with Apple Developer Services programmatically
|
||||
|
||||
## Getting Started
|
||||
|
||||
1. Follow the guide to install `xtool`
|
||||
- [Installation (Linux/Windows)](https://swiftpackageindex.com/xtool-org/xtool/documentation/xtool/installation-linux)
|
||||
- [Installation (macOS)](https://swiftpackageindex.com/xtool-org/xtool/documentation/xtool/installation-macos)
|
||||
2. Create and run your first xtool-powered app by following the [tutorial](https://swiftpackageindex.com/xtool-org/xtool/tutorials/xtool/first-app)!
|
||||
|
||||
## Examples
|
||||
|
||||
### Screenshot
|
||||
|
||||

|
||||
|
||||
### Command line interface
|
||||
|
||||
```bash
|
||||
$ git clone https://github.com/SuperchargeApp/Supersign
|
||||
$ cd Supersign
|
||||
$ swift run SupersignCLI --help
|
||||
OVERVIEW: The Supersign command line tool
|
||||
$ xtool --help
|
||||
OVERVIEW: Cross-platform Xcode replacement
|
||||
|
||||
USAGE: supersign <subcommand>
|
||||
USAGE: xtool <subcommand>
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Show help information.
|
||||
|
||||
SUBCOMMANDS:
|
||||
CONFIGURATION SUBCOMMANDS:
|
||||
setup Set up xtool for iOS development
|
||||
auth Manage Apple Developer Services authentication
|
||||
sdk Manage the Darwin Swift SDK
|
||||
|
||||
DEVELOPMENT SUBCOMMANDS:
|
||||
new Create a new xtool SwiftPM project
|
||||
dev Build and run an xtool SwiftPM project
|
||||
ds Interact with Apple Developer Services
|
||||
|
||||
DEVICE SUBCOMMANDS:
|
||||
devices List devices
|
||||
install Install an ipa file to your device
|
||||
uninstall Uninstall an installed app
|
||||
run Run an installed app
|
||||
launch Launch an installed app
|
||||
|
||||
See 'supersign help <subcommand>' for detailed help.
|
||||
See 'xtool help <subcommand>' for detailed help.
|
||||
```
|
||||
|
||||
## Installation (Library)
|
||||
### Library
|
||||
|
||||
Just add it as a SwiftPM dependency!
|
||||
xtool includes a library that you can use to interact with Apple Developer Services, iOS devices, and more from your own app. You can use this by adding `XKit` as a SwiftPM dependency.
|
||||
|
||||
```swift
|
||||
// package dependency:
|
||||
.package(url: "https://github.com/SuperchargeApp/Supersign", .upToNextMinor(from: "1.2.0"))
|
||||
.package(url: "https://github.com/xtool-org/xtool", .upToNextMinor(from: "1.2.0"))
|
||||
// target dependency:
|
||||
.product(name: "Supersign", package: "Supersign")
|
||||
.product(name: "XKit", package: "xtool")
|
||||
```
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
module CSupersette [extern_c] {
|
||||
header "supersette.h"
|
||||
link "supersette"
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#include <stdint.h>
|
||||
|
||||
void supersette_Load(const char *path);
|
||||
int32_t supersette_SetAndroidID(const char *identifier, uint32_t length);
|
||||
int32_t supersette_SetProvisioningPath(const char *path);
|
||||
int32_t supersette_ProvisioningErase(uint64_t dsId);
|
||||
int32_t supersette_Synchronize(uint64_t dsId, const void *serverIntermediateMetadata, uint32_t serverIntermediateMetadataLength, void **machineIdentifier, uint32_t *machineIdentifierLength, void **synchronizationResumeMetadata, uint32_t *synchronizationResumeMetadataLength);
|
||||
int32_t supersette_ProvisioningDestroy(uint32_t session);
|
||||
int32_t supersette_ProvisioningEnd(uint32_t session, const void *persistentTokenMetadata, uint32_t persistentTokenMetadataLength, const void *trustKey, uint32_t trustKeyLength);
|
||||
int32_t supersette_ProvisioningStart(uint64_t dsId, const void *serverProvisioningIntermediateMetadata, uint32_t serverProvisioningIntermediateMetadataLength, void **clientProvisioningIntermediateMetadata, uint32_t *clientProvisioningIntermediateMetadataLength, uint32_t *session);
|
||||
int32_t supersette_GetLoginCode(uint64_t dsId);
|
||||
int32_t supersette_Dispose(void *ptr);
|
||||
int32_t supersette_OTPRequest(uint64_t dsId, void **machineIdentifier, uint32_t *machineIdentifierLength, void **oneTimePassword, uint32_t *oneTimePasswordLength);
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// mobileprovision_utils.h
|
||||
// supersign
|
||||
// XKit
|
||||
//
|
||||
// Created by Kabir Oberai on 05/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// mobileprovision_utils.c
|
||||
// supersign
|
||||
// XKit
|
||||
//
|
||||
// Created by Kabir Oberai on 05/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
File diff suppressed because it is too large
Load Diff
+7888
-7231
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,8 @@
|
||||
generate:
|
||||
- types
|
||||
- client
|
||||
accessModifier: package
|
||||
accessModifier: public
|
||||
namingStrategy: idiomatic
|
||||
filter:
|
||||
tags:
|
||||
- BundleIds
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
overlay: 1.0.0
|
||||
info:
|
||||
title: Overlay for App Store Connect API
|
||||
version: 1.0.0
|
||||
actions:
|
||||
- target: '$.components.schemas.BundleIdCapabilityCreateRequest.properties.data.properties.relationships'
|
||||
update:
|
||||
properties:
|
||||
capability:
|
||||
type: object
|
||||
properties:
|
||||
data:
|
||||
type: object
|
||||
properties:
|
||||
type:
|
||||
type: string
|
||||
enum: [capabilities]
|
||||
id:
|
||||
"$ref": "#/components/schemas/CapabilityType"
|
||||
required: [id, type]
|
||||
required: [data]
|
||||
required: [capability]
|
||||
- target: '$.components.schemas.Device.properties.attributes.properties.deviceClass'
|
||||
update:
|
||||
enum: ["APPLE_VISION_PRO"]
|
||||
@@ -0,0 +1,94 @@
|
||||
import Foundation
|
||||
|
||||
public struct BuildSettings: Sendable {
|
||||
private static let customBinDir =
|
||||
// this is the same option used by SwiftPM itself for dev builds
|
||||
ProcessInfo.processInfo.environment["SWIFTPM_CUSTOM_BIN_DIR"].map { URL(fileURLWithPath: $0) }
|
||||
|
||||
private static let envURL = URL(fileURLWithPath: "/usr/bin/env")
|
||||
|
||||
public let packagePath: String
|
||||
public let configuration: BuildConfiguration
|
||||
public let triple: String
|
||||
public let sdkOptions: [String]
|
||||
public let options: [String]
|
||||
|
||||
public init(
|
||||
configuration: BuildConfiguration,
|
||||
packagePath: String = ".",
|
||||
options: [String] = []
|
||||
) async throws {
|
||||
self.packagePath = packagePath
|
||||
self.configuration = configuration
|
||||
self.options = options
|
||||
|
||||
// TODO: allow customizing?
|
||||
self.triple = "arm64-apple-ios"
|
||||
|
||||
// on macOS we don't explicitly install a Swift SDK but
|
||||
// SwiftPM vends "implicit" Darwin SDKs as of Swift 6.1,
|
||||
// i.e. we can pass `--swift-sdk arm64-apple-ios` and it
|
||||
// just works. See:
|
||||
// https://github.com/swiftlang/swift-package-manager/pull/6828
|
||||
self.sdkOptions = ["--swift-sdk", triple]
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
private static func xcrun(_ arguments: [String]) async throws -> String {
|
||||
let xcrun = Process()
|
||||
let pipe = Pipe()
|
||||
xcrun.executableURL = URL(fileURLWithPath: "/usr/bin/xcrun")
|
||||
xcrun.arguments = arguments
|
||||
xcrun.standardOutput = pipe
|
||||
try await xcrun.runUntilExit()
|
||||
return String(decoding: pipe.fileHandleForReading.readDataToEndOfFile(), as: UTF8.self)
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
|
||||
private static let swiftURL = Task {
|
||||
try await URL(fileURLWithPath: xcrun(["-f", "swift"]))
|
||||
}
|
||||
#endif
|
||||
|
||||
public func swiftPMInvocation(
|
||||
forTool tool: String,
|
||||
arguments: [String],
|
||||
packagePathOverride: String? = nil
|
||||
) async throws -> Process {
|
||||
let process = Process()
|
||||
|
||||
let baseArguments: [String]
|
||||
if let customBinDir = Self.customBinDir {
|
||||
process.executableURL = customBinDir.appendingPathComponent("swift-\(tool)")
|
||||
baseArguments = []
|
||||
} else {
|
||||
#if os(macOS)
|
||||
// xcrun/libxcrun (via the /usr/bin/swift trampoline) is very trigger-happy
|
||||
// to add SDKROOT=.../MacOSX.sdk to our invocations. We avoid this by
|
||||
// 1) invoking the real swift executable (located with `xcrun -f`) and
|
||||
// 2) explicitly removing SDKROOT from the env, as it may be inherited
|
||||
// through the `swift run pack` invocation.
|
||||
process.executableURL = try await Self.swiftURL.value
|
||||
#else
|
||||
process.executableURL = try await ToolRegistry.locate("swift")
|
||||
#endif
|
||||
baseArguments = [tool]
|
||||
}
|
||||
|
||||
let extraArguments: [String] = [
|
||||
"--package-path", packagePathOverride ?? packagePath,
|
||||
"--configuration", configuration.rawValue,
|
||||
]
|
||||
|
||||
var env = ProcessInfo.processInfo.environment
|
||||
env.removeValue(forKey: "SDKROOT")
|
||||
process.environment = env
|
||||
process.arguments = baseArguments + extraArguments + sdkOptions + options + arguments
|
||||
return process
|
||||
}
|
||||
}
|
||||
|
||||
public enum BuildConfiguration: String, CaseIterable, Sendable {
|
||||
case debug
|
||||
case release
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import Foundation
|
||||
|
||||
package struct TemporaryDirectory: ~Copyable {
|
||||
private var shouldDelete = true
|
||||
|
||||
package let url: URL
|
||||
|
||||
package init(name: String) throws {
|
||||
self.url = FileManager.default.temporaryDirectory.appendingPathComponent(name, isDirectory: true)
|
||||
_delete()
|
||||
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
|
||||
}
|
||||
|
||||
private func _delete() {
|
||||
try? FileManager.default.removeItem(at: url)
|
||||
}
|
||||
|
||||
package consuming func persist() -> URL {
|
||||
shouldDelete = false
|
||||
return url
|
||||
}
|
||||
|
||||
package consuming func persist(at location: URL) throws {
|
||||
try FileManager.default.moveItem(at: url, to: location)
|
||||
// we do this after moving, so that if the move fails we clean up
|
||||
shouldDelete = false
|
||||
}
|
||||
|
||||
deinit {
|
||||
if shouldDelete { _delete() }
|
||||
}
|
||||
}
|
||||
|
||||
extension Data {
|
||||
// AsyncBytes is Darwin-only :/
|
||||
|
||||
package init(reading fileHandle: FileHandle) async throws {
|
||||
#if canImport(Darwin)
|
||||
self = try await fileHandle.bytes.reduce(into: Data()) { $0.append($1) }
|
||||
#else
|
||||
self = try fileHandle.readToEnd() ?? Data()
|
||||
#endif
|
||||
}
|
||||
|
||||
package init(reading file: URL) async throws {
|
||||
#if canImport(Darwin)
|
||||
self = try await file.resourceBytes.reduce(into: Data()) { $0.append($1) }
|
||||
#else
|
||||
try self.init(contentsOf: file)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
package func stderrPrint(_ message: String, terminator: String = "\n") {
|
||||
try? FileHandle.standardError.write(contentsOf: Data("\(message)\(terminator)".utf8))
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import Foundation
|
||||
import Yams
|
||||
|
||||
public struct PackSchemaBase: Codable, Sendable {
|
||||
public enum Version: Int, Codable, Sendable {
|
||||
case v1 = 1
|
||||
}
|
||||
|
||||
public var version: Version
|
||||
|
||||
public var orgID: String?
|
||||
public var bundleID: String?
|
||||
|
||||
public var product: String?
|
||||
|
||||
public var infoPath: String?
|
||||
public var iconPath: String?
|
||||
public var resources: [String]?
|
||||
}
|
||||
|
||||
public struct PackSchema: Sendable {
|
||||
public enum IDSpecifier: Sendable {
|
||||
case orgID(String)
|
||||
case bundleID(String)
|
||||
|
||||
func formBundleID(product: String) -> String {
|
||||
switch self {
|
||||
case .orgID(let orgID): "\(orgID).\(product)"
|
||||
case .bundleID(let bundleID): bundleID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public let base: PackSchemaBase
|
||||
public let idSpecifier: IDSpecifier
|
||||
|
||||
public init(validating base: PackSchemaBase) throws {
|
||||
self.base = base
|
||||
|
||||
if base.version != .v1 {
|
||||
throw StringError("xtool.yml: Unsupported schema version: \(base.version.rawValue)")
|
||||
}
|
||||
|
||||
switch (base.bundleID, base.orgID) {
|
||||
case (let bundleID?, _):
|
||||
idSpecifier = .bundleID(bundleID)
|
||||
case (nil, let orgID?):
|
||||
idSpecifier = .orgID(orgID)
|
||||
case (nil, nil):
|
||||
throw StringError("xtool.yml: Must specify either orgID or bundleID")
|
||||
}
|
||||
|
||||
if let iconPath = base.iconPath {
|
||||
let ext = URL(fileURLWithPath: iconPath).pathExtension
|
||||
guard ext == "png" else {
|
||||
throw StringError("xtool.yml: iconPath should have a 'png' path extension. Got '\(ext)'.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static let `default` = try! PackSchema(validating: .init(
|
||||
version: .v1,
|
||||
orgID: "com.example"
|
||||
))
|
||||
|
||||
public init(url: URL) async throws {
|
||||
let data = try await Data(reading: url)
|
||||
let base = try YAMLDecoder().decode(PackSchemaBase.self, from: data)
|
||||
try self.init(validating: base)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
import Foundation
|
||||
|
||||
public struct Packer: Sendable {
|
||||
public let buildSettings: BuildSettings
|
||||
public let plan: Plan
|
||||
|
||||
public init(buildSettings: BuildSettings, plan: Plan) {
|
||||
self.plan = plan
|
||||
self.buildSettings = buildSettings
|
||||
}
|
||||
|
||||
private func build() async throws {
|
||||
let xtoolDir = URL(fileURLWithPath: "xtool")
|
||||
let packageDir = xtoolDir.appendingPathComponent(".xtool-tmp")
|
||||
try? FileManager.default.removeItem(at: packageDir)
|
||||
try FileManager.default.createDirectory(at: packageDir, withIntermediateDirectories: true)
|
||||
|
||||
let packageSwift = packageDir.appendingPathComponent("Package.swift")
|
||||
let contents = """
|
||||
// swift-tools-version: 6.0
|
||||
import PackageDescription
|
||||
let package = Package(
|
||||
name: "\(plan.product)-Builder",
|
||||
platforms: [
|
||||
.iOS("\(plan.deploymentTarget)"),
|
||||
],
|
||||
dependencies: [
|
||||
.package(name: "RootPackage", path: "../.."),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "\(plan.product)-App",
|
||||
dependencies: [
|
||||
.product(name: "\(plan.product)", package: "RootPackage"),
|
||||
]
|
||||
),
|
||||
]
|
||||
)\n
|
||||
"""
|
||||
try Data(contents.utf8).write(to: packageSwift)
|
||||
let sources = packageDir.appendingPathComponent("Sources")
|
||||
try? FileManager.default.createDirectory(at: sources, withIntermediateDirectories: true)
|
||||
try Data().write(to: sources.appendingPathComponent("stub.c"))
|
||||
|
||||
let builder = try await buildSettings.swiftPMInvocation(
|
||||
forTool: "build",
|
||||
arguments: [
|
||||
"--package-path", packageDir.path,
|
||||
"--scratch-path", ".build",
|
||||
"--product", "\(plan.product)-App",
|
||||
// resolving can cause SwiftPM to overwrite the root package deps
|
||||
// with just the deps needed for the builder package (which is to
|
||||
// say, any "dev dependencies" of the root package may be removed.)
|
||||
// fortunately we've already resolved the root package by this point
|
||||
// in order to dump the plan, so we can skip resolution here to skirt
|
||||
// the issue.
|
||||
"--disable-automatic-resolution",
|
||||
"-Xlinker", "-rpath", "-Xlinker", "@executable_path/Frameworks",
|
||||
]
|
||||
)
|
||||
builder.standardOutput = FileHandle.standardError
|
||||
try await builder.runUntilExit()
|
||||
}
|
||||
|
||||
public func pack() async throws -> URL {
|
||||
try await build()
|
||||
|
||||
let output = try TemporaryDirectory(name: "\(plan.product).app")
|
||||
|
||||
let binDir = URL(
|
||||
fileURLWithPath: ".build/\(buildSettings.triple)/\(buildSettings.configuration.rawValue)",
|
||||
isDirectory: true
|
||||
)
|
||||
|
||||
let outputURL = output.url
|
||||
|
||||
@Sendable func packFileToRoot(srcName: String) async throws {
|
||||
let srcURL = URL(fileURLWithPath: srcName)
|
||||
let destURL = outputURL.appendingPathComponent(srcURL.lastPathComponent)
|
||||
try FileManager.default.copyItem(at: srcURL, to: destURL)
|
||||
|
||||
try Task.checkCancellation()
|
||||
}
|
||||
|
||||
@Sendable func packFile(srcName: String, dstName: String? = nil, sign: Bool = false) async throws {
|
||||
let srcURL = URL(fileURLWithPath: srcName, relativeTo: binDir)
|
||||
let dstURL = URL(fileURLWithPath: dstName ?? srcURL.lastPathComponent, relativeTo: outputURL)
|
||||
try? FileManager.default.createDirectory(at: dstURL.deletingLastPathComponent(), withIntermediateDirectories: true)
|
||||
try FileManager.default.copyItem(at: srcURL, to: dstURL)
|
||||
|
||||
try Task.checkCancellation()
|
||||
}
|
||||
|
||||
try await withThrowingTaskGroup(of: Void.self) { group in
|
||||
for command in plan.resources {
|
||||
group.addTask {
|
||||
switch command {
|
||||
case .bundle(let package, let target):
|
||||
try await packFile(srcName: "\(package)_\(target).bundle")
|
||||
case .binaryTarget(let name):
|
||||
let src = URL(fileURLWithPath: "\(name).framework/\(name)", relativeTo: binDir)
|
||||
let magic = Data("!<arch>\n".utf8)
|
||||
let thinMagic = Data("!<thin>\n".utf8)
|
||||
let bytes = try FileHandle(forReadingFrom: src).read(upToCount: magic.count)
|
||||
// if the magic matches one of these it's a static archive; don't embed it.
|
||||
// https://github.com/apple/llvm-project/blob/e716ff14c46490d2da6b240806c04e2beef01f40/llvm/include/llvm/Object/Archive.h#L33
|
||||
if bytes != magic && bytes != thinMagic {
|
||||
try await packFile(srcName: "\(name).framework", dstName: "Frameworks/\(name).framework", sign: true)
|
||||
}
|
||||
case .library(let name):
|
||||
try await packFile(srcName: "lib\(name).dylib", dstName: "Frameworks/lib\(name).dylib", sign: true)
|
||||
case .root(let source):
|
||||
try await packFileToRoot(srcName: source)
|
||||
}
|
||||
}
|
||||
}
|
||||
if let iconPath = plan.iconPath {
|
||||
group.addTask {
|
||||
try await packFileToRoot(srcName: iconPath)
|
||||
}
|
||||
}
|
||||
group.addTask {
|
||||
try await packFile(srcName: "\(plan.product)-App", dstName: plan.product)
|
||||
}
|
||||
group.addTask {
|
||||
var info = plan.infoPlist
|
||||
|
||||
if let iconPath = plan.iconPath {
|
||||
let iconName = URL(fileURLWithPath: iconPath).deletingPathExtension().lastPathComponent
|
||||
info["CFBundleIconFile"] = iconName
|
||||
}
|
||||
|
||||
let infoPath = outputURL.appendingPathComponent("Info.plist")
|
||||
let encodedPlist = try PropertyListSerialization.data(
|
||||
fromPropertyList: info,
|
||||
format: .xml,
|
||||
options: 0
|
||||
)
|
||||
try encodedPlist.write(to: infoPath)
|
||||
}
|
||||
while !group.isEmpty {
|
||||
do {
|
||||
try await group.next()
|
||||
} catch is CancellationError {
|
||||
// continue
|
||||
} catch {
|
||||
group.cancelAll()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let dest = URL(fileURLWithPath: "xtool")
|
||||
.appendingPathComponent(output.url.lastPathComponent)
|
||||
try? FileManager.default.removeItem(at: dest)
|
||||
try output.persist(at: dest)
|
||||
return dest
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
import Foundation
|
||||
|
||||
public struct Planner: Sendable {
|
||||
public var buildSettings: BuildSettings
|
||||
public var schema: PackSchema
|
||||
|
||||
public init(
|
||||
buildSettings: BuildSettings,
|
||||
schema: PackSchema
|
||||
) {
|
||||
self.buildSettings = buildSettings
|
||||
self.schema = schema
|
||||
}
|
||||
|
||||
private static let decoder: JSONDecoder = {
|
||||
let decoder = JSONDecoder()
|
||||
decoder.keyDecodingStrategy = .convertFromSnakeCase
|
||||
return decoder
|
||||
}()
|
||||
|
||||
public func createPlan() async throws -> Plan {
|
||||
// TODO: cache plan using (Package.swift+Package.resolved) as the key?
|
||||
|
||||
let dependencyData = try await _dumpAction(
|
||||
arguments: ["show-dependencies", "--format", "json"],
|
||||
path: buildSettings.packagePath
|
||||
)
|
||||
let dependencyRoot = try Self.decoder.decode(PackageDependency.self, from: dependencyData)
|
||||
|
||||
let packages = try await withThrowingTaskGroup(
|
||||
of: (PackageDependency, PackageDump).self,
|
||||
returning: [String: PackageDump].self
|
||||
) { group in
|
||||
var visited: Set<String> = []
|
||||
var dependencies: [PackageDependency] = [dependencyRoot]
|
||||
while let dependencyNode = dependencies.popLast() {
|
||||
guard visited.insert(dependencyNode.identity).inserted else { continue }
|
||||
dependencies.append(contentsOf: dependencyNode.dependencies)
|
||||
group.addTask { (dependencyNode, try await dumpPackage(at: dependencyNode.path)) }
|
||||
}
|
||||
|
||||
var packages: [String: PackageDump] = [:]
|
||||
while let result = await group.nextResult() {
|
||||
switch result {
|
||||
case .success((let dependency, let dump)):
|
||||
packages[dependency.identity] = dump
|
||||
case .failure(_ as CancellationError):
|
||||
// continue loop
|
||||
break
|
||||
case .failure(let error):
|
||||
group.cancelAll()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
return packages
|
||||
}
|
||||
|
||||
var packagesByProductName: [String: String] = [:]
|
||||
for (packageID, package) in packages {
|
||||
for product in package.products ?? [] {
|
||||
packagesByProductName[product.name] = packageID
|
||||
}
|
||||
}
|
||||
|
||||
let rootPackage = packages[dependencyRoot.identity]!
|
||||
let deploymentTarget = rootPackage.platforms?.first { $0.name == "ios" }?.version ?? "13.0"
|
||||
|
||||
let libraries = rootPackage.products?.filter { $0.type == .autoLibrary } ?? []
|
||||
|
||||
let library = try selectLibrary(
|
||||
from: libraries,
|
||||
matching: schema.base.product
|
||||
)
|
||||
|
||||
var resources: [Resource] = []
|
||||
var visited: Set<String> = []
|
||||
var targets = library.targets.map { (rootPackage, $0) }
|
||||
while let (targetPackage, targetName) = targets.popLast() {
|
||||
guard let target = targetPackage.targets?.first(where: { $0.name == targetName }) else {
|
||||
throw StringError("Could not find target '\(targetName)' in package '\(targetPackage.name)'")
|
||||
}
|
||||
guard visited.insert(targetName).inserted else { continue }
|
||||
if target.moduleType == "BinaryTarget" {
|
||||
resources.append(.binaryTarget(name: targetName))
|
||||
}
|
||||
if target.resources?.isEmpty == false {
|
||||
resources.append(.bundle(package: targetPackage.name, target: targetName))
|
||||
}
|
||||
for targetName in (target.targetDependencies ?? []) {
|
||||
targets.append((targetPackage, targetName))
|
||||
}
|
||||
for productName in (target.productDependencies ?? []) {
|
||||
guard let packageID = packagesByProductName[productName] else {
|
||||
throw StringError("Could not find package containing product '\(productName)'")
|
||||
}
|
||||
guard let package = packages[packageID] else {
|
||||
throw StringError("Could not find package by id '\(packageID)'")
|
||||
}
|
||||
guard let product = package.products?.first(where: { $0.name == productName }) else {
|
||||
throw StringError("Could not find product '\(productName)' in package '\(packageID)'")
|
||||
}
|
||||
if product.type == .dynamicLibrary {
|
||||
resources.append(.library(name: productName))
|
||||
}
|
||||
targets.append(contentsOf: product.targets.map { (package, $0) })
|
||||
}
|
||||
}
|
||||
|
||||
if let rootResources = schema.base.resources {
|
||||
resources += rootResources.map { .root(source: $0) }
|
||||
}
|
||||
|
||||
let bundleID = schema.idSpecifier.formBundleID(product: library.name)
|
||||
|
||||
var infoPlist: [String: Sendable] = [
|
||||
"CFBundleInfoDictionaryVersion": "6.0",
|
||||
"UIRequiredDeviceCapabilities": ["arm64"],
|
||||
"LSRequiresIPhoneOS": true,
|
||||
"CFBundleSupportedPlatforms": ["iPhoneOS"],
|
||||
"CFBundlePackageType": "APPL",
|
||||
"UIDeviceFamily": [1, 2],
|
||||
"CFBundleDevelopmentRegion": "en",
|
||||
"UISupportedInterfaceOrientations": ["UIInterfaceOrientationPortrait"],
|
||||
"UISupportedInterfaceOrientations~ipad": [
|
||||
"UIInterfaceOrientationPortrait",
|
||||
"UIInterfaceOrientationPortraitUpsideDown",
|
||||
"UIInterfaceOrientationLandscapeLeft",
|
||||
"UIInterfaceOrientationLandscapeRight"
|
||||
],
|
||||
"UILaunchScreen": [:] as [String: Sendable],
|
||||
"CFBundleVersion": "1",
|
||||
"CFBundleShortVersionString": "1.0.0",
|
||||
"MinimumOSVersion": deploymentTarget,
|
||||
"CFBundleIdentifier": bundleID,
|
||||
"CFBundleName": "\(library.name)",
|
||||
"CFBundleExecutable": "\(library.name)",
|
||||
]
|
||||
|
||||
if let plist = self.schema.base.infoPath {
|
||||
let data = try await Data(reading: URL(fileURLWithPath: plist))
|
||||
let info = try PropertyListSerialization.propertyList(from: data, format: nil)
|
||||
if let info = info as? [String: Sendable] {
|
||||
infoPlist.merge(info, uniquingKeysWith: { $1 })
|
||||
} else {
|
||||
throw StringError("Info.plist has invalid format: expected a dictionary.")
|
||||
}
|
||||
}
|
||||
|
||||
return Plan(
|
||||
product: library.name,
|
||||
deploymentTarget: deploymentTarget,
|
||||
bundleID: bundleID,
|
||||
infoPlist: infoPlist,
|
||||
resources: resources,
|
||||
iconPath: self.schema.base.iconPath
|
||||
)
|
||||
}
|
||||
|
||||
private func dumpPackage(at path: String) async throws -> PackageDump {
|
||||
let data = try await _dumpAction(arguments: ["describe", "--type", "json"], path: path)
|
||||
try Task.checkCancellation()
|
||||
return try Self.decoder.decode(PackageDump.self, from: data)
|
||||
}
|
||||
|
||||
private func _dumpAction(arguments: [String], path: String) async throws -> Data {
|
||||
let dump = try await buildSettings.swiftPMInvocation(
|
||||
forTool: "package",
|
||||
arguments: arguments,
|
||||
packagePathOverride: path
|
||||
)
|
||||
let pipe = Pipe()
|
||||
dump.standardOutput = pipe
|
||||
async let task = Data(reading: pipe.fileHandleForReading)
|
||||
try await dump.runUntilExit()
|
||||
return try await task
|
||||
}
|
||||
|
||||
private func selectLibrary(
|
||||
from products: [PackageDump.Product],
|
||||
matching name: String?
|
||||
) throws -> PackageDump.Product {
|
||||
switch products.count {
|
||||
case 0:
|
||||
throw StringError("No library products were found in the package")
|
||||
case 1:
|
||||
let product = products[0]
|
||||
if let name, product.name != name {
|
||||
throw StringError("""
|
||||
Product name ('\(product.name)') does not match the 'product' value in the schema ('\(name)')
|
||||
""")
|
||||
}
|
||||
return product
|
||||
default:
|
||||
guard let name else {
|
||||
throw StringError("""
|
||||
Multiple library products were found (\(products.map(\.name))). Please either:
|
||||
1) Expose exactly one library product, or
|
||||
2) Specify the product you want via the 'product' key in xtool.yml.
|
||||
""")
|
||||
}
|
||||
guard let product = products.first(where: { $0.name == name }) else {
|
||||
throw StringError("""
|
||||
Schema declares a 'product' name of '\(name)' but no matching product was found.
|
||||
Found: \(products.map(\.name)).
|
||||
""")
|
||||
}
|
||||
return product
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct Plan: Sendable {
|
||||
public var product: String
|
||||
public var deploymentTarget: String
|
||||
public var bundleID: String
|
||||
public var infoPlist: [String: any Sendable]
|
||||
public var resources: [Resource]
|
||||
public var iconPath: String?
|
||||
}
|
||||
|
||||
public enum Resource: Codable, Sendable {
|
||||
case bundle(package: String, target: String)
|
||||
case binaryTarget(name: String)
|
||||
case library(name: String)
|
||||
case root(source: String)
|
||||
}
|
||||
|
||||
private struct PackageDependency: Decodable {
|
||||
let identity: String
|
||||
let name: String
|
||||
let path: String // on disk
|
||||
let dependencies: [PackageDependency]
|
||||
}
|
||||
|
||||
private struct PackageDump: Decodable {
|
||||
enum ProductType: Decodable {
|
||||
case executable
|
||||
case dynamicLibrary
|
||||
case staticLibrary
|
||||
case autoLibrary
|
||||
case other
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case executable
|
||||
case library
|
||||
}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
if container.contains(.executable) {
|
||||
self = .executable
|
||||
} else if let library = try container.decodeIfPresent([String].self, forKey: .library) {
|
||||
if library.count == 1 {
|
||||
switch library[0] {
|
||||
case "dynamic":
|
||||
self = .dynamicLibrary
|
||||
case "static":
|
||||
self = .staticLibrary
|
||||
case "automatic":
|
||||
self = .autoLibrary
|
||||
default:
|
||||
self = .other
|
||||
}
|
||||
} else {
|
||||
self = .other
|
||||
}
|
||||
} else {
|
||||
self = .other
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Product: Decodable {
|
||||
let name: String
|
||||
let targets: [String]
|
||||
let type: ProductType
|
||||
}
|
||||
|
||||
struct Target: Decodable {
|
||||
let name: String
|
||||
let moduleType: String
|
||||
let productDependencies: [String]?
|
||||
let targetDependencies: [String]?
|
||||
let resources: [Resource]?
|
||||
}
|
||||
|
||||
struct Resource: Decodable {
|
||||
let path: String
|
||||
}
|
||||
|
||||
struct Platform: Decodable {
|
||||
let name: String
|
||||
let version: String
|
||||
}
|
||||
|
||||
let name: String
|
||||
let products: [Product]?
|
||||
let targets: [Target]?
|
||||
let platforms: [Platform]?
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import Foundation
|
||||
|
||||
extension Process {
|
||||
/// Launches the process and suspends until the receiver is finished.
|
||||
///
|
||||
/// - Parameter onCancel: The action to take if the current
|
||||
/// task is cancelled.
|
||||
public func runUntilExit(onCancel: TaskCancelAction = .interrupt) async throws {
|
||||
try Task.checkCancellation()
|
||||
|
||||
let (terminationStream, terminationContinuation) = AsyncStream<Never>.makeStream()
|
||||
terminationHandler = { _ in
|
||||
terminationContinuation.finish()
|
||||
}
|
||||
|
||||
do {
|
||||
try run()
|
||||
} catch {
|
||||
terminationContinuation.finish()
|
||||
throw error
|
||||
}
|
||||
|
||||
await withTaskCancellationHandler {
|
||||
for await _ in terminationStream {}
|
||||
} onCancel: {
|
||||
switch onCancel {
|
||||
case .interrupt:
|
||||
interrupt()
|
||||
case .terminate:
|
||||
terminate()
|
||||
case .ignore:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
try Task.checkCancellation()
|
||||
|
||||
switch terminationReason {
|
||||
case .exit where terminationStatus == 0:
|
||||
break
|
||||
case .exit:
|
||||
throw Failure.exit(terminationStatus)
|
||||
case .uncaughtSignal:
|
||||
throw Failure.uncaughtSignal(terminationStatus)
|
||||
@unknown default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
public enum Failure: Error {
|
||||
case exit(CInt)
|
||||
case uncaughtSignal(CInt)
|
||||
}
|
||||
|
||||
public enum TaskCancelAction: Sendable {
|
||||
/// Sends `SIGINT` to the process.
|
||||
case interrupt
|
||||
/// Sends `SIGTERM` to the process.
|
||||
case terminate
|
||||
/// Don't participate in cooperative cancellation.
|
||||
case ignore
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package struct StringError: Error, CustomStringConvertible {
|
||||
package var description: String
|
||||
package init(_ description: String) {
|
||||
self.description = description
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import Foundation
|
||||
|
||||
package enum ToolRegistry {
|
||||
package enum Errors: Error, CustomStringConvertible {
|
||||
case toolNotFound(String)
|
||||
|
||||
package var description: String {
|
||||
switch self {
|
||||
case .toolNotFound(let tool):
|
||||
"Could not find executable '\(tool)' in PATH"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static let cache = Cache()
|
||||
|
||||
/// Obtain the full path to a tool in the user's `PATH`.
|
||||
///
|
||||
/// This effectively invokes `/bin/sh -c "command -v '$tool'"`.
|
||||
///
|
||||
/// - Warning: Make sure you trust/sanitize the `tool` parameter. If it
|
||||
/// contains a single quote, it can be used in a shell escape.
|
||||
///
|
||||
/// - Throws: `Errors.toolNotFound` if the tool could not be located.
|
||||
package static func locate(_ tool: String) async throws -> URL {
|
||||
try await cache.locate(tool: tool)
|
||||
}
|
||||
|
||||
private actor Cache {
|
||||
private var cache: [String: Task<URL, Error>] = [:]
|
||||
|
||||
private func _locate(tool: String) async throws -> URL {
|
||||
let pipe = Pipe()
|
||||
let proc = Process()
|
||||
proc.executableURL = URL(fileURLWithPath: "/bin/sh")
|
||||
proc.arguments = ["-c", "command -v '\(tool)'"]
|
||||
proc.standardOutput = pipe
|
||||
async let bytes = pipe.fileHandleForReading.readToEnd()
|
||||
do {
|
||||
try await proc.runUntilExit()
|
||||
} catch is Process.Failure {
|
||||
throw Errors.toolNotFound(tool)
|
||||
}
|
||||
let path = String(decoding: try await bytes ?? Data(), as: UTF8.self)
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
return URL(fileURLWithPath: path)
|
||||
}
|
||||
|
||||
func locate(tool: String) async throws -> URL {
|
||||
let task: Task<URL, Error>
|
||||
if let cached = cache[tool] {
|
||||
task = cached
|
||||
} else {
|
||||
task = Task { try await _locate(tool: tool) }
|
||||
cache[tool] = task
|
||||
}
|
||||
|
||||
return try await task.value
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
#if os(macOS)
|
||||
import Foundation
|
||||
import PathKit
|
||||
import Version
|
||||
import ProjectSpec
|
||||
import XcodeGenKit
|
||||
import XcodeProj
|
||||
|
||||
public struct XcodePacker {
|
||||
public var plan: Plan
|
||||
|
||||
public init(plan: Plan) {
|
||||
self.plan = plan
|
||||
}
|
||||
|
||||
public func createProject() async throws -> URL {
|
||||
let targetName = "\(plan.product)-App"
|
||||
|
||||
let xtoolDir: Path = "xtool"
|
||||
|
||||
let projectDir: Path = xtoolDir + ".xtool-tmp"
|
||||
try? xtoolDir.delete()
|
||||
try projectDir.mkpath()
|
||||
|
||||
let infoPath = projectDir + "Info.plist"
|
||||
|
||||
var plist = plan.infoPlist
|
||||
let families = (plist.removeValue(forKey: "UIDeviceFamily") as? [Int]) ?? [1, 2]
|
||||
plist["CFBundleExecutable"] = targetName
|
||||
plist["CFBundleName"] = targetName
|
||||
plist["CFBundleDisplayName"] = plan.product
|
||||
|
||||
let encodedPlist = try PropertyListSerialization.data(fromPropertyList: plist, format: .xml, options: 0)
|
||||
try infoPath.write(encodedPlist)
|
||||
|
||||
let emptyFile = projectDir + "empty.c"
|
||||
try emptyFile.write(Data("// leave this file empty".utf8))
|
||||
|
||||
let fromProjectToRoot = try Path(".").relativePath(from: projectDir)
|
||||
|
||||
guard let deploymentTarget = Version(tolerant: plan.deploymentTarget) else {
|
||||
throw StringError("Could not parse deployment target '\(plan.deploymentTarget)'")
|
||||
}
|
||||
|
||||
let project = Project(
|
||||
name: plan.product,
|
||||
targets: [
|
||||
Target(
|
||||
name: targetName,
|
||||
type: .application,
|
||||
platform: .iOS,
|
||||
deploymentTarget: deploymentTarget,
|
||||
settings: Settings(buildSettings: [
|
||||
"PRODUCT_BUNDLE_IDENTIFIER": plan.bundleID,
|
||||
"TARGETED_DEVICE_FAMILY": families.map { "\($0)" }.joined(separator: ","),
|
||||
]),
|
||||
sources: [
|
||||
TargetSource(path: (fromProjectToRoot + emptyFile).string),
|
||||
],
|
||||
dependencies: [
|
||||
Dependency(
|
||||
type: .package(products: [plan.product]),
|
||||
reference: "RootPackage"
|
||||
),
|
||||
],
|
||||
info: Plist(
|
||||
path: (fromProjectToRoot + infoPath).string,
|
||||
attributes: [:]
|
||||
)
|
||||
)
|
||||
],
|
||||
packages: [
|
||||
"RootPackage": .local(
|
||||
path: fromProjectToRoot.string,
|
||||
group: nil,
|
||||
excludeFromProject: false
|
||||
),
|
||||
],
|
||||
options: SpecOptions(
|
||||
localPackagesGroup: ""
|
||||
)
|
||||
)
|
||||
|
||||
// TODO: Handle plan.resources of type .root
|
||||
// TODO: Handle plan.iconPath
|
||||
|
||||
let generator = ProjectGenerator(project: project)
|
||||
let xcodeproj = projectDir + "\(plan.product).xcodeproj"
|
||||
let xcworkspace = xtoolDir + "\(plan.product).xcworkspace"
|
||||
do {
|
||||
let current = Path.current
|
||||
Path.current = xcodeproj.parent()
|
||||
defer { Path.current = current }
|
||||
let xcodeProject = try generator.generateXcodeProject(userName: NSUserName())
|
||||
if let packageRef = xcodeProject.pbxproj.fileReferences.first(where: { $0.name == ".." }) {
|
||||
for group in xcodeProject.pbxproj.groups {
|
||||
group.children.removeAll(where: { $0.uuid == packageRef.uuid })
|
||||
}
|
||||
xcodeProject.pbxproj.delete(object: packageRef)
|
||||
}
|
||||
|
||||
if let emptyFileRef = xcodeProject.pbxproj.fileReferences.first(where: { $0.path == "empty.c" }),
|
||||
let existingGroup = xcodeProject.pbxproj.groups.first(where: {
|
||||
$0.children.contains { $0.uuid == emptyFileRef.uuid }
|
||||
}),
|
||||
let existingGroupGroup = xcodeProject.pbxproj.groups.first(where: {
|
||||
$0.children.contains { $0.uuid == existingGroup.uuid }
|
||||
}) {
|
||||
existingGroupGroup.children.removeAll(where: { $0.uuid == existingGroup.uuid })
|
||||
existingGroupGroup.children.insert(emptyFileRef, at: 0)
|
||||
xcodeProject.pbxproj.delete(object: existingGroup)
|
||||
}
|
||||
|
||||
try xcodeProject.write(path: Path(xcodeproj.lastComponent))
|
||||
}
|
||||
|
||||
do {
|
||||
let current = Path.current
|
||||
Path.current = xcworkspace.parent()
|
||||
defer { Path.current = current }
|
||||
|
||||
let xcworkspaceDirectory = xcworkspace.parent()
|
||||
let fromWorkspaceToSelf = try Path(".").relativePath(from: xcworkspaceDirectory).withName()
|
||||
let fromWorkspaceToProject = try xcodeproj.relativePath(from: xcworkspaceDirectory).withName()
|
||||
let workspace = XCWorkspace(data: .init(children: [
|
||||
.file(.init(location: .container(fromWorkspaceToSelf.string))),
|
||||
.file(.init(location: .group(fromWorkspaceToProject.string))),
|
||||
]))
|
||||
try workspace.write(path: Path(xcworkspace.lastComponent))
|
||||
}
|
||||
|
||||
return xcworkspace.url
|
||||
}
|
||||
}
|
||||
|
||||
extension Path {
|
||||
fileprivate func withName() -> Path {
|
||||
// eg if curr dir is Foo, this converts "." to "../Foo"
|
||||
// which includes the name in the path, and therefore
|
||||
// in the Xcode navigator
|
||||
self.parent() + self.absolute().lastComponent
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,66 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesAddAppIDRequest.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 24/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesAddAppIDRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable, Sendable {
|
||||
let appId: DeveloperServicesAppID
|
||||
}
|
||||
public typealias Value = DeveloperServicesAppID
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let teamID: DeveloperServicesTeam.ID
|
||||
public let bundleID: String
|
||||
public let appName: String
|
||||
public let entitlements: Entitlements
|
||||
public let additionalFeatures: [DeveloperServicesFeature]
|
||||
public let isFree: Bool
|
||||
|
||||
var subAction: String { return "addAppId" }
|
||||
var subParameters: [String: Any] {
|
||||
var parameters: [String: Any] = [
|
||||
"teamId": teamID.rawValue,
|
||||
"identifier": bundleID,
|
||||
"name": appName
|
||||
]
|
||||
|
||||
DeveloperServicesAppIDRequestApplier.apply(
|
||||
entitlements: entitlements,
|
||||
additionalFeatures: additionalFeatures,
|
||||
to: ¶meters,
|
||||
isFree: isFree
|
||||
)
|
||||
|
||||
return parameters
|
||||
}
|
||||
|
||||
public func parse(_ response: Response) -> DeveloperServicesAppID {
|
||||
response.appId
|
||||
}
|
||||
|
||||
public init(
|
||||
platform: DeveloperServicesPlatform,
|
||||
teamID: DeveloperServicesTeam.ID,
|
||||
bundleID: String,
|
||||
appName: String,
|
||||
entitlements: Entitlements,
|
||||
additionalFeatures: [DeveloperServicesFeature],
|
||||
isFree: Bool
|
||||
) {
|
||||
self.platform = platform
|
||||
self.teamID = teamID
|
||||
self.bundleID = bundleID
|
||||
self.appName = appName
|
||||
self.entitlements = entitlements
|
||||
self.additionalFeatures = additionalFeatures
|
||||
self.isFree = isFree
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,192 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesAddAppOperation.swift
|
||||
// Supersign
|
||||
//
|
||||
// Created by Kabir Oberai on 14/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
|
||||
|
||||
public enum Error: LocalizedError {
|
||||
case invalidApp(URL)
|
||||
case teamNotFound(DeveloperServicesTeam.ID)
|
||||
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .invalidApp(let url):
|
||||
return url.path.withCString {
|
||||
String.localizedStringWithFormat(
|
||||
NSLocalizedString(
|
||||
"add_app_operation.error.invalid_app", value: "Invalid app: %s", comment: ""
|
||||
), $0
|
||||
)
|
||||
}
|
||||
case .teamNotFound(let id):
|
||||
return id.rawValue.withCString {
|
||||
String.localizedStringWithFormat(
|
||||
NSLocalizedString(
|
||||
"add_app_operation.error.team_not_found",
|
||||
value: "A team with the ID '%s' could not be found. Please select another team.",
|
||||
comment: ""
|
||||
), $0
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public let context: SigningContext
|
||||
public let root: URL
|
||||
public init(context: SigningContext, root: URL) {
|
||||
self.context = context
|
||||
self.root = root
|
||||
}
|
||||
|
||||
/// Registers the app with the given entitlements
|
||||
private func upsertApp(
|
||||
bundleID: String,
|
||||
entitlements: Entitlements,
|
||||
team: DeveloperServicesTeam,
|
||||
appIDs: [String: DeveloperServicesAppID]
|
||||
) async throws -> DeveloperServicesAppID {
|
||||
if let appID = appIDs[bundleID] {
|
||||
let request = DeveloperServicesUpdateAppIDRequest(
|
||||
platform: self.context.platform,
|
||||
teamID: self.context.teamID,
|
||||
appIDID: appID.id,
|
||||
entitlements: entitlements,
|
||||
additionalFeatures: [],
|
||||
isFree: team.isFree
|
||||
)
|
||||
return try await context.client.send(request)
|
||||
} else {
|
||||
let newBundleID = ProvisioningIdentifiers.identifier(fromSanitized: bundleID, context: self.context)
|
||||
let name = ProvisioningIdentifiers.appName(fromSanitized: bundleID)
|
||||
let request = DeveloperServicesAddAppIDRequest(
|
||||
platform: self.context.platform,
|
||||
teamID: self.context.teamID,
|
||||
bundleID: newBundleID,
|
||||
appName: name,
|
||||
entitlements: entitlements,
|
||||
additionalFeatures: [],
|
||||
isFree: team.isFree
|
||||
)
|
||||
return try await context.client.send(request)
|
||||
}
|
||||
}
|
||||
|
||||
/// Registers the app and creates a profile. Returns the resultant entitlements as well as
|
||||
/// the profile (note that the profile does not necessarily include all of the entitlements
|
||||
/// that the app has).
|
||||
private func addApp(
|
||||
_ app: URL,
|
||||
team: DeveloperServicesTeam,
|
||||
appIDs: [String: DeveloperServicesAppID]
|
||||
) async throws -> ProvisioningInfo {
|
||||
let infoURL = app.appendingPathComponent("Info.plist")
|
||||
guard let data = try? Data(contentsOf: infoURL),
|
||||
let dict = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any],
|
||||
let bundleID = dict["CFBundleIdentifier"] as? String,
|
||||
let executable = dict["CFBundleExecutable"] as? String else {
|
||||
throw Error.invalidApp(app)
|
||||
}
|
||||
let executableURL = app.appendingPathComponent(executable)
|
||||
|
||||
var entitlements: Entitlements
|
||||
// if the executable doesn't already have entitlements, that's
|
||||
// okay. We don't have to throw an error.
|
||||
if let entitlementsData = try? await context.signerImpl.analyze(executable: executableURL),
|
||||
let decodedEntitlements = try? PropertyListDecoder().decode(Entitlements.self, from: entitlementsData) {
|
||||
entitlements = decodedEntitlements
|
||||
|
||||
if team.isFree {
|
||||
// re-assign rather than using updateEntitlements since the latter will
|
||||
// retain unrecognized entitlements
|
||||
let filtered = try entitlements.entitlements().filter { type(of: $0).isFree }
|
||||
entitlements = try Entitlements(entitlements: filtered)
|
||||
}
|
||||
} else {
|
||||
entitlements = try Entitlements(entitlements: [])
|
||||
}
|
||||
|
||||
let appID = try await upsertApp(bundleID: bundleID, entitlements: entitlements, team: team, appIDs: appIDs)
|
||||
|
||||
try entitlements.update(teamID: self.context.teamID, bundleID: appID.bundleID)
|
||||
// set get-task-allow to YES, required for dev certs
|
||||
try entitlements.updateEntitlements { ents in
|
||||
if let getTaskAllow = ents.firstIndex(where: { $0 is GetTaskAllowEntitlement }) {
|
||||
ents[getTaskAllow] = GetTaskAllowEntitlement(rawValue: true)
|
||||
} else {
|
||||
ents.append(GetTaskAllowEntitlement(rawValue: true))
|
||||
}
|
||||
}
|
||||
|
||||
if var entitlementsArray = try? entitlements.entitlements(),
|
||||
let groupsIdx = entitlementsArray.firstIndex(where: { $0 is AppGroupEntitlement }),
|
||||
let groupsEntitlement = entitlementsArray[groupsIdx] as? AppGroupEntitlement {
|
||||
let groups = groupsEntitlement.rawValue
|
||||
|
||||
let newGroups = try await DeveloperServicesAssignAppGroupsOperation(
|
||||
context: self.context,
|
||||
groupIDs: groups,
|
||||
appID: appID
|
||||
).perform()
|
||||
|
||||
entitlementsArray[groupsIdx] = AppGroupEntitlement(rawValue: newGroups)
|
||||
try entitlements.setEntitlements(entitlementsArray)
|
||||
}
|
||||
|
||||
let profile = try await DeveloperServicesFetchProfileOperation(context: self.context, appID: appID).perform()
|
||||
guard let mobileprovision = profile.mobileprovision
|
||||
else { throw Mobileprovision.Error.invalidProfile }
|
||||
return ProvisioningInfo(
|
||||
newBundleID: appID.bundleID, entitlements: entitlements, mobileprovision: mobileprovision
|
||||
)
|
||||
}
|
||||
|
||||
private func getTeam() async throws -> DeveloperServicesTeam {
|
||||
let request = DeveloperServicesListTeamsRequest()
|
||||
let teams = try await context.client.send(request)
|
||||
guard let team = teams.first(where: { $0.id == self.context.teamID })
|
||||
else { throw Error.teamNotFound(self.context.teamID) }
|
||||
return team
|
||||
}
|
||||
|
||||
// keyed by sanitized bundle ID
|
||||
private func getCurrentAppIDs() async throws -> [String: DeveloperServicesAppID] {
|
||||
let request = DeveloperServicesListAppIDsRequest(platform: context.platform, teamID: context.teamID)
|
||||
let appIDs = try await context.client.send(request)
|
||||
let keyedIDs = appIDs.map { (ProvisioningIdentifiers.sanitize(identifier: $0.bundleID), $0) }
|
||||
return Dictionary(keyedIDs, uniquingKeysWith: { $1 })
|
||||
}
|
||||
|
||||
/// Registers the app + its extensions, returning the profile and entitlements of each
|
||||
public func perform() async throws -> [URL: ProvisioningInfo] {
|
||||
var apps: [URL] = [root]
|
||||
let plugins = root.appendingPathComponent("PlugIns")
|
||||
if plugins.dirExists {
|
||||
apps += plugins.implicitContents.filter { $0.pathExtension.lowercased() == "appex" }
|
||||
}
|
||||
|
||||
async let teamTask = getTeam()
|
||||
async let appIDsTask = getCurrentAppIDs()
|
||||
let (team, appIDs) = try await (teamTask, appIDsTask)
|
||||
|
||||
return try await withThrowingTaskGroup(
|
||||
of: (URL, ProvisioningInfo).self,
|
||||
returning: [URL: ProvisioningInfo].self
|
||||
) { group in
|
||||
for app in apps {
|
||||
group.addTask {
|
||||
let info = try await addApp(app, team: team, appIDs: appIDs)
|
||||
return (app, info)
|
||||
}
|
||||
}
|
||||
return try await group.reduce(into: [:]) { $0[$1.0] = $1.1 }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
//
|
||||
// DeveloperServiceAppID.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 29/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ProtoCodable
|
||||
|
||||
public struct DeveloperServicesAppID: Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public let id: ID
|
||||
public let name: String
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let bundleID: String
|
||||
public let isWildCard: Bool
|
||||
|
||||
private let _features: DeveloperServicesFeatures
|
||||
public var features: [DeveloperServicesFeature] { return _features.values }
|
||||
|
||||
private let _enabledFeatures: [String]?
|
||||
public var enabledFeatures: [DeveloperServicesFeature.Type] {
|
||||
guard let enabledFeatures = _enabledFeatures else { return [] }
|
||||
return enabledFeatures.compactMap { identifier in
|
||||
let type = ProtoCodableIdentifierMapper.shared.type(
|
||||
for: identifier, in: DeveloperServicesFeatureContainer.self
|
||||
)
|
||||
return type as? DeveloperServicesFeature.Type
|
||||
}
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case id = "appIdId"
|
||||
case name
|
||||
case platform = "appIdPlatform"
|
||||
case bundleID = "identifier"
|
||||
case isWildCard
|
||||
case _features = "features"
|
||||
case _enabledFeatures = "enabledFeatures"
|
||||
}
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesAppIDRequestApplier.swift
|
||||
// Supersign
|
||||
//
|
||||
// Created by Kabir Oberai on 11/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum DeveloperServicesAppIDRequestApplier {
|
||||
|
||||
static func apply(
|
||||
entitlements: Entitlements, additionalFeatures: [DeveloperServicesFeature],
|
||||
to dict: inout [String: Any], isFree: Bool
|
||||
) {
|
||||
var entitlements = entitlements
|
||||
try? entitlements.updateEntitlements {
|
||||
$0.removeAll {
|
||||
let type = Swift.type(of: $0)
|
||||
return !type.canList || (isFree && !type.isFree)
|
||||
}
|
||||
}
|
||||
dict["entitlements"] = try? entitlements.plistValue()
|
||||
|
||||
let entFeatures = (try? entitlements.entitlements().compactMap { $0.feature() }) ?? []
|
||||
let allFeatures = entFeatures + additionalFeatures
|
||||
guard let features = try? DeveloperServicesFeatures(values: allFeatures).plistValue() as? [String: Any]
|
||||
else { return }
|
||||
dict.merge(features) { a, _ in a }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesDeleteAppIDRequest.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 24/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesDeleteAppIDRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable, Sendable {}
|
||||
public typealias Value = Response
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let teamID: DeveloperServicesTeam.ID
|
||||
public let appIDID: DeveloperServicesAppID.ID
|
||||
|
||||
var subAction: String { return "deleteAppId" }
|
||||
var subParameters: [String: Any] {
|
||||
return ["teamId": teamID.rawValue, "appIdId": appIDID.rawValue]
|
||||
}
|
||||
|
||||
public init(
|
||||
platform: DeveloperServicesPlatform,
|
||||
teamID: DeveloperServicesTeam.ID,
|
||||
appIDID: DeveloperServicesAppID.ID
|
||||
) {
|
||||
self.platform = platform
|
||||
self.teamID = teamID
|
||||
self.appIDID = appIDID
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesListAppIDsRequest.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 24/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesListAppIDsRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable, Sendable {
|
||||
public let appIds: [DeveloperServicesAppID]
|
||||
}
|
||||
public typealias Value = [DeveloperServicesAppID]
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let teamID: DeveloperServicesTeam.ID
|
||||
|
||||
var subAction: String { return "listAppIds" }
|
||||
var subParameters: [String: Any] {
|
||||
return ["teamId": teamID.rawValue]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response) -> [DeveloperServicesAppID] {
|
||||
response.appIds
|
||||
}
|
||||
|
||||
public init(platform: DeveloperServicesPlatform, teamID: DeveloperServicesTeam.ID) {
|
||||
self.platform = platform
|
||||
self.teamID = teamID
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesUpdateAppIDRequest.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 24/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesUpdateAppIDRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable, Sendable {
|
||||
let appId: DeveloperServicesAppID
|
||||
}
|
||||
public typealias Value = DeveloperServicesAppID
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let teamID: DeveloperServicesTeam.ID
|
||||
public let appIDID: DeveloperServicesAppID.ID
|
||||
public let entitlements: Entitlements
|
||||
public let additionalFeatures: [DeveloperServicesFeature]
|
||||
public let isFree: Bool
|
||||
|
||||
var subAction: String { return "updateAppId" }
|
||||
var subParameters: [String: Any] {
|
||||
var parameters: [String: Any] = [
|
||||
"teamId": teamID.rawValue,
|
||||
"appIdId": appIDID.rawValue
|
||||
]
|
||||
|
||||
DeveloperServicesAppIDRequestApplier.apply(
|
||||
entitlements: entitlements,
|
||||
additionalFeatures: additionalFeatures,
|
||||
to: ¶meters,
|
||||
isFree: isFree
|
||||
)
|
||||
|
||||
return parameters
|
||||
}
|
||||
|
||||
public func parse(_ response: Response) -> DeveloperServicesAppID {
|
||||
response.appId
|
||||
}
|
||||
|
||||
public init(
|
||||
platform: DeveloperServicesPlatform,
|
||||
teamID: DeveloperServicesTeam.ID,
|
||||
appIDID: DeveloperServicesAppID.ID,
|
||||
entitlements: Entitlements,
|
||||
additionalFeatures: [DeveloperServicesFeature],
|
||||
isFree: Bool
|
||||
) {
|
||||
self.platform = platform
|
||||
self.teamID = teamID
|
||||
self.appIDID = appIDID
|
||||
self.entitlements = entitlements
|
||||
self.additionalFeatures = additionalFeatures
|
||||
self.isFree = isFree
|
||||
}
|
||||
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
//
|
||||
// Entitlement+DeveloperServicesFeature.swift
|
||||
// Supersign
|
||||
//
|
||||
// Created by Kabir Oberai on 09/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol BaseEntitlementWithFeature: Entitlement {
|
||||
func baseFeature() -> DeveloperServicesFeature
|
||||
}
|
||||
|
||||
protocol EntitlementWithFeature: BaseEntitlementWithFeature {
|
||||
associatedtype Feature: DeveloperServicesFeature
|
||||
func typedFeature() -> Feature
|
||||
}
|
||||
extension EntitlementWithFeature {
|
||||
func baseFeature() -> DeveloperServicesFeature {
|
||||
return typedFeature()
|
||||
}
|
||||
}
|
||||
|
||||
extension EntitlementWithFeature
|
||||
where Self: RawRepresentable,
|
||||
Feature: RawRepresentable,
|
||||
RawValue == Feature.RawValue {
|
||||
func typedFeature() -> Feature {
|
||||
return Feature(rawValue: rawValue)!
|
||||
}
|
||||
}
|
||||
|
||||
public extension Entitlement {
|
||||
func feature() -> DeveloperServicesFeature? {
|
||||
return (self as? BaseEntitlementWithFeature)?.baseFeature()
|
||||
}
|
||||
}
|
||||
-273
@@ -1,273 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesFeatureTypes.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 29/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ProtoCodable
|
||||
|
||||
// swiftlint:disable type_name
|
||||
|
||||
extension DeveloperServicesFeatureContainer {
|
||||
static let supportedTypes: [ProtoCodable.Type] = [
|
||||
DeveloperServicesCloudKitFeature.self,
|
||||
DeveloperServicesDataProtectionFeature.self,
|
||||
DeveloperServicesAccessWifiFeature.self,
|
||||
DeveloperServicesAppGroupFeature.self,
|
||||
DeveloperServicesApplePayFeature.self,
|
||||
DeveloperServicesAssociatedDomainsFeature.self,
|
||||
DeveloperServicesClassKitFeature.self,
|
||||
DeveloperServicesAutoFillCredentialFeature.self,
|
||||
DeveloperServicesGameCenterFeature.self,
|
||||
DeveloperServicesHealthKitFeature.self,
|
||||
DeveloperServicesHomeKitFeature.self,
|
||||
DeveloperServicesHotspotFeature.self,
|
||||
DeveloperServicesCloudFeature.self,
|
||||
DeveloperServicesInAppPurchaseFeature.self,
|
||||
DeveloperServicesInterAppAudioFeature.self,
|
||||
DeveloperServicesMultipathFeature.self,
|
||||
DeveloperServicesNetworkExtensionFeature.self,
|
||||
DeveloperServicesNFCTagReadingFeature.self,
|
||||
DeveloperServicesPersonalVPNFeature.self,
|
||||
DeveloperServicesPassbookFeature.self,
|
||||
DeveloperServicesPushNotificationFeature.self,
|
||||
DeveloperServicesSiriKitFeature.self,
|
||||
DeveloperServicesVPNConfigurationFeature.self,
|
||||
DeveloperServicesWalletFeature.self,
|
||||
DeveloperServicesWirelessAccessoryFeature.self,
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Special Features
|
||||
|
||||
public enum DeveloperServicesCloudKitFeature: Int, DeveloperServicesFeature {
|
||||
public static let identifier = "cloudKitVersion"
|
||||
|
||||
case xcode5Compatible = 1
|
||||
case cloudKit = 2
|
||||
}
|
||||
|
||||
public enum DeveloperServicesDataProtectionFeature: String, DeveloperServicesFeature {
|
||||
public static let identifier = "dataProtection"
|
||||
|
||||
case off = ""
|
||||
case complete
|
||||
case unlessOpen = "unlessopen"
|
||||
case untilFirstAuth = "untilfirstauth"
|
||||
}
|
||||
extension DataProtectionEntitlement: EntitlementWithFeature {
|
||||
func typedFeature() -> DeveloperServicesDataProtectionFeature {
|
||||
switch self {
|
||||
case .complete: return .complete
|
||||
case .unlessOpen: return .unlessOpen
|
||||
case .untilFirstAuth: return .untilFirstAuth
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Boolean Features
|
||||
|
||||
// https://github.com/fastlane/fastlane/blob/master/spaceship/lib/spaceship/portal/app_service.rb
|
||||
|
||||
public struct DeveloperServicesAccessWifiFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "AWEQ28MY3E"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public struct DeveloperServicesAppGroupFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "APG3427HIY"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
extension AppGroupEntitlement: EntitlementWithFeature {
|
||||
func typedFeature() -> DeveloperServicesAppGroupFeature {
|
||||
.init(rawValue: !rawValue.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
public struct DeveloperServicesApplePayFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "OM633U5T5G"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public struct DeveloperServicesAssociatedDomainsFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "SKC3T5S89Y"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
extension AssociatedDomainsEntitlement: EntitlementWithFeature {
|
||||
func typedFeature() -> DeveloperServicesAssociatedDomainsFeature {
|
||||
.init(rawValue: true)
|
||||
}
|
||||
}
|
||||
|
||||
public struct DeveloperServicesClassKitFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "PKTJAN2017"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public struct DeveloperServicesAutoFillCredentialFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "CPEQ28MX4E"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public struct DeveloperServicesGameCenterFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "gameCenter"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public struct DeveloperServicesHealthKitFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "HK421J6T7P"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
extension HealthKitEntitlement: EntitlementWithFeature {
|
||||
typealias Feature = DeveloperServicesHealthKitFeature
|
||||
}
|
||||
|
||||
public struct DeveloperServicesHomeKitFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "homeKit"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
extension HomeKitEntitlement: EntitlementWithFeature {
|
||||
typealias Feature = DeveloperServicesHomeKitFeature
|
||||
}
|
||||
|
||||
public struct DeveloperServicesHotspotFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "HSC639VEI8"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public struct DeveloperServicesCloudFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "iCloud"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public struct DeveloperServicesInAppPurchaseFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "inAppPurchase"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public struct DeveloperServicesInterAppAudioFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "IAD53UNK2F"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
extension InterAppAudioEntitlement: EntitlementWithFeature {
|
||||
typealias Feature = DeveloperServicesInterAppAudioFeature
|
||||
}
|
||||
|
||||
public struct DeveloperServicesMultipathFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "MP49FN762P"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
extension MultipathEntitlement: EntitlementWithFeature {
|
||||
typealias Feature = DeveloperServicesMultipathFeature
|
||||
}
|
||||
|
||||
public struct DeveloperServicesNetworkExtensionFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "NWEXT04537"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
extension NetworkExtensionEntitlement: EntitlementWithFeature {
|
||||
typealias Feature = DeveloperServicesNetworkExtensionFeature
|
||||
}
|
||||
|
||||
public struct DeveloperServicesNFCTagReadingFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "NFCTRMAY17"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public struct DeveloperServicesPersonalVPNFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "V66P55NK2I"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public struct DeveloperServicesPassbookFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "passbook"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public struct DeveloperServicesPushNotificationFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "push"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
extension APSEnvironmentEntitlement: EntitlementWithFeature {
|
||||
func typedFeature() -> DeveloperServicesPushNotificationFeature {
|
||||
.init(rawValue: true)
|
||||
}
|
||||
}
|
||||
|
||||
public struct DeveloperServicesSiriKitFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "SI015DKUHP"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
extension SiriKitEntitlement: EntitlementWithFeature {
|
||||
typealias Feature = DeveloperServicesSiriKitFeature
|
||||
}
|
||||
|
||||
public struct DeveloperServicesVPNConfigurationFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "V66P55NK2I"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
extension VPNConfigurationEntitlement: EntitlementWithFeature {
|
||||
typealias Feature = DeveloperServicesVPNConfigurationFeature
|
||||
}
|
||||
|
||||
public struct DeveloperServicesWalletFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "pass"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public struct DeveloperServicesWirelessAccessoryFeature: DeveloperServicesFeature, RawRepresentable {
|
||||
public static let identifier = "WC421J6T7P"
|
||||
|
||||
public let rawValue: Bool
|
||||
public init(rawValue: Bool) { self.rawValue = rawValue }
|
||||
}
|
||||
extension WirelessAccessoryEntitlement: EntitlementWithFeature {
|
||||
typealias Feature = DeveloperServicesWirelessAccessoryFeature
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesFeatures.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 19/09/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ProtoCodable
|
||||
|
||||
struct DeveloperServicesFeatureContainer: ProtoCodableContainer {
|
||||
var value: DeveloperServicesFeature
|
||||
}
|
||||
|
||||
typealias DeveloperServicesFeatures = ProtoCodableKeyValueContainer<DeveloperServicesFeatureContainer>
|
||||
@@ -1,35 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesCSRResponse.swift
|
||||
// Supersign
|
||||
//
|
||||
// Created by Kabir Oberai on 09/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesCSRResponse: Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
public let id: ID
|
||||
public let certificateID: DeveloperServicesCertificate.ID
|
||||
public let serialNumber: DeveloperServicesCertificate.SerialNumber
|
||||
public let status: String
|
||||
public let statusCode: Int
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let machineID: String?
|
||||
public let machineName: String?
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case id = "certRequestId"
|
||||
case certificateID = "certificateId"
|
||||
case serialNumber = "serialNum"
|
||||
case status = "statusString"
|
||||
case statusCode
|
||||
case platform = "csrPlatform"
|
||||
case machineID = "machineId"
|
||||
case machineName
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesCertificate.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 29/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesCertificate: Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
public let id: ID
|
||||
|
||||
public struct SerialNumber: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public enum Kind: String, Decodable, CaseIterable, Sendable {
|
||||
case development = "DEVELOPMENT"
|
||||
case distribution = "DISTRIBUTION"
|
||||
case iOSDevelopment = "IOS_DEVELOPMENT"
|
||||
case iOSDistribution = "IOS_DISTRIBUTION"
|
||||
case macAppDistribution = "MAC_APP_DISTRIBUTION"
|
||||
case macInstallerDistribution = "MAC_INSTALLER_DISTRIBUTION"
|
||||
case developerIDKext = "DEVELOPER_ID_KEXT"
|
||||
case developerIDApplication = "DEVELOPER_ID_APPLICATION"
|
||||
case unknown
|
||||
|
||||
public init(platform: DeveloperServicesPlatform) {
|
||||
switch platform {
|
||||
case .iOS: self = .iOSDevelopment
|
||||
default: self = .development
|
||||
}
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let rawValue = try String(from: decoder)
|
||||
self = Self.allCases.first { $0.rawValue == rawValue } ?? .unknown
|
||||
}
|
||||
}
|
||||
|
||||
public struct Attributes: Decodable, Sendable {
|
||||
public let serialNumber: SerialNumber
|
||||
public let name: String
|
||||
public let kind: Kind
|
||||
public let expiry: Date
|
||||
public let machineID: String?
|
||||
public let machineName: String?
|
||||
public let content: Certificate
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case serialNumber
|
||||
case name
|
||||
case kind = "certificateType"
|
||||
case expiry = "expirationDate"
|
||||
case content = "certificateContent"
|
||||
case machineID = "machineId"
|
||||
case machineName
|
||||
}
|
||||
}
|
||||
public let attributes: Attributes
|
||||
}
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesFetchCertificateOperation.swift
|
||||
// Supersign
|
||||
//
|
||||
// Created by Kabir Oberai on 13/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOperation {
|
||||
|
||||
public enum Error: LocalizedError {
|
||||
case csrFailed
|
||||
case userCancelled
|
||||
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .csrFailed:
|
||||
return NSLocalizedString(
|
||||
"fetch_certificate_operation.error.csr_failed", value: "CSR request failed", comment: ""
|
||||
)
|
||||
case .userCancelled:
|
||||
return NSLocalizedString(
|
||||
"fetch_certificate_operation.error.user_cancelled", value: "The operation was cancelled", comment: ""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public let context: SigningContext
|
||||
public let confirmRevocation: @Sendable ([DeveloperServicesCertificate]) async -> Bool
|
||||
public init(
|
||||
context: SigningContext,
|
||||
confirmRevocation: @escaping @Sendable ([DeveloperServicesCertificate]) async -> Bool
|
||||
) {
|
||||
self.context = context
|
||||
self.confirmRevocation = confirmRevocation
|
||||
}
|
||||
|
||||
private func createCertificate() async throws -> SigningInfo {
|
||||
let keypair = try Keypair()
|
||||
let csr = try keypair.generateCSR()
|
||||
let privateKey = try keypair.privateKey()
|
||||
|
||||
let request = DeveloperServicesSubmitCSRRequest(
|
||||
platform: context.platform,
|
||||
teamID: context.teamID,
|
||||
csr: csr,
|
||||
machineName: "Supercharge: \(SigningContext.hostName)",
|
||||
machineID: context.client.deviceInfo.deviceID
|
||||
)
|
||||
let partialCert = try await context.client.send(request)
|
||||
|
||||
let serialNumber = partialCert.serialNumber
|
||||
let listRequest = DeveloperServicesListCertificatesRequest(
|
||||
teamID: self.context.teamID, certificateKind: .init(platform: self.context.platform)
|
||||
)
|
||||
let certificates = try await context.client.send(listRequest)
|
||||
guard let fullCert = certificates.first(where: { $0.attributes.serialNumber == serialNumber })
|
||||
else { throw Error.csrFailed }
|
||||
return .init(privateKey: privateKey, certificate: fullCert.attributes.content)
|
||||
}
|
||||
|
||||
private func revokeCreateSaveCertificate(certificates: [DeveloperServicesCertificate]) async throws -> SigningInfo {
|
||||
if !certificates.isEmpty {
|
||||
guard await confirmRevocation(certificates)
|
||||
else { throw CancellationError() }
|
||||
}
|
||||
try await withThrowingTaskGroup(of: Void.self) { group in
|
||||
for certificate in certificates {
|
||||
group.addTask {
|
||||
let request = DeveloperServicesRevokeCertificateRequest(
|
||||
teamID: context.teamID, certificateID: certificate.id
|
||||
)
|
||||
_ = try await context.client.send(request)
|
||||
}
|
||||
}
|
||||
try await group.waitForAll()
|
||||
}
|
||||
let signingInfo = try await createCertificate()
|
||||
self.context.signingInfoManager[self.context.teamID] = signingInfo
|
||||
return signingInfo
|
||||
}
|
||||
|
||||
public func perform() async throws -> SigningInfo {
|
||||
let request = DeveloperServicesListCertificatesRequest(
|
||||
teamID: context.teamID, certificateKind: .init(platform: context.platform)
|
||||
)
|
||||
let certificates = try await context.client.send(request)
|
||||
|
||||
guard let certificate = certificates.first(where: {
|
||||
$0.attributes.machineID == self.context.client.deviceInfo.deviceID
|
||||
}) else {
|
||||
// we need to revoke existing certs, otherwise it doesn't always let us make a new one
|
||||
return try await self.revokeCreateSaveCertificate(certificates: certificates)
|
||||
}
|
||||
|
||||
guard let signingInfo = self.context.signingInfoManager[self.context.teamID],
|
||||
certificate.attributes.serialNumber.rawValue == signingInfo.certificate.serialNumber(),
|
||||
certificate.attributes.expiry > Date() else {
|
||||
// we have a certificate for this machine but it's not usable
|
||||
return try await self.revokeCreateSaveCertificate(certificates: [certificate])
|
||||
}
|
||||
|
||||
return signingInfo
|
||||
}
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesListCertificatesRequest.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 24/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesListCertificatesRequest: DeveloperServicesRequest, Sendable {
|
||||
|
||||
public typealias Response = [DeveloperServicesCertificate]
|
||||
public typealias Value = Response
|
||||
|
||||
public var apiVersion: DeveloperServicesAPIVersion { DeveloperServicesAPIVersionV1() }
|
||||
public var methodOverride: String? { "GET" }
|
||||
|
||||
public let teamID: DeveloperServicesTeam.ID
|
||||
public let certificateKind: DeveloperServicesCertificate.Kind
|
||||
|
||||
public var action: String { "certificates" }
|
||||
public var parameters: [String: Any] {
|
||||
[
|
||||
"teamId": teamID.rawValue,
|
||||
"filter[certificateType]": certificateKind.rawValue
|
||||
]
|
||||
}
|
||||
|
||||
public init(teamID: DeveloperServicesTeam.ID, certificateKind: DeveloperServicesCertificate.Kind) {
|
||||
self.teamID = teamID
|
||||
self.certificateKind = certificateKind
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesRevokeCertificateRequest.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 24/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
// swiftlint:disable:next type_name
|
||||
public struct DeveloperServicesRevokeCertificateRequest: DeveloperServicesRequest {
|
||||
|
||||
public typealias Response = EmptyResponse
|
||||
public typealias Value = Response
|
||||
|
||||
public var apiVersion: DeveloperServicesAPIVersion { DeveloperServicesAPIVersionV1() }
|
||||
public var methodOverride: String? { "DELETE" }
|
||||
|
||||
public let teamID: DeveloperServicesTeam.ID
|
||||
public let certificateID: DeveloperServicesCertificate.ID
|
||||
|
||||
public var action: String { "certificates/\(certificateID.rawValue)" }
|
||||
public var parameters: [String: Any] {
|
||||
["teamId": teamID.rawValue]
|
||||
}
|
||||
|
||||
public init(
|
||||
teamID: DeveloperServicesTeam.ID,
|
||||
certificateID: DeveloperServicesCertificate.ID
|
||||
) {
|
||||
self.teamID = teamID
|
||||
self.certificateID = certificateID
|
||||
}
|
||||
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesSubmitCSRRequest.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 24/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public final class DeveloperServicesSubmitCSRRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable, Sendable {
|
||||
public let certRequest: DeveloperServicesCSRResponse
|
||||
}
|
||||
public typealias Value = DeveloperServicesCSRResponse
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let teamID: DeveloperServicesTeam.ID
|
||||
public let csr: CSR
|
||||
public let machineName: String
|
||||
public let machineID: String
|
||||
|
||||
var subAction: String { return "submitDevelopmentCSR" }
|
||||
var subParameters: [String: Any] {
|
||||
return [
|
||||
"teamId": teamID.rawValue,
|
||||
"csrContent": csr.pemString,
|
||||
"machineId": machineID,
|
||||
"machineName": machineName
|
||||
]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response) -> DeveloperServicesCSRResponse {
|
||||
response.certRequest
|
||||
}
|
||||
|
||||
public init(
|
||||
platform: DeveloperServicesPlatform,
|
||||
teamID: DeveloperServicesTeam.ID,
|
||||
csr: CSR,
|
||||
machineName: String,
|
||||
machineID: String
|
||||
) {
|
||||
self.platform = platform
|
||||
self.teamID = teamID
|
||||
self.csr = csr
|
||||
self.machineName = machineName
|
||||
self.machineID = machineID
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesAddDeviceRequest.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 24/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesAddDeviceRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable, Sendable {
|
||||
let device: DeveloperServicesDevice
|
||||
}
|
||||
public typealias Value = DeveloperServicesDevice
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let teamID: DeveloperServicesTeam.ID
|
||||
public let udid: String
|
||||
public let name: String
|
||||
|
||||
var subAction: String { return "addDevice" }
|
||||
var subParameters: [String: Any] {
|
||||
return [
|
||||
"teamId": teamID.rawValue,
|
||||
"deviceNumber": udid,
|
||||
"name": name
|
||||
]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response) -> DeveloperServicesDevice {
|
||||
response.device
|
||||
}
|
||||
|
||||
public init(
|
||||
platform: DeveloperServicesPlatform,
|
||||
teamID: DeveloperServicesTeam.ID,
|
||||
udid: String,
|
||||
name: String
|
||||
) {
|
||||
self.platform = platform
|
||||
self.teamID = teamID
|
||||
self.udid = udid
|
||||
self.name = name
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesDevice.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 07/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesDevice: Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public let id: ID
|
||||
public let name: String
|
||||
public let udid: String
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let type: String // TODO: Create enum
|
||||
public let model: String?
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case id = "deviceId"
|
||||
case name
|
||||
case udid = "deviceNumber"
|
||||
case platform = "devicePlatform"
|
||||
case type = "deviceClass"
|
||||
case model
|
||||
}
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesFetchDeviceOperation.swift
|
||||
// Supersign
|
||||
//
|
||||
// Created by Kabir Oberai on 13/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesFetchDeviceOperation: DeveloperServicesOperation {
|
||||
public let context: SigningContext
|
||||
public init(context: SigningContext) {
|
||||
self.context = context
|
||||
}
|
||||
|
||||
public func perform() async throws -> DeveloperServicesDevice {
|
||||
let listRequest = DeveloperServicesListDevicesRequest(platform: context.platform, teamID: context.teamID)
|
||||
let devices = try await context.client.send(listRequest)
|
||||
if let device = devices.first(where: { $0.udid == self.context.udid }) {
|
||||
return device
|
||||
}
|
||||
|
||||
let addRequest = DeveloperServicesAddDeviceRequest(
|
||||
platform: self.context.platform,
|
||||
teamID: self.context.teamID,
|
||||
udid: self.context.udid,
|
||||
name: self.context.deviceName
|
||||
)
|
||||
return try await context.client.send(addRequest)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesListDevicesRequest.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 24/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesListDevicesRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable, Sendable {
|
||||
public let devices: [DeveloperServicesDevice]
|
||||
}
|
||||
public typealias Value = [DeveloperServicesDevice]
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let teamID: DeveloperServicesTeam.ID
|
||||
|
||||
var subAction: String { return "listDevices" }
|
||||
var subParameters: [String: Any] {
|
||||
return [
|
||||
"teamId": teamID.rawValue,
|
||||
"pageSize": "500",
|
||||
"includeRemovedDevices": "false"
|
||||
]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response) -> Value {
|
||||
response.devices
|
||||
}
|
||||
|
||||
public init(platform: DeveloperServicesPlatform, teamID: DeveloperServicesTeam.ID) {
|
||||
self.platform = platform
|
||||
self.teamID = teamID
|
||||
}
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesDeleteProfileRequest.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 24/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesDeleteProfileRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable, Sendable {}
|
||||
public typealias Value = Response
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let teamID: DeveloperServicesTeam.ID
|
||||
public let profileID: DeveloperServicesProfile.ID
|
||||
|
||||
var subAction: String { return "deleteProvisioningProfile" }
|
||||
var subParameters: [String: Any] {
|
||||
return ["teamId": teamID.rawValue, "provisioningProfileId": profileID.rawValue]
|
||||
}
|
||||
|
||||
public init(
|
||||
platform: DeveloperServicesPlatform,
|
||||
teamID: DeveloperServicesTeam.ID,
|
||||
profileID: DeveloperServicesProfile.ID
|
||||
) {
|
||||
self.platform = platform
|
||||
self.teamID = teamID
|
||||
self.profileID = profileID
|
||||
}
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesFetchProfileOperation.swift
|
||||
// Supersign
|
||||
//
|
||||
// Created by Kabir Oberai on 13/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Superutils
|
||||
|
||||
public struct DeveloperServicesFetchProfileOperation: DeveloperServicesOperation {
|
||||
|
||||
public let context: SigningContext
|
||||
public let appID: DeveloperServicesAppID
|
||||
public init(context: SigningContext, appID: DeveloperServicesAppID) {
|
||||
self.context = context
|
||||
self.appID = appID
|
||||
}
|
||||
|
||||
public func perform() async throws -> DeveloperServicesProfile {
|
||||
let profiles = try await context.client.send(DeveloperServicesListProfilesRequest(
|
||||
platform: context.platform, teamID: context.teamID
|
||||
))
|
||||
if let profile = profiles.first(where: { $0.appID.id == self.appID.id }) {
|
||||
_ = try await context.client.send(DeveloperServicesDeleteProfileRequest(
|
||||
platform: context.platform, teamID: context.teamID, profileID: profile.id
|
||||
))
|
||||
}
|
||||
return try await context.client.send(DeveloperServicesGetProfileRequest(
|
||||
platform: context.platform, teamID: context.teamID, appIDID: appID.id
|
||||
))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesGetProfileRequest.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 24/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesGetProfileRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable, Sendable {
|
||||
public let provisioningProfile: DeveloperServicesProfile
|
||||
}
|
||||
public typealias Value = DeveloperServicesProfile
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let teamID: DeveloperServicesTeam.ID
|
||||
public let appIDID: DeveloperServicesAppID.ID
|
||||
|
||||
var subAction: String { return "downloadTeamProvisioningProfile" }
|
||||
var subParameters: [String: Any] {
|
||||
return ["teamId": teamID.rawValue, "appIdId": appIDID.rawValue]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response) -> DeveloperServicesProfile {
|
||||
response.provisioningProfile
|
||||
}
|
||||
|
||||
public init(
|
||||
platform: DeveloperServicesPlatform,
|
||||
teamID: DeveloperServicesTeam.ID,
|
||||
appIDID: DeveloperServicesAppID.ID
|
||||
) {
|
||||
self.platform = platform
|
||||
self.teamID = teamID
|
||||
self.appIDID = appIDID
|
||||
}
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesListProfilesRequest.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 24/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesListProfilesRequest: DeveloperServicesPlatformRequest {
|
||||
|
||||
public struct Response: Decodable, Sendable {
|
||||
public let provisioningProfiles: [DeveloperServicesProfile]
|
||||
}
|
||||
public typealias Value = [DeveloperServicesProfile]
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let teamID: DeveloperServicesTeam.ID
|
||||
|
||||
var subAction: String { return "listProvisioningProfiles" }
|
||||
var subParameters: [String: Any] {
|
||||
return ["teamId": teamID.rawValue]
|
||||
}
|
||||
|
||||
public func parse(_ response: Response) -> [DeveloperServicesProfile] {
|
||||
response.provisioningProfiles
|
||||
}
|
||||
|
||||
public init(platform: DeveloperServicesPlatform, teamID: DeveloperServicesTeam.ID) {
|
||||
self.platform = platform
|
||||
self.teamID = teamID
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesProfile.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 29/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesProfile: Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
public let id: ID
|
||||
public let name: String
|
||||
public let status: String
|
||||
public let type: String
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let uuid: String
|
||||
public let version: String
|
||||
public let expiry: Date
|
||||
public let appIDID: DeveloperServicesAppID.ID
|
||||
public let appID: DeveloperServicesAppID
|
||||
public let isFree: Bool
|
||||
public let mobileprovision: Mobileprovision?
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case id = "provisioningProfileId"
|
||||
case name
|
||||
case status
|
||||
case type
|
||||
case platform = "proProPlatform"
|
||||
case uuid = "UUID"
|
||||
case version
|
||||
case expiry = "dateExpire"
|
||||
case appIDID = "appIdId"
|
||||
case appID = "appId"
|
||||
case isFree = "isFreeProvisioningProfile"
|
||||
case mobileprovision = "encodedProfile"
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
//
|
||||
// AnisetteDataProvider.swift
|
||||
// Supersign
|
||||
//
|
||||
// Created by Kabir Oberai on 19/11/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol AnisetteDataProvider: Sendable {
|
||||
// This is a suggestion and not a requirement.
|
||||
func resetProvisioning() async
|
||||
func provisioningData() -> ProvisioningData?
|
||||
|
||||
func fetchAnisetteData() async throws -> AnisetteData
|
||||
}
|
||||
|
||||
public struct ProvisioningData: Hashable, Codable, Sendable {
|
||||
public var localUserUID: UUID
|
||||
public var routingInfo: UInt64
|
||||
public var adiPb: Data
|
||||
}
|
||||
|
||||
extension AnisetteDataProvider {
|
||||
public func provisioningData() -> ProvisioningData? { nil }
|
||||
public func setProvisioningData(_ data: ProvisioningData) {}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
//
|
||||
// GrandSlamClient.swift
|
||||
// Supersign
|
||||
//
|
||||
// Created by Kabir Oberai on 19/11/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
final class GrandSlamClient: Sendable {
|
||||
|
||||
private let encoder = PropertyListEncoder()
|
||||
|
||||
private let lookupManager: GrandSlamLookupManager
|
||||
|
||||
let deviceInfo: DeviceInfo
|
||||
let anisetteDataProvider: AnisetteDataProvider
|
||||
private let httpClient: HTTPClientProtocol
|
||||
init(
|
||||
deviceInfo: DeviceInfo,
|
||||
anisetteProvider: AnisetteDataProvider,
|
||||
httpFactory: HTTPClientFactory = defaultHTTPClientFactory
|
||||
) {
|
||||
self.deviceInfo = deviceInfo
|
||||
self.anisetteDataProvider = anisetteProvider
|
||||
self.lookupManager = .init(deviceInfo: deviceInfo, httpFactory: httpFactory)
|
||||
self.httpClient = httpFactory.makeClient()
|
||||
}
|
||||
|
||||
func send<R: GrandSlamRequest>(_ request: R) async throws -> R.Decoder.Value {
|
||||
let anisetteData = try await anisetteDataProvider.fetchAnisetteData()
|
||||
let url = try await lookupManager.fetchURL(forEndpoint: R.endpoint)
|
||||
|
||||
let method = request.method(deviceInfo: deviceInfo, anisetteData: anisetteData)
|
||||
var httpRequest = HTTPRequest(url: url, method: method.name)
|
||||
httpRequest.headers = [
|
||||
"Content-Type": "text/x-xml-plist",
|
||||
DeviceInfo.clientInfoKey: deviceInfo.clientInfo.clientString
|
||||
]
|
||||
switch method {
|
||||
case .get:
|
||||
break
|
||||
case .post(let body):
|
||||
httpRequest.body = try .buffer(PropertyListSerialization.data(
|
||||
fromPropertyList: body, format: .xml, options: 0
|
||||
))
|
||||
}
|
||||
request.configure(request: &httpRequest, deviceInfo: deviceInfo, anisetteData: anisetteData)
|
||||
|
||||
let resp = try await httpClient.makeRequest(httpRequest)
|
||||
return try R.Decoder.decode(data: resp.body ?? .init())
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
//
|
||||
// AsyncHTTPClient+HTTP.swift
|
||||
//
|
||||
//
|
||||
// Created by Kabir Oberai on 05/05/21.
|
||||
//
|
||||
|
||||
#if os(Linux)
|
||||
import Foundation
|
||||
import AsyncHTTPClient
|
||||
import NIO
|
||||
import NIOHTTP1
|
||||
import NIOSSL
|
||||
import NIOFoundationCompat
|
||||
import WebSocketKit
|
||||
import OpenAPIRuntime
|
||||
import OpenAPIAsyncHTTPClient
|
||||
|
||||
extension HTTPClient: HTTPClientProtocol {
|
||||
@discardableResult
|
||||
public func makeRequest(_ request: HTTPRequest, onProgress: sending @isolated(any) (Double?) -> Void) async throws -> HTTPResponse {
|
||||
// print("Requesting \(request.url)")
|
||||
var httpRequest = HTTPClientRequest(url: request.url.absoluteString)
|
||||
httpRequest.method = request.method.map(HTTPMethod.init(rawValue:)) ?? .GET
|
||||
httpRequest.headers = HTTPHeaders(request.headers.map { $0 })
|
||||
httpRequest.body = switch request.body {
|
||||
case .buffer(let data):
|
||||
.bytes(data)
|
||||
case nil:
|
||||
nil
|
||||
}
|
||||
let response = try await execute(httpRequest, deadline: .distantFuture)
|
||||
let expectedBytes = response.headers.first(name: "content-length").flatMap(Int.init).map(Double.init)
|
||||
if expectedBytes == nil {
|
||||
await onProgress(nil)
|
||||
}
|
||||
var body = Data()
|
||||
for try await chunk in response.body {
|
||||
body += chunk.readableBytesView
|
||||
if let expectedBytes {
|
||||
await onProgress(min(Double(body.count) / expectedBytes, 1))
|
||||
}
|
||||
}
|
||||
return HTTPResponse(
|
||||
url: request.url,
|
||||
status: Int(response.status.code),
|
||||
headers: [:],
|
||||
body: body
|
||||
)
|
||||
}
|
||||
|
||||
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
|
||||
defer { continuation.finish() }
|
||||
// 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: eventLoopGroup) {
|
||||
continuation.yield(WebSocketSessionWrapper(webSocket: $0))
|
||||
}
|
||||
try await future.get()
|
||||
guard let webSocket = await value else {
|
||||
throw Errors.connectFailed
|
||||
}
|
||||
return webSocket
|
||||
}
|
||||
|
||||
private enum Errors: Error {
|
||||
case connectFailed
|
||||
}
|
||||
|
||||
public var asOpenAPITransport: any ClientTransport {
|
||||
AsyncHTTPClientTransport(configuration: .init(client: self))
|
||||
}
|
||||
}
|
||||
|
||||
private final class WebSocketSessionWrapper: WebSocketSession {
|
||||
let webSocket: WebSocket
|
||||
let stream: AsyncStream<WebSocketMessage>
|
||||
private let finishStream: @Sendable () -> Void
|
||||
|
||||
init(webSocket: WebSocket) {
|
||||
self.webSocket = webSocket
|
||||
|
||||
let (stream, continuation) = AsyncStream<WebSocketMessage>.makeStream(bufferingPolicy: .unbounded)
|
||||
self.stream = stream
|
||||
self.finishStream = { continuation.finish() }
|
||||
webSocket.onText { _, text in
|
||||
continuation.yield(.text(text))
|
||||
}
|
||||
webSocket.onBinary { _, data in
|
||||
continuation.yield(.data(Data(data.readableBytesView)))
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
close()
|
||||
}
|
||||
|
||||
func close() {
|
||||
finishStream()
|
||||
Task { [webSocket] in try? await webSocket.close() }
|
||||
}
|
||||
|
||||
func send(_ message: WebSocketMessage) async throws {
|
||||
switch message {
|
||||
case .text(let text):
|
||||
try await webSocket.send(text)
|
||||
case .data(let data):
|
||||
try await webSocket.send(.init(data))
|
||||
}
|
||||
}
|
||||
|
||||
func receive() async throws -> WebSocketMessage {
|
||||
await stream.first(where: { _ in true }) ?? .data(Data())
|
||||
}
|
||||
}
|
||||
|
||||
final class AsyncHTTPClientFactory: HTTPClientFactory {
|
||||
private static let appleRootPEM = """
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEuzCCA6OgAwIBAgIBAjANBgkqhkiG9w0BAQUFADBiMQswCQYDVQQGEwJVUzET
|
||||
MBEGA1UEChMKQXBwbGUgSW5jLjEmMCQGA1UECxMdQXBwbGUgQ2VydGlmaWNhdGlv
|
||||
biBBdXRob3JpdHkxFjAUBgNVBAMTDUFwcGxlIFJvb3QgQ0EwHhcNMDYwNDI1MjE0
|
||||
MDM2WhcNMzUwMjA5MjE0MDM2WjBiMQswCQYDVQQGEwJVUzETMBEGA1UEChMKQXBw
|
||||
bGUgSW5jLjEmMCQGA1UECxMdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkx
|
||||
FjAUBgNVBAMTDUFwcGxlIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
|
||||
ggEKAoIBAQDkkakJH5HbHkdQ6wXtXnmELes2oldMVeyLGYne+Uts9QerIjAC6Bg+
|
||||
+FAJ039BqJj50cpmnCRrEdCju+QbKsMflZ56DKRHi1vUFjczy8QPTc4UadHJGXL1
|
||||
XQ7Vf1+b8iUDulWPTV0N8WQ1IxVLFVkds5T39pyez1C6wVhQZ48ItCD3y6wsIG9w
|
||||
tj8BMIy3Q88PnT3zK0koGsj+zrW5DtleHNbLPbU6rfQPDgCSC7EhFi501TwN22IW
|
||||
q6NxkkdTVcGvL0Gz+PvjcM3mo0xFfh9Ma1CWQYnEdGILEINBhzOKgbEwWOxaBDKM
|
||||
aLOPHd5lc/9nXmW8Sdh2nzMUZaF3lMktAgMBAAGjggF6MIIBdjAOBgNVHQ8BAf8E
|
||||
BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUK9BpR5R2Cf70a40uQKb3
|
||||
R01/CF4wHwYDVR0jBBgwFoAUK9BpR5R2Cf70a40uQKb3R01/CF4wggERBgNVHSAE
|
||||
ggEIMIIBBDCCAQAGCSqGSIb3Y2QFATCB8jAqBggrBgEFBQcCARYeaHR0cHM6Ly93
|
||||
d3cuYXBwbGUuY29tL2FwcGxlY2EvMIHDBggrBgEFBQcCAjCBthqBs1JlbGlhbmNl
|
||||
IG9uIHRoaXMgY2VydGlmaWNhdGUgYnkgYW55IHBhcnR5IGFzc3VtZXMgYWNjZXB0
|
||||
YW5jZSBvZiB0aGUgdGhlbiBhcHBsaWNhYmxlIHN0YW5kYXJkIHRlcm1zIGFuZCBj
|
||||
b25kaXRpb25zIG9mIHVzZSwgY2VydGlmaWNhdGUgcG9saWN5IGFuZCBjZXJ0aWZp
|
||||
Y2F0aW9uIHByYWN0aWNlIHN0YXRlbWVudHMuMA0GCSqGSIb3DQEBBQUAA4IBAQBc
|
||||
NplMLXi37Yyb3PN3m/J20ncwT8EfhYOFG5k9RzfyqZtAjizUsZAS2L70c5vu0mQP
|
||||
y3lPNNiiPvl4/2vIB+x9OYOLUyDTOMSxv5pPCmv/K/xZpwUJfBdAVhEedNO3iyM7
|
||||
R6PVbyTi69G3cN8PReEnyvFteO3ntRcXqNx+IjXKJdXZD9Zr1KIkIxH3oayPc4Fg
|
||||
xhtbCS+SsvhESPBgOJ4V9T0mZyCKM2r3DYLP3uujL/lTaltkwGMzd/c6ByxW69oP
|
||||
IQ7aunMZT7XZNn/Bh1XZp5m5MkL72NVxnn6hUrcbvZNCJBIqxw8dtk2cXmPIS4AX
|
||||
UKqK1drk/NAJBzewdXUh
|
||||
-----END CERTIFICATE-----
|
||||
"""
|
||||
|
||||
private let client: HTTPClient
|
||||
private init() {
|
||||
// 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(Self.appleRootPEM.utf8), format: .pem)
|
||||
var tlsConfiguration: TLSConfiguration = .makeClientConfiguration()
|
||||
tlsConfiguration.additionalTrustRoots = [.certificates([appleRootCA])]
|
||||
let config = HTTPClient.Configuration(
|
||||
tlsConfiguration: tlsConfiguration,
|
||||
decompression: .enabled(limit: .none)
|
||||
)
|
||||
client = HTTPClient(configuration: config)
|
||||
}
|
||||
static let shared = AsyncHTTPClientFactory()
|
||||
|
||||
func shutdown() {
|
||||
// swiftlint:disable:next force_try
|
||||
try! client.syncShutdown()
|
||||
}
|
||||
|
||||
func makeClient() -> HTTPClientProtocol { client }
|
||||
}
|
||||
#endif
|
||||
@@ -1,91 +0,0 @@
|
||||
//
|
||||
// HTTPClientProtocol.swift
|
||||
//
|
||||
//
|
||||
// Created by Kabir Oberai on 05/05/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import OpenAPIRuntime
|
||||
|
||||
public struct HTTPRequest: Sendable {
|
||||
public enum Body: Sendable {
|
||||
case buffer(Data)
|
||||
}
|
||||
|
||||
public var url: URL
|
||||
public var method: String?
|
||||
public var headers: [String: String]
|
||||
public var body: Body?
|
||||
|
||||
public init(
|
||||
url: URL,
|
||||
method: String? = nil,
|
||||
headers: [String: String] = [:],
|
||||
body: Body? = nil
|
||||
) {
|
||||
self.url = url
|
||||
self.method = method
|
||||
self.headers = headers
|
||||
self.body = body
|
||||
}
|
||||
}
|
||||
|
||||
public struct HTTPResponse: Sendable {
|
||||
public var url: URL
|
||||
public var status: Int
|
||||
public var headers: [String: String]
|
||||
public var body: Data?
|
||||
|
||||
public init(
|
||||
url: URL,
|
||||
status: Int,
|
||||
headers: [String: String] = [:],
|
||||
body: Data? = nil
|
||||
) {
|
||||
self.url = url
|
||||
self.status = status
|
||||
self.headers = headers
|
||||
self.body = body
|
||||
}
|
||||
}
|
||||
|
||||
public protocol HTTPClientProtocol: Sendable {
|
||||
var asOpenAPITransport: ClientTransport { get }
|
||||
|
||||
func makeRequest(
|
||||
_ request: HTTPRequest,
|
||||
onProgress: sending @isolated(any) (Double?) -> Void
|
||||
) async throws -> HTTPResponse
|
||||
func makeWebSocket(url: URL) async throws -> WebSocketSession
|
||||
}
|
||||
|
||||
extension HTTPClientProtocol {
|
||||
public func makeRequest(_ request: HTTPRequest) async throws -> HTTPResponse {
|
||||
try await makeRequest(request) { _ in }
|
||||
}
|
||||
}
|
||||
|
||||
public protocol WebSocketSession: Sendable {
|
||||
func receive() async throws -> WebSocketMessage
|
||||
func send(_ message: WebSocketMessage) async throws
|
||||
func close()
|
||||
}
|
||||
|
||||
public enum WebSocketMessage: Sendable {
|
||||
case text(String)
|
||||
case data(Data)
|
||||
}
|
||||
|
||||
public protocol HTTPClientFactory: Sendable {
|
||||
func shutdown() // client is invalidated after this
|
||||
func makeClient() -> HTTPClientProtocol
|
||||
}
|
||||
|
||||
public let defaultHTTPClientFactory: HTTPClientFactory = {
|
||||
#if os(Linux)
|
||||
return AsyncHTTPClientFactory.shared
|
||||
#else
|
||||
return URLHTTPClientFactory.shared
|
||||
#endif
|
||||
}()
|
||||
@@ -1,21 +0,0 @@
|
||||
//
|
||||
// Entitlement.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 29/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ProtoCodable
|
||||
|
||||
public protocol Entitlement: ProtoCodable, Sendable {
|
||||
static var identifier: String { get }
|
||||
static var isFree: Bool { get }
|
||||
/// whether this entitlement should be included in developer services API requests
|
||||
static var canList: Bool { get }
|
||||
}
|
||||
|
||||
public extension Entitlement {
|
||||
static var canList: Bool { return true }
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
//
|
||||
// SigningInfo.swift
|
||||
// Supersign
|
||||
//
|
||||
// Created by Kabir Oberai on 12/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ConcurrencyExtras
|
||||
|
||||
public struct SigningInfo: Codable, Sendable {
|
||||
public let privateKey: PrivateKey
|
||||
public let certificate: Certificate
|
||||
}
|
||||
|
||||
public protocol SigningInfoManager: Sendable {
|
||||
func info(forTeamID teamID: DeveloperServicesTeam.ID) throws -> SigningInfo?
|
||||
func setInfo(_ info: SigningInfo?, forTeamID teamID: DeveloperServicesTeam.ID) throws
|
||||
}
|
||||
|
||||
extension SigningInfoManager {
|
||||
subscript(teamID: DeveloperServicesTeam.ID) -> SigningInfo? {
|
||||
get {
|
||||
try? info(forTeamID: teamID)
|
||||
}
|
||||
nonmutating set {
|
||||
try? setInfo(newValue, forTeamID: teamID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final class MemoryBackedSigningInfoManager: SigningInfoManager {
|
||||
private let infos = LockIsolated<[String: SigningInfo]>([:])
|
||||
|
||||
public init() {}
|
||||
|
||||
public func info(forTeamID teamID: DeveloperServicesTeam.ID) throws -> SigningInfo? {
|
||||
infos[teamID.rawValue]
|
||||
}
|
||||
|
||||
public func setInfo(_ info: SigningInfo?, forTeamID teamID: DeveloperServicesTeam.ID) throws {
|
||||
infos.withValue {
|
||||
$0[teamID.rawValue] = info
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct KeyValueSigningInfoManager: SigningInfoManager {
|
||||
private let encoder = PropertyListEncoder()
|
||||
private let decoder = PropertyListDecoder()
|
||||
|
||||
public let storage: KeyValueStorage
|
||||
public init(storage: KeyValueStorage) {
|
||||
self.storage = storage
|
||||
}
|
||||
|
||||
public func info(forTeamID teamID: DeveloperServicesTeam.ID) throws -> SigningInfo? {
|
||||
guard let data = try storage.data(forKey: teamID.rawValue)
|
||||
else { return nil }
|
||||
return try decoder.decode(SigningInfo.self, from: data)
|
||||
}
|
||||
|
||||
public func setInfo(_ info: SigningInfo?, forTeamID teamID: DeveloperServicesTeam.ID) throws {
|
||||
let data = try encoder.encode(info)
|
||||
try storage.setData(data, forKey: teamID.rawValue)
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import Foundation
|
||||
import Supersign
|
||||
import SupersignCLISupport
|
||||
|
||||
// let app = Bundle.module.url(forResource: "Supercharge", withExtension: "ipa")!
|
||||
|
||||
#warning("Improve persistence on Windows/Linux")
|
||||
|
||||
// for Windows, we could use dpapi.h or wincred.h.
|
||||
// for Linux, maybe use libsecret?
|
||||
// see https://github.com/atom/node-keytar
|
||||
|
||||
let storage: KeyValueStorage
|
||||
// #if os(macOS)
|
||||
// storage = KeychainStorage(service: "com.kabiroberai.Supercharge-Keychain.credentials")
|
||||
// #else
|
||||
let directory = URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent(".config/Supercharge/data")
|
||||
storage = DirectoryStorage(base: directory)
|
||||
// #endif
|
||||
|
||||
try await SupersignCLI.run(configuration: SupersignCLI.Configuration(
|
||||
superchargeApp: nil,
|
||||
storage: storage
|
||||
))
|
||||
@@ -1,72 +0,0 @@
|
||||
import Foundation
|
||||
import Supersign
|
||||
|
||||
struct AuthToken {
|
||||
let appleID: String
|
||||
let dsToken: DeveloperServicesLoginToken
|
||||
}
|
||||
|
||||
extension AuthToken {
|
||||
|
||||
// encoded format:
|
||||
// - appleID (null terminated string)
|
||||
// - adsid (null terminated string)
|
||||
// - expiry (double)
|
||||
// - token (data)
|
||||
|
||||
init?(string: String) {
|
||||
guard string.hasPrefix("@") else { return nil }
|
||||
guard let data = Data(base64Encoded: String(string.dropFirst())) else { return nil }
|
||||
let components = data.split(separator: 0, maxSplits: 2, omittingEmptySubsequences: false)
|
||||
guard components.count == 3,
|
||||
let appleID = String(data: components[0], encoding: .utf8),
|
||||
!appleID.isEmpty,
|
||||
let adsid = String(data: components[1], encoding: .utf8),
|
||||
!adsid.isEmpty
|
||||
else { return nil }
|
||||
|
||||
let rest = components[2]
|
||||
guard rest.count > MemoryLayout<Double>.size else { return nil }
|
||||
var expiry: Double = 0
|
||||
withUnsafeMutableBytes(of: &expiry) { _ = rest.copyBytes(to: $0) }
|
||||
|
||||
let token = rest.advanced(by: MemoryLayout<Double>.size).base64EncodedString()
|
||||
|
||||
self.appleID = appleID
|
||||
self.dsToken = DeveloperServicesLoginToken(
|
||||
adsid: adsid,
|
||||
token: token,
|
||||
expiry: Date(timeIntervalSince1970: expiry)
|
||||
)
|
||||
}
|
||||
|
||||
var string: String? {
|
||||
guard var data = appleID.data(using: .utf8)
|
||||
else { return nil }
|
||||
data.append(0)
|
||||
guard let adsidData = dsToken.adsid.data(using: .utf8)
|
||||
else { return nil }
|
||||
data.append(adsidData)
|
||||
data.append(0)
|
||||
withUnsafeBytes(of: dsToken.expiry.timeIntervalSince1970) {
|
||||
data.append(Data($0))
|
||||
}
|
||||
guard let rawToken = Data(base64Encoded: dsToken.token)
|
||||
else { return nil }
|
||||
data.append(rawToken)
|
||||
return "@\(data.base64EncodedString())"
|
||||
}
|
||||
|
||||
static func saved() throws -> Self {
|
||||
guard let string = try SupersignCLI.config.storage.string(forKey: "SUPAuthToken"),
|
||||
let token = AuthToken(string: string) else {
|
||||
throw Console.Error("Please log in with `supersign ds login` before running this command.")
|
||||
}
|
||||
return token
|
||||
}
|
||||
|
||||
func save() throws {
|
||||
try SupersignCLI.config.storage.setString(string, forKey: "SUPAuthToken")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
import Foundation
|
||||
import Supersign
|
||||
|
||||
enum Console {
|
||||
// nil = EOF
|
||||
static func prompt(_ message: String) -> String? {
|
||||
if !message.isEmpty {
|
||||
print(message, terminator: "")
|
||||
}
|
||||
fflush(stdoutSafe)
|
||||
return readLine()
|
||||
}
|
||||
|
||||
static func getPassword(_ message: String) -> String? {
|
||||
if !message.isEmpty {
|
||||
print(message, terminator: "")
|
||||
}
|
||||
let password = withoutEcho { prompt("") }
|
||||
print()
|
||||
return password
|
||||
}
|
||||
|
||||
private static func withoutEcho<T>(_ action: () throws -> T) rethrows -> T {
|
||||
#if os(Windows)
|
||||
// based on https://stackoverflow.com/a/4497117/3769927
|
||||
// TODO: Confirm that this works (or even compiles)
|
||||
|
||||
let hConsole = CreateFileA("CONIN$", GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0)
|
||||
var dwOldMode: DWORD = 0
|
||||
GetConsoleMode(hConsole, &dwOldMode)
|
||||
|
||||
let dwNewMode = dwOldMode & ~ENABLE_ECHO_INPUT
|
||||
SetConsoleMode(hConsole, dwNewMode)
|
||||
defer { SetConsoleMode(hConsole, dwOldMode) }
|
||||
|
||||
return try action()
|
||||
#else
|
||||
var origAttr = termios()
|
||||
tcgetattr(STDIN_FILENO, &origAttr)
|
||||
|
||||
var newAttr = origAttr
|
||||
newAttr.c_lflag = newAttr.c_lflag & ~tcflag_t(ECHO)
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &newAttr)
|
||||
defer { tcsetattr(STDIN_FILENO, TCSANOW, &origAttr) }
|
||||
|
||||
return try action()
|
||||
#endif
|
||||
}
|
||||
|
||||
static func chooseNumber(in range: Range<Int>) -> Int {
|
||||
let message = "Choice (\(range.lowerBound)-\(range.upperBound - 1)): "
|
||||
while true {
|
||||
if let choice = prompt(message).flatMap(Int.init), range.contains(choice) {
|
||||
return choice
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static func choose<T>(
|
||||
from elements: [T],
|
||||
onNoElement: () throws -> T,
|
||||
multiPrompt: @autoclosure () -> String,
|
||||
formatter: (T) throws -> String
|
||||
) rethrows -> T {
|
||||
switch elements.count {
|
||||
case 0:
|
||||
return try onNoElement()
|
||||
case 1:
|
||||
return elements[0]
|
||||
default:
|
||||
print(multiPrompt())
|
||||
try elements.enumerated().forEach { index, element in
|
||||
try print("\(index): \(formatter(element))")
|
||||
}
|
||||
let choice = chooseNumber(in: elements.indices)
|
||||
return elements[choice]
|
||||
}
|
||||
}
|
||||
|
||||
private static let yesSet: Set<String> = ["yes", "y"]
|
||||
private static let noSet: Set<String> = ["no", "n"]
|
||||
|
||||
static func confirm(_ message: String) -> Bool {
|
||||
while true {
|
||||
if let resp = prompt("\(message) (yes/no): ")?.lowercased() {
|
||||
if yesSet.contains(resp) {
|
||||
return true
|
||||
} else if noSet.contains(resp) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Error: Swift.Error, CustomStringConvertible {
|
||||
let description: String
|
||||
init(_ description: String) {
|
||||
self.description = description
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
import Foundation
|
||||
import Supersign
|
||||
import ArgumentParser
|
||||
|
||||
extension DeviceInfo {
|
||||
static func fetch() throws -> Self {
|
||||
guard let deviceInfo = DeviceInfo.current() else {
|
||||
throw Console.Error("Could not fetch client info.")
|
||||
}
|
||||
return deviceInfo
|
||||
}
|
||||
}
|
||||
|
||||
struct DSLoginCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "login",
|
||||
abstract: "Obtain an Apple ID authentication token"
|
||||
)
|
||||
|
||||
@Flag(name: [.short, .long]) var resetProvisioning = false
|
||||
@Option(name: [.short, .long], help: "Apple ID") var username: String?
|
||||
@Option(name: [.short, .long]) var password: String?
|
||||
@Flag(
|
||||
name: [.long],
|
||||
help: "Print the auth token to standard output instead of persisting it."
|
||||
) var printToken = false
|
||||
|
||||
func run() async throws {
|
||||
guard let username = username ?? Console.prompt("Apple ID: "), !username.isEmpty else {
|
||||
throw Console.Error("A non-empty Apple ID is required.")
|
||||
}
|
||||
guard let password = password ?? Console.getPassword("Password: "), !password.isEmpty else {
|
||||
throw Console.Error("A non-empty password is required.")
|
||||
}
|
||||
|
||||
let deviceInfo = try DeviceInfo.fetch()
|
||||
|
||||
let provider = try ADIDataProvider.adiProvider(
|
||||
deviceInfo: deviceInfo,
|
||||
storage: SupersignCLI.config.storage
|
||||
)
|
||||
if resetProvisioning {
|
||||
provider.resetProvisioning()
|
||||
}
|
||||
let authDelegate = SupersignCLIAuthDelegate()
|
||||
let manager = try DeveloperServicesLoginManager(
|
||||
deviceInfo: deviceInfo,
|
||||
anisetteProvider: provider
|
||||
)
|
||||
let token = try await manager.logIn(
|
||||
withUsername: username,
|
||||
password: password,
|
||||
twoFactorDelegate: authDelegate
|
||||
)
|
||||
let fullToken = AuthToken(appleID: username, dsToken: token)
|
||||
|
||||
if printToken {
|
||||
guard let string = fullToken.string else {
|
||||
throw Console.Error("Could not encode token.")
|
||||
}
|
||||
print(string)
|
||||
} else {
|
||||
try fullToken.save()
|
||||
print("Logged in!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct DSTeamsListCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "list",
|
||||
abstract: "List Developer Services teams"
|
||||
)
|
||||
|
||||
@Option(name: .shortAndLong) var account: String?
|
||||
|
||||
func run() async throws {
|
||||
let token = try account.flatMap(AuthToken.init(string:)) ?? AuthToken.saved()
|
||||
|
||||
let deviceInfo = try DeviceInfo.fetch()
|
||||
let anisetteProvider = try ADIDataProvider.adiProvider(
|
||||
deviceInfo: deviceInfo, storage: SupersignCLI.config.storage
|
||||
)
|
||||
|
||||
let client = DeveloperServicesClient(
|
||||
loginToken: token.dsToken,
|
||||
deviceInfo: deviceInfo,
|
||||
anisetteProvider: anisetteProvider
|
||||
)
|
||||
let teams: [DeveloperServicesTeam] = try await client.send(DeveloperServicesListTeamsRequest())
|
||||
print(
|
||||
teams.map {
|
||||
"\($0.name) [\($0.status)]: \($0.id.rawValue)" +
|
||||
$0.memberships.map { "\n- \($0.name) (\($0.platform))" }.joined()
|
||||
}.joined(separator: "\n")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
struct DSAnisetteCommand: AsyncParsableCommand {
|
||||
private final class Provider: RawADIProvider, RawADIProvisioningSession {
|
||||
func startProvisioning(spim: Data, userID: UUID) -> (RawADIProvisioningSession, Data) {
|
||||
print("spim: \(spim.base64EncodedString())")
|
||||
return (self, Data(base64Encoded: Console.prompt("cpim: ")!)!)
|
||||
}
|
||||
|
||||
func endProvisioning(
|
||||
routingInfo: UInt64,
|
||||
ptm: Data,
|
||||
tk: Data
|
||||
) -> Data {
|
||||
print("""
|
||||
rinfo: \(routingInfo)
|
||||
ptm: \(ptm.base64EncodedString())
|
||||
tk: \(tk.base64EncodedString())
|
||||
""")
|
||||
return Data(base64Encoded: Console.prompt("pinfo: ")!)!
|
||||
}
|
||||
|
||||
func requestOTP(
|
||||
userID: UUID,
|
||||
routingInfo: inout UInt64,
|
||||
provisioningInfo: Data
|
||||
) -> (machineID: Data, otp: Data) {
|
||||
print("otp; pinfo: \(provisioningInfo)")
|
||||
return (Data(), Data())
|
||||
}
|
||||
}
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "anisette",
|
||||
abstract: "Test out Anisette data"
|
||||
)
|
||||
|
||||
func run() async throws {
|
||||
// swiftlint:disable:next force_try
|
||||
let res = try! await ADIDataProvider(
|
||||
rawProvider: Provider(),
|
||||
deviceInfo: .current()!,
|
||||
storage: SupersignCLI.config.storage
|
||||
).fetchAnisetteData()
|
||||
|
||||
print(res)
|
||||
}
|
||||
}
|
||||
|
||||
struct DSTeamsCommand: ParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "teams",
|
||||
abstract: "Interact with Developer Services teams",
|
||||
subcommands: [DSTeamsListCommand.self],
|
||||
defaultSubcommand: DSTeamsListCommand.self
|
||||
)
|
||||
}
|
||||
|
||||
struct DSCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "ds",
|
||||
abstract: "Interact with Apple Developer Services",
|
||||
subcommands: [
|
||||
DSLoginCommand.self,
|
||||
DSTeamsCommand.self,
|
||||
DSAnisetteCommand.self
|
||||
]
|
||||
)
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
import Foundation
|
||||
import ArgumentParser
|
||||
import PackLib
|
||||
import Supersign
|
||||
|
||||
struct DevCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "dev",
|
||||
abstract: "Build and run apps with SwiftPM",
|
||||
discussion: """
|
||||
This command deploys the SwiftPM-based iOS app in the current directory \
|
||||
using https://github.com/kabiroberai/swiftpack
|
||||
"""
|
||||
)
|
||||
|
||||
@OptionGroup var connectionOptions: ConnectionOptions
|
||||
|
||||
@Option(
|
||||
name: .shortAndLong,
|
||||
help: "Build with configuration"
|
||||
) var configuration: BuildConfiguration = .debug
|
||||
|
||||
@Option(
|
||||
name: .shortAndLong,
|
||||
help: "Preferred team ID"
|
||||
) var team: String?
|
||||
|
||||
func run() async throws {
|
||||
print("Planning...")
|
||||
|
||||
let schema: PackSchema
|
||||
let configPath = URL(fileURLWithPath: "swiftpack.yml")
|
||||
if FileManager.default.fileExists(atPath: configPath.path) {
|
||||
schema = try await PackSchema(url: configPath)
|
||||
} else {
|
||||
schema = .default
|
||||
print("""
|
||||
warning: Could not locate configuration file '\(configPath.path)'. Using default \
|
||||
configuration with 'com.example' organization ID.
|
||||
""")
|
||||
}
|
||||
|
||||
let buildSettings = try await BuildSettings(
|
||||
configuration: configuration,
|
||||
options: []
|
||||
)
|
||||
|
||||
let planner = Planner(
|
||||
buildSettings: buildSettings,
|
||||
schema: schema
|
||||
)
|
||||
let plan = try await planner.createPlan()
|
||||
|
||||
let packer = Packer(
|
||||
buildSettings: buildSettings,
|
||||
plan: plan
|
||||
)
|
||||
let output = try await packer.pack()
|
||||
|
||||
let token = try AuthToken.saved()
|
||||
|
||||
let client = try await connectionOptions.client()
|
||||
print("Installing to device: \(client.deviceName) (udid: \(client.udid))")
|
||||
|
||||
let installDelegate = SupersignCLIDelegate(preferredTeam: team.map(DeveloperServicesTeam.ID.init))
|
||||
let installer = IntegratedInstaller(
|
||||
udid: client.udid,
|
||||
lookupMode: .only(client.connectionType),
|
||||
appleID: token.appleID,
|
||||
token: token.dsToken,
|
||||
configureDevice: false,
|
||||
storage: SupersignCLI.config.storage,
|
||||
delegate: installDelegate
|
||||
)
|
||||
|
||||
try await installer.install(app: output)
|
||||
}
|
||||
}
|
||||
|
||||
extension BuildConfiguration: @retroactive ExpressibleByArgument {}
|
||||
@@ -1,60 +0,0 @@
|
||||
import Foundation
|
||||
import Supersign
|
||||
import ArgumentParser
|
||||
|
||||
struct InstallSuperchargeCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "install",
|
||||
abstract: "Install Supercharge"
|
||||
)
|
||||
|
||||
@OptionGroup var connectionOptions: ConnectionOptions.WithoutSearchMode
|
||||
|
||||
func run() async throws {
|
||||
guard let app = SupersignCLI.config.superchargeApp else {
|
||||
throw Console.Error("This copy of Supersign is not configured to install Supercharge.")
|
||||
}
|
||||
|
||||
let auth = try AuthToken.saved()
|
||||
|
||||
let client = try await connectionOptions.client(searchMode: .usb)
|
||||
|
||||
print("Installing to device: \(client.deviceName) (udid: \(client.udid))")
|
||||
|
||||
let installDelegate = SupersignCLIDelegate(preferredTeam: nil)
|
||||
let installer = IntegratedInstaller(
|
||||
udid: client.udid,
|
||||
lookupMode: .only(client.connectionType),
|
||||
appleID: auth.appleID,
|
||||
token: auth.dsToken,
|
||||
configureDevice: true,
|
||||
storage: SupersignCLI.config.storage,
|
||||
delegate: installDelegate
|
||||
)
|
||||
|
||||
do {
|
||||
let bundleID = try await installer.install(app: app)
|
||||
print("\nSuccessfully installed!")
|
||||
if let file = ProcessInfo.processInfo.environment["SUPERSIGN_METADATA_FILE"] {
|
||||
do {
|
||||
try Data("\(bundleID)\n".utf8).write(to: URL(fileURLWithPath: file))
|
||||
} catch {
|
||||
print("warning: Failed to write metadata to SUPERSIGN_METADATA_FILE: \(error)")
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
print("\nFailed :(")
|
||||
print("Error: \(error)")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SuperchargeCommand: ParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "supercharge",
|
||||
abstract: "Configure/install Supercharge",
|
||||
subcommands: [InstallSuperchargeCommand.self],
|
||||
defaultSubcommand: InstallSuperchargeCommand.self
|
||||
)
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
import Foundation
|
||||
import Supersign
|
||||
import ConcurrencyExtras
|
||||
|
||||
final class SupersignCLIAuthDelegate: TwoFactorAuthDelegate {
|
||||
func fetchCode() async -> String? {
|
||||
Console.prompt("Code: ")
|
||||
}
|
||||
}
|
||||
|
||||
actor SupersignCLIDelegate: IntegratedInstallerDelegate {
|
||||
public enum Error: Swift.Error {
|
||||
case decompressionFailed
|
||||
case compressionFailed
|
||||
}
|
||||
|
||||
let preferredTeam: DeveloperServicesTeam.ID?
|
||||
init(preferredTeam: DeveloperServicesTeam.ID?) {
|
||||
self.preferredTeam = preferredTeam
|
||||
}
|
||||
|
||||
private let updateTask = LockIsolated<Task<Void, Never>?>(nil)
|
||||
|
||||
func fetchTeam(fromTeams teams: [DeveloperServicesTeam]) async -> DeveloperServicesTeam? {
|
||||
if let preferredTeam = preferredTeam {
|
||||
// Fails if a team with the requested ID isn't found.
|
||||
// This is intentional to avoid interactivity.
|
||||
return teams.first(where: { $0.id == preferredTeam })
|
||||
}
|
||||
|
||||
return Console.choose(
|
||||
from: teams,
|
||||
onNoElement: { fatalError("No development teams available") },
|
||||
multiPrompt: "\nSelect a team",
|
||||
formatter: {
|
||||
"\($0.name) (\($0.id.rawValue))"
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
nonisolated func setPresentedMessage(_ message: IntegratedInstaller.Message?) {
|
||||
let text: String
|
||||
switch message {
|
||||
case .pairDevice:
|
||||
text = "Please tap 'trust' on your device..."
|
||||
case .unlockDevice:
|
||||
text = "Please unlock your device..."
|
||||
case nil:
|
||||
text = "Continuing..."
|
||||
}
|
||||
print("\n\(text)", terminator: "")
|
||||
fflush(stdoutSafe)
|
||||
}
|
||||
|
||||
var prevStage: String?
|
||||
var prevProgress: String?
|
||||
|
||||
private func _installerDidUpdate(toStage stage: String, progress: Double?) {
|
||||
let progString: String?
|
||||
if let progress = progress {
|
||||
let progInt = Int(progress * 100)
|
||||
if progInt < 10 {
|
||||
progString = " \(progInt)%"
|
||||
} else if progInt < 100 {
|
||||
progString = " \(progInt)%"
|
||||
} else {
|
||||
progString = "\(progInt)%"
|
||||
}
|
||||
} else {
|
||||
progString = nil
|
||||
}
|
||||
|
||||
defer {
|
||||
prevStage = stage
|
||||
prevProgress = progString
|
||||
}
|
||||
|
||||
if stage != prevStage {
|
||||
if let progString = progString {
|
||||
print("\n[\(stage)] \(progString)", terminator: "")
|
||||
fflush(stdoutSafe)
|
||||
} else {
|
||||
print("\n[\(stage)] ...", terminator: "")
|
||||
fflush(stdoutSafe)
|
||||
}
|
||||
} else if progString != prevProgress {
|
||||
if let progString = progString {
|
||||
print("\r[\(stage)] \(progString)", terminator: "")
|
||||
fflush(stdoutSafe)
|
||||
} else {
|
||||
print("\r[\(stage)]", terminator: "")
|
||||
fflush(stdoutSafe)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated func installerDidUpdate(toStage stage: String, progress: Double?) {
|
||||
updateTask.withValue { task in
|
||||
task = Task { [prev = task] in
|
||||
await prev?.value
|
||||
await _installerDidUpdate(toStage: stage, progress: progress)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func confirmRevocation(of certificates: [DeveloperServicesCertificate]) async -> Bool {
|
||||
print("\nThe following certificates must be revoked:")
|
||||
print(
|
||||
certificates.map {
|
||||
"- \($0.attributes.name) (expires \($0.attributes.expiry.formatted(date: .abbreviated, time: .shortened)))"
|
||||
}.joined(separator: "\n")
|
||||
)
|
||||
return await Task.detached { Console.confirm("Continue?") }.value
|
||||
}
|
||||
|
||||
// TODO: Use `powershell Compress-Archive` and `powershell Expand-Archive` on Windows
|
||||
|
||||
func decompress(
|
||||
ipa: URL,
|
||||
in directory: URL,
|
||||
progress: @escaping (Double?) -> Void
|
||||
) async throws {
|
||||
progress(nil)
|
||||
|
||||
let unzip = Process()
|
||||
unzip.launchPath = "/usr/bin/unzip"
|
||||
unzip.arguments = ["-q", ipa.path, "-d", directory.path]
|
||||
try await unzip.launchAndWait()
|
||||
guard unzip.terminationStatus == 0 else {
|
||||
throw Error.decompressionFailed
|
||||
}
|
||||
}
|
||||
|
||||
func compress(
|
||||
payloadDir: URL,
|
||||
progress: @escaping (Double?) -> Void
|
||||
) async throws -> URL {
|
||||
progress(nil)
|
||||
|
||||
let dest = payloadDir.deletingLastPathComponent().appendingPathComponent("app.ipa")
|
||||
|
||||
let zip = Process()
|
||||
zip.launchPath = "/usr/bin/zip"
|
||||
zip.currentDirectoryPath = payloadDir.deletingLastPathComponent().path
|
||||
zip.arguments = ["-yqru0", dest.path, "Payload"]
|
||||
try await zip.launchAndWait()
|
||||
guard zip.terminationStatus == 0 else { throw Error.compressionFailed }
|
||||
|
||||
return dest
|
||||
}
|
||||
}
|
||||
|
||||
extension Process {
|
||||
fileprivate func launchAndWait() async throws {
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
terminationHandler = { _ in
|
||||
continuation.resume()
|
||||
}
|
||||
do {
|
||||
try self.run()
|
||||
} catch {
|
||||
continuation.resume(throwing: error)
|
||||
return
|
||||
}
|
||||
Task.detached { self.waitUntilExit() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
import Foundation
|
||||
import Supersign
|
||||
import ArgumentParser
|
||||
|
||||
public enum SupersignCLI {
|
||||
public struct Configuration: Sendable {
|
||||
public let superchargeApp: URL?
|
||||
public let storage: KeyValueStorage
|
||||
|
||||
public init(
|
||||
superchargeApp: URL?,
|
||||
storage: KeyValueStorage
|
||||
) {
|
||||
self.superchargeApp = superchargeApp
|
||||
self.storage = storage
|
||||
}
|
||||
}
|
||||
|
||||
private static nonisolated(unsafe) var _config: Configuration!
|
||||
static var config: Configuration { _config }
|
||||
|
||||
public static func run(configuration: Configuration, arguments: [String]? = nil) async throws {
|
||||
_config = configuration
|
||||
defer { defaultHTTPClientFactory.shutdown() }
|
||||
do {
|
||||
var command = try SupersignCommand.parseAsRoot(arguments)
|
||||
if var asyncCommand = command as? AsyncParsableCommand {
|
||||
try await asyncCommand.run()
|
||||
} else {
|
||||
try command.run()
|
||||
}
|
||||
} catch {
|
||||
SupersignCommand.exit(withError: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SupersignCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "supersign",
|
||||
abstract: "The Supersign command line tool",
|
||||
subcommands: [
|
||||
DSCommand.self,
|
||||
DevicesCommand.self,
|
||||
InstallCommand.self,
|
||||
UninstallCommand.self,
|
||||
DevCommand.self,
|
||||
// no Supercharge support... yet...
|
||||
// SuperchargeCommand.self,
|
||||
RunCommand.self,
|
||||
]
|
||||
)
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import Foundation
|
||||
import Supersign
|
||||
|
||||
func withSyncContinuation<T>(
|
||||
_ action: (_ cont: @escaping (T) -> Void) -> Void
|
||||
) -> T {
|
||||
var value: T!
|
||||
let sem = DispatchSemaphore(value: 0)
|
||||
action {
|
||||
value = $0
|
||||
sem.signal()
|
||||
}
|
||||
sem.wait()
|
||||
return value
|
||||
}
|
||||
|
||||
func withSyncContinuation<T>(
|
||||
_ action: (_ cont: @escaping (Result<T, Error>) -> Void) -> Void
|
||||
) throws -> T {
|
||||
try withSyncContinuation(action).get()
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
module XADI [extern_c] {
|
||||
header "xadi.h"
|
||||
link "xadi"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <stdint.h>
|
||||
|
||||
void xadi_Load(const char *path);
|
||||
int32_t xadi_SetAndroidID(const char *identifier, uint32_t length);
|
||||
int32_t xadi_SetProvisioningPath(const char *path);
|
||||
int32_t xadi_ProvisioningErase(uint64_t dsId);
|
||||
int32_t xadi_Synchronize(uint64_t dsId, const void *serverIntermediateMetadata, uint32_t serverIntermediateMetadataLength, void **machineIdentifier, uint32_t *machineIdentifierLength, void **synchronizationResumeMetadata, uint32_t *synchronizationResumeMetadataLength);
|
||||
int32_t xadi_ProvisioningDestroy(uint32_t session);
|
||||
int32_t xadi_ProvisioningEnd(uint32_t session, const void *persistentTokenMetadata, uint32_t persistentTokenMetadataLength, const void *trustKey, uint32_t trustKeyLength);
|
||||
int32_t xadi_ProvisioningStart(uint64_t dsId, const void *serverProvisioningIntermediateMetadata, uint32_t serverProvisioningIntermediateMetadataLength, void **clientProvisioningIntermediateMetadata, uint32_t *clientProvisioningIntermediateMetadataLength, uint32_t *session);
|
||||
int32_t xadi_GetLoginCode(uint64_t dsId);
|
||||
int32_t xadi_Dispose(void *ptr);
|
||||
int32_t xadi_OTPRequest(uint64_t dsId, void **machineIdentifier, uint32_t *machineIdentifierLength, void **oneTimePassword, uint32_t *oneTimePasswordLength);
|
||||
@@ -0,0 +1,100 @@
|
||||
import Foundation
|
||||
import Crypto
|
||||
|
||||
public struct ASCKey: Sendable {
|
||||
public var id: String
|
||||
public var issuerID: String
|
||||
public var pem: String
|
||||
|
||||
public init(id: String, issuerID: String, pem: String) {
|
||||
self.id = id
|
||||
self.issuerID = issuerID
|
||||
self.pem = pem
|
||||
}
|
||||
}
|
||||
|
||||
actor ASCJWTGenerator {
|
||||
// the duration for which we generate JWTs.
|
||||
// ASC allows a maximum of 20 minutes.
|
||||
private static let ttl: TimeInterval = 60 * 20
|
||||
|
||||
// the minimum remaining ttl for us to consider reusing a previous key.
|
||||
// that is, we reuse the last JWT if it has at least [threshold] seconds
|
||||
// left before it expires.
|
||||
private static let tolerance: TimeInterval = 60
|
||||
|
||||
private static let encoder: JSONEncoder = {
|
||||
let encoder = JSONEncoder()
|
||||
encoder.dateEncodingStrategy = .secondsSince1970
|
||||
encoder.outputFormatting = .sortedKeys
|
||||
return encoder
|
||||
}()
|
||||
|
||||
private var lastJWT: (jwt: String, renewAt: Date)?
|
||||
|
||||
private var parsedKey: P256.Signing.PrivateKey?
|
||||
|
||||
nonisolated let key: ASCKey
|
||||
init(key: ASCKey) {
|
||||
self.key = key
|
||||
}
|
||||
|
||||
private struct Header: Encodable {
|
||||
let alg = "ES256"
|
||||
let typ = "JWT"
|
||||
let kid: String
|
||||
}
|
||||
|
||||
private struct Payload: Encodable {
|
||||
let aud = "appstoreconnect-v1"
|
||||
let iss: String
|
||||
let iat: Date
|
||||
let exp: Date
|
||||
}
|
||||
|
||||
private func encode(_ value: some Encodable) throws -> String {
|
||||
try ASCJWTGenerator.encoder.encode(value).base64URLEncodedString()
|
||||
}
|
||||
|
||||
private func getKey() throws -> P256.Signing.PrivateKey {
|
||||
if let parsedKey { return parsedKey }
|
||||
|
||||
let key = try P256.Signing.PrivateKey(pemRepresentation: key.pem)
|
||||
self.parsedKey = key
|
||||
|
||||
return key
|
||||
}
|
||||
|
||||
func generate() throws -> String {
|
||||
if let lastJWT, lastJWT.renewAt > Date() {
|
||||
return lastJWT.jwt
|
||||
}
|
||||
|
||||
let encodedHeader = try encode(Header(kid: key.id))
|
||||
|
||||
let issuedAt = Date()
|
||||
let expiry = issuedAt + ASCJWTGenerator.ttl
|
||||
let renewAt = expiry - ASCJWTGenerator.tolerance
|
||||
let encodedPayload = try encode(Payload(iss: key.issuerID, iat: issuedAt, exp: expiry))
|
||||
|
||||
let body = "\(encodedHeader).\(encodedPayload)"
|
||||
let signature = try getKey()
|
||||
.signature(for: Data(body.utf8))
|
||||
.rawRepresentation
|
||||
.base64URLEncodedString()
|
||||
|
||||
let jwt = "\(body).\(signature)"
|
||||
lastJWT = (jwt, renewAt)
|
||||
return jwt
|
||||
}
|
||||
}
|
||||
|
||||
extension Data {
|
||||
fileprivate func base64URLEncodedString() -> String {
|
||||
self
|
||||
.base64EncodedString()
|
||||
.replacingOccurrences(of: "+", with: "-")
|
||||
.replacingOccurrences(of: "/", with: "_")
|
||||
.replacingOccurrences(of: "=", with: "")
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -15,14 +15,14 @@ public final class DeveloperServicesAssignAppGroupRequest: DeveloperServicesPlat
|
||||
|
||||
public let platform: DeveloperServicesPlatform
|
||||
public let teamID: DeveloperServicesTeam.ID
|
||||
public let appIDID: DeveloperServicesAppID.ID
|
||||
public let appIDID: String
|
||||
public let groupID: DeveloperServicesAppGroup.ID
|
||||
|
||||
var subAction: String { return "assignApplicationGroupToAppId" }
|
||||
var subParameters: [String: Any] {
|
||||
return [
|
||||
"teamId": teamID.rawValue,
|
||||
"appIdId": appIDID.rawValue,
|
||||
"appIdId": appIDID,
|
||||
"applicationGroups": groupID.rawValue
|
||||
]
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public final class DeveloperServicesAssignAppGroupRequest: DeveloperServicesPlat
|
||||
public init(
|
||||
platform: DeveloperServicesPlatform,
|
||||
teamID: DeveloperServicesTeam.ID,
|
||||
appIDID: DeveloperServicesAppID.ID,
|
||||
appIDID: String,
|
||||
groupID: DeveloperServicesAppGroup.ID
|
||||
) {
|
||||
self.platform = platform
|
||||
+34
-13
@@ -1,28 +1,41 @@
|
||||
//
|
||||
// DeveloperServicesAssignAppGroupsOperation.swift
|
||||
// Supersign
|
||||
// XKit
|
||||
//
|
||||
// Created by Kabir Oberai on 14/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import DeveloperAPI
|
||||
|
||||
public struct DeveloperServicesAssignAppGroupsOperation: DeveloperServicesOperation {
|
||||
|
||||
public let context: SigningContext
|
||||
public let groupIDs: [DeveloperServicesAppGroup.GroupID]
|
||||
public let appID: DeveloperServicesAppID
|
||||
public init(context: SigningContext, groupIDs: [DeveloperServicesAppGroup.GroupID], appID: DeveloperServicesAppID) {
|
||||
public let appID: Components.Schemas.BundleId
|
||||
public let xcodeAuthData: XcodeAuthData
|
||||
|
||||
private let client: DeveloperServicesClient
|
||||
|
||||
public init?(
|
||||
context: SigningContext,
|
||||
groupIDs: [DeveloperServicesAppGroup.GroupID],
|
||||
appID: Components.Schemas.BundleId
|
||||
) {
|
||||
self.context = context
|
||||
self.groupIDs = groupIDs
|
||||
self.appID = appID
|
||||
|
||||
guard case .xcode(let authData) = context.auth else { return nil }
|
||||
self.xcodeAuthData = authData
|
||||
|
||||
self.client = DeveloperServicesClient(authData: authData)
|
||||
}
|
||||
|
||||
private func upsertAppGroup(
|
||||
_ groupID: DeveloperServicesAppGroup.GroupID,
|
||||
existingGroups: [String: DeveloperServicesAppGroup],
|
||||
appID: DeveloperServicesAppID
|
||||
existingGroups: [String: DeveloperServicesAppGroup]
|
||||
) async throws -> DeveloperServicesAppGroup.GroupID {
|
||||
let sanitized = ProvisioningIdentifiers.sanitize(groupID: groupID)
|
||||
let group: DeveloperServicesAppGroup
|
||||
@@ -32,28 +45,36 @@ public struct DeveloperServicesAssignAppGroupsOperation: DeveloperServicesOperat
|
||||
let groupID = ProvisioningIdentifiers.groupID(fromSanitized: sanitized, context: context)
|
||||
let name = ProvisioningIdentifiers.groupName(fromSanitized: sanitized)
|
||||
let request = DeveloperServicesAddAppGroupRequest(
|
||||
platform: context.platform, teamID: context.teamID, name: name, groupID: groupID
|
||||
platform: .iOS,
|
||||
teamID: xcodeAuthData.teamID,
|
||||
name: name,
|
||||
groupID: groupID
|
||||
)
|
||||
group = try await context.client.send(request)
|
||||
group = try await client.send(request)
|
||||
}
|
||||
|
||||
_ = try await context.client.send(DeveloperServicesAssignAppGroupRequest(
|
||||
platform: context.platform, teamID: context.teamID, appIDID: appID.id, groupID: group.id
|
||||
))
|
||||
_ = try await client.send(
|
||||
DeveloperServicesAssignAppGroupRequest(
|
||||
platform: .iOS,
|
||||
teamID: xcodeAuthData.teamID,
|
||||
appIDID: appID.id,
|
||||
groupID: group.id
|
||||
)
|
||||
)
|
||||
|
||||
return group.groupID
|
||||
}
|
||||
|
||||
public func perform() async throws -> [DeveloperServicesAppGroup.GroupID] {
|
||||
let existing = try await context.client.send(DeveloperServicesListAppGroupsRequest(
|
||||
platform: context.platform, teamID: context.teamID
|
||||
let existing = try await client.send(DeveloperServicesListAppGroupsRequest(
|
||||
platform: .iOS, teamID: xcodeAuthData.teamID
|
||||
))
|
||||
let sanitized = existing.map { (ProvisioningIdentifiers.sanitize(groupID: $0.groupID), $0) }
|
||||
let dict = Dictionary(sanitized, uniquingKeysWith: { $1 })
|
||||
return try await withThrowingTaskGroup(of: DeveloperServicesAppGroup.GroupID.self) { group in
|
||||
for groupID in groupIDs {
|
||||
group.addTask {
|
||||
try await upsertAppGroup(groupID, existingGroups: dict, appID: appID)
|
||||
try await upsertAppGroup(groupID, existingGroups: dict)
|
||||
}
|
||||
}
|
||||
return try await group.reduce(into: []) { $0.append($1) }
|
||||
@@ -0,0 +1,265 @@
|
||||
//
|
||||
// DeveloperServicesAddAppOperation.swift
|
||||
// XKit
|
||||
//
|
||||
// Created by Kabir Oberai on 14/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import DeveloperAPI
|
||||
|
||||
public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
|
||||
|
||||
public enum Error: LocalizedError {
|
||||
case invalidApp(URL)
|
||||
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .invalidApp(let url):
|
||||
return url.path.withCString {
|
||||
String.localizedStringWithFormat(
|
||||
NSLocalizedString(
|
||||
"add_app_operation.error.invalid_app", value: "Invalid app: %s", comment: ""
|
||||
), $0
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public let context: SigningContext
|
||||
public let signingInfo: SigningInfo
|
||||
public let root: URL
|
||||
public init(context: SigningContext, signingInfo: SigningInfo, root: URL) {
|
||||
self.context = context
|
||||
self.signingInfo = signingInfo
|
||||
self.root = root
|
||||
}
|
||||
|
||||
/// Registers the app with the given entitlements
|
||||
private func upsertApp(
|
||||
bundleID: String,
|
||||
entitlements: Entitlements,
|
||||
isFreeTeam: Bool,
|
||||
appIDs: [String: Components.Schemas.BundleId]
|
||||
) async throws -> Components.Schemas.BundleId {
|
||||
let appID: Components.Schemas.BundleId
|
||||
if let existing = appIDs[bundleID] {
|
||||
appID = existing
|
||||
} else {
|
||||
let newBundleID = ProvisioningIdentifiers.identifier(fromSanitized: bundleID, context: self.context)
|
||||
let name = ProvisioningIdentifiers.appName(fromSanitized: bundleID)
|
||||
let createResponse = try await context.developerAPIClient.bundleIdsCreateInstance(
|
||||
body: .json(
|
||||
.init(
|
||||
data: .init(
|
||||
_type: .bundleIds,
|
||||
attributes: .init(
|
||||
name: name,
|
||||
platform: .ios,
|
||||
identifier: newBundleID
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
appID = try createResponse.created.body.json.data
|
||||
}
|
||||
|
||||
let existingCapabilitiesList = try await context.developerAPIClient
|
||||
.bundleIdsBundleIdCapabilitiesGetToManyRelated(.init(path: .init(id: appID.id)))
|
||||
.ok.body.json.data
|
||||
let existingCapabilities = [Components.Schemas.CapabilityType: Components.Schemas.BundleIdCapability](
|
||||
existingCapabilitiesList.compactMap { cap in
|
||||
(cap.attributes?.capabilityType).map { ($0, cap) }
|
||||
},
|
||||
uniquingKeysWith: { $1 }
|
||||
)
|
||||
|
||||
let wantedCapabilitiesList = try entitlements.entitlements().compactMap(\.anyCapability)
|
||||
let wantedCapabilities = [Components.Schemas.CapabilityType: [Components.Schemas.CapabilitySetting]](
|
||||
wantedCapabilitiesList.map { ($0.capabilityType, $0.settings ?? []) },
|
||||
uniquingKeysWith: { $1 }
|
||||
)
|
||||
|
||||
for (typ, cap) in existingCapabilities {
|
||||
if let wantedSettings = wantedCapabilities[typ] {
|
||||
if wantedSettings != (cap.attributes?.settings ?? []) {
|
||||
_ = try await context.developerAPIClient.bundleIdCapabilitiesUpdateInstance(
|
||||
path: .init(id: cap.id),
|
||||
body: .json(
|
||||
.init(
|
||||
data: .init(
|
||||
_type: .bundleIdCapabilities,
|
||||
id: cap.id,
|
||||
attributes: .init(
|
||||
capabilityType: typ,
|
||||
settings: wantedSettings
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
.ok
|
||||
}
|
||||
} else {
|
||||
// DeveloperServices doesn't allow deleting these capabilities
|
||||
let requiredCapabilities: Set<Components.Schemas.CapabilityType> = [.inAppPurchase]
|
||||
if let capType = cap.attributes?.capabilityType, !requiredCapabilities.contains(capType) {
|
||||
_ = try await context.developerAPIClient
|
||||
.bundleIdCapabilitiesDeleteInstance(path: .init(id: cap.id))
|
||||
.noContent
|
||||
}
|
||||
}
|
||||
}
|
||||
for (typ, settings) in wantedCapabilities {
|
||||
guard existingCapabilities[typ] == nil else { continue }
|
||||
_ = try await context.developerAPIClient.bundleIdCapabilitiesCreateInstance(
|
||||
body: .json(.init(data: .init(
|
||||
_type: .bundleIdCapabilities,
|
||||
attributes: .init(
|
||||
capabilityType: typ,
|
||||
settings: settings
|
||||
),
|
||||
relationships: .init(
|
||||
bundleId: .init(
|
||||
data: .init(
|
||||
_type: .bundleIds,
|
||||
id: appID.id
|
||||
)
|
||||
),
|
||||
// not public but required when using ds2 API
|
||||
capability: .init(
|
||||
data: .init(
|
||||
_type: .capabilities,
|
||||
id: typ
|
||||
)
|
||||
)
|
||||
)
|
||||
)))
|
||||
)
|
||||
.created.body
|
||||
}
|
||||
|
||||
return appID
|
||||
}
|
||||
|
||||
/// Registers the app and creates a profile. Returns the resultant entitlements as well as
|
||||
/// the profile (note that the profile does not necessarily include all of the entitlements
|
||||
/// that the app has).
|
||||
private func addApp(
|
||||
_ app: URL,
|
||||
isFreeTeam: Bool,
|
||||
appIDs: [String: Components.Schemas.BundleId]
|
||||
) async throws -> ProvisioningInfo {
|
||||
let infoURL = app.appendingPathComponent("Info.plist")
|
||||
guard let data = try? Data(contentsOf: infoURL),
|
||||
let dict = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any],
|
||||
let bundleID = dict["CFBundleIdentifier"] as? String,
|
||||
let executable = dict["CFBundleExecutable"] as? String else {
|
||||
throw Error.invalidApp(app)
|
||||
}
|
||||
let executableURL = app.appendingPathComponent(executable)
|
||||
|
||||
var entitlements: Entitlements
|
||||
// if the executable doesn't already have entitlements, that's
|
||||
// okay. We don't have to throw an error.
|
||||
if let entitlementsData = try? await context.signerImpl.analyze(executable: executableURL),
|
||||
let decodedEntitlements = try? PropertyListDecoder().decode(Entitlements.self, from: entitlementsData) {
|
||||
entitlements = decodedEntitlements
|
||||
|
||||
if isFreeTeam {
|
||||
// re-assign rather than using updateEntitlements since the latter will
|
||||
// retain unrecognized entitlements
|
||||
let filtered = try entitlements.entitlements().filter { $0.anyCapability?.isFree != false }
|
||||
entitlements = try Entitlements(entitlements: filtered)
|
||||
}
|
||||
} else {
|
||||
entitlements = try Entitlements(entitlements: [])
|
||||
}
|
||||
|
||||
let appID = try await upsertApp(bundleID: bundleID, entitlements: entitlements, isFreeTeam: isFreeTeam, appIDs: appIDs)
|
||||
let newBundleID = appID.attributes!.identifier!
|
||||
|
||||
let teamID = try signingInfo.certificate.teamID()
|
||||
try entitlements.update(
|
||||
teamID: .init(rawValue: teamID),
|
||||
bundleID: newBundleID
|
||||
)
|
||||
// set get-task-allow to YES, required for dev certs
|
||||
try entitlements.updateEntitlements { ents in
|
||||
if let getTaskAllow = ents.firstIndex(where: { $0 is GetTaskAllowEntitlement }) {
|
||||
ents[getTaskAllow] = GetTaskAllowEntitlement(rawValue: true)
|
||||
} else {
|
||||
ents.append(GetTaskAllowEntitlement(rawValue: true))
|
||||
}
|
||||
}
|
||||
|
||||
if var entitlementsArray = try? entitlements.entitlements(),
|
||||
let groupsIdx = entitlementsArray.firstIndex(where: { $0 is AppGroupEntitlement }),
|
||||
let groupsEntitlement = entitlementsArray[groupsIdx] as? AppGroupEntitlement {
|
||||
let groups = groupsEntitlement.rawValue
|
||||
|
||||
if let operation = DeveloperServicesAssignAppGroupsOperation(
|
||||
context: self.context,
|
||||
groupIDs: groups,
|
||||
appID: appID
|
||||
) {
|
||||
let newGroups = try await operation.perform()
|
||||
entitlementsArray[groupsIdx] = AppGroupEntitlement(rawValue: newGroups)
|
||||
try entitlements.setEntitlements(entitlementsArray)
|
||||
}
|
||||
}
|
||||
|
||||
let mobileprovision = try await DeveloperServicesFetchProfileOperation(
|
||||
context: self.context,
|
||||
bundleID: newBundleID,
|
||||
signingInfo: signingInfo
|
||||
).perform()
|
||||
|
||||
return ProvisioningInfo(
|
||||
newBundleID: newBundleID,
|
||||
entitlements: entitlements,
|
||||
mobileprovision: mobileprovision
|
||||
)
|
||||
}
|
||||
|
||||
// keyed by sanitized bundle ID
|
||||
private func getCurrentAppIDs() async throws -> [String: Components.Schemas.BundleId] {
|
||||
let bundleIDs = try await context.developerAPIClient.bundleIdsGetCollection().ok.body.json.data
|
||||
let keyedIDs = bundleIDs
|
||||
.compactMap { id -> (String, Components.Schemas.BundleId)? in
|
||||
guard let bundleID = id.attributes?.identifier else { return nil }
|
||||
return (ProvisioningIdentifiers.sanitize(identifier: bundleID), id)
|
||||
}
|
||||
return Dictionary(keyedIDs, uniquingKeysWith: { $1 })
|
||||
}
|
||||
|
||||
/// Registers the app + its extensions, returning the profile and entitlements of each
|
||||
public func perform() async throws -> [URL: ProvisioningInfo] {
|
||||
var apps: [URL] = [root]
|
||||
let plugins = root.appendingPathComponent("PlugIns")
|
||||
if plugins.dirExists {
|
||||
apps += plugins.implicitContents.filter { $0.pathExtension.lowercased() == "appex" }
|
||||
}
|
||||
|
||||
async let isFreeTeamTask = context.auth.team()?.isFree == true
|
||||
async let appIDsTask = getCurrentAppIDs()
|
||||
let (isFreeTeam, appIDs) = try await (isFreeTeamTask, appIDsTask)
|
||||
|
||||
return try await withThrowingTaskGroup(
|
||||
of: (URL, ProvisioningInfo).self,
|
||||
returning: [URL: ProvisioningInfo].self
|
||||
) { group in
|
||||
for app in apps {
|
||||
group.addTask {
|
||||
let info = try await addApp(app, isFreeTeam: isFreeTeam, appIDs: appIDs)
|
||||
return (app, info)
|
||||
}
|
||||
}
|
||||
return try await group.reduce(into: [:]) { $0[$1.0] = $1.1 }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// DeveloperServicesFeatureTypes.swift
|
||||
// Supercharge
|
||||
//
|
||||
// Created by Kabir Oberai on 29/07/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import DeveloperAPI
|
||||
|
||||
public struct DeveloperServicesCapability: Sendable, Hashable {
|
||||
public var capabilityType: Components.Schemas.CapabilityType
|
||||
public var isFree: Bool
|
||||
public var settings: [Components.Schemas.CapabilitySetting]?
|
||||
|
||||
public init(
|
||||
_ capabilityType: Components.Schemas.CapabilityType,
|
||||
isFree: Bool,
|
||||
settings: [Components.Schemas.CapabilitySetting]? = nil
|
||||
) {
|
||||
self.capabilityType = capabilityType
|
||||
self.isFree = isFree
|
||||
self.settings = settings
|
||||
}
|
||||
}
|
||||
|
||||
protocol EntitlementWithCapability: Entitlement {
|
||||
var capability: DeveloperServicesCapability { get }
|
||||
}
|
||||
|
||||
extension Entitlement {
|
||||
var anyCapability: DeveloperServicesCapability? {
|
||||
(self as? EntitlementWithCapability)?.capability
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Special Features
|
||||
|
||||
extension DataProtectionEntitlement: EntitlementWithCapability {
|
||||
var capability: DeveloperServicesCapability {
|
||||
let option: Components.Schemas.CapabilityOption.KeyPayload = switch self {
|
||||
case .complete: .completeProtection
|
||||
case .unlessOpen: .protectedUnlessOpen
|
||||
case .untilFirstAuth: .protectedUntilFirstUserAuth
|
||||
}
|
||||
return DeveloperServicesCapability(
|
||||
.dataProtection,
|
||||
isFree: true,
|
||||
settings: [
|
||||
.init(
|
||||
key: .dataProtectionPermissionLevel,
|
||||
options: [.init(key: option)]
|
||||
)
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Boolean Features
|
||||
|
||||
// https://github.com/fastlane/fastlane/blob/master/spaceship/lib/spaceship/portal/app_service.rb
|
||||
|
||||
extension AppGroupEntitlement: EntitlementWithCapability {
|
||||
var capability: DeveloperServicesCapability {
|
||||
// FIXME: Enable app groups on free accounts
|
||||
// but we need to always assign only one group
|
||||
DeveloperServicesCapability(.appGroups, isFree: false)
|
||||
}
|
||||
}
|
||||
|
||||
extension AssociatedDomainsEntitlement: EntitlementWithCapability {
|
||||
var capability: DeveloperServicesCapability {
|
||||
DeveloperServicesCapability(.associatedDomains, isFree: false)
|
||||
}
|
||||
}
|
||||
|
||||
extension HealthKitEntitlement: EntitlementWithCapability {
|
||||
var capability: DeveloperServicesCapability {
|
||||
DeveloperServicesCapability(.healthkit, isFree: true)
|
||||
}
|
||||
}
|
||||
|
||||
extension HomeKitEntitlement: EntitlementWithCapability {
|
||||
var capability: DeveloperServicesCapability {
|
||||
DeveloperServicesCapability(.homekit, isFree: true)
|
||||
}
|
||||
}
|
||||
|
||||
extension InterAppAudioEntitlement: EntitlementWithCapability {
|
||||
var capability: DeveloperServicesCapability {
|
||||
DeveloperServicesCapability(.interAppAudio, isFree: true)
|
||||
}
|
||||
}
|
||||
|
||||
extension MultipathEntitlement: EntitlementWithCapability {
|
||||
var capability: DeveloperServicesCapability {
|
||||
DeveloperServicesCapability(.multipath, isFree: false)
|
||||
}
|
||||
}
|
||||
|
||||
extension NetworkExtensionEntitlement: EntitlementWithCapability {
|
||||
var capability: DeveloperServicesCapability {
|
||||
DeveloperServicesCapability(.networkExtensions, isFree: false)
|
||||
}
|
||||
}
|
||||
|
||||
extension VPNConfigurationEntitlement: EntitlementWithCapability {
|
||||
public var capability: DeveloperServicesCapability {
|
||||
DeveloperServicesCapability(.personalVpn, isFree: false)
|
||||
}
|
||||
}
|
||||
|
||||
extension APSEnvironmentEntitlement: EntitlementWithCapability {
|
||||
var capability: DeveloperServicesCapability {
|
||||
DeveloperServicesCapability(.pushNotifications, isFree: false)
|
||||
}
|
||||
}
|
||||
|
||||
extension SiriKitEntitlement: EntitlementWithCapability {
|
||||
var capability: DeveloperServicesCapability {
|
||||
DeveloperServicesCapability(.sirikit, isFree: false)
|
||||
}
|
||||
}
|
||||
|
||||
extension WirelessAccessoryEntitlement: EntitlementWithCapability {
|
||||
var capability: DeveloperServicesCapability {
|
||||
DeveloperServicesCapability(.wirelessAccessoryConfiguration, isFree: true)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// EntitlementWithTeamOrBundleID.swift
|
||||
// Supersign
|
||||
// XKit
|
||||
//
|
||||
// Created by Kabir Oberai on 12/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
//
|
||||
// DeveloperServicesFetchCertificateOperation.swift
|
||||
// XKit
|
||||
//
|
||||
// Created by Kabir Oberai on 13/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import DeveloperAPI
|
||||
import Dependencies
|
||||
|
||||
public typealias DeveloperServicesCertificate = Components.Schemas.Certificate
|
||||
|
||||
public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOperation {
|
||||
|
||||
public enum Error: LocalizedError {
|
||||
case csrFailed
|
||||
case userCancelled
|
||||
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .csrFailed:
|
||||
return NSLocalizedString(
|
||||
"fetch_certificate_operation.error.csr_failed", value: "CSR request failed", comment: ""
|
||||
)
|
||||
case .userCancelled:
|
||||
return NSLocalizedString(
|
||||
"fetch_certificate_operation.error.user_cancelled", value: "The operation was cancelled", comment: ""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Dependency(\.signingInfoManager) var signingInfoManager
|
||||
|
||||
public let context: SigningContext
|
||||
public let confirmRevocation: @Sendable ([DeveloperServicesCertificate]) async -> Bool
|
||||
public init(
|
||||
context: SigningContext,
|
||||
confirmRevocation: @escaping @Sendable ([DeveloperServicesCertificate]) async -> Bool
|
||||
) {
|
||||
self.context = context
|
||||
self.confirmRevocation = confirmRevocation
|
||||
}
|
||||
|
||||
private func createCertificate() async throws -> SigningInfo {
|
||||
let keypair = try Keypair()
|
||||
let csr = try keypair.generateCSR()
|
||||
let privateKey = try keypair.privateKey()
|
||||
|
||||
let response = try await context.developerAPIClient.certificatesCreateInstance(
|
||||
body: .json(.init(data: .init(
|
||||
_type: .certificates,
|
||||
attributes: .init(
|
||||
csrContent: csr.pemString,
|
||||
certificateType: .development
|
||||
)
|
||||
)))
|
||||
)
|
||||
|
||||
guard let contentString = try response.created.body.json.data.attributes?.certificateContent,
|
||||
let contentData = Data(base64Encoded: contentString)
|
||||
else { throw Error.csrFailed }
|
||||
|
||||
let certificate = try Certificate(data: contentData)
|
||||
|
||||
return SigningInfo(privateKey: privateKey, certificate: certificate)
|
||||
}
|
||||
|
||||
private func replaceCertificates(
|
||||
_ certificates: [DeveloperServicesCertificate],
|
||||
requireConfirmation: Bool
|
||||
) async throws -> SigningInfo {
|
||||
if try await context.auth.team()?.isFree == true {
|
||||
if !certificates.isEmpty, requireConfirmation {
|
||||
guard await confirmRevocation(certificates)
|
||||
else { throw CancellationError() }
|
||||
}
|
||||
try await withThrowingTaskGroup(of: Void.self) { group in
|
||||
for certificate in certificates {
|
||||
group.addTask {
|
||||
_ = try await context.developerAPIClient
|
||||
.certificatesDeleteInstance(path: .init(id: certificate.id))
|
||||
.noContent
|
||||
}
|
||||
}
|
||||
try await group.waitForAll()
|
||||
}
|
||||
}
|
||||
let signingInfo = try await createCertificate()
|
||||
signingInfoManager[self.context.auth.identityID] = signingInfo
|
||||
return signingInfo
|
||||
}
|
||||
|
||||
public func perform() async throws -> SigningInfo {
|
||||
let certificates = try await context.developerAPIClient.certificatesGetCollection().ok.body.json.data
|
||||
|
||||
guard let signingInfo = signingInfoManager[self.context.auth.identityID] else {
|
||||
return try await self.replaceCertificates(certificates, requireConfirmation: true)
|
||||
}
|
||||
|
||||
let knownSerialNumber = signingInfo.certificate.serialNumber()
|
||||
guard let certificate = certificates.first(where: { $0.attributes?.serialNumber == knownSerialNumber }) else {
|
||||
// we need to revoke existing certs, otherwise it doesn't always let us make a new one
|
||||
return try await self.replaceCertificates(certificates, requireConfirmation: true)
|
||||
}
|
||||
|
||||
if let date = certificate.attributes?.expirationDate, date > Date() {
|
||||
return signingInfo
|
||||
} else {
|
||||
// we have a certificate for this machine but it's not usable
|
||||
return try await self.replaceCertificates(
|
||||
[certificate],
|
||||
requireConfirmation: false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+90
-36
@@ -3,67 +3,91 @@ import DeveloperAPI
|
||||
import HTTPTypes
|
||||
import OpenAPIRuntime
|
||||
import OpenAPIURLSession
|
||||
import Dependencies
|
||||
|
||||
extension DeveloperAPIClient {
|
||||
public init(
|
||||
middlewares: [any ClientMiddleware],
|
||||
httpFactory: HTTPClientFactory = defaultHTTPClientFactory
|
||||
auth: DeveloperAPIAuthData
|
||||
) {
|
||||
@Dependency(\.httpClient) var httpClient
|
||||
self.init(
|
||||
serverURL: try! Servers.Server1.url(),
|
||||
configuration: .init(
|
||||
dateTranscoder: .iso8601WithFractionalSeconds
|
||||
),
|
||||
transport: httpFactory.makeClient().asOpenAPITransport,
|
||||
middlewares: middlewares
|
||||
)
|
||||
}
|
||||
|
||||
public init(
|
||||
xcodeAPI: DeveloperAPIXcodeMiddleware,
|
||||
httpFactory: HTTPClientFactory = defaultHTTPClientFactory
|
||||
) {
|
||||
self.init(
|
||||
middlewares: [xcodeAPI],
|
||||
httpFactory: httpFactory
|
||||
transport: httpClient.asOpenAPITransport,
|
||||
middlewares: [
|
||||
auth.middleware
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public struct DeveloperAPIXcodeMiddleware: ClientMiddleware {
|
||||
public let loginToken: DeveloperServicesLoginToken
|
||||
public let deviceInfo: DeviceInfo
|
||||
public let teamID: String
|
||||
public let anisetteDataProvider: AnisetteDataProvider
|
||||
public enum DeveloperAPIAuthData: Sendable {
|
||||
case appStoreConnect(ASCKey)
|
||||
case xcode(XcodeAuthData)
|
||||
|
||||
fileprivate var middleware: ClientMiddleware {
|
||||
switch self {
|
||||
case .appStoreConnect(let key):
|
||||
DeveloperAPIASCAuthMiddleware(key: key)
|
||||
case .xcode(let authData):
|
||||
DeveloperAPIXcodeAuthMiddleware(authData: authData)
|
||||
}
|
||||
}
|
||||
|
||||
// A unique ID tied to this token
|
||||
public var identityID: String {
|
||||
switch self {
|
||||
case .appStoreConnect(let key):
|
||||
key.issuerID
|
||||
case .xcode(let data):
|
||||
data.teamID.rawValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct XcodeAuthData: Sendable {
|
||||
public var loginToken: DeveloperServicesLoginToken
|
||||
public var teamID: DeveloperServicesTeam.ID
|
||||
|
||||
public init(
|
||||
anisetteDataProvider: AnisetteDataProvider,
|
||||
loginToken: DeveloperServicesLoginToken,
|
||||
deviceInfo: DeviceInfo,
|
||||
teamID: String
|
||||
teamID: DeveloperServicesTeam.ID
|
||||
) {
|
||||
self.anisetteDataProvider = anisetteDataProvider
|
||||
self.loginToken = loginToken
|
||||
self.deviceInfo = deviceInfo
|
||||
self.teamID = teamID
|
||||
}
|
||||
}
|
||||
|
||||
public struct DeveloperAPIXcodeAuthMiddleware: ClientMiddleware {
|
||||
@Dependency(\.deviceInfoProvider) private var deviceInfoProvider
|
||||
@Dependency(\.anisetteDataProvider) private var anisetteDataProvider
|
||||
|
||||
public var authData: XcodeAuthData
|
||||
|
||||
public init(authData: XcodeAuthData) {
|
||||
self.authData = authData
|
||||
}
|
||||
|
||||
private static let baseURL = URL(string: "https://developerservices2.apple.com/services")!
|
||||
private static let queryEncoder = JSONEncoder()
|
||||
|
||||
public func intercept(
|
||||
_ request: HTTPTypes.HTTPRequest,
|
||||
body: OpenAPIRuntime.HTTPBody?,
|
||||
_ request: HTTPRequest,
|
||||
body: HTTPBody?,
|
||||
baseURL: URL,
|
||||
operationID: String,
|
||||
next: @Sendable (
|
||||
_ request: HTTPTypes.HTTPRequest,
|
||||
_ body: OpenAPIRuntime.HTTPBody?,
|
||||
_ request: HTTPRequest,
|
||||
_ body: HTTPBody?,
|
||||
_ baseURL: URL
|
||||
) async throws -> (HTTPTypes.HTTPResponse, OpenAPIRuntime.HTTPBody?)
|
||||
) async throws -> (HTTPTypes.HTTPResponse, OpenAPIRuntime.HTTPBody?) {
|
||||
) async throws -> (HTTPResponse, HTTPBody?)
|
||||
) async throws -> (HTTPResponse, HTTPBody?) {
|
||||
var request = request
|
||||
|
||||
let deviceInfo = try deviceInfoProvider.fetch()
|
||||
|
||||
// General
|
||||
request.headerFields[.acceptLanguage] = Locale.preferredLanguages.joined(separator: ", ")
|
||||
request.headerFields[.accept] = "application/vnd.api+json"
|
||||
@@ -82,8 +106,8 @@ public struct DeveloperAPIXcodeMiddleware: ClientMiddleware {
|
||||
|
||||
// GrandSlam authentication
|
||||
request.headerFields[.init("X-Apple-App-Info")!] = AppTokenKey.xcode.rawValue
|
||||
request.headerFields[.init("X-Apple-I-Identity-Id")!] = loginToken.adsid
|
||||
request.headerFields[.init("X-Apple-GS-Token")!] = loginToken.token
|
||||
request.headerFields[.init("X-Apple-I-Identity-Id")!] = authData.loginToken.adsid
|
||||
request.headerFields[.init("X-Apple-GS-Token")!] = authData.loginToken.token
|
||||
|
||||
// Anisette
|
||||
let anisetteData = try await anisetteDataProvider.fetchAnisetteData()
|
||||
@@ -102,14 +126,14 @@ public struct DeveloperAPIXcodeMiddleware: ClientMiddleware {
|
||||
let path = request.path ?? "/"
|
||||
var components = URLComponents(string: path) ?? .init()
|
||||
components.queryItems = (components.queryItems ?? []) + [
|
||||
URLQueryItem(name: "teamId", value: teamID)
|
||||
URLQueryItem(name: "teamId", value: authData.teamID.rawValue)
|
||||
]
|
||||
let query = components.percentEncodedQuery ?? ""
|
||||
|
||||
components.query = nil
|
||||
request.path = components.path
|
||||
|
||||
let bodyData = try Self.queryEncoder.encode(["urlEncodedQueryParams": query])
|
||||
let bodyData = try DeveloperAPIXcodeAuthMiddleware.queryEncoder.encode(["urlEncodedQueryParams": query])
|
||||
body = HTTPBody(bodyData)
|
||||
case .patch, .post:
|
||||
// set .data.attributes.teamId = teamID
|
||||
@@ -139,7 +163,7 @@ public struct DeveloperAPIXcodeMiddleware: ClientMiddleware {
|
||||
workingAttributes = decodedAttributes
|
||||
}
|
||||
|
||||
workingAttributes["teamId"] = teamID
|
||||
workingAttributes["teamId"] = authData.teamID.rawValue
|
||||
workingData["attributes"] = workingAttributes
|
||||
workingBody["data"] = workingData
|
||||
|
||||
@@ -151,7 +175,7 @@ public struct DeveloperAPIXcodeMiddleware: ClientMiddleware {
|
||||
throw Errors.unrecognizedHTTPMethod(originalMethod.rawValue)
|
||||
}
|
||||
|
||||
var (response, responseBody) = try await next(request, body, Self.baseURL)
|
||||
var (response, responseBody) = try await next(request, body, DeveloperAPIXcodeAuthMiddleware.baseURL)
|
||||
|
||||
if response.headerFields[.contentType] == "application/vnd.api+json" {
|
||||
response.headerFields[.contentType] = "application/json"
|
||||
@@ -165,3 +189,33 @@ public struct DeveloperAPIXcodeMiddleware: ClientMiddleware {
|
||||
case malformedPayload(String)
|
||||
}
|
||||
}
|
||||
|
||||
public struct DeveloperAPIASCAuthMiddleware: ClientMiddleware {
|
||||
private var generator: ASCJWTGenerator
|
||||
|
||||
public var key: ASCKey {
|
||||
get { generator.key }
|
||||
set { generator = ASCJWTGenerator(key: newValue) }
|
||||
}
|
||||
|
||||
public init(key: ASCKey) {
|
||||
generator = ASCJWTGenerator(key: key)
|
||||
}
|
||||
|
||||
public func intercept(
|
||||
_ request: HTTPRequest,
|
||||
body: HTTPBody?,
|
||||
baseURL: URL,
|
||||
operationID: String,
|
||||
next: @Sendable (
|
||||
_ request: HTTPRequest,
|
||||
_ body: HTTPBody?,
|
||||
_ baseURL: URL
|
||||
) async throws -> (HTTPResponse, HTTPBody?)
|
||||
) async throws -> (HTTPResponse, HTTPBody?) {
|
||||
let jwt = try await generator.generate()
|
||||
var request = request
|
||||
request.headerFields[.authorization] = "Bearer \(jwt)"
|
||||
return try await next(request, body, baseURL)
|
||||
}
|
||||
}
|
||||
+2
-73
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// DeveloperServicesAPIVersion.swift
|
||||
// Supersign
|
||||
// XKit
|
||||
//
|
||||
// Created by Kabir Oberai on 10/04/20.
|
||||
// Copyright © 2020 Kabir Oberai. All rights reserved.
|
||||
@@ -17,7 +17,7 @@ public protocol DeveloperServicesAPIVersion: Sendable {
|
||||
func decode<R: Decodable>(response: Data) throws -> R
|
||||
}
|
||||
|
||||
public struct DeveloperServicesAPIVersionOld: DeveloperServicesAPIVersion {
|
||||
public struct DeveloperServicesAPIVersionLegacy: DeveloperServicesAPIVersion {
|
||||
|
||||
public struct Error: LocalizedError {
|
||||
public let code: Int
|
||||
@@ -117,74 +117,3 @@ public struct DeveloperServicesAPIVersionOld: DeveloperServicesAPIVersion {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public struct DeveloperServicesAPIVersionV1: DeveloperServicesAPIVersion {
|
||||
|
||||
public struct UnknownError: Swift.Error {}
|
||||
|
||||
public struct Error: LocalizedError, Decodable {
|
||||
public let status: String
|
||||
public let code: String
|
||||
public let title: String
|
||||
public let detail: String
|
||||
|
||||
public var errorDescription: String? {
|
||||
"\(code) (\(status)): \(title)\n\(detail)"
|
||||
}
|
||||
}
|
||||
|
||||
private struct Response<T: Decodable>: Decodable {
|
||||
private let errors: [Error]?
|
||||
private let data: T?
|
||||
|
||||
fileprivate var result: Result<T, Swift.Error> {
|
||||
if let data = data { return .success(data) }
|
||||
let errors = self.errors ?? []
|
||||
switch errors.count {
|
||||
case 0: return .failure(UnknownError())
|
||||
case 1: return .failure(errors[0])
|
||||
default: return .failure(ErrorList(errors))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static let decoder: JSONDecoder = {
|
||||
let decoder = JSONDecoder()
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
|
||||
formatter.calendar = Calendar(identifier: .iso8601)
|
||||
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||
decoder.dateDecodingStrategy = .formatted(formatter)
|
||||
return decoder
|
||||
}()
|
||||
|
||||
public func url(forAction action: String) -> URL? {
|
||||
let urlString = "https://developerservices2.apple.com/services/v1/\(action)"
|
||||
return URL(string: urlString)
|
||||
}
|
||||
|
||||
public let contentType = "application/vnd.api+json"
|
||||
public let accept = "application/vnd.api+json"
|
||||
|
||||
public func body(withParameters parameters: [String: Any]) throws -> Data {
|
||||
var components = URLComponents()
|
||||
components.queryItems = parameters.map { URLQueryItem(name: $0, value: "\($1)") }
|
||||
let query = components.query ?? ""
|
||||
let dict = ["urlEncodedQueryParams": query]
|
||||
return try JSONSerialization.data(withJSONObject: dict)
|
||||
}
|
||||
|
||||
public func decode<R: Decodable>(response: Data) throws -> R {
|
||||
// If `response` is empty and R is EmptyResponse, just return a new EmptyResponse
|
||||
// instead of crashing
|
||||
if let type = R.self as? EmptyResponse.Type {
|
||||
// swiftlint:disable:next force_cast
|
||||
return type.init() as! R
|
||||
} else {
|
||||
return try Self.decoder
|
||||
.decode(Response<R>.self, from: response)
|
||||
.result.get()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+29
-33
@@ -7,8 +7,9 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Dependencies
|
||||
|
||||
public final class DeveloperServicesClient: Sendable {
|
||||
public struct DeveloperServicesClient: Sendable {
|
||||
|
||||
public enum Error: LocalizedError {
|
||||
case noData
|
||||
@@ -53,21 +54,18 @@ public final class DeveloperServicesClient: Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
public let loginToken: DeveloperServicesLoginToken
|
||||
public let deviceInfo: DeviceInfo
|
||||
public let anisetteDataProvider: AnisetteDataProvider
|
||||
private let httpClient: HTTPClientProtocol
|
||||
@Dependency(\.deviceInfoProvider) var deviceInfoProvider
|
||||
@Dependency(\.anisetteDataProvider) var anisetteDataProvider
|
||||
@Dependency(\.httpClient) var httpClient
|
||||
|
||||
public init(
|
||||
loginToken: DeveloperServicesLoginToken,
|
||||
deviceInfo: DeviceInfo,
|
||||
anisetteProvider: AnisetteDataProvider,
|
||||
httpFactory: HTTPClientFactory = defaultHTTPClientFactory
|
||||
) {
|
||||
public let loginToken: DeveloperServicesLoginToken
|
||||
|
||||
public init(loginToken: DeveloperServicesLoginToken) {
|
||||
self.loginToken = loginToken
|
||||
self.deviceInfo = deviceInfo
|
||||
self.anisetteDataProvider = anisetteProvider
|
||||
self.httpClient = httpFactory.makeClient()
|
||||
}
|
||||
|
||||
public init(authData: XcodeAuthData) {
|
||||
self.loginToken = authData.loginToken
|
||||
}
|
||||
|
||||
private func send<R: DeveloperServicesRequest>(
|
||||
@@ -78,34 +76,32 @@ public final class DeveloperServicesClient: Sendable {
|
||||
throw Error.malformedRequest
|
||||
}
|
||||
|
||||
var httpRequest = HTTPRequest(url: url, method: "POST")
|
||||
let deviceInfo = try deviceInfoProvider.fetch()
|
||||
|
||||
var httpRequest = HTTPRequest(method: .post, url: url)
|
||||
let acceptedLanguages = Locale.preferredLanguages.joined(separator: ", ")
|
||||
|
||||
httpRequest.headers["Accept-Language"] = acceptedLanguages
|
||||
httpRequest.headers["Accept"] = request.apiVersion.accept
|
||||
httpRequest.headers["Content-Type"] = request.apiVersion.contentType
|
||||
httpRequest.headers["User-Agent"] = "Xcode"
|
||||
request.methodOverride.map { httpRequest.headers["X-HTTP-Method-Override"] = $0 }
|
||||
httpRequest.headerFields[.acceptLanguage] = acceptedLanguages
|
||||
httpRequest.headerFields[.accept] = request.apiVersion.accept
|
||||
httpRequest.headerFields[.contentType] = request.apiVersion.contentType
|
||||
httpRequest.headerFields[.userAgent] = "Xcode"
|
||||
request.methodOverride.map { httpRequest.headerFields[.init("X-HTTP-Method-Override")!] = $0 }
|
||||
|
||||
httpRequest.headers[DeviceInfo.xcodeVersionKey] = DeviceInfo.xcodeVersion
|
||||
httpRequest.headers[DeviceInfo.clientInfoKey] = deviceInfo.clientInfo.clientString
|
||||
httpRequest.headers[DeviceInfo.deviceIDKey] = deviceInfo.deviceID
|
||||
httpRequest.headerFields[.init(DeviceInfo.xcodeVersionKey)!] = DeviceInfo.xcodeVersion
|
||||
httpRequest.headerFields[.init(DeviceInfo.clientInfoKey)!] = deviceInfo.clientInfo.clientString
|
||||
httpRequest.headerFields[.init(DeviceInfo.deviceIDKey)!] = deviceInfo.deviceID
|
||||
|
||||
httpRequest.headers["X-Apple-I-Identity-Id"] = loginToken.adsid
|
||||
httpRequest.headers["X-Apple-App-Info"] = AppTokenKey.xcode.rawValue
|
||||
httpRequest.headers["X-Apple-GS-Token"] = loginToken.token
|
||||
httpRequest.headerFields[.init("X-Apple-I-Identity-Id")!] = loginToken.adsid
|
||||
httpRequest.headerFields[.init("X-Apple-App-Info")!] = AppTokenKey.xcode.rawValue
|
||||
httpRequest.headerFields[.init("X-Apple-GS-Token")!] = loginToken.token
|
||||
|
||||
anisetteData.dictionary.forEach { httpRequest.headers[$0] = $1 }
|
||||
|
||||
httpRequest.body = try .buffer(request.apiVersion.body(withParameters: request.parameters))
|
||||
anisetteData.dictionary.forEach { httpRequest.headerFields[.init($0)!] = $1 }
|
||||
|
||||
request.configure(urlRequest: &httpRequest)
|
||||
|
||||
let resp = try await httpClient.makeRequest(httpRequest)
|
||||
let body = try request.apiVersion.body(withParameters: request.parameters)
|
||||
|
||||
// we don't throw if data is nil because sometimes no data is
|
||||
// okay (eg in the case of EmptyResponse)
|
||||
let data = resp.body ?? Data()
|
||||
let (_, data) = try await httpClient.makeRequest(httpRequest, body: body)
|
||||
|
||||
// String(data: data, encoding: .utf8).map { print("\(url): \($0)") }
|
||||
|
||||
+6
-18
@@ -1,12 +1,13 @@
|
||||
//
|
||||
// DeveloperServicesLoginManager.swift
|
||||
// Supersign
|
||||
// XKit
|
||||
//
|
||||
// Created by Kabir Oberai on 10/04/20.
|
||||
// Copyright © 2020 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Dependencies
|
||||
|
||||
public struct DeveloperServicesLoginToken: Codable, Sendable {
|
||||
public let adsid: String
|
||||
@@ -26,23 +27,9 @@ public struct DeveloperServicesLoginManager: Sendable {
|
||||
case missingLoginToken
|
||||
}
|
||||
|
||||
public let deviceInfo: DeviceInfo
|
||||
public let anisetteProvider: AnisetteDataProvider
|
||||
private let client: GrandSlamClient
|
||||
private let client = GrandSlamClient()
|
||||
|
||||
public init(
|
||||
deviceInfo: DeviceInfo,
|
||||
anisetteProvider: AnisetteDataProvider,
|
||||
httpFactory: HTTPClientFactory = defaultHTTPClientFactory
|
||||
) throws {
|
||||
self.deviceInfo = deviceInfo
|
||||
self.anisetteProvider = anisetteProvider
|
||||
self.client = GrandSlamClient(
|
||||
deviceInfo: deviceInfo,
|
||||
anisetteProvider: anisetteProvider,
|
||||
httpFactory: httpFactory
|
||||
)
|
||||
}
|
||||
public init() {}
|
||||
|
||||
private func logIn(
|
||||
withLoginData loginData: GrandSlamLoginData
|
||||
@@ -64,7 +51,8 @@ public struct DeveloperServicesLoginManager: Sendable {
|
||||
) async throws -> DeveloperServicesLoginToken {
|
||||
let loginData = try await GrandSlamAuthenticateOperation(
|
||||
client: client,
|
||||
username: username,
|
||||
// GSA requires Apple IDs in lowercase for SRP
|
||||
username: username.lowercased(),
|
||||
password: password,
|
||||
twoFactorDelegate: twoFactorDelegate
|
||||
).authenticate()
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// DeveloperServicesOperation.swift
|
||||
// Supersign
|
||||
// XKit
|
||||
//
|
||||
// Created by Kabir Oberai on 13/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
+6
-2
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// DeveloperServicesProvisioningOperation.swift
|
||||
// Supersign
|
||||
// XKit
|
||||
//
|
||||
// Created by Kabir Oberai on 12/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
@@ -48,7 +48,11 @@ public struct DeveloperServicesProvisioningOperation: DeveloperServicesOperation
|
||||
).perform()
|
||||
|
||||
progress(2/3)
|
||||
let provisioningDict = try await DeveloperServicesAddAppOperation(context: context, root: app).perform()
|
||||
let provisioningDict = try await DeveloperServicesAddAppOperation(
|
||||
context: context,
|
||||
signingInfo: signingInfo,
|
||||
root: app
|
||||
).perform()
|
||||
|
||||
progress(3/3)
|
||||
return .init(signingInfo: signingInfo, provisioningDict: provisioningDict)
|
||||
+1
-1
@@ -27,7 +27,7 @@ public protocol DeveloperServicesRequest: Sendable {
|
||||
}
|
||||
|
||||
public extension DeveloperServicesRequest {
|
||||
var apiVersion: DeveloperServicesAPIVersion { DeveloperServicesAPIVersionOld() }
|
||||
var apiVersion: DeveloperServicesAPIVersion { DeveloperServicesAPIVersionLegacy() }
|
||||
var methodOverride: String? { nil }
|
||||
func configure(urlRequest: inout HTTPRequest) {}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import Foundation
|
||||
|
||||
private actor DeveloperServicesTeamFetcher {
|
||||
static let shared = DeveloperServicesTeamFetcher()
|
||||
|
||||
private var cache: [DeveloperServicesTeam.ID: Task<DeveloperServicesTeam, Error>] = [:]
|
||||
|
||||
private init() {}
|
||||
|
||||
func teams(forXcodeLogin auth: XcodeAuthData) async throws -> DeveloperServicesTeam {
|
||||
let teamID = auth.teamID
|
||||
if let cached = cache[teamID] {
|
||||
return try await cached.value
|
||||
}
|
||||
let task = Task {
|
||||
let client = DeveloperServicesClient(authData: auth)
|
||||
let teams = try await client.send(DeveloperServicesListTeamsRequest())
|
||||
guard let team = teams.first(where: { $0.id == teamID })
|
||||
else { throw Errors.teamNotFound(teamID) }
|
||||
return team
|
||||
}
|
||||
cache[auth.teamID] = task
|
||||
return try await task.value
|
||||
}
|
||||
|
||||
enum Errors: LocalizedError {
|
||||
case teamNotFound(DeveloperServicesTeam.ID)
|
||||
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .teamNotFound(let id):
|
||||
return id.rawValue.withCString {
|
||||
String.localizedStringWithFormat(
|
||||
NSLocalizedString(
|
||||
"add_app_operation.error.team_not_found",
|
||||
value: "A team with the ID '%s' could not be found. Please select another team.",
|
||||
comment: ""
|
||||
), $0
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension XcodeAuthData {
|
||||
public func team() async throws -> DeveloperServicesTeam {
|
||||
try await DeveloperServicesTeamFetcher.shared.teams(forXcodeLogin: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension DeveloperAPIAuthData {
|
||||
public func team() async throws -> DeveloperServicesTeam? {
|
||||
switch self {
|
||||
case .appStoreConnect: nil
|
||||
case .xcode(let auth): try await auth.team()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// DeveloperServicesFetchDeviceOperation.swift
|
||||
// XKit
|
||||
//
|
||||
// Created by Kabir Oberai on 13/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import DeveloperAPI
|
||||
|
||||
public struct DeveloperServicesFetchDeviceOperation: DeveloperServicesOperation {
|
||||
public let context: SigningContext
|
||||
public init(context: SigningContext) {
|
||||
self.context = context
|
||||
}
|
||||
|
||||
public func perform() async throws -> Components.Schemas.Device {
|
||||
let devices = try await context.developerAPIClient.devicesGetCollection().ok.body.json.data
|
||||
|
||||
if let device = devices.first(where: { $0.attributes?.udid == self.context.udid }) {
|
||||
return device
|
||||
}
|
||||
|
||||
let response = try await context.developerAPIClient.devicesCreateInstance(
|
||||
body: .json(.init(data: .init(
|
||||
_type: .devices,
|
||||
attributes: .init(
|
||||
name: self.context.deviceName,
|
||||
platform: .ios,
|
||||
udid: self.context.udid
|
||||
)
|
||||
)))
|
||||
)
|
||||
|
||||
return try response.created.body.json.data
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// DeveloperServicesFetchProfileOperation.swift
|
||||
// XKit
|
||||
//
|
||||
// Created by Kabir Oberai on 13/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Superutils
|
||||
import DeveloperAPI
|
||||
|
||||
public struct DeveloperServicesFetchProfileOperation: DeveloperServicesOperation {
|
||||
|
||||
public enum Errors: Error {
|
||||
case bundleIDNotFound
|
||||
case tooManyMatchingBundleIDs
|
||||
case invalidProfileData
|
||||
}
|
||||
|
||||
public let context: SigningContext
|
||||
public let bundleID: String
|
||||
public let signingInfo: SigningInfo
|
||||
public init(context: SigningContext, bundleID: String, signingInfo: SigningInfo) {
|
||||
self.context = context
|
||||
self.bundleID = bundleID
|
||||
self.signingInfo = signingInfo
|
||||
}
|
||||
|
||||
public func perform() async throws -> Mobileprovision {
|
||||
let bundleIDs = try await context.developerAPIClient
|
||||
.bundleIdsGetCollection(query: .init(
|
||||
filter_lbrack_identifier_rbrack_: [bundleID],
|
||||
fields_lbrack_profiles_rbrack_: [.bundleId],
|
||||
include: [.profiles]
|
||||
))
|
||||
.ok.body.json
|
||||
|
||||
// filter[identifier] is a prefix filter so we need to manually upgrade to equality
|
||||
let filtered = bundleIDs.data.filter { $0.attributes?.identifier == self.bundleID }
|
||||
|
||||
let bundleID: Components.Schemas.BundleId
|
||||
switch filtered.count {
|
||||
case 0:
|
||||
throw Errors.bundleIDNotFound
|
||||
case 1:
|
||||
bundleID = filtered[0]
|
||||
default:
|
||||
throw Errors.tooManyMatchingBundleIDs
|
||||
}
|
||||
|
||||
let profiles = bundleID.relationships?.profiles?.data ?? []
|
||||
switch profiles.count {
|
||||
case 0:
|
||||
// we're good
|
||||
break
|
||||
case 1:
|
||||
_ = try await context.developerAPIClient.profilesDeleteInstance(path: .init(id: profiles[0].id)).noContent
|
||||
default:
|
||||
// if the user has >1 profile, it's probably okay to add another one (acceptable for non-free accounts?)
|
||||
break
|
||||
}
|
||||
|
||||
let serialNumber = signingInfo.certificate.serialNumber()
|
||||
let certs = try await context.developerAPIClient.certificatesGetCollection(
|
||||
query: .init(
|
||||
filter_lbrack_serialNumber_rbrack_: [serialNumber]
|
||||
)
|
||||
)
|
||||
.ok.body.json.data
|
||||
|
||||
let allDevices = try await context.developerAPIClient.devicesGetCollection()
|
||||
.ok.body.json.data
|
||||
|
||||
let response = try await context.developerAPIClient.profilesCreateInstance(
|
||||
body: .json(
|
||||
.init(
|
||||
data: .init(
|
||||
_type: .profiles,
|
||||
attributes: .init(
|
||||
name: "SC profile \(bundleID.id)",
|
||||
profileType: .iosAppDevelopment
|
||||
),
|
||||
relationships: .init(
|
||||
bundleId: .init(
|
||||
data: .init(_type: .bundleIds, id: bundleID.id)
|
||||
),
|
||||
devices: .init(data: allDevices.map {
|
||||
.init(_type: .devices, id: $0.id)
|
||||
}),
|
||||
certificates: .init(data: certs.map {
|
||||
.init(_type: .certificates, id: $0.id)
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
.created.body.json.data
|
||||
|
||||
guard let contentString = response.attributes?.profileContent,
|
||||
let contentData = Data(base64Encoded: contentString)
|
||||
else { throw Errors.invalidProfileData }
|
||||
|
||||
return try Mobileprovision(data: contentData)
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
|
||||
public struct DeveloperServicesTeam: Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable {
|
||||
public struct ID: RawRepresentable, Decodable, Sendable, Hashable {
|
||||
public let rawValue: String
|
||||
public init(rawValue: String) { self.rawValue = rawValue }
|
||||
}
|
||||
+63
-42
@@ -1,6 +1,7 @@
|
||||
import Foundation
|
||||
import Crypto
|
||||
import ConcurrencyExtras
|
||||
import Dependencies
|
||||
|
||||
public protocol RawADIProvider: Sendable {
|
||||
func clientInfo() async throws -> String
|
||||
@@ -26,6 +27,43 @@ extension RawADIProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private struct UnimplementedRawADIProvider: RawADIProvider {
|
||||
func startProvisioning(
|
||||
spim: Data,
|
||||
userID: UUID
|
||||
) async throws -> (any RawADIProvisioningSession, Data) {
|
||||
let closure: (Data, UUID) async throws -> (any RawADIProvisioningSession, Data) = unimplemented()
|
||||
return try await closure(spim, userID)
|
||||
}
|
||||
|
||||
func requestOTP(
|
||||
userID: UUID,
|
||||
routingInfo: inout UInt64,
|
||||
provisioningInfo: Data
|
||||
) async throws -> (machineID: Data, otp: Data) {
|
||||
let closure: (UUID, inout UInt64, Data) async throws -> (Data, Data) = unimplemented()
|
||||
return try await closure(userID, &routingInfo, provisioningInfo)
|
||||
}
|
||||
}
|
||||
|
||||
private enum RawADIProviderDependencyKey: DependencyKey {
|
||||
static let testValue: RawADIProvider = UnimplementedRawADIProvider()
|
||||
static let liveValue: RawADIProvider = {
|
||||
#if os(Linux)
|
||||
return XADIProvider()
|
||||
#else
|
||||
return OmnisetteADIProvider()
|
||||
#endif
|
||||
}()
|
||||
}
|
||||
|
||||
extension DependencyValues {
|
||||
public var rawADIProvider: RawADIProvider {
|
||||
get { self[RawADIProviderDependencyKey.self] }
|
||||
set { self[RawADIProviderDependencyKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
public protocol RawADIProvisioningSession: Sendable {
|
||||
func endProvisioning(
|
||||
routingInfo: UInt64,
|
||||
@@ -35,7 +73,7 @@ public protocol RawADIProvisioningSession: Sendable {
|
||||
}
|
||||
|
||||
// uses CoreADI APIs
|
||||
public final class ADIDataProvider: AnisetteDataProvider {
|
||||
public struct ADIDataProvider: AnisetteDataProvider {
|
||||
|
||||
public enum ADIError: Error {
|
||||
case hashingFailed
|
||||
@@ -44,41 +82,28 @@ public final class ADIDataProvider: AnisetteDataProvider {
|
||||
case badEndResponse
|
||||
}
|
||||
|
||||
public let rawProvider: RawADIProvider
|
||||
public let deviceInfo: DeviceInfo
|
||||
public let storage: KeyValueStorage
|
||||
@Dependency(\.keyValueStorage) var storage
|
||||
@Dependency(\.rawADIProvider) var rawProvider
|
||||
@Dependency(\.httpClient) var httpClient
|
||||
|
||||
private let httpClient: HTTPClientProtocol
|
||||
private let lookupManager: GrandSlamLookupManager
|
||||
private let lookupManager = GrandSlamLookupManager()
|
||||
private let localUserUID: UUID
|
||||
private let localUserID: String
|
||||
|
||||
private let _clientInfo = LockIsolated<String?>(nil)
|
||||
|
||||
public init(
|
||||
rawProvider: RawADIProvider,
|
||||
deviceInfo: DeviceInfo,
|
||||
storage: KeyValueStorage, // ideally secure, eg keychain
|
||||
provisioningData: ProvisioningData? = nil,
|
||||
httpFactory: HTTPClientFactory = defaultHTTPClientFactory
|
||||
) throws {
|
||||
self.rawProvider = rawProvider
|
||||
self.deviceInfo = deviceInfo
|
||||
self.storage = storage
|
||||
|
||||
self.httpClient = httpFactory.makeClient()
|
||||
self.lookupManager = .init(deviceInfo: deviceInfo, httpFactory: httpFactory)
|
||||
|
||||
public init(provisioningData: ProvisioningData? = nil) {
|
||||
@Dependency(\.keyValueStorage) var storage
|
||||
if let provisioningData {
|
||||
self.localUserUID = provisioningData.localUserUID
|
||||
try? storage.setData(provisioningData.adiPb, forKey: Self.provisioningKey)
|
||||
try? storage.setString("\(provisioningData.routingInfo)", forKey: Self.routingInfoKey)
|
||||
} else if let localUserUIDString = try storage.string(forKey: Self.localUserUIDKey),
|
||||
} else if let localUserUIDString = try? storage.string(forKey: Self.localUserUIDKey),
|
||||
let localUserUID = UUID(uuidString: localUserUIDString) {
|
||||
self.localUserUID = localUserUID
|
||||
} else {
|
||||
let localUserUID = UUID()
|
||||
try storage.setString(localUserUID.uuidString, forKey: Self.localUserUIDKey)
|
||||
try? storage.setString(localUserUID.uuidString, forKey: Self.localUserUIDKey)
|
||||
self.localUserUID = localUserUID
|
||||
}
|
||||
// localUserID = SHA256(local user UID)
|
||||
@@ -87,9 +112,9 @@ public final class ADIDataProvider: AnisetteDataProvider {
|
||||
.joined()
|
||||
}
|
||||
|
||||
private static let localUserUIDKey = "SUPLocalUserUID"
|
||||
private static let provisioningKey = "SUPProvisioningInfo"
|
||||
private static let routingInfoKey = "SUPRoutingInfo"
|
||||
private static let localUserUIDKey = "XTLLocalUserUID"
|
||||
private static let provisioningKey = "XTLProvisioningInfo"
|
||||
private static let routingInfoKey = "XTLRoutingInfo"
|
||||
|
||||
private struct GSARequest<T: Encodable>: Encodable {
|
||||
let header: [String: String] = [:]
|
||||
@@ -142,29 +167,25 @@ public final class ADIDataProvider: AnisetteDataProvider {
|
||||
|
||||
let body = try Self.encoder.encode(GSARequest(request: request))
|
||||
|
||||
var request = HTTPRequest(
|
||||
url: endpointURL,
|
||||
method: "POST",
|
||||
headers: [
|
||||
"Content-Type": "text/x-xml-plist",
|
||||
AnisetteData.localUserIDKey: self.localUserID,
|
||||
"Accept-Language": "en_US"
|
||||
],
|
||||
body: .buffer(body)
|
||||
)
|
||||
request.headers["X-MMe-Country"] = Locale.current.regionCode
|
||||
var request = HTTPRequest(url: endpointURL)
|
||||
request.method = .post
|
||||
request.headerFields = [
|
||||
.contentType: "text/x-xml-plist",
|
||||
.acceptLanguage: "en_US",
|
||||
.init(AnisetteData.localUserIDKey)!: self.localUserID,
|
||||
]
|
||||
request.headerFields[.init("X-MMe-Country")!] = Locale.current.regionCode
|
||||
|
||||
request.headers[DeviceInfo.clientInfoKey] = try await clientInfo()
|
||||
request.headers[DeviceInfo.deviceIDKey] = self.localUserUID.uuidString
|
||||
request.headerFields[.init(DeviceInfo.clientInfoKey)!] = try await clientInfo()
|
||||
request.headerFields[.init(DeviceInfo.deviceIDKey)!] = self.localUserUID.uuidString
|
||||
// request.headers[DeviceInfo.clientInfoKey] = self.deviceInfo.clientInfo.clientString
|
||||
// self.deviceInfo.dictionary.forEach { request.headers[$0] = $1 }
|
||||
|
||||
let resp = try await self.httpClient.makeRequest(request)
|
||||
let (_, response) = try await self.httpClient.makeRequest(request, body: body)
|
||||
|
||||
guard let body = resp.body else { throw ADIError.noResponse }
|
||||
// print(String(data: body, encoding: .utf8) ?? "<no utf8 data>")
|
||||
// print(String(data: response, encoding: .utf8) ?? "<no utf8 data>")
|
||||
|
||||
return try GrandSlamOperationDecoder<Response>.decode(data: body)
|
||||
return try GrandSlamOperationDecoder<Response>.decode(data: response)
|
||||
}
|
||||
|
||||
private func endProvisioning(
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user