This document explains how SideStore currently authenticates, signs, installs and
refreshes apps, and enumerates every place that assumes a single Apple
Developer account. It is the basis for the incremental refactor described in
PLAN.md.
TL;DR — The signing/provisioning pipeline is already parameterised by an
AuthenticatedOperationContextthat carries asession+team+certificate. The single-account assumption is not in the pipeline; it is concentrated in five places: the globalKeychain,AuthenticationOperation,AppManager.refresh,InstallAppOperation, and the account UI. Generalising those five is the whole job.
AltStore/Operations/AuthenticationOperation.swiftis the whole login flow. It is aResultOperation<(ALTTeam, ALTCertificate?, ALTAppleAPISession)>.- Login path (
signIn()→authenticate(appleID:password:)/authenticateWithToken(adsid:xcodeToken:)): fetch anisette data → callALTAppleAPI.shared.authenticate(...)(2FA handled via alert) → obtainALTAccount+ALTAppleAPISession. - Team selection:
fetchTeam(for:session:)→ALTAppleAPI.fetchTeams→ if a DB "active team" exists use it, elseselectTeam(UI if >1). - Certificate:
fetchCertificate(for:session:)reuses the cachedsigningCertificateif it matches a live cert, else requests/replaces one. - Device registration +
cacheAppIDs.
AltStoreCore/Components/Keychain.swift— a singleton (Keychain.shared) that stores exactly one set of credentials:appleIDEmailAddress,appleIDPassword,appleIDAdsid(dsid),appleIDXcodeToken(authToken) — per-account values, stored globally.signingCertificate(PKCS#12),signingCertificatePassword— per-account.identifier,adiPb— per-device anisette state (correctly shared across accounts; must NOT be duplicated per account).- In-memory cache:
certificate,session,team— one of each.
- The cached
session/team/certificateshort-circuit re-login inAuthenticationOperation.main().
- Team, certificate, device, App ID and provisioning-profile calls all take an
explicit
team+session, so they are not globally bound — they are driven by whatever the operation's context holds.
| Location | Assumption |
|---|---|
Keychain.swift (all credential keys + certificate/session/team) |
One credential set, one cached session/cert/team for the whole app. |
AuthenticationOperation.main L96-134 |
Reuses the single cached Keychain.shared.session/team/certificate. |
AuthenticationOperation.postAuthenticationCleanup L237-256 |
Sets isActiveAccount = true on this account and false on all others, and same for isActiveTeam — i.e. exactly one active account/team. |
AuthenticationOperation.signIn L358-382 |
Reads the single global appleIDEmailAddress/appleIDAdsid. |
AuthenticationOperation.fetchTeam L505-509 |
Uses DatabaseManager.activeTeam as "the" team. |
Entry points live in AltStore/Managing Apps/AppManager.swift; the heavy
lifting is in AltStore/Operations/*. Every operation is threaded an
AppOperationContext whose authenticatedContext is an
AuthenticatedOperationContext (session/team/certificate).
- IPA preparation + resign —
ResignAppOperation.swift. Usesself.context.team+self.context.certificateandALTSigner(team:certificate:). Already account-agnostic. The only global read is theapp.isAltStoreAppself-refresh branch (L142-144) which embedsKeychain.shared.signingCertificateinto the SideStore bundle. - Provisioning profiles —
FetchProvisioningProfilesOperation.swift(self.context.team/session). Account-agnostic. - App IDs —
FetchAppIDsOperation.swift(self.context.team/session). Account-agnostic. - Entitlements — handled inside
ResignAppOperation.prepare(...)from the provisioning profile. Account-agnostic. - Install —
InstallAppOperation.swift. Usesself.context.certificateand provisioning profiles from context. But L153 binds the newInstalledApp.team = DatabaseManager.shared.activeTeam— the single point where the app→account link is (incorrectly, for multi-account) set to the active team instead of the team that actually signed it.
| Location | Assumption |
|---|---|
InstallAppOperation.findOrCreateInstalledApp L153 |
New apps are always bound to the active team. |
ResignAppOperation.prepareAppBundle L142-144 |
SideStore self-refresh embeds the single global certificate. |
AppManager._refresh L1600 |
Certificate-match check falls back to the single global Keychain.shared.signingCertificate. |
- Model —
AltStoreCore/Model/InstalledApp.swift+ Core Data entityInstalledApp(current model versionAltStore 17_1).- Relationship chain already present:
InstalledApp.team → Team.account → Account. - So an app already can name its account via
team?.account. There is no explicit, permanentsigningAccountIDfield yet.
- Relationship chain already present:
- Persistence —
AltStoreCore/Model/DatabaseManager/DatabaseManager.swiftoverRSTPersistentContainer(AltStoreCore/Roxas/RSTPersistentContainer.swift).- Migration is progressive and falls back to
NSMappingModel.inferredMappingModel(lightweight). Adding an optional attribute in a new model version therefore migrates automatically with no explicit mapping model.
- Migration is progressive and falls back to
- Refresh queue —
AppManageroperationQueue(concurrent) +serialOperationQueue(install/refresh/backup serialised; SideStore-self last). - Expiration tracking —
InstalledApp.expirationDate(from the provisioning profile).fetchAppsForRefreshingAll/fetchAppsForBackgroundRefreshselect apps to refresh, sorted by expiration.
| Location | Assumption |
|---|---|
Account.isActiveAccount, Team.isActiveTeam (model + DatabaseManager.activeAccount/activeTeam) |
Exactly one "current" account/team. |
InstalledApp |
No permanent per-app account field; the account is only implied by the mutable team relationship. |
Migrations/Policies/InstalledAppPolicy.swift L24 |
Migration policy fetches the single isActiveTeam team. |
- Foreground —
MyAppsViewController/ app detail →AppManager.refresh(_:). - Background —
BackgroundRefreshAppsOperation.swiftcollectsfetchAppsForBackgroundRefreshand callsAppManager.shared.refresh(apps, …). AppManager.refresh(_:presentingViewController:group:)(L784) creates oneRefreshGroup(oneAuthenticatedOperationContext) for all apps.AppManager.perform(_:group:)(L1131): ifgroup.context.session == nil, authenticate once (L1148) using the group's context (→ global keychain), then run every app's operations against that single shared session/team/cert.
| Location | Assumption |
|---|---|
AppManager.refresh L784-798 |
All apps refreshed in a single group / single account. |
AppManager.perform L1146-1159 |
Exactly one authentication per refresh batch. |
BackgroundRefreshAppsOperation |
All background apps go through one refresh(...) group. |
Consequence for failure isolation: because there is one context and one
context.error, an auth/cert/provisioning failure for the single account fails
the entire batch. There is currently no isolation because there is only ever
one account.
| Location | Use |
|---|---|
AltStore/Settings/SettingsViewController.swift (activeTeam, signIn, signOut, .signIn/.account sections) |
Shows the one signed-in account; sign-in/out. |
AltStore/App IDs/AppIDsViewController.swift L91/223/322 |
Uses activeTeam. |
AltStore/My Apps/MyAppsViewController.swift L1805/2187 |
Footer / sizing keyed on activeTeam != nil. |
AltStore/LaunchViewController.swift L185-192 & SettingsViewController L286-295 |
"Import account" writes the global keychain credentials. |
AltStore/Settings/Certificates/CertificatesViewModel.swift |
Manages the single global certificate. |
Keychain— one credential set + one cached session/cert/team → keyed by account identifier (device-level anisetteidentifier/adiPbstay global).AuthenticationOperation— authenticate a specified account; stop forcing a singleisActiveAccount/isActiveTeam.AppManager.refresh— partition apps by their assigned account and refresh each account in its own group/context (→ natural failure isolation).InstallAppOperation— bind a new app to the team/account that signed it, and persist a permanentsigningAccountID.- UI — manage N accounts (add/remove/list/status) and show/change an app's signing account.
Everything else (resign, provisioning, App IDs, entitlements, install transport) is already context-driven and needs no change.