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
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ ipaforge/
| `apps/desktop/src/main/rpc/serve-engine.ts` | Serves the Engine to the window: a fresh `MessageChannelMain` per page load, `createRpcServer` on one end, the other posted to the page |
| `apps/desktop/src/preload/forward-port.ts` | The preload's main job: forward the rpc and update ports to the page (`expose-file-paths.ts` adds its one function, a dropped file's path) |
| `apps/desktop/src/main/rpc/choose-ipas.ts` | The IPA file dialog behind "Choose files…" on the Preload page, in the main process |
| `apps/desktop/src/main/rpc/choose-save-folder.ts` | The folder dialog behind Save signed .ipa instead (the RPC server keeps the path; the page gets an id) |
| `apps/desktop/src/renderer/engine-port.ts` | Renderer: receives the ports and wraps each in a `Transport` for `createEngineClient` and `createUpdateClient` |
| `apps/desktop/src/renderer/main.tsx` | Electron renderer: connects the `EngineClient` and the update client, then mounts `@ipaforge/ui` with the browser services and a hash history |
| `apps/desktop/electron-builder.yml` | Installers (DMG and zip, NSIS and MSI, AppImage, deb, rpm) and the update metadata: `pnpm --filter @ipaforge/desktop dist` |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Sideloading tools tend to fail in a few recurring ways. IPAForge is designed aro

Sideload signing has been verified against real devices and Apple accounts: Apple's own `codesign --verify --deep --strict` accepts the output, including a full SideStore build signed in about half a second. Details: [Code Signing](docs/signing.md).

New: the **Developer Portal** page, with your team's certificates (and the apps each one signs), App IDs, the profiles on your device, app groups and registered devices, and the iOS 17+ remote pairing file for SideStore. Pairing files per app: place, remove or give your own apps one, in one dialog. Coming next: `.p12` import and export, saving signed `.ipa` files, and guided onboarding. Installing over Wi-Fi to a device paired before already works.
New: the **Developer Portal** page, with your team's certificates (and the apps each one signs), App IDs, the profiles on your device, app groups and registered devices, and the iOS 17+ remote pairing file for SideStore. Pairing files per app: place, remove or give your own apps one, in one dialog. Save signed `.ipa` files instead of installing them. Coming next: `.p12` import and export, and guided onboarding. Installing over Wi-Fi to a device paired before already works.

## Requirements

Expand Down
74 changes: 74 additions & 0 deletions apps/desktop/src/main/adapters/file-signed-ipa-folder.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { mkdtemp, readdir, readFile, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'

import { afterEach, describe, expect, it } from 'vitest'

import { createFileSignedIpaFolder } from '@desktop/main/adapters/file-signed-ipa-folder.ts'
import { utf8Encode } from '@ipaforge/kernel'

const dirs: string[] = []

afterEach(async () => {
for (const dir of dirs.splice(0))
await rm(dir, { recursive: true, force: true })
})

const folder = async () => {
const dir = await mkdtemp(join(tmpdir(), 'ipaforge-signed-'))

dirs.push(dir)

return dir
}

const streamOf = (text: string) =>
new ReadableStream<Uint8Array>({
start(controller) {
controller.enqueue(utf8Encode(text))
controller.close()
}
})

const failing = () =>
new ReadableStream<Uint8Array>({
pull(controller) {
controller.error(new Error('signing stopped'))
}
})

describe('saving signed IPAs to a folder', () => {
it('writes the app under its name, and never replaces one already there', async () => {
const dir = await folder()
const output = createFileSignedIpaFolder()

const first = await output.save(dir, 'App 1.0.ipa', streamOf('one'))
const second = await output.save(dir, 'App 1.0.ipa', streamOf('two'))

expect(first).toBe(join(dir, 'App 1.0.ipa'))
expect(second).toBe(join(dir, 'App 1.0 (2).ipa'))
expect(await readFile(first, 'utf8')).toBe('one')
expect(await readFile(second, 'utf8')).toBe('two')
})

it('keeps a name with folders in it inside the folder', async () => {
const dir = await folder()

const path = await createFileSignedIpaFolder().save(
dir,
'../../escape.ipa',
streamOf('x')
)

expect(path).toBe(join(dir, 'escape.ipa'))
})

it('leaves nothing behind when the signed app fails to arrive', async () => {
const dir = await folder()

await expect(
createFileSignedIpaFolder().save(dir, 'App.ipa', failing())
).rejects.toThrow('signing stopped')
expect(await readdir(dir)).toEqual([])
})
})
73 changes: 73 additions & 0 deletions apps/desktop/src/main/adapters/file-signed-ipa-folder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SignedIpaFolder on disk: Save signed .ipa instead writes into the folder the user picked. A file already there is
// never replaced: "App.ipa" becomes "App (2).ipa". It's written under a temporary name and renamed once complete,
// so an interrupted save leaves no half-written app.
import { open, rename, rm } from 'node:fs/promises'
import { basename, extname, join } from 'node:path'

import type { SignedIpaFolder } from '@ipaforge/installer'

const PARTIAL = '.part'
const MAX_TRIES = 100

/** The name as given, or with " (2)", " (3)"… before its extension. */
const numbered = (name: string, count: number): string => {
if (count === 1) return name
const extension = extname(name)

return `${basename(name, extension)} (${count})${extension}`
}

/** Creates `path` only if it doesn't exist yet (the name stays taken while it's written). */
const claim = async (path: string): Promise<boolean> => {
try {
await (await open(path, 'wx')).close()
return true
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'EEXIST') return false
throw error
}
}

