Skip to content

About

Generate Apple Anisette headers locally in Swift on macOS 14+ and Linux

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Repository files navigation

swift-anisette

Generate Apple Anisette headers locally in Swift on macOS 14+ and Linux — no external server or Mac required.

Anisette headers are hard-to-generate tokens that Apple requires when you're doing authenticated Apple ID requests (such as sign-in, Find My, iMessage, App Store, etc.) to verify a request is coming from an actual Apple device. This library fetches the relevant token-generator binaries from Apple's macOS restore image (IPSW) and runs them inside an isolated VM/emulator to generate said tokens.

Requires Swift 6.2 or later. iOS is not supported.

Installation

Add the package to Package.swift and depend on .product(name: "Anisette", package: "swift-anisette"):

.package(url: "https://github.com/KishanBagaria/swift-anisette", from: "0.1.1")

Linux requires zlib development headers (zlib1g-dev on Ubuntu).

Execution backends

Platform Backend Requirements
Apple Silicon macOS Hypervisor.framework com.apple.security.hypervisor entitlement
ARM64 Linux /dev/kvm Read/write access to /dev/kvm
Everywhere else (Intel macOS, x86_64 Linux, unentitled/no KVM) Unicorn fallback Hardened macOS apps: com.apple.security.cs.allow-unsigned-executable-memory and com.apple.security.cs.disable-library-validation

Usage

To try it immediately (no Apple ID required), run Examples/anisette-example:

git clone https://github.com/KishanBagaria/swift-anisette && cd swift-anisette
swift run anisette-example

Generate an OTP and Anisette headers for a provisioned identity:

import Foundation
import Anisette

let otp = try await AnisetteContext.with(
    identifier: stableDeviceUUID,
    provisioningState: savedProvisioningState
) { context in
    try await context.requestOTP()
}
// Persist otp.provisioningState before using this identity again.

let headers = otp.headers(
    identifier: stableDeviceUUID,
    routingInfo: savedRoutingInfo,
    system: try AnisetteSystemInfo.current()
)

Provision a new identity by exchanging challenges with Apple's servers (see Examples/anisette-example for the HTTP exchange):

let state = try await AnisetteContext.provision(
    identifier: stableDeviceUUID,
    challenge: serverChallenge
) { clientChallenge in
    try await sendToApple(clientChallenge)
}

Keep each identity's identifier UUID stable and serialize its read → generate → persist cycle.

Runtime & Configuration

First use fetches ~215 MB from Apple's restore image via range requests and caches ~90 MB under swift-anisette in the user's cache directory (plus Unicorn when the fallback backend is used). Call AnisetteContext.prepare(configuration:) at startup to pre-warm the cache.

Pass AnisetteConfiguration to customize cacheDirectory, offline paths (appleDirectory, unicornLibrary), backend (.automatic, .hypervisor, .kvm, .unicorn), or httpClient.

License

MIT. Third-party notices are in Resources. The optional Unicorn fallback is GPLv2.

About

Generate Apple Anisette headers locally in Swift on macOS 14+ and Linux

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages