Skip to content
95 changes: 91 additions & 4 deletions README-NG.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ What that means for AltServer-Linux:
Verified on 2026-10-27: with this anisette, AltStore Classic signed in to a new free Apple ID
through AltServer-Linux and installed an app on iOS 27.

**Since 2026-11-05 Apple answers `mac-ani.jkcoxson.com`'s identity with `-80043`**, even for a made-up
account. `https://new.ani.sidestore.io` provides Mac anisette with the same client info and is now the
default anisette server, spoken to with the v3 protocol (Fix 8).

**Protect your Apple account.** Repeated failed sign-ins make Apple lock the account. While these
errors were being worked out, the maintainer's account was locked twice in four days. Stop after one
or two failures and find the cause first. After a lock or a password reset Apple can answer
Expand All @@ -158,6 +162,87 @@ during that period. If `iforgot.apple.com` says the account cannot be unlocked o
Settings on an Apple device that is signed in with it. Use a separate free Apple ID for sideloading,
so a lock never hits your main account.

## Fix 7 — SMS codes for accounts without a trusted device

An Apple ID with no trusted Apple device gets its verification code by SMS. GrandSlam then answers
the password step with `au` = `secondaryAuth`. AltSign recognised only `trustedDeviceSecondaryAuth`, so
it treated such an account as having no two-factor authentication and the sign-in failed later.

`AltSign/AppleAPI+Authentication.cpp` now requests the code by SMS and validates it with the JSON
endpoints that rileytestut/AltSign#62 proposes and [isideload](https://github.com/nab138/isideload) uses:
`PUT /auth/verify/phone` with `{"phoneNumber":{"id":1},"mode":"sms"}`, then
`POST /auth/verify/phone/securitycode` with the code. The code goes to the account's first trusted
phone number (id 1). AltServer prints `Enter two factor code` and reads the code from standard input.
If Apple says a code was already sent and is still valid (HTTP 412, or `-22979` / `-22981`), no new
SMS is requested. A wrong code is `-21669`; any other error, also inside a 2xx answer, shows Apple's
message.

GrandSlam does not always report such an account as `secondaryAuth`. On 2026-11-05 an account without
a trusted device got `trustedDeviceSecondaryAuth`: the trusted-device code request made Apple send an
SMS, the trusted-device validation answered that code with HTTP 200, and the second sign-in still
required two-factor authentication.

So the method is chosen from the account's 2FA info. `ALTSERVER_2FA` selects it:

- `auto` (default): when a code is needed, AltServer reads the 2FA info (`GET /auth`, which sends
nothing). With `noTrustedDevices` it takes the SMS path for the `trustedPhoneNumber`. Apple sends that
SMS on its own, so AltServer requests no second one. `au` = `secondaryAuth` also takes the SMS path,
requesting the code with `PUT`. Any other account keeps the trusted-device path. `pushMode` doesn't
decide, because it is `sms` for the phone numbers of trusted-device accounts too.
- `sms`: always the SMS path, requesting the code with `PUT`.
- `trusteddevice`: the trusted-device path, as before Fix 7, except for `au` = `secondaryAuth`, which
has no trusted device to send a code to.

At the SMS code prompt, `resend` requests one new SMS, for when the expected one doesn't arrive. The
log shows `au` and `hsc` of the sign-in response, the 2FA info (without the phone number), the chosen
method and which SMS code to enter.

Apple ties the code to the anisette identity it was validated with. `new.ani.sidestore.io` returns a new
identity (Device-Id, MD-LU, MD-M) on every request, so the anisette refreshes added in Fix 4 made the
second sign-in come from another device than the one that validated the code. A refresh is now used only
when it returns the same device; otherwise the sign-in keeps its original anisette data. The log names
the Device-Id (first 8 characters) at each step. With such a server every sign-in is still a new device
to Apple, so it asks for a code every time.

Verified on 2026-11-05: an account without trusted devices signed in with `ALTSERVER_2FA=sms` and
v1 anisette from `new.ani.sidestore.io`, and AltServer installed an app. The `auto` choice has not been
tried against Apple yet. If a sign-in fails, stop and read the log before trying again; see the
account-lock warning above.