const writeTo = async (
path: string,
stream: ReadableStream<Uint8Array>
): Promise<void> => {
const file = await open(path, 'w')
const reader = stream.getReader()

try {
for (;;) {
const { done, value } = await reader.read()

if (done) return
await file.write(value)
}
} finally {
reader.releaseLock()
await file.close()
}
}

export const createFileSignedIpaFolder = (): SignedIpaFolder => ({
save: async (folder, name, stream) => {
// Only a plain name is ever joined to the folder: nothing can climb out of it.
const safe = basename(name)

for (let count = 1; count <= MAX_TRIES; count++) {
const path = join(folder, numbered(safe, count))

if (!(await claim(path))) continue
const partial = `${path}${PARTIAL}`
try {
await writeTo(partial, stream)
await rename(partial, path)
return path
} catch (error) {
await rm(partial, { force: true })
await rm(path, { force: true })
throw error
}
}
throw new Error(`no free name for ${safe} in ${folder}`)
}
})
3 changes: 3 additions & 0 deletions apps/desktop/src/main/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createFileDownloadStore } from '@desktop/main/adapters/file-download-st
import { createFileKeptIpaStore } from '@desktop/main/adapters/file-kept-ipa-store.ts'
import { createFileScratchStore } from '@desktop/main/adapters/file-scratch-store.ts'
import { createFileSecretStore } from '@desktop/main/adapters/file-secret-store.ts'
import { createFileSignedIpaFolder } from '@desktop/main/adapters/file-signed-ipa-folder.ts'
import { createNodeHttpClient } from '@desktop/main/adapters/http-client.ts'
import { createNodeUsbmuxTransport } from '@desktop/main/adapters/usbmux-transport.ts'
import { createWebSocketFactory } from '@desktop/main/adapters/web-socket.ts'
Expand Down Expand Up @@ -54,6 +55,8 @@ export const createDesktopEngine = ({
// What was installed on each device (not secret), and each app's original IPA, for Refresh.
installed: createFileSecretStore(join(dataDir, 'installed.json')),
kept: createFileKeptIpaStore(join(dataDir, 'kept')),
// Save signed .ipa instead: into the folder the user picked in the dialog.
signedIpaFolder: createFileSignedIpaFolder(),
logger
})
}
11 changes: 11 additions & 0 deletions apps/desktop/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { createNodeHttpClient } from '@desktop/main/adapters/http-client.ts'
import { createDesktopEngine } from '@desktop/main/engine.ts'
import { createMainLogging, type MainLogging } from '@desktop/main/logger.ts'
import { createIpaChooser } from '@desktop/main/rpc/choose-ipas.ts'
import { createSaveFolderChooser } from '@desktop/main/rpc/choose-save-folder.ts'
import { createIpaResolver } from '@desktop/main/rpc/resolve-ipa.ts'
import { serveEngine } from '@desktop/main/rpc/serve-engine.ts'
import { createDesktopSecrets } from '@desktop/main/secrets.ts'
Expand Down Expand Up @@ -79,6 +80,16 @@ const createEngineConnector = ({ logger, logs }: MainLogging) => {
: dialog.showOpenDialog(settings)
}
}),
chooseSaveFolder: createSaveFolderChooser({
showOpenDialog: (options) => {
const window = BrowserWindow.fromWebContents(contents)
const settings = { properties: [...options.properties] }

return window
? dialog.showOpenDialog(window, settings)
: dialog.showOpenDialog(settings)
}
}),
logger,
createChannel: () => new MessageChannelMain()
})
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/main/rpc/choose-ipas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('createIpaChooser', () => {
])
expect(showOpenDialog).toHaveBeenCalledWith({
properties: ['openFile', 'multiSelections'],
filters: [{ name: 'iOS apps', extensions: ['ipa'] }]
filters: [{ name: 'IPA', extensions: ['ipa'] }]
})
})

Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/main/rpc/choose-ipas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { basename } from 'node:path'
import type { ChooseIpasDeps } from '@desktop/main/rpc/types.ts'
import type { ChooseIpas } from '@ipaforge/rpc'

