Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,18 @@ version ≤ 14` is the two decryptor tests for the macOS-local route: **they ski
since GitHub stopped offering macOS 14 runners in November 2026, and run only by hand on a Mac
that old. A skip naming `_tkinter` means the window tests did not run.

#### The emulated Mac's engine, for real

`test_emulated_mac.py` runs Apple's macOS CoreADI under Unicorn only when `OTV_COREADI` names a
copy of the library, and otherwise skips that one class. It sends Apple nothing: `info` is
`Initialize` and `IsMachineProvisioned`. Fetching the library is one 3.5 MB range request to
Apple, and is the only network use:

```bash
uv run python -c "from pathlib import Path; from exporter import macadi; macadi.ensure_library(Path('/tmp/CoreADI.x86_64'))"
OTV_COREADI=/tmp/CoreADI.x86_64 uv run pytest test/test_emulated_mac.py -rs
```

### Tooling tests

```bash
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ chaquopy {
// wheel for desktop platforms and a pure-Python `py3-none-any` one as well.
// There is no Android wheel, so pip falls back to the pure-Python build - which
// is correct but markedly slower. The messages here are small enough not to care.
install("git+https://github.com/parawanderer/FindMy.py@00fd962a0e8ec9f5601fe0b9db3f16ccea252a3c")
install("git+https://github.com/parawanderer/FindMy.py@37d5ca0b4ab0143e53ca158d61cf6d5e18bd6ba8")

install("NSKeyedUnArchiver==1.5")

Expand Down
2 changes: 1 addition & 1 deletion app/src/test/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# `FindMy==0.9.8` here for as long as the app built the fork, so every bridge test
# ran against a library the app does not ship - which is not a small difference:
# the fork's Anisette providers take `serial=` and PyPI's do not.
git+https://github.com/parawanderer/FindMy.py@00fd962a0e8ec9f5601fe0b9db3f16ccea252a3c
git+https://github.com/parawanderer/FindMy.py@37d5ca0b4ab0143e53ca158d61cf6d5e18bd6ba8
NSKeyedUnArchiver==1.5
PyYAML==6.0.2

Expand Down
9 changes: 7 additions & 2 deletions python/exporter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,18 @@ def build_parser() -> argparse.ArgumentParser:
"--anisette-url",
help=(
"Use a remote Anisette server instead of running it locally. Local is the default and"
" keeps the sign-in between this machine and Apple."
" keeps the sign-in between this machine and Apple: an emulated Mac, running Apple's"
" own macOS CoreADI, which is fetched from Apple on first use."
),
)
parser.add_argument(
"--anisette-libs",
type=Path,
help="Where to cache Apple's ADI libraries, so a later run does not download them again.",
help=(
"Sign in as the Android ADI machine instead of the emulated Mac, caching its libraries"
" here. Apple has served that machine differently since October 2026 (#248), so this"
" is for comparison, not for use."
),
)
parser.add_argument(
"-v",
Expand Down
93 changes: 93 additions & 0 deletions python/exporter/icloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ def make_account(
identity = ClientIdentity(
serial=serial_from(stored), device_name=identity.device_name)

# **The emulated Mac unless something else was asked for.** Apple stopped serving the Android
# ADI machine `anisette` provisions (#248), so it is reached only by naming its library cache.
# See `exporter.macadi`.
if provider is None and anisette_url is None and libs_path is None:
return _emulated_mac_account(stored, identity, identity_path)

# After the substitution above, never before: the provider is what actually sends
# `X-Apple-I-SRL-NO`, so building it from the placeholder identity would present the constant
# this change exists to stop presenting.
Expand Down Expand Up @@ -327,6 +333,48 @@ def make_account(
)


def _emulated_mac_account(
stored: dict[str, Any] | None,
identity: ClientIdentity,
identity_path: Path | None,
) -> AsyncAppleAccount:
"""
An account on the emulated Mac kept beside the device identity, provisioning it if needed.
**The ids are the machine's.** Provisioning registered one device id and one local user id
with Apple, and `X-Apple-I-MD-M` is derived from that registration; an account sending other
ids alongside it is a shape no real Mac produces. So they come from the machine, not from
`device-identity.json` - which only confirms the stored session is this machine's.
"""
from exporter import macadi # noqa: PLC0415 - the app imports this module and never needs it

root = (identity_path or device.identity_path()).parent / macadi.DIRNAME
provider = macadi.EmulatedMacAnisetteProvider(macadi.EmulatedMac.open(root, identity.serial))

if stored is not None and (stored["uid"], stored["devid"]) == (provider.uid, provider.devid):
logger.info("Reusing the stored emulated Mac, so this is not a new device to Apple")
state: Any = {
"type": "account",
"ids": {"uid": stored["uid"], "devid": stored["devid"]},
"account": {"username": None, "password": None, "info": None},
"login": {"state": LoginState.LOGGED_OUT.value, "data": None},
"anisette": provider.to_json(),
}
return AsyncAppleAccount(
provider, state_info=state, device_name=identity.device_name,
timeout=LOGIN_TIMEOUT_SECONDS)

if stored is not None:
# Unavoidable once: the stored ids are the Android ADI machine Apple stopped serving.
logger.warning(
"This install signed in before as a different machine; signing in as the emulated Mac"
" adds one entry to the account's device list. The serial stays %s.", provider.serial)

return AsyncAppleAccount(
provider, uid=provider.uid, devid=provider.devid, device_name=identity.device_name,
timeout=LOGIN_TIMEOUT_SECONDS)


def _make_provider(
anisette_url: str | None,
libs_path: str | None,
Expand Down Expand Up @@ -751,6 +799,50 @@ def _describe_factor(method: object) -> str:
return type(method).__name__


class _CloudKitDeviceView:
"""
The account, except that `device_uuid` is a UUID - for the keychain and CloudKit clients only.
FindMy.py's CloudKit client sends `uuid.UUID(account.device_uuid)`, and a Mac's device id is a
provisioning UDID - `00006000-` and sixteen hex - so opening the client failed with "badly
formed hexadecimal UUID string" before anything was sent. CloudKit's identifier is a separate
field from `X-Mme-Device-Id`, so it is answered with another stable value, and everything else -
Grand Slam, tokens, PET renewal - reaches the real account. After #274's `_forCloudKit`, and
sacca97/os-findmy-e's `tag_keys.CloudKitIdentity` before it.
"""

def __init__(self, account: AsyncAppleAccount, device_uuid: str) -> None:
self._account = account
self._device_uuid = device_uuid

@property
def device_uuid(self) -> str:
return self._device_uuid

def __getattr__(self, name: str) -> Any:
return getattr(self._account, name)


def _with_a_uuid_for_cloudkit(account: Any) -> Any:
"""`account`, or a view of it whose device id CloudKit can parse."""
device_id = getattr(account, "device_uuid", None)
if not isinstance(device_id, str):
return account
try:
uuid.UUID(device_id)
return account
except ValueError:
pass

# The emulated Mac's host UUID when the provider can say; otherwise one derived from the
# device id, which is as stable as the device id is.
stable = getattr(getattr(account, "_anisette", None), "cloudkit_device_uuid", None)
if not isinstance(stable, str):
stable = str(uuid.uuid5(uuid.NAMESPACE_URL, f"opentagviewer:device:{device_id}")).upper()
logger.info("The device id is not a UUID; CloudKit is told %s instead", stable)
return _CloudKitDeviceView(account, stable)


async def open_client(
account: AsyncAppleAccount, identity: ClientIdentity = EXPORTER_IDENTITY,
) -> AsyncFindMyClient:
Expand All @@ -761,6 +853,7 @@ async def open_client(
client with the library's own device name. Rule 11: every path has to send the same identity,
and a second name here would be a second device in the user's list.
"""
account = _with_a_uuid_for_cloudkit(account)
session = await AsyncKeychainSession.open(account)
try:
store = AsyncBeaconStore(
Expand Down
Loading
Loading