## Fix 8 — anisette v3: one identity, a code only once

A v1 anisette server (`GET /`) hands out whatever identity it likes. `new.ani.sidestore.io` hands out a
new one on every request, so Apple sees a new device at every sign-in and asks for a code each time.
An anisette v3 server provisions one identity instead, and the identity's keychain identifier and
`adi.pb` stay on this computer. After the first sign-in with a code, Apple knows the device.

`src/AnisetteV3.cpp` speaks SideStore's anisette-v3-server protocol, as omnisette and Sideloader do:
`GET /v3/client_info`, provisioning over the `/v3/provisioning_session` websocket with Apple's
`midStartProvisioning` and `midFinishProvisioning` (relayed by this computer as the device), and
`POST /v3/get_headers` for each set of anisette data. The identity is kept in
`$XDG_CONFIG_HOME/AltServer/anisette-v3/<host>.json` (default `~/.config/...`), readable by its owner
only. A port or path in the server URL is added to the file name. Delete that file to start over with a
new identity. The v3 client's requests (anisette server and provisioning) honour `HTTPS_PROXY`,
`HTTP_PROXY` and `NO_PROXY`; the v1 client and the Apple sign-in itself do not use a proxy.

`ALTSERVER_ANISETTE_PROTOCOL` selects the protocol: `auto` (default) uses v3 when the server answers
`/v3/client_info` and v1 otherwise; `v3` and `v1` force one. A server that can't be reached is an
error, not a reason to fall back to v1. The log shows the protocol, whether the identity was
provisioned or loaded, and the first 8 characters of its device ID.

AltStore receives the same identity when it asks AltServer for anisette data.

Verified on 2026-11-05 against `new.ani.sidestore.io` with a made-up account: the first run provisioned
an identity and saved it (mode 600), the second run reused it without provisioning, and both times
Apple answered the password step with `-20970`, so the v3 anisette passed every check before it.

## Log output

The log, with or without `-d`, shows the steps, status codes, `au`/`hsc` and the first 8 characters
of the anisette device ID. It does not show passwords, verification codes, GSA tokens, the decrypted
sign-in response or anisette secrets (one-time password, machine ID, local user ID, `adi.pb`). `-d`
also turns on libimobiledevice's own debug output for the device connection.

## Prebuilt binaries

Static binaries for x86_64, aarch64, armv7 and i586 are attached to the
Expand All @@ -181,24 +266,26 @@ docker run --rm --platform linux/amd64 -v "$PWD:/workdir" -w /workdir \
The result is a statically linked `build/AltServer-x86_64`. Other architectures use the
`altserver_builder_alpine_{aarch64,armv7,i386}` images.

Sanity-check that all three fixes are present:
Sanity-check that the fixes are present:

```bash
strings build/AltServer-x86_64 | grep -c "missing path separator" # Fix 1, new ldid -> 1
strings build/AltServer-x86_64 | grep -c "Sanitized client info" # Fix 2, sign-in -> 1
grep -c idevice_sockaddr_len libraries/libimobiledevice/src/idevice.c # Fix 3, netmuxd -> >= 1
strings build/AltServer-x86_64 | grep -c "noTrustedDevices" # Fix 7, 2FA choice -> >= 1
strings build/AltServer-x86_64 | grep -c "/v3/provisioning_session" # Fix 8, anisette v3 -> 1
```

## Running

```bash
USBMUXD_SOCKET_ADDRESS=127.0.0.1:27015 \
ALTSERVER_ANISETTE_SERVER=https://mac-ani.jkcoxson.com \
./AltServer-x86_64 -d -u <UDID> -a <apple-id> -p <password> AltStore.ipa
```

`-d` enables debug output. Wi-Fi installs need netmuxd listening on that address (see Fix 3). Any
anisette server that provides Mac anisette works; see Fix 5 before you choose one.
`-d` enables debug output. Wi-Fi installs need netmuxd listening on that address (see Fix 3). The
default anisette server is `https://new.ani.sidestore.io` with the v3 protocol (Fix 8);
`ALTSERVER_ANISETTE_SERVER` selects another one, which must provide Mac anisette (Fix 5).