const IPA_FILTER = { name: 'iOS apps', extensions: ['ipa'] }
// The file type's name is the same in every language: this process doesn't know the user's.
const IPA_FILTER = { name: 'IPA', extensions: ['ipa'] }

export const createIpaChooser =
({ showOpenDialog }: ChooseIpasDeps): ChooseIpas =>
Expand Down
15 changes: 15 additions & 0 deletions apps/desktop/src/main/rpc/choose-save-folder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// The folder dialog behind Save signed .ipa instead on the Preload page. It runs here, in the main process: the
// window is sandboxed and never sees the file system; the RPC server keeps the path and gives the page an id for it.
import type { ChooseSaveFolderDeps } from '@desktop/main/rpc/types.ts'
import type { ChooseSaveFolder } from '@ipaforge/rpc'

export const createSaveFolderChooser =
({ showOpenDialog }: ChooseSaveFolderDeps): ChooseSaveFolder =>
async () => {
const { canceled, filePaths } = await showOpenDialog({
// The system's own button text: it's in the user's language, which this process doesn't know.
properties: ['openDirectory', 'createDirectory']
})

return canceled ? undefined : filePaths[0]
}
4 changes: 3 additions & 1 deletion apps/desktop/src/main/rpc/serve-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const serveEngine = <P>(
resolveIpa,
logs,
chooseIpas,
chooseSaveFolder,
logger,
createChannel
}: ServeEngineDeps<P>
Expand All @@ -31,7 +32,8 @@ export const serveEngine = <P>(
resolveIpa,
logger,
...(logs ? { logs } : {}),
...(chooseIpas ? { chooseIpas } : {})
...(chooseIpas ? { chooseIpas } : {}),
...(chooseSaveFolder ? { chooseSaveFolder } : {})
})
contents.postMessage(RPC_PORT_CHANNEL, null, [port2])
logger.info('engine connected to the renderer')
Expand Down
19 changes: 18 additions & 1 deletion apps/desktop/src/main/rpc/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { Engine } from '@ipaforge/installer'
import type { Logger } from '@ipaforge/kernel'
import type { ChooseIpas, LogSource, ResolveIpa } from '@ipaforge/rpc'
import type {
ChooseIpas,
ChooseSaveFolder,
LogSource,
ResolveIpa
} from '@ipaforge/rpc'

export type MessageListener = (event: { readonly data: unknown }) => void

Expand Down Expand Up @@ -34,11 +39,23 @@ export type ServeEngineDeps<P> = {
readonly logs?: LogSource
/** The file dialog for this window's "Choose files…" (main process only). */
readonly chooseIpas?: ChooseIpas
/** The folder dialog for Save signed .ipa instead (main process only). */
readonly chooseSaveFolder?: ChooseSaveFolder
readonly logger: Logger
/** `() => new MessageChannelMain()` */
readonly createChannel: () => ChannelPair<P>
}

/** The part of Electron's `dialog.showOpenDialog` the save-folder chooser uses, already bound to the window. */
export type ChooseSaveFolderDeps = {
showOpenDialog(options: {
readonly properties: readonly ('openDirectory' | 'createDirectory')[]
}): Promise<{
readonly canceled: boolean
readonly filePaths: readonly string[]
}>
}

