App Licensing & Purchasing Mechanics
Relevant source files
The following files were used as context for generating this wiki page:
The App Licensing and Purchasing Mechanics within ipatool facilitate the acquisition of legitimate licenses for iOS applications and the subsequent management of Store Interface (SINF) data. This system ensures that downloaded apps are associated with a valid Apple ID, allowing them to be installed on authorized devices. The process involves interacting with private iTunes and App Store APIs to simulate a purchase (specifically for free apps) and obtaining the necessary cryptographic signatures for the application package.
The core functionality is divided between obtaining a license (Purchasing) and applying that license to an IPA package (SINF Replication). This ensures that the downloaded .ipa file is not just a raw binary but a licensed package containing the necessary iTunesMetadata.plist and SC_Info signatures.
Purchasing Logic and Workflow
The purchasing module is designed to obtain a license for a specific app ID (adamId) associated with an authenticated Apple ID. Currently, the implementation is restricted to free applications, as purchasing paid apps is explicitly unsupported to prevent unauthorized transactions.
Purchase Execution Flow
The process begins by generating a unique Hardware GUID from the machine's MAC address. The tool then attempts a purchase using standard App Store pricing parameters. If the item is marked as "temporarily unavailable," the system automatically retries using Apple Arcade pricing parameters to ensure maximum compatibility.
Note: The flow shows the fallback mechanism from standard App Store parameters to Apple Arcade parameters when encountering availability issues.
Sources: pkg/appstore/appstore_purchase.go:31-52, pkg/appstore/constants.go:27-28
API Interaction Parameters
Purchases are conducted via POST requests to the buyProduct endpoint. The request payload includes critical identifiers and flags to bypass interactive authorization.
| Parameter | Type | Description |
|---|---|---|
salableAdamId | int64 | The unique ID of the target iOS app. |
guid | string | Uppercase MAC address without colons. |
pricingParameters | string | Either STDQ (Standard) or GAME (Apple Arcade). |
buyWithoutAuthorization | string | Set to true to facilitate non-interactive purchasing. |
appExtVrsId | string | External version identifier, typically set to 0 for purchase. |
Sources: pkg/appstore/appstore_purchase.go:94-118, pkg/appstore/constants.go:21-22
Licensing and SINF Replication
Once an app is "purchased" or licensed to an account, the App Store provides SINF (Store Interface) data. This data is critical for the FairPlay DRM used by iOS. ipatool must replicate these signatures into the downloaded IPA file to make it valid for the device.
SINF Structures
The system uses the Sinf struct to hold the cryptographic data retrieved during the download phase.
type Sinf struct {
ID int64 `plist:"id,omitempty"`
Data []byte `plist:"sinf,omitempty"`
}
Sources: pkg/appstore/appstore_replicate_sinf.go:14-17
Replication Process
The replication involves modifying the IPA (which is a ZIP archive) by adding or updating specific files:
- Metadata Injection: The tool writes
iTunesMetadata.plistinto the root of the archive, containing the user's email and account details. - Signature Placement: Depending on the app's structure, the SINF data is written to either a path specified in
SC_Info/Manifest.plistor a default path based on the application's executable name (SC_Info/[ExecutableName].sinf).
Note: This sequence illustrates how the tool patches the raw download with user-specific licensing information.
Sources: pkg/appstore/appstore_replicate_sinf.go:24-69, pkg/appstore/appstore_download.go:167-185
Error Handling and Failure Types
The licensing system interprets specific Apple API error codes to provide actionable feedback to the user. These are defined as constants and checked during every network interaction.
| Constant | Code | Meaning |
|---|---|---|
FailureTypePasswordTokenExpired | 2034 | The session has expired; user must re-authenticate. |
FailureTypeSignInRequired | 2042 | The request requires a valid login session. |
FailureTypeLicenseNotFound | 9610 | The user does not own the app and must purchase it. |
FailureTypeTemporarilyUnavailable | 2059 | The item cannot be purchased with current parameters. |
Sources: pkg/appstore/constants.go:4-8, pkg/appstore/appstore_purchase.go:12-16
Summary of Mechanics
The "App Licensing & Purchasing Mechanics" system bridge the gap between a raw binary and a functional iOS application. By simulating the purchase of free apps and injecting the resulting SINF data and metadata into the IPA package, ipatool ensures that the apps are legally tied to the user's Apple ID. The system's robustness is enhanced by its ability to handle multiple pricing tiers (App Store vs. Apple Arcade) and its support for various IPA internal structures during the SINF replication phase.