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
32 changes: 32 additions & 0 deletions .github/workflows/exporter-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ jobs:
--name "OpenTagViewer" `
--icon=OpenTagViewer.ico `
--collect-all unicorn `
--collect-submodules machoadi `
--collect-data findmy `
--collect-data anisette `
--noconfirm `
Expand Down Expand Up @@ -143,3 +144,34 @@ jobs:
Write-Host "killed it - a native fault raises nothing, so there is no traceback to find."
exit 1
}

# **The emulated Mac, run by the frozen binary the way a sign-in runs it.** The exporter has no
# interpreter once frozen, so it starts itself with --run-emulated-mac and the engine answers
# through two files (exporter/macadi.py). This is that, for real: Apple's CoreADI under Unicorn
# inside the PyInstaller bundle, with Control Flow Guard already cleared above. `info` is
# Initialize and IsMachineProvisioned - nothing is sent to Apple but the library download.
- name: Run the emulated Mac's engine from the binary
shell: pwsh
run: |
$lib = Join-Path $env:RUNNER_TEMP 'CoreADI.x86_64'
Push-Location python
uv run --frozen python -c "import sys; from pathlib import Path; from exporter import macadi; macadi.ensure_library(Path(sys.argv[1]))" $lib
Pop-Location

$out = Join-Path $env:RUNNER_TEMP 'engine.out'
$err = Join-Path $env:RUNNER_TEMP 'engine.err'
$env:COREADI_PATH = $lib
& ./python/dist/OpenTagViewer/OpenTagViewer --run-emulated-mac $out $err info --state (Join-Path $env:RUNNER_TEMP 'mac') | Out-Null
$code = $LASTEXITCODE

$answer = if (Test-Path $out) { Get-Content $out -Raw } else { '' }
$problem = if (Test-Path $err) { Get-Content $err -Raw } else { '' }
Write-Host $answer
Write-Host $problem
Write-Host ("engine exit code: '{0}'" -f $code)

# On the answer, like the self-test above: an exit code from a killed process proves nothing.
if ($answer -notmatch '"provisioned": false') {
Write-Host "The frozen engine did not report an unprovisioned machine."
exit 1
}
3 changes: 3 additions & 0 deletions .github/workflows/macos-exporter-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ jobs:
--osx-bundle-identifier "dev.wander.opentagviewer" \
--icon=OpenTagViewer.icns \
--collect-all unicorn \
--collect-submodules machoadi \
--collect-data findmy \
--collect-data anisette \
--noconfirm \
Expand All @@ -279,6 +280,7 @@ jobs:
--name "OpenTagViewer" `
--icon=OpenTagViewer.ico `
--collect-all unicorn `
--collect-submodules machoadi `
--collect-data findmy `
--collect-data anisette `
--noconfirm `
Expand Down Expand Up @@ -315,6 +317,7 @@ jobs:
uv run --frozen pyinstaller \
--name "OpenTagViewer" \
--collect-all unicorn \
--collect-submodules machoadi \
--collect-data findmy \
--collect-data anisette \
--noconfirm \
Expand Down
14 changes: 13 additions & 1 deletion 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 Expand Up @@ -895,7 +907,7 @@ run regardless: each AES entry carries a fresh random salt.
| `build-release.yml` | on release | Translation check, JVM tests, Chaquopy bridge tests, release APK |
| `macos-scripts-python.yml` | `python/**` or its own changes, or by hand | Exporter and shared-package tests across Python 3.10–3.13 on macOS 15, and 3.13 on Ubuntu under Xvfb |
| `macos-exporter-python.yml` | on release | Tag/version check, exporter tests, and the PyInstaller build for macOS (both architectures), Windows and Linux |
| `exporter-build-check.yml` | PR and push to `main`, `python/**` | Builds the Windows binary and starts it. The release workflow above only runs on `release: published`, so without this a broken bundle is first run by whoever downloads it |
| `exporter-build-check.yml` | PR and push to `main`, `python/**` | Builds the Windows binary, starts it, and runs the emulated Mac's engine from inside it (`--run-emulated-mac … info`, which sends Apple nothing but the library download). The release workflow above only runs on `release: published`, so without this a broken bundle is first run by whoever downloads it |
| `update-contributors.yml` | weekly, **and on merging a PR by anyone but the owner** | Regenerates the contributor list on the Information page, opens a PR if it changed. The merge run names who it expected to find and fails if GitHub's cached stats did not have them yet — the weekly run is still the guarantee |
| `check-adi-libraries.yml` | weekly | Checks Apple's ADI libraries still match what is checked in, opens an issue if they drifted |
| `native-stubs.yml` | `app/src/main/cpp/**`, `app/src/test/cpp/**` changes | Builds the stand-ins for Apple's two stubbed libraries on x86_64 and arm64 Linux and checks what they export and return. Seconds, no Android |
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/OpenTagViewer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# The release workflow passes flags rather than using this file, because it needs three different
# invocations for three platforms. The two must agree, and the flags there carry the same comment.

from PyInstaller.utils.hooks import collect_all, collect_data_files
from PyInstaller.utils.hooks import collect_all, collect_data_files, collect_submodules

# unicorn loads its native library through ctypes at runtime, so PyInstaller's analysis never sees
# it. Without this the build succeeds and the binary dies at startup with "Failed to load the
Expand All @@ -20,6 +20,11 @@ from PyInstaller.utils.hooks import collect_all, collect_data_files
# lets signing in work without a third-party Anisette server.
unicorn_datas, unicorn_binaries, unicorn_hiddenimports = collect_all('unicorn')

# The emulated Mac's engine (exporter/macadi.py). Nothing imports it at build time - the frozen
# exporter runs it as a child of itself with --run-emulated-mac - so analysis never finds it, and
# a build without this signs in as nothing. The release workflow passes --collect-submodules.
machoadi_hiddenimports = collect_submodules('machoadi')

# FindMy.py keeps Apple's pinned root certificates as `.crt` files beside its code, and anisette
# keeps `apple-root.pem` beside its own. PyInstaller bundles code, not the files next to it - so
# without these the binary starts, signs in, and dies opening the keychain session with
Expand All @@ -35,7 +40,7 @@ a = Analysis(
pathex=['.'],
binaries=unicorn_binaries,
datas=unicorn_datas + findmy_datas + anisette_datas,
hiddenimports=unicorn_hiddenimports,
hiddenimports=unicorn_hiddenimports + machoadi_hiddenimports,
hookspath=[],
hooksconfig={},
runtime_hooks=[],
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