/** The part of Electron's `dialog.showOpenDialog` the IPA chooser uses, already bound to the window. */
export type ChooseIpasDeps = {
showOpenDialog(options: {
Expand Down
4 changes: 2 additions & 2 deletions docs/design/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ Every feature below maps to the phases that deliver it. "Automatic" means the us
- progress:
- [x] **10a** the Developer Portal page (Certificates in the sidebar before): the team's certificates (who made each, this computer's, which apps on the device each signs, Revoke with what stops opening), App IDs (the app using each, Unused, Delete, the weekly limit), the device's provisioning profiles (Expired, Unused, Another team, Remove and Remove unused), app groups and registered devices, in small tabs with counts, also used by Preload (#86)
- [x] **10b** pairing files per app, in one Pairing files dialog on the Apps page: whose files each pairing app and each other app IPAForge installed holds, Place, Remove, a path of your own for your own apps, a new remote pairing for SideStore, a No pairing file tag on an app that needs one, and Save pairing file on the Devices page (#87)
- [ ] **10c** `.p12` export and import of this computer's certificate, and saving a signed `.ipa` instead of installing it
- [x] **10c** Save signed .ipa instead, per app on Preload: signed for the team and saved in a folder picked in the host's dialog (named by an id, never a path from the page), without the certificate's private key, in the same run as the apps installed (#90)
- [ ] **10d** `.p12` export and import of this computer's certificate
- later: signing in with a security key (today detected and explained, not completed)
- export signed IPAs (save the signed `.ipa` instead of installing it)
- [ ] **11. Wireless and remote pairing**: pairing over Wi-Fi and finding devices beyond those usbmuxd lists, and the iOS 17+ remote-pairing (RP) file for SideStore
- already in: installing over Wi-Fi to a device usbmuxd sees on the network (compressed, 1 MiB AFC writes), and a device seen over both USB and Wi-Fi listed once
- **11.1** remote pairing for SideStore (iOS 17.4 and later): made over USB through the lockdown service `com.apple.dt.remotepairingdeviced.lockdown` (JSON framed with `RPPairing` and a 2-byte big-endian length, no tunnel): pair-setup (SRP-6a, 3072-bit group, SHA-512, the fixed USB PIN; Ed25519 identities under ChaCha20-Poly1305, the device's signature checked) and pair-verify before a saved one is reused. One identity per device, kept encrypted. SideStore gets it as its own file, `PairingFile_RemoteRP.plist` (`public_key`, `private_key`, `identifier`, `alt_irk`), next to the classic `PairingFile_Lockdown.plist`: a file with both key sets is ambiguous to SideStore. Repair SideStore checks it. Also: anisette server tests ask once, without retries (#82)
Expand Down
3 changes: 3 additions & 0 deletions docs/install-flows.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ A new certificate is stored with its private key, per account and team, as soon

Installs one or more IPAs, from the catalog, from files or from links (an app source's apps are added by their download link), one after another (the Preload page). All apps are downloaded and inspected first, each checked against the device (minimum iOS, device family, architecture), so an app the device cannot run stops the run before any Apple call. The account steps then run once (sign-in, team, device, certificate) and check the App ID budget for all apps together. After that, each app goes through `free-apps`, `provision`, `sign` and `install`. When the list holds SideStore from the catalog (on its own or in LiveContainer), the run ends with the `pairing` step as Install SideStore does, so it gets this computer's pairing file too. Each app's steps carry its place in the list (`inspect-0`, `install-1`), which the UI groups them by.

**Save signed .ipa instead.** `installApps` takes `save: { folder, apps }`: the apps at those positions are provisioned and signed like the others, then written to `folder` (`save-N`, through the host's `SignedIpaFolder`; desktop: never over a file already there, `App (2).ipa` instead) and not installed. They take no free-app slot and get no pairing file. A saved IPA never carries the signing certificate's private key, whatever the app, and is always compressed. The folder comes from the host's folder dialog: the RPC server keeps its path and the page names it only by an id, so a run can only write where the user chose.

The signing certificate goes only into an app IPAForge has a reason to trust:

- a catalog release whose download matched its published SHA-256;
Expand Down Expand Up @@ -91,6 +93,7 @@ Each step tells the UI what it did, with `context.detail(detail)` (a `step-detai
| `provision-N` | the number of profiles |
| `sign-N` | the number of bundles signed, and whether the IPA was compressed (over Wi-Fi) |
| `install-N` | uploading, then installing |
| `save-N` | where the signed IPA was saved |

While they run, steps also report how far they are (`step-progress` with a detail):

Expand Down
2 changes: 1 addition & 1 deletion docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The detailed roadmap, with each phase's scope, is [design/roadmap.md](design/roa
| 7 | Onboarding | First-run guided wizard |
| 8 | Install & preload UX ✓ | One-click SideStore ✓, live run view ✓, recovery screens ✓, Apple ID switch ✓, preload picker ✓ (#59), app sources ✓ (#66), detailed install progress ✓ (#67), the Apps section ✓ (#68), Repair SideStore ✓ (#70), SideStore QR codes ✓ (#71), on-device checklist ✓ (#72), the smaller notes ✓ (#73), anisette servers in Settings ✓ (#80), days left as SideStore counts them and SideStore refreshed with its own date ✓ (#81) |
| 9 | Desktop app ✓ (#61, #62, #63, #64, #65, #69, #74, #75, #77) | Electron packages for Windows, macOS, Linux ✓; the macOS app signed with IPAForge's own certificate ✓; auto-update and What's new ✓ (#74); Windows signing and notarisation moved to 1.0 |
| 10 | Management tools | Developer Portal page ✓ (#86), pairing files per app ✓ (#87); `.p12` import/export, saving signed IPAs |
| 10 | Management tools | Developer Portal page ✓ (#86), pairing files per app ✓ (#87), saving signed IPAs ✓ (#90); `.p12` import/export |
| 11 | Wireless & remote pairing | 11.1 the iOS 17.4+ remote pairing file for SideStore ✓ (#82); 11.2 installing through the iOS 17+ device tunnel over USB and Wi-Fi, and finding devices on the network; 11.3 Apple TV and Vision Pro (installing over Wi-Fi to a paired device works already) |
| 12 | Release 1.0 | Docs site, translations, security review, Windows code signing and Apple notarisation, reusable packages on npm |

Expand Down
Loading
Loading