To check sign-in without real credentials, run it with a throwaway account. HTTP 503 means Apple's
edge is blocking, `-80045` means the client info does not match the anisette provisioning (Fix 4),
Expand Down
128 changes: 75 additions & 53 deletions src/AnisetteDataManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "Error.hpp"
#include "ServerError.hpp"

#include <map>
#include <mutex>
#include <set>
#include <ctime>
#include <cstdlib>
Expand All @@ -12,6 +14,7 @@

#include "AnisetteData.h"
#include "AltServerApp.h"
#include "AnisetteV3.h"

#define odslog(msg) { std::stringstream ss; ss << msg << std::endl; OutputDebugStringA(ss.str().c_str()); }

Expand Down Expand Up @@ -53,10 +56,11 @@ using namespace web::http::client; // HTTP client features

std::string GetAnisetteURL() {
const char *server = getenv("ALTSERVER_ANISETTE_SERVER");
if (server) {
if (server && strlen(server) > 0) {
return server;
}
return U("https://armconverter.com/anisette/irGb3Quww8zrhgqnzmrx");
// Provides Mac anisette (README-NG, Fix 5) and speaks anisette v3 (Fix 8).
return U("https://new.ani.sidestore.io");
}

// Apple rejects any gsa.apple.com request whose X-Mme-Client-Info (aka
Expand All @@ -80,18 +84,76 @@ std::string SanitizeClientInfo(const std::string& clientInfo)
return result;
}

std::shared_ptr<AnisetteData> AnisetteDataManager::FetchAnisetteData()
// Client info sent to Apple as X-Mme-Client-Info (and handed to AltStore with the anisette data).
// Default: the anisette server's own value. Since 2026-10-21 Apple accepts only a client info that
// matches the platform the anisette data was provisioned as, and only Mac anisette at the 2FA/apptokens
// steps (README-NG, Fix 5). ALTSERVER_CLIENT_INFO overrides it: "windows" selects the Windows AuthKit
// identity AltServer for Windows uses, any other non-empty value is sent as is. Any value still goes
// through SanitizeClientInfo, because gsa.apple.com rejects every client info containing com.apple.dt.Xcode.
std::string FilterClientInfo(const std::string& serverClientInfo)
{
// auto client = web::http::client::http_client(U("https://armconverter.com"));
// std::string wideURI = ("/anisette/irGb3Quww8zrhgqnzmrx");

// auto encodedURI = web::uri::encode_uri(wideURI);
// uri_builder builder(encodedURI);
std::string clientInfo = serverClientInfo;
const char* envClientInfo = getenv("ALTSERVER_CLIENT_INFO");
if (envClientInfo && strlen(envClientInfo) > 0)
{
std::string value(envClientInfo);
if (value == "windows")
{
clientInfo = "<PC> <Windows;6.2(0,0);9200> <com.apple.AuthKit/1 (com.apple.iTunes/12.12.4.1)>";
}
else if (value != "anisette" && value != "original")
{
clientInfo = value;
}
}

// http_request request(methods::GET);
// request.set_request_uri(builder.to_string());
std::string sanitizedClientInfo = SanitizeClientInfo(clientInfo);
odslog("Sanitized client info: " << sanitizedClientInfo);
return sanitizedClientInfo;
}

// ALTSERVER_ANISETTE_PROTOCOL: "v3", "v1", or "auto" (the default), which uses v3 when the server answers
// /v3/client_info. v3 keeps one provisioned identity on this computer; v1 takes whatever identity the
// server hands out, which for some servers (new.ani.sidestore.io) is a new one on every request.
bool UsesAnisetteV3(const std::string& serverURL)
{
const char* value = getenv("ALTSERVER_ANISETTE_PROTOCOL");
std::string protocol = (value != nullptr && strlen(value) > 0) ? value : "auto";

if (protocol == "v3" || protocol == "v1")
{
return protocol == "v3";
}

if (protocol != "auto")
{
odslog("Unknown ALTSERVER_ANISETTE_PROTOCOL value " << protocol << ", using auto.");
}

auto client = web::http::client::http_client(GetAnisetteURL());
static std::mutex mutex;
static std::map<std::string, bool> supportsV3;

std::lock_guard<std::mutex> lock(mutex);
if (supportsV3.count(serverURL) == 0)
{
supportsV3[serverURL] = AnisetteV3::IsSupported(serverURL);
odslog("Anisette server " << serverURL << ": using " << (supportsV3[serverURL] ? "v3" : "v1") << " (auto).");
}

return supportsV3[serverURL];
}

