SINF Replication (DRM Handshake)
Relevant source files
The following files were used as context for generating this wiki page:
SINF Replication is a critical post-processing phase in the ipatool download workflow. Its primary purpose is to apply Digital Rights Management (DRM) signatures, known as "SINF" (Shared Information) data, to a downloaded iOS application package (IPA). This process ensures that the app package contains the necessary authorization metadata required by iOS to execute the application.
This module handles the extraction of existing package manifests, identification of bundle names, and the surgical insertion of SINF data into specific locations within the IPA's internal directory structure (typically under SC_Info).
Architecture and Data Structures
The replication logic is encapsulated within the appstore package and relies on specific data structures to map DRM data to the correct file paths within the encrypted ZIP archive.
Core Data Structures
| Structure | Description | Fields |
|---|---|---|
Sinf | Represents the DRM signature data returned by the App Store. | ID (int64), Data ([]byte) |
ReplicateSinfInput | Input parameters for the replication process. | Sinfs ([]Sinf), PackagePath (string) |
packageManifest | Structure representing the Manifest.plist found in SC_Info. | SinfPaths ([]string) |
packageInfo | Structure for parsing the Info.plist to find the executable name. | BundleExecutable (string) |
Sources: pkg/appstore/appstore_replicate_sinf.go:16-24, pkg/appstore/appstore_replicate_sinf.go:87-93
Logical Flow
The following diagram illustrates the high-level logic used to determine where SINF data should be written within the IPA package.
Detailed Logic and Implementation
The replication process is divided into two primary strategies: Manifest-based and Info-based.
Manifest-based Replication
If the IPA contains a SC_Info/Manifest.plist, the tool reads the SinfPaths array. This array contains the relative paths where the system expects to find SINF files. The replicateSinfFromManifest function pairs the provided SINF data objects with these paths and writes them into the new ZIP archive under the Payload/[BundleName].app/ directory.
Sources: pkg/appstore/appstore_replicate_sinf.go:95-115
Info-based Replication
In the absence of a manifest, the tool falls back to using the Info.plist. It extracts the CFBundleExecutable value and constructs a path at Payload/[BundleName].app/SC_Info/[ExecutableName].sinf. This is the standard location for single-binary applications.
Sources: pkg/appstore/appstore_replicate_sinf.go:117-130
ZIP Replication Strategy
To maintain the integrity of the IPA while modifying specific files, the tool uses a "copy-and-update" approach:
- It opens the original IPA using
zip.OpenReader. - It creates a temporary file and a
zip.NewWriter. - It iterates through all existing files in the source ZIP using
OpenRaw()and copies them to the destination usingCreateRaw(). This preserves original compression settings and metadata. - It appends the new SINF files and the
iTunesMetadata.plist.
Metadata Injection
Beyond the SINF data, the applyPatches method (called during the download process) injects account-specific metadata into a file named iTunesMetadata.plist.
| Field | Source | Description |
|---|---|---|
apple-id | Account.Email | The email address of the purchasing account. |
userName | Account.Email | Duplicate of the Apple ID for compatibility. |
bundleShortVersionString | downloadItemResult | Extracted from the App Store response metadata. |
Sources: pkg/appstore/appstore_download.go:245-267, pkg/appstore/appstore_download.go:68-71
Error Handling and Constraints
The replication process includes several safety checks to prevent package corruption:
- Bundle Identification: The tool searches for
Info.plistfiles that are not within a/Watch/subdirectory to identify the primary application bundle name. If no bundle name is found, the process fails. - Atomic Replacement: The original file is only removed and replaced by the temporary file if all write operations (replicate ZIP, write manifest, write SINF) succeed.
- SINF Mapping: The
util.Zipfunction is used to align the slice ofSinfdata with the slice of paths defined in the manifest.
Sources: pkg/appstore/appstore_replicate_sinf.go:50-78, pkg/appstore/appstore_replicate_sinf.go:193-209
Conclusion
SINF Replication is the final bridge between a raw encrypted download and a valid IPA package. By accurately mimicking the App Store's internal file placement logic for DRM signatures and metadata, ipatool ensures that downloaded packages remain structurally compatible with iOS requirements while reflecting the user's specific purchase license.