Compare commits

...
3 Commits
Author SHA1 Message Date
Majd Alfhaily ff43c07a32 Patch old code signature revisions as fallback (#94) 2022-07-03 14:38:57 +00:00
Majd Alfhaily 07a0f3310d Update Makefile (#93) 2022-07-02 21:59:14 +00:00
Majd Alfhaily 9cfd72d142 Fix keychain access on iOS (#92) 2022-07-02 21:24:39 +00:00
8 changed files with 135 additions and 68 deletions

No files matched your search

+3 -29
View File
@@ -51,7 +51,7 @@ jobs:
- name: Inject version
run: ./Scripts/version
- name: Build
run: make build
run: make build-macos
- name: Upload binary
uses: actions/upload-artifact@v2
with:
@@ -77,34 +77,8 @@ jobs:
run: ./Scripts/version
- name: Install dependencies
run: brew install xcodegen ldid
- name: Generate Xcode project
run: xcodegen -s ios-project.yml
- name: Build archive
run: |
xcodebuild archive -scheme CLI \
-sdk iphoneos \
-configuration Release \
-derivedDataPath .build \
-archivePath .build/ipatool.xcarchive \
CODE_SIGN_IDENTITY='' \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGN_ENTITLEMENTS='' \
CODE_SIGNING_ALLOWED=NO
cp .build/ipatool.xcarchive/Products/Applications/CLI.app/CLI .build/ipatool
- name: Fakesign executable
run: |
cat <<EOF >"$PWD/.build/entitlements.xml"
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>platform-application</key>
<true />
<key>com.apple.private.security.container-required</key>
<false />
</dict>
</plist>
EOF
ldid -S.build/entitlements.xml ./.build/ipatool
- name: Build
run: make build-ios
- name: Upload binary
uses: actions/upload-artifact@v2
with:
+5 -30
View File
@@ -20,39 +20,14 @@ jobs:
restore-keys: |
${{ runner.os }}-spm-${{ hashFiles('Package.resolved') }}
${{ runner.os }}-spm-
- name: Inject version
run: ./Scripts/version
- name: Install dependencies
run: brew install xcodegen ldid
- name: Generate Xcode project
run: xcodegen -s ios-project.yml
- name: Build archive
- name: Inject version
run: ./Scripts/version
- name: Build
run: |
xcodebuild archive -scheme CLI \
-sdk iphoneos \
-configuration Release \
-derivedDataPath .build \
-archivePath .build/ipatool.xcarchive \
CODE_SIGN_IDENTITY='' \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGN_ENTITLEMENTS='' \
CODE_SIGNING_ALLOWED=NO
cp .build/ipatool.xcarchive/Products/Applications/CLI.app/CLI .build/ipatool
make build-ios
file .build/ipatool
- name: Fakesign executable
run: |
cat <<EOF >"$PWD/.build/entitlements.xml"
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>platform-application</key>
<true />
<key>com.apple.private.security.container-required</key>
<false />
</dict>
</plist>
EOF
ldid -S.build/entitlements.xml ./.build/ipatool
build_macos:
name: Dry build (macOS)
runs-on: macos-12
@@ -71,5 +46,5 @@ jobs:
run: ./Scripts/version
- name: Build
run: |
make build
make build-macos
file .build/ipatool
+1 -1
View File
@@ -26,7 +26,7 @@ jobs:
- name: Inject version
run: ./Scripts/version
- name: Build
run: make build
run: make build-macos
- name: Upload binary
uses: actions/upload-artifact@v2
with:
+39 -4
View File
@@ -1,22 +1,57 @@
prefix ?= /usr/local
bindir = $(prefix)/bin
define ios_entitlements
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>keychain-access-groups</key>
<array>
<string>ipatool</string>
</array>
<key>application-identifier</key>
<string>ipatool</string>
<key>platform-application</key>
<true />
<key>com.apple.private.security.container-required</key>
<false />
</dict>
</plist>
endef
lint:
swiftlint lint --config .swiftlint.yml --path Sources/ Tests/m Plugins/
build: lint
build-macos: lint
swift build -c release --arch arm64
swift build -c release --arch x86_64
lipo -create -output .build/ipatool .build/arm64-apple-macosx/release/ipatool .build/x86_64-apple-macosx/release/ipatool
install: build
build-ios: lint
xcodegen -s ios-project.yml
xcodebuild archive -scheme CLI \
-sdk iphoneos \
-configuration Release \
-derivedDataPath .build \
-archivePath .build/ipatool.xcarchive \
CODE_SIGN_IDENTITY='' \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGN_ENTITLEMENTS='' \
CODE_SIGNING_ALLOWED=NO
cp .build/ipatool.xcarchive/Products/Applications/CLI.app/CLI .build/ipatool
echo "$$ios_entitlements" > "${PWD}/.build/entitlements.xml"
ldid -S.build/entitlements.xml ./.build/ipatool
install-macos: build
install -d "$(bindir)"
install ".build/ipatool" "$(bindir)"
uninstall:
uninstall-macos:
rm -rf "$(bindir)/ipatool"
clean:
rm -rf .build
.PHONY: build install uninstall clean
.PHONY: build-macos install-macos uninstall-macos clean
export ios_entitlements
+26 -2
View File
@@ -110,7 +110,7 @@ extension Download {
"The country provided does not match with the account you are using.",
"Supply a valid country using the \"--country\" flag."
].joined(separator: " "), level: .error)
case StoreResponse.Error.passwordTokenExpired:
case StoreResponse.Error.passwordTokenExpired, StoreResponse.Error.passwordChanged:
logger.log("Token expired. Login again using the \"auth\" command.", level: .error)
default:
logger.log("An unknown error has occurred.", level: .error)
@@ -164,7 +164,7 @@ extension Download {
"The country provided does not match with the account you are using.",
"Supply a valid country using the \"--country\" flag."
].joined(separator: " "), level: .error)
case StoreResponse.Error.passwordTokenExpired:
case StoreResponse.Error.passwordTokenExpired, StoreResponse.Error.passwordChanged:
logger.log("Token expired. Login again using the \"auth\" command.", level: .error)
default:
logger.log([
@@ -203,6 +203,30 @@ extension Download {
logger.log("Applying patches...", level: .info)
try signatureClient.appendMetadata(item: item, email: email)
try signatureClient.appendSignature(item: item)
} catch {
switch error {
case SignatureClient.Error.fileNotFound:
logger.log(
"App uses old code signature version, falling back to alternative patching mechanism.",
level: .debug
)
logger.log("The produced app package may not be compatible with modern iOS releases.", level: .info)
applyOldPatches(item: item, email: email, path: path)
default:
logger.log("\(error)", level: .debug)
logger.log("Failed to apply patches. The ipa file will be left incomplete.", level: .error)
_exit(1)
}
}
}
private mutating func applyOldPatches(item: StoreResponse.Item, email: String, path: String) {
logger.log("Creating signature client...", level: .debug)
let signatureClient = SignatureClient(fileManager: .default, filePath: path)
do {
logger.log("Applying fallback patches...", level: .info)
try signatureClient.appendOldSignature(item: item)
} catch {
logger.log("\(error)", level: .debug)
logger.log("Failed to apply patches. The ipa file will be left incomplete.", level: .error)
+1 -1
View File
@@ -103,7 +103,7 @@ extension Purchase {
"The country provided does not match with the account you are using.",
"Supply a valid country using the \"--country\" flag."
].joined(separator: " "), level: .error)
case StoreResponse.Error.passwordTokenExpired:
case StoreResponse.Error.passwordTokenExpired, StoreResponse.Error.passwordChanged:
logger.log("Token expired. Login again using the \"auth\" command.", level: .error)
default:
logger.log("An unknown error has occurred.", level: .error)
@@ -51,6 +51,18 @@ public final class SignatureClient: SignatureClientInterface {
throw Error.invalidArchive
}
try appendSignatureFromManfiest(forItem: item, inArchive: archive)
}
public func appendOldSignature(item: StoreResponse.Item) throws {
guard let archive = Archive(url: URL(fileURLWithPath: filePath), accessMode: .update) else {
throw Error.invalidArchive
}
try appendOldSignature(forItem: item, inArchive: archive)
}
private func appendSignatureFromManfiest(forItem item: StoreResponse.Item, inArchive archive: Archive) throws {
let manifest = try readPlist(
archive: archive,
matchingSuffix: ".app/SC_Info/Manifest.plist",
@@ -87,6 +99,52 @@ public final class SignatureClient: SignatureClientInterface {
try fileManager.removeItem(at: signatureBaseUrl)
}
private func appendOldSignature(forItem item: StoreResponse.Item, inArchive archive: Archive) throws {
guard let infoEntry = archive.first(where: { $0.path.hasSuffix(".app/Info.plist") }) else {
throw Error.invalidAppBundle
}
let temporaryInfoURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString)
_ = try archive.extract(infoEntry, to: temporaryInfoURL, skipCRC32: true)
let infoData = try Data(contentsOf: temporaryInfoURL)
guard let infoPlist = try PropertyListSerialization.propertyList(
from: infoData,
format: nil
) as? [String: Any] else {
throw Error.invalidAppBundle
}
guard let executableName = infoPlist["CFBundleExecutable"] as? String else {
throw Error.invalidAppBundle
}
let appBundleName = URL(fileURLWithPath: infoEntry.path)
.deletingLastPathComponent()
.deletingPathExtension()
.lastPathComponent
guard let signatureItem = item.signatures.first(where: { $0.id == 0 }) else {
throw Error.invalidSignature
}
let signatureBaseUrl = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString)
let signatureUrl = signatureBaseUrl
.appendingPathComponent("Payload")
.appendingPathComponent(appBundleName)
.appendingPathExtension("app")
.appendingPathComponent("SC_Info")
.appendingPathComponent(executableName)
.appendingPathExtension("sinf")
let signatureRelativePath = signatureUrl.path.replacingOccurrences(of: "\(signatureBaseUrl.path)/", with: "")
try fileManager.createDirectory(at: signatureUrl.deletingLastPathComponent(), withIntermediateDirectories: true)
try signatureItem.sinf.write(to: signatureUrl)
try archive.addEntry(with: signatureRelativePath, relativeTo: signatureBaseUrl)
try fileManager.removeItem(at: signatureBaseUrl)
}
private func readPlist<T: Decodable>(archive: Archive, matchingSuffix: String, type: T.Type) throws -> T {
guard let entry = archive.first(where: { $0.path.hasSuffix(matchingSuffix) }) else {
throw Error.fileNotFound(matchingSuffix)
@@ -115,7 +173,7 @@ extension SignatureClient {
}
}
enum Error: Swift.Error {
public enum Error: Swift.Error {
case invalidArchive
case invalidAppBundle
case invalidSignature
@@ -15,6 +15,7 @@ public enum StoreResponse {
public enum Error: Int, Swift.Error {
case unknownError = 0
case passwordChanged = 2002
case genericError = 5002
case codeRequired = 1
case invalidLicense = 9610