std::shared_ptr<AnisetteData> AnisetteDataManager::FetchAnisetteData()
{
std::string serverURL = GetAnisetteURL();
if (UsesAnisetteV3(serverURL))
{
auto anisetteData = AnisetteV3::FetchAnisetteData(serverURL, FilterClientInfo);
odslog(*anisetteData);
return anisetteData;
}

auto client = web::http::client::http_client(serverURL);
http_request request(methods::GET);

std::map<utility::string_t, utility::string_t> headers = {
Expand Down Expand Up @@ -122,24 +184,8 @@ std::shared_ptr<AnisetteData> AnisetteDataManager::FetchAnisetteData()
})
.then([&anisetteData](pplx::task<json::value> previousTask)
{
odslog("parse anisette data ret");
// The values are anisette secrets (machine ID, one-time password), so they stay out of the log.
json::value jsonVal = previousTask.get();
odslog("Got anisetteData json: " << jsonVal);
std::vector<std::string> keys = {
"X-Apple-I-MD-M",
"X-Apple-I-MD",
"X-Apple-I-MD-LU",
"X-Apple-I-MD-RINFO",
"X-Mme-Device-Id",
"X-Apple-I-SRL-NO",
"X-MMe-Client-Info",
"X-Apple-I-Client-Time",
"X-Apple-Locale",
"X-Apple-I-TimeZone"
};
for (auto &key : keys) {
odslog(key << ": " << jsonVal.at(key).as_string().c_str());
}

// X-Apple-I-Client-Time is UTC, for example 2026-09-26T12:34:56Z. Some anisette servers add
// fractional seconds or leave out the Z; both name the same UTC instant. Any other value,
Expand Down Expand Up @@ -169,32 +215,8 @@ std::shared_ptr<AnisetteData> AnisetteDataManager::FetchAnisetteData()
tv.tv_sec = ts;
tv.tv_usec = 0;

// Client info sent to Apple as X-Mme-Client-Info (and handed to AltStore with the
// anisette data). Default: the anisette server's own value. Since 2026-10-21 Apple
// accepts only a client info that matches the platform the anisette data was
// provisioned as, and only Mac anisette at the 2FA/apptokens steps (README-NG, Fix 5).
// ALTSERVER_CLIENT_INFO overrides it: "windows" selects the Windows AuthKit identity
// AltServer for Windows uses, any other non-empty value is sent as is. Any value
// still goes through SanitizeClientInfo, because gsa.apple.com rejects every client
// info containing com.apple.dt.Xcode.
std::string clientInfo = jsonVal.at("X-MMe-Client-Info").as_string();
const char* envClientInfo = getenv("ALTSERVER_CLIENT_INFO");
if (envClientInfo && strlen(envClientInfo) > 0)
{
std::string value(envClientInfo);
if (value == "windows")
{
clientInfo = "<PC> <Windows;6.2(0,0);9200> <com.apple.AuthKit/1 (com.apple.iTunes/12.12.4.1)>";
}
else if (value != "anisette" && value != "original")
{
clientInfo = value;
}
}
std::string sanitizedClientInfo = SanitizeClientInfo(clientInfo);
odslog("Sanitized client info: " << sanitizedClientInfo);
std::string sanitizedClientInfo = FilterClientInfo(jsonVal.at("X-MMe-Client-Info").as_string());

odslog("Building anisetteData obj...");
anisetteData = std::make_shared<AnisetteData>(
jsonVal.at("X-Apple-I-MD-M").as_string(),
jsonVal.at("X-Apple-I-MD").as_string(),
Expand Down
Loading
Loading