Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

All notable changes to SideInstaller are documented here.

## 2.4.1

### Fixed
- **An Apple ID with a capital letter signs in.** Apple's sign-in proof is made from the email as
Apple keeps it, in lower case, so `Name@icloud.com`, as autofill or the Shift key types it, was
turned down as a wrong password. The email now goes to Apple in lower case wherever SideInstaller
signs in (installs, certificates, entitlements, Side by Side), and a sign-in saved under the
capitals keeps its session and signing key.
- **Every custom IPA stays** (#192, #194). Importing a custom IPA deleted the one before it, so
only the last custom app could be refreshed, from My apps or a Shortcut, and an app My apps
found by its IPA dropped out of the list. Each app now keeps its own: an import replaces only an
earlier one of the same app, and Settings › Downloaded IPAs lists them, to delete one by one.
Custom .ipa on the Install tab still installs the one imported last.
- **SideInstaller shows in My apps after installing itself** (#194). iOS closes SideInstaller as it
replaces it, which came before it noted the install; it now notes it first.
- **Apps that carry an Apple Watch app install.** The Watch app went along unsigned for your team,
still naming the app's old bundle ID, and such apps installed only once its folder was deleted
by hand. It's now left out, and so are the AppleDouble (`._`) files macOS adds to an IPA it zips.
- **Device IP is kept** (#198). One typed under Settings › Advanced, such as a reflector's over
Tailscale, went back to 10.7.0.1 at the next launch; it now stays until you change it.

## 2.4.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
**Install SideStore and LiveContainer directly on your iPhone. No PC required.**

[![Install](https://img.shields.io/badge/Install-SideInstaller-2ea44f?style=for-the-badge)](https://sideinstaller.net/)
[![Version](https://img.shields.io/badge/version-2.4.0-2669ed?style=for-the-badge)](CHANGELOG.md)
[![Version](https://img.shields.io/badge/version-2.4.1-2669ed?style=for-the-badge)](CHANGELOG.md)
[![Platform](https://img.shields.io/badge/platform-iOS-lightgrey?style=for-the-badge&logo=apple)](#requirements)
[![License](https://img.shields.io/badge/license-Custom-orange?style=for-the-badge)](LICENSE.md)

Expand Down
3 changes: 2 additions & 1 deletion ios-app/AccountStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ struct SavedAccount: Identifiable, Codable, Equatable {
self.appleID = appleID
}

/// The email as sent to Apple; a stray space breaks the SRP proof.
/// The email as typed, trimmed: a stray space breaks the SRP proof.
/// rust-core sends it to Apple in lower case (`apple_session::normalize_id`).
var normalized: String {
appleID.trimmingCharacters(in: .whitespacesAndNewlines)
}
Expand Down
30 changes: 25 additions & 5 deletions ios-app/Engine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,22 @@ final class Engine {

static let verboseLoggingKey = "verboseLogging"

// The loopback VPN's device-side IP; configurable in Advanced.
var deviceIP: String = Engine.defaultDeviceIP
// The loopback VPN's device-side IP; configurable in Advanced, and kept
// from one launch to the next (a reflector reached over Tailscale has its
// own: #198). The default isn't stored, so a later default applies.
var deviceIP: String = UserDefaults.standard.string(forKey: Engine.deviceIPKey) ?? Engine.defaultDeviceIP {
didSet {
let typed = deviceIP.trimmingCharacters(in: .whitespacesAndNewlines)
if typed.isEmpty || typed == Engine.defaultDeviceIP {
UserDefaults.standard.removeObject(forKey: Engine.deviceIPKey)
} else {
UserDefaults.standard.set(typed, forKey: Engine.deviceIPKey)
}
}
}
/// Device IP's default: LocalDevVPN's far end of the tunnel.
static let defaultDeviceIP = "10.7.0.1"
static let deviceIPKey = "deviceIP"
/// `deviceIP` normalized to a dialable host, e.g. `10.7.0.1/32` → `10.7.0.1`.
var deviceHost: String { NetworkStatus.host(deviceIP) }
// Which build to install (SideStore, LiveContainer + SideStore, Madeira, or
Expand Down Expand Up @@ -1106,7 +1118,8 @@ final class Engine {

// MARK: Step 4 — Apple ID sign-in

/// The Apple ID as sent to Apple; a stray space breaks the SRP proof.
/// The Apple ID as typed, trimmed: a stray space breaks the SRP proof.
/// rust-core sends it to Apple in lower case (`apple_session::normalize_id`).
var normalizedAppleID: String {
appleID.trimmingCharacters(in: .whitespacesAndNewlines)
}
Expand Down Expand Up @@ -2205,6 +2218,14 @@ final class Engine {
installProgress = 0
let ip = deviceHost
let path = pairingFilePath ?? PairingController.pairingFilePath()
// So My apps can tell it from apps other tools installed. SideInstaller
// installing itself is noted first: iOS ends this process as it
// replaces the app, before anything after the install runs (#194).
let installed = signedAppBundleID()
let replacesItself = installed != nil && installed == Bundle.main.bundleIdentifier
if replacesItself, let installed {
InstalledAppsLedger.record(installed, flush: true)
}
do {
// iOS drops the idle tunnel during sign-in and signing, and
// `isConnected` doesn't detect it, so reconnect first. Mobile Data
Expand All @@ -2223,8 +2244,7 @@ final class Engine {
throw EngineError.appLimit
}
installProgress = 1
// So My apps can tell it from apps other tools installed.
if let installed = signedAppBundleID() {
if !replacesItself, let installed {
InstalledAppsLedger.record(installed)
}
setStep(.install, .done)
Expand Down
7 changes: 5 additions & 2 deletions ios-app/MyAppsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ enum InstalledAppsLedger {
Set(all(defaults).keys)
}

/// Notes an app SideInstaller has just installed.
static func record(_ bundleID: String, defaults: UserDefaults = .standard) {
/// Notes an app SideInstaller has just installed. `flush` writes it out at
/// once, for when this process is about to end (SideInstaller replacing
/// itself).
static func record(_ bundleID: String, flush: Bool = false, defaults: UserDefaults = .standard) {
var apps = all(defaults)
apps[bundleID] = Date()
defaults.set(apps, forKey: key)
if flush { defaults.synchronize() }
}

/// Forgets the apps that aren't among `onDevice` any more.
Expand Down
54 changes: 39 additions & 15 deletions ios-app/SideStoreDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1820,8 +1820,8 @@ enum IPALibrary {
FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
}

/// Folder for the imported custom IPA, separate so its name can't clash with
/// a download.
/// Folder for the imported custom IPAs, one per app (bundle ID), separate
/// so their names can't clash with a download.
static var customDir: URL {
documentsDir.appendingPathComponent("Custom", isDirectory: true)
}
Expand Down Expand Up @@ -1869,21 +1869,28 @@ enum IPALibrary {
version: isManaged
? kind.source.version(inFileName: name, channel: kind.channel) : nil)
}
return (entries + [customImport()].compactMap { $0 })
return (entries + customImports())
.sorted { ($0.modified ?? .distantPast) > ($1.modified ?? .distantPast) }
}

/// The imported IPA, if there is one; the newest wins if a stale one survives.
static func customImport() -> Entry? {
describe(namesIn: customDir)
/// Every imported IPA, newest first: one per app, so each custom app
/// installed keeps the IPA My apps and Shortcuts refresh it from (#192).
/// `dir` is for the tests.
static func customImports(in dir: URL = IPALibrary.customDir) -> [Entry] {
describe(namesIn: dir)
.filter { $0.name.lowercased().hasSuffix(".ipa") }
.map { (name, url, attrs) in
Entry(source: .custom, channel: .stable, url: url,
size: (attrs[.size] as? Int) ?? 0,
modified: attrs[.modificationDate] as? Date,
isImported: true, version: nil)
}
.max { ($0.modified ?? .distantPast) < ($1.modified ?? .distantPast) }
.sorted { ($0.modified ?? .distantPast) > ($1.modified ?? .distantPast) }
}

/// The IPA the Install tab installs as Custom: the one imported last.
static func customImport() -> Entry? {
customImports().first
}

/// Directory listing paired with each entry's attributes.
Expand Down Expand Up @@ -1944,10 +1951,12 @@ enum IPALibrary {
case notAnIPA
}

/// Replaces the custom import with `url`, forcing a `.ipa` extension.
/// Blocking. Copies to a staging directory first, so only a complete, valid
/// IPA replaces the old one. The caller handles security-scoped access.
static func replaceCustomImport(with url: URL) throws -> URL {
/// Imports `url` as the custom IPA, forcing a `.ipa` extension: it replaces
/// an earlier import of the same app (bundle ID) or name, and the others
/// stay, so every custom app keeps its IPA. Blocking. Copies to a staging
/// directory first, so only a complete, valid IPA replaces the old one. The
/// caller handles security-scoped access. `dir` is for the tests.
static func replaceCustomImport(with url: URL, into dir: URL = IPALibrary.customDir) throws -> URL {
let fm = FileManager.default
let name = url.deletingPathExtension().lastPathComponent
let staging = fm.temporaryDirectory
Expand All @@ -1959,12 +1968,27 @@ enum IPALibrary {
try copy(url, to: staged)
guard looksLikeIPA(staged) else { throw ImportError.notAnIPA }

// One import at a time, so "the custom IPA" stays unambiguous.
try? fm.removeItem(at: customDir)
try fm.createDirectory(at: customDir, withIntermediateDirectories: true)
let dest = customDir.appendingPathComponent(name).appendingPathExtension("ipa")
try fm.createDirectory(at: dir, withIntermediateDirectories: true)
var dest = dir.appendingPathComponent(name).appendingPathExtension("ipa")
// An earlier import of the same app gives way to this one (one whose
// app can't be read, to one of the same name).
let app = appInfo(at: staged)?.bundleID
for old in customImports(in: dir) {
let same = app.map { appInfo(at: old.url)?.bundleID == $0 }
?? (old.url.lastPathComponent == dest.lastPathComponent)
if same { try? fm.removeItem(at: old.url) }
}
// Another app's import of the same name stays: this one takes a free name.
var copyNumber = 2
while fm.fileExists(atPath: dest.path) {
dest = dir.appendingPathComponent("\(name) \(copyNumber)").appendingPathExtension("ipa")
copyNumber += 1
}
// Same volume as the staging dir, so this is a rename, not a second copy.
try fm.moveItem(at: staged, to: dest)
// A copy keeps the picked file's date; the Install tab's custom IPA is
// the newest, so this one is dated now.
try? fm.setAttributes([.modificationDate: Date()], ofItemAtPath: dest.path)
return dest
}

Expand Down
58 changes: 58 additions & 0 deletions ios-tests/MyAppsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,62 @@ struct MyAppsTests {
#expect(InstalledAppsLedger.installed(defaults) == ["com.kdt.livecontainer.ABCDE12345"])
defaults.removePersistentDomain(forName: "MyAppsTests")
}

/// An IPA as far as IPALibrary reads one: a zip holding only
/// `Payload/App.app/Info.plist`, stored.
private func ipa(_ bundleID: String, named fileName: String, in dir: URL) throws -> URL {
let plist = try PropertyListSerialization.data(fromPropertyList: ["CFBundleIdentifier": bundleID],
format: .xml, options: 0)
let name = Data("Payload/App.app/Info.plist".utf8)
var archive = Data()
func put16(_ value: Int) { withUnsafeBytes(of: UInt16(value).littleEndian) { archive.append(contentsOf: $0) } }
func put32(_ value: Int) { withUnsafeBytes(of: UInt32(value).littleEndian) { archive.append(contentsOf: $0) } }
// Local header: version, flags, method (stored), time, date, CRC, sizes, name length, extra length.
put32(0x0403_4B50); put16(20); put16(0); put16(0); put16(0); put16(0)
put32(0); put32(plist.count); put32(plist.count); put16(name.count); put16(0)
archive.append(name); archive.append(plist)
// Central directory: as above, after "made by"; then comment, disk,
// attributes and the local header's offset.
let central = archive.count
put32(0x0201_4B50); put16(20); put16(20); put16(0); put16(0); put16(0); put16(0)
put32(0); put32(plist.count); put32(plist.count); put16(name.count); put16(0)
put16(0); put16(0); put16(0); put32(0); put32(0)
archive.append(name)
// End of central directory.
let centralLength = archive.count - central
put32(0x0605_4B50); put16(0); put16(0); put16(1); put16(1)
put32(centralLength); put32(central); put16(0)
let url = dir.appendingPathComponent(fileName)
try archive.write(to: url)
return url
}

@Test("Every custom app keeps its IPA; a new one of the same app replaces it (#192)")
func customImports() throws {
let fm = FileManager.default
let scratch = fm.temporaryDirectory.appendingPathComponent("MyAppsTests-\(UUID().uuidString)")
let picked = scratch.appendingPathComponent("Picked")
let custom = scratch.appendingPathComponent("Custom")
try fm.createDirectory(at: picked, withIntermediateDirectories: true)
defer { try? fm.removeItem(at: scratch) }
func kept() -> Set<String> { Set(IPALibrary.customImports(in: custom).map(\.url.lastPathComponent)) }

let liveContainer = try ipa("com.kdt.livecontainer", named: "LiveContainer.ipa", in: picked)
#expect(IPALibrary.appInfo(at: liveContainer)?.bundleID == "com.kdt.livecontainer")
_ = try IPALibrary.replaceCustomImport(with: liveContainer, into: custom)
_ = try IPALibrary.replaceCustomImport(
with: ipa("com.frizzle.SideInstaller", named: "SideInstaller.ipa", in: picked), into: custom)
#expect(kept() == ["LiveContainer.ipa", "SideInstaller.ipa"])

// A newer LiveContainer, whatever its name, takes the older one's place.
_ = try IPALibrary.replaceCustomImport(
with: ipa("com.kdt.livecontainer", named: "LiveContainer 3.8.1.ipa", in: picked), into: custom)
#expect(kept() == ["LiveContainer 3.8.1.ipa", "SideInstaller.ipa"])

// Another app under a name already taken: both stay.
let other = try IPALibrary.replaceCustomImport(
with: ipa("com.example.Other", named: "SideInstaller.ipa", in: picked), into: custom)
#expect(other.lastPathComponent == "SideInstaller 2.ipa")
#expect(kept() == ["LiveContainer 3.8.1.ipa", "SideInstaller.ipa", "SideInstaller 2.ipa"])
}
}
2 changes: 1 addition & 1 deletion rust-core/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ pub unsafe fn apple_signin(
out_summary: *mut *mut c_char,
out_error: *mut *mut c_char,
) -> i32 {
let apple_id = opt(apple_id, "");
let password = opt(password, "");
let anisette_url = opt(anisette_url, "https://ani.sidestore.io");
let machine_name = opt(machine_name, "SideInstaller");
let storage_dir = opt(storage_dir, ".");
let apple_id = apple_session::normalized(Path::new(&storage_dir), &opt(apple_id, ""));
let wanted = opt(team_id, "").trim().to_string();
let twofa = make_2fa(twofa_cb, TwoFaCtx(ctx));
let team_ctx = TwoFaCtx(ctx);
Expand Down
Loading
Loading