diff --git a/.env.example b/.env.example index a94d755..21294ad 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,9 @@ # Optional advanced settings. No .env file is needed for a fresh installation. # The build helper tags the image as wrapper-v2:local automatically. # WRAPPER_IMAGE=wrapper-v2:1.0.0-local-arm64 -# WRAPPER_DEVICE_INFO=Music/4.9/Android/10/Samsung S9/7663313/en-US/en-US/your-stable-guid +# For a manual device override, replace the suffix with a unique, stable +# 16-character lowercase hexadecimal Android ID. Never rotate it after login. +# WRAPPER_DEVICE_INFO=Music/5.0.2/Android/10/Pixel 8/7663314/en-US/en-US/0123456789abcdef # If you already have a session volume from the old Wrapper, keep both its # existing WRAPPER_DEVICE_INFO and WRAPPER_DATA_DIR rather than starting fresh. # Optional auto-login: uncomment BOTH lines and provide nonempty values. diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bc1c7a..1e1ca3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## Unreleased + +- Correct the generated first-install device fingerprint using the combined + client tuple and 64-bit Android-ID representation reported to complete + fresh login and 2FA. Existing persisted identities, native identity hashes, + and cached sessions are not rewritten. +- Retain independent 128-bit randomness for temporary identity-file names + and add regression coverage for fresh identity generation, concurrent + initialization, explicit overrides, and legacy identity preservation. +- Add one clean Linux installation runbook and a separate source audit with + the successful x86_64 reproduction and its limits. The reproduction does + not establish ARM64 end-to-end support. +- Correct the documented Android application build target to API 21, matching + the pinned profile and CMake configuration. + ## 1.0.0 — 2026-11-19 Wrapper v2 1.0.0 is a ground-up rewrite of the original Wrapper v2, built for @@ -18,8 +33,8 @@ decryption locally using [Temari](https://github.com/WorldObservationLog/Temari) through `/playback`, `/session`, and `/session/credentials`. - Report supported features, architecture, profile and protocol through `/info` so clients can reject incompatible servers before attempting authentication. -- Support native **x86-64** and **ARM64** workers, each with verified - architecture-specific runtime and Apple Music library profiles. +- Provide architecture-specific x86-64 and ARM64 worker implementations and + runtime profiles. Live validation scope is documented separately. ### Authentication and lifecycle @@ -37,15 +52,14 @@ decryption locally using [Temari](https://github.com/WorldObservationLog/Temari) ### Docker installation - Use a multi-stage Docker build for the Rust server, native worker, Linux - launcher, and full Android runtime. Host-installed Rust and Android NDK are - not required. -- Bundle verified Google Android system image components for both supported - architectures, together with their third-party notices. -- Accept an authorized, pinned Apple Music **3.6.0-beta (build 1109)** standalone - `.apk` or `.apkm` bundle directly as an argument to - `tools/build-docker.sh`. Verify the expected manifests and native libraries - before staging. -- Pass the private package through an isolated Docker BuildKit build context + launcher, and Android runtime. Host-installed Rust and Android NDK are not + required. +- Bundle Google Android system runtime components for both architectures, + together with their original third-party notices. +- Accept an operator-supplied local Apple Music 3.6.0-beta (build 1109) + standalone APK or supported split APKM. Validate the expected manifests, + native libraries, and architecture before staging. +- Pass the private package through an isolated Docker BuildKit named context rather than copying the raw package into an image layer. - Start Docker Compose without a `.env` file. Generate a persistent device identity on first startup and retain it with account/session data in a named @@ -58,8 +72,8 @@ decryption locally using [Temari](https://github.com/WorldObservationLog/Temari) - **Breaking change:** Existing clients using the former `/decrypt` endpoint must migrate to the 1.0.0 session, playback, and Temari context APIs. -- **No APK is distributed with the source code.** Users must supply their own - authorized copy of the pinned Apple Music version. +- **No Apple Music APK is distributed with the source code.** The operator + supplies an authorized local package compatible with the pinned profile. - **Do not publish or redistribute locally built Docker images.** Those images include Apple's extracted proprietary libraries even though the Git repository does not. @@ -67,7 +81,7 @@ decryption locally using [Temari](https://github.com/WorldObservationLog/Temari) persistent Docker volume and retain existing explicit identity settings when upgrading an older deployment. - This rewrite has received substantial AI coding assistance. See the - [README acknowledgements and AI disclosure](README.md#acknowledgements). + [README AI usage note](README.md#ai-usage). ## 0.0.2 and earlier diff --git a/README.md b/README.md index 58663f1..94e3766 100644 --- a/README.md +++ b/README.md @@ -1,139 +1,111 @@ # Wrapper v2 -**A self-hosted Apple Music playback and Temari-compatible context server.** +**Self-hosted Apple Music playback and Temari-compatible context server.** -Wrapper v2 provides an HTTP API for authenticated Apple Music sessions, playback information, and decryption contexts used by compatible clients such as [Gamdl](https://github.com/glomatico/gamdl). The 1.0.0 rewrite uses a Rust HTTP supervisor and a native C++ worker. +Wrapper v2 exposes an HTTP API for authenticated Apple Music sessions, playback data, and decryption contexts consumed by compatible clients such as [Gamdl](https://github.com/glomatico/gamdl). Version 1.0.0 uses a Rust HTTP supervisor and a native C++ worker. -For release history and breaking changes, see the [Changelog](CHANGELOG.md). +The server does **not** download or decrypt media. Decryption is performed by the client. The legacy `/decrypt` endpoint is not part of the 1.0.0 API. -The server **does not decrypt or download media**. Decryption, when supported, takes place on the client side. The legacy `/decrypt` endpoint is **not** part of the 1.0.0 API. +See [CHANGELOG.md](CHANGELOG.md) for release history. + +## Current validation status + +- **x86_64:** clean Docker installation, fresh Apple Account login, 2FA, session credentials, worker recycle/session recovery, playback, and `/key` HTTP requests were exercised successfully with Apple Music 3.6.0-beta, build 1109. +- **ARM64:** architecture-specific profiles and native code are present, but this change has not been validated through a complete live ARM64 build, login, playback, and context run. Treat ARM64 as unverified for this change. +- The device-fingerprint correction follows the combined configuration reported in [issue #23](https://github.com/glomatico/wrapper-v2/issues/23). The report changed the client tuple and Android ID length together; it did not isolate their individual effects. + +Detailed source findings and sanitized x86_64 evidence are in [the source audit](docs/source-audit-2026-11.md). ## Features -- **Temari-compatible API** for playback and client-side decryption contexts. -- **x86-64 and ARM64** Linux hosts, with architecture-specific Android workers. -- **Session management** with cached authentication, manual login, and two-factor authentication. -- **Automatic session recovery** and transparent, bounded retries during planned worker recycling. -- **Isolated native workers** with separate mount and PID namespaces, process supervision, and cleanup. -- **Self-contained, privately built Docker images** with the verified Android runtime and Apple Music libraries. -- **Persistent account state** stored separately from the image. -- **Structured JSON logs** with sanitized request metadata. +- Temari-compatible playback and context API. +- Session login, 2FA, cached-session restore, and optional automatic login. +- Bounded worker supervision, recycling, and session recovery. +- Separate native workers and context-capture profiles for x86_64 and ARM64. +- Persistent device identity and session storage. +- Structured JSON logs with sanitized request metadata. +- Private Docker image build with architecture-specific Android runtime files and verified Apple native-library inputs. ## Requirements | Component | Requirement | | --- | --- | -| Host | Linux, `x86_64` or `aarch64` | -| Deployment | Docker with Compose **2.24+** (required for optional `.env`) | -| Apple Music | **Version 3.6.0-beta, build 1109**, for the selected architecture | -| Android runtime | Bundled, architecture-specific Android system files (x86-64: API 21; ARM64: API 22) | -| Building | Docker with Buildx/BuildKit and standard Linux shell tools | -| Toolchains | Android NDK **r23b**, Rust, CMake, Ninja, and cross-compilers are installed **inside Docker** | - -The Apple Music build and bundled Android runtime are **strictly pinned**. Other APK versions and substitute libraries are not supported merely because they have the same architecture. - -**You must supply your own authorized copy of the pinned Apple Music APK.** The Android system libraries are bundled from [verified Google system images](vendor/android-system/README.md), with their [third-party notices](THIRD_PARTY_NOTICES.md). The APK never enters Git or the ordinary source build context: the build script supplies it through an isolated, read-only BuildKit named context. **The final, locally built image contains the extracted proprietary Apple libraries. Do not publish or redistribute that image.** Login credentials and saved sessions are never built into the image. - -## Getting started - -The build helper defaults to your host architecture. For ARM64, use the `--arch arm64-v8a` flag instead. **No local Android NDK, Rust toolchain, or Android system image is needed.** Docker compiles both architectures with an x86-64 NDK builder. Cross-architecture builds also require QEMU/binfmt emulation for the target image's runtime setup, or a remote multi-platform Buildx builder. On an x86-64 Linux host without ARM64 emulation, enable it with `docker run --privileged --rm tonistiigi/binfmt --install arm64` (this registers a host-level emulator). Docker Desktop may already provide this support. +| Host | Linux, x86_64 or aarch64 | +| Deployment | Docker Engine, Docker Compose plugin 2.24+, Buildx/BuildKit | +| Build input | An authorized local Apple Music 3.6.0-beta, build 1109 package for the target ABI; standalone APK or supported split APKM | +| Host tools | Git, Bash, coreutils, curl | +| Build toolchains | Android NDK r23b, Rust, CMake, Ninja, and cross-compilers are installed inside Docker | -### 1. Obtain the supported Apple Music APK or APKM +The package version, manifests, architecture, and required Apple native libraries are pinned in the profiles. The build accepts a local package path; this repository does not provide the Apple Music package or direct users to a download source. -Clone this repository and obtain your authorized Apple Music **3.6.0-beta (build 1109)** APK/APKM: +**Verification boundary:** the build helper calculates the SHA-256 of the supplied package and passes it to BuildKit to keep the input consistent during the build. This is not a trusted, pre-pinned checksum of the original APK/APKM archive. Compatibility is checked using the expected Android manifests and the SHA-256 hashes of the extracted native libraries in the selected profile. -```bash -git clone https://github.com/glomatico/wrapper-v2.git -cd wrapper-v2 -``` +## Quick start -Provide either an `.apkm` bundle (containing `base.apk` and the correct architecture split) or a standalone `.apk` with the pinned architecture-specific native libraries. A `base.apk` taken alone from a split bundle may not contain the required libraries. The Android system files are already in `vendor/android-system/`; the APK manifest and individual Apple libraries are verified against pinned SHA-256 hashes. +Use a source revision containing the device-identity correction. The full procedure, including the current branch to use while the upstream pull request is pending, is in [docs/clean-install-linux.md](docs/clean-install-linux.md). -### 2. Build everything in Docker - -```bash -./tools/build-docker.sh /path/to/AppleMusic.apk -# Or an APKM bundle: -# ./tools/build-docker.sh /path/to/AppleMusic.apkm -# For an ARM64 image: -# ./tools/build-docker.sh /path/to/AppleMusic.apkm --arch arm64-v8a -``` - -The file path is passed directly to the build script; no environment variable is required. The multi-stage Docker build installs the pinned NDK and a Rust toolchain, compiles the native worker, Linux launcher, and Rust supervisor, and assembles the complete Android rootfs **inside the image**. The APK or APKM is bind-mounted read-only from its isolated named build context (and its SHA-256 controls cache invalidation); the raw package is **not copied into an image layer**. The Docker builder still receives the archive, so use only a trusted, private builder. The verified Apple libraries extracted from it are present in the resulting runtime image. - -The generated image is `wrapper-v2:1.0.0-local-amd64` for x86-64 or `wrapper-v2:1.0.0-local-arm64` for ARM64. It is also tagged `wrapper-v2:local`, which Docker Compose uses automatically. Initial builds download the Android NDK and toolchains and therefore require substantial time, network access, and disk space; subsequent builds can reuse Docker layer caches. - -### 3. Start Wrapper +From the repository root, provide the path to your locally held, authorized Apple Music build 1109 package: ```bash +./tools/build-docker.sh "/absolute/path/to/your/AppleMusic-build-1109.apk" --arch x86_64 docker compose up -d +docker compose ps ``` -**No `.env` file or manual login is needed.** On first startup, Wrapper generates a unique, nine-part device identity and saves it in the persistent Docker volume alongside the session cache. The identity is reused on future restarts and image upgrades. **Preserve this volume**: deleting it (including via `docker compose down -v`) loses both the identity and cached login. The Android runtime is embedded in the image and must not be bind-mounted from the host. - -To configure an alternative image, port, DNS, device identity, or optional automatic login, copy `.env.example` to `.env` and uncomment only the settings you need. For automatic login, set **both** `WRAPPER_USERNAME` and `WRAPPER_PASSWORD`; otherwise leave them absent. Manual overrides must use a stable, slash-separated nine-field `WRAPPER_DEVICE_INFO`. +The build helper also accepts a supported `.apkm` split bundle. The tested live path is x86_64; the ARM64 build command is documented in the runbook but has not been validated end to end in the reproduction recorded here. -**Existing installations:** Keep your current `.env` values for `WRAPPER_DEVICE_INFO` and `WRAPPER_DATA_DIR` and reuse the same session directory. A legacy cache without a saved generated identity will **not** be assigned a different identity automatically; the server rejects that setup until the original identity is supplied. Do not remove your existing `.env` or switch from a `./data` bind mount to the new named volume without migrating the session state. +Check the local service: ```bash -docker compose logs -f wrapper +curl -fsS http://127.0.0.1:8080/health curl -fsS http://127.0.0.1:8080/info curl -fsS http://127.0.0.1:8080/session ``` -**Ready for Gamdl:** Once the container is running, point [Gamdl](https://github.com/glomatico/gamdl) to your Wrapper v2 endpoint. Gamdl prompts for your Apple Music credentials and handles two-factor authentication (2FA) when needed. You do **not** need to log in through the HTTP API or configure `WRAPPER_USERNAME` / `WRAPPER_PASSWORD` just to use Gamdl. +Compose binds the HTTP service to loopback on port 8080 by default and stores account state in the persistent `wrapper_data` volume. No `.env` file is required for a normal fresh installation. + +### Device identity and existing installations + +A new installation generates a random 64-bit Android ID and persists the complete device identity in the session volume. The identity is reused across restarts and image rebuilds. -The Compose configuration binds the HTTP service to **127.0.0.1:8080** by default and preserves account data in a named volume. **Do not rebuild the image with account data or publish it to a registry.** `GET /health` confirms the HTTP server is responding; use `GET /session` to check actual worker and authentication state. If using the HTTP API directly instead of Gamdl, send a JSON `POST` to `/session/login` containing `username` and `password`, and complete any required 2FA challenge using the endpoints below. Avoid putting real credentials directly in shell history. +Existing `.wrapper-device-info` identities are not rewritten or migrated. The identity is paired with the native `.worker-device` hash and cached session state. Preserve the original session volume and, for legacy deployments, the existing `WRAPPER_DEVICE_INFO` and `WRAPPER_DATA_DIR` settings. Do not switch a legacy bind mount to the default named volume without migrating the data. + +**Do not run `docker compose down -v` unless deleting the identity and cached session is intentional.** ## HTTP API -The API is **unversioned** in 1.0.0. Requests and responses use JSON; the internal native-worker IPC protocol is separate. +The 1.0.0 HTTP API is unversioned. Requests and responses use JSON; the native-worker IPC protocol is separate. | Method | Endpoint | Purpose | | --- | --- | --- | | `GET` | `/health` | HTTP liveness | -| `GET` | `/info` | Version, features, profile and architecture | -| `GET` | `/session` | Current session state and operation count | -| `GET` | `/session/credentials` | Export session credentials for a compatible client | -| `POST` | `/session/restore` | Restore the previously cached session | +| `GET` | `/info` | Version, features, profile, and architecture | +| `GET` | `/session` | Session state and operation count | +| `GET` | `/session/credentials` | Export session credentials to a compatible client | +| `POST` | `/session/restore` | Restore a cached session | | `POST` | `/session/login` | Start login with `username` and `password` | -| `GET` | `/session/challenge` | Retrieve the pending two-factor challenge | +| `GET` | `/session/challenge` | Retrieve the pending 2FA challenge | | `POST` | `/session/challenge` | Submit `challenge_id` and six-digit `code`; empty code cancels | | `POST` | `/session/close` | Close the session | -| `GET` | `/playback?adam_id=...` | Obtain playback data for an Apple Music catalog ID | -| `GET` | `/context?adam_id=...&key_uri=...` | Obtain a Temari-compatible context for a valid `skd://` URI | +| `GET` | `/playback?adam_id=...` | Retrieve playback data | +| `GET` | `/context?adam_id=...&key_uri=...` | Retrieve a Temari-compatible context | | `GET` | `/key?adamId=...&uri=...` | Compatibility alias for `/context` | -Example requests after authentication: +Playback and context requests are serialized through a single native worker. Concurrent requests may receive `503 worker_busy`. Eligible requests are retried internally after planned worker recycling. -```bash -curl -fsS 'http://127.0.0.1:8080/playback?adam_id=123456789' -curl -fsS -G 'http://127.0.0.1:8080/context' \ - --data-urlencode 'adam_id=123456789' \ - --data-urlencode 'key_uri=skd://your-key-identifier' -``` +## Security and operations -If an interactive login requires 2FA, the login endpoint returns **HTTP 202** with a challenge ID. Use `GET /session/challenge` to retrieve it, then submit: +**Do not expose the HTTP API directly to the Internet.** It has no built-in authentication or TLS, and `GET /session/credentials` returns sensitive session material. Keep the loopback binding, restrict Docker daemon access, and use an authenticated TLS gateway for deliberate remote access. -```json -{"challenge_id":"","code":"123456"} -``` - -to `POST /session/challenge`. The displayed code is an example, **not** a real authentication code. - -Errors use the form `{"error":{"code":"...","retryable":false,"restart_required":false}}`. Normal recycling is handled internally for playback and context requests. Simultaneous requests may receive `503 worker_busy` because the server deliberately serializes access to its single native worker. +The container runs the HTTP process as a non-root UID, with a read-only filesystem and an init process. The native launcher temporarily requires `CAP_SYS_ADMIN` and `CAP_SYS_CHROOT` for namespaces, mounts, and chroot. The Compose profile also relaxes AppArmor; this is a deployment security trade-off documented by the current configuration and should not be copied into a more restrictive production policy without testing. -## Security and operational notes +The locally built image contains extracted proprietary Apple libraries. Keep it private; do not publish or redistribute it without the necessary rights. Do not commit the package, extracted libraries, `.env`, credentials, logs containing session data, or the session volume. -**Do not expose Wrapper v2 directly to the internet.** There is no built-in HTTP authentication or TLS, and `/session/credentials` returns sensitive account material. Use a loopback binding, a private network, or a separately authenticated TLS gateway. Restrict access to the host, Docker socket, `.env`, staged rootfs, and session volumes. Environment-based auto-login credentials are visible to users with access to Docker container configuration. +See [docs/logging.md](docs/logging.md) for log fields and redaction, and [docs/worker-launch.md](docs/worker-launch.md) for namespace and worker lifecycle details. -The Compose configuration starts the HTTP process as a non-root UID. The native launcher temporarily needs `CAP_SYS_ADMIN` and `CAP_SYS_CHROOT` for namespaces, mounts, and `chroot`; those privileges are dropped before the Android worker runs. The service also uses a read-only container filesystem and an init process for child reaping. Container runtimes with stricter seccomp/LSM policies may need corresponding namespace/mount permissions. **Any user with permission to pull/export the locally built image can extract its embedded Apple libraries.** Keep the image private and restrict Docker daemon access. +## Development and tests -Workers have a bounded operation budget and are replaced when necessary, with authenticated sessions restored before protected requests continue. Each worker receives a fresh PID namespace to avoid a known mutex/TID overflow in the pinned Android runtime. See [worker lifecycle](docs/worker-launch.md). - -Logs are JSON lines on stderr and intentionally omit raw URLs, query parameters, credentials, key URIs, and contexts. See [logging](docs/logging.md). Treat error logs as sensitive operational data nonetheless. - -## Development and testing +Run the source-level test suite from the repository root: ```bash cargo fmt --check @@ -142,30 +114,31 @@ cargo test --locked python3 -B -m unittest discover -s tests -p 'test_*.py' -v ``` -The automated HTTP tests use a **synthetic worker**; they do not require Apple account credentials or proprietary files. Additional Linux namespace tests require `unshare` support and elevated namespace permissions; follow [worker lifecycle](docs/worker-launch.md) for instructions. Validate the actual architecture-specific worker and cached session before production deployment. +The HTTP integration tests use a synthetic worker; they do not exercise Apple's proprietary authentication path. Linux namespace tests require `unshare` and the relevant kernel permissions. The GitHub Actions workflow runs formatting, Clippy, Rust unit tests, namespace tests, and Python integration/staging tests. Passing those checks does not replace a live test against the pinned Apple Music build. -For development, `tools/build.sh` can still build the native worker and launcher on a host with Android NDK r23b installed. Maintainers with the locally provisioned `wrapper-v2:native-build` image can use `tools/build-local.sh --arch arm64-v8a` instead. These are **optional native-only developer workflows**; the recommended Docker build does not require either. When using the host tools, first extract verified Apple libraries with `tools/prepare_rootfs.py --extract-libraries`. +Optional native-only developer workflows are available through `tools/build.sh` and `tools/build-local.sh`; they require their documented toolchains and are not necessary for the Docker build. -## Limitations +## Project documentation -- Supports only the pinned Apple Music APK build and architecture-specific runtime profiles currently in `profiles/`. -- Does not implement the previous Wrapper v2 `/decrypt` API or decrypt files server-side. -- Serves one native operation at a time; concurrent requests may be rejected with `worker_busy`. -- Requires the operator to supply the pinned Apple Music APK, maintain an authorized Apple Music account, and comply with applicable service and licensing restrictions. +- [Clean Linux installation runbook](docs/clean-install-linux.md) +- [Source audit, findings, and x86_64 validation evidence](docs/source-audit-2026-11.md) +- [Structured logging](docs/logging.md) +- [Native worker lifecycle](docs/worker-launch.md) +- [Changelog](CHANGELOG.md) +- [Third-party notices](THIRD_PARTY_NOTICES.md) ## Acknowledgements -Wrapper v2 owes a great deal to the projects and people who helped build the Apple Music wrapper ecosystem: - -- **[zhaarey/wrapper](https://github.com/zhaarey/wrapper)** — the original Wrapper project, which laid the groundwork for running Apple Music's Android components without a full Android emulator. -- **[WorldObservationLog](https://github.com/WorldObservationLog)** — for their work on [Wrapper and Wrapper Lite](https://github.com/WorldObservationLog/wrapper/tree/lite), and on the [Temari](https://github.com/WorldObservationLog/Temari) decryption library and related tooling. +- **[zhaarey/wrapper](https://github.com/zhaarey/wrapper)** — the original Wrapper project. +- **[WorldObservationLog](https://github.com/WorldObservationLog)** — Wrapper Lite, Temari, and related research. +- **[@rocketguedes](https://github.com/rocketguedes)** — the diagnostic lead in [issue #23](https://github.com/glomatico/wrapper-v2/issues/23) that identified a device fingerprint configuration which completed fresh login and 2FA in the reported environment. -Thank you to their contributors and the wider community for sharing their research and making continued development possible. Wrapper v2 1.0.0 is a rewrite with its own implementation; these acknowledgements recognize the preceding work and ideas, not an endorsement of this project by the upstream authors. +These acknowledgements recognize prior research and diagnostic contributions; they do not imply endorsement by the upstream authors. ## AI usage -**This project was developed with substantial assistance from AI coding tools.** AI was used throughout development for implementation, architecture discussions, debugging, testing, and documentation. AI-generated suggestions and code can be incorrect or introduce security vulnerabilities, even when automated tests pass. The project maintainer remains responsible for reviewing, testing, and maintaining the published code. Issues and independent reviews are welcome. +This project received substantial assistance from AI coding tools for implementation, architecture discussion, debugging, testing, and documentation. AI-generated output can be incorrect or introduce security defects. The maintainer remains responsible for reviewing, testing, and maintaining the code. ## License -Wrapper v2's original source code is released under [The Unlicense](LICENSE). The bundled Android system files retain their own licenses and required notices, documented in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md), and included in locally built images. Apple's proprietary libraries are **not shipped in the source repository** but **are embedded in private Docker builds**. Do not redistribute those images without the necessary rights. This project is not affiliated with or endorsed by Apple. +The original Wrapper source code is released under [The Unlicense](LICENSE). The bundled Android system files retain their own licenses and notices, documented in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). Apple proprietary libraries are not included in the source repository but are embedded in private Docker builds. This project is not affiliated with or endorsed by Apple. diff --git a/docs/clean-install-linux.md b/docs/clean-install-linux.md new file mode 100644 index 0000000..06abd11 --- /dev/null +++ b/docs/clean-install-linux.md @@ -0,0 +1,190 @@ +# Clean Linux installation + +This runbook describes the validated x86_64 installation path for Wrapper v2 1.0.0. It keeps the complete setup procedure in one place; the repository README contains only the quick start and project overview. + +## 1. Validation boundary + +The live reproduction used Windows 10 IoT Enterprise LTSC 2021, openSUSE Tumbleweed under WSL, Docker Compose inside Linux, Wrapper 1.0.0, an x86_64 native worker, and Apple Music 3.6.0-beta build 1109. Gamdl was installed separately on Windows. + +Fresh login, 2FA, session-credential retrieval, worker replacement/session recovery, playback, and `/key` HTTP requests succeeded on x86_64. The test did not validate ARM64. Its build and runtime profiles exist, but treat ARM64 live authentication, playback, and context capture as unverified. + +See [the source audit](source-audit-2026-11.md) for the sanitized event sequence, exact test scope, and unresolved findings. + +## 2. Linux host prerequisites + +Use Linux on x86_64 for the validated path. The codebase also contains an ARM64 build profile, but that target has not been end-to-end validated by this reproduction. + +Install and configure: + +- Docker Engine with a running daemon. +- Docker Compose plugin 2.24 or newer. +- Docker Buildx with BuildKit enabled. +- Git, Bash, coreutils (including `realpath`, `sha256sum`, and `mktemp`), and `curl`. + +Rust, Android NDK, CMake, Ninja, and cross-compilers are installed inside the Docker builder; they are not required on the host. + +Verify the environment: + +```bash +uname -m +git --version +docker version +docker compose version +docker buildx version +docker buildx inspect --bootstrap +``` + +The Docker CLI must show both client and server sections. Buildx must report a usable builder. Docker daemon access is effectively privileged host access; grant it only to trusted users. + +## 3. Clone a source revision containing the correction + +After the upstream pull request is merged, use the canonical repository: + +```bash +git clone https://github.com/glomatico/wrapper-v2.git +cd wrapper-v2 +``` + +While the upstream pull request is pending, the tested correction is on this fork branch: + +```bash +git clone --branch fix/device-info-apple-auth-1109 --single-branch \ + https://github.com/TuPapaPendejo/wrapper-v2-Tests.git wrapper-v2 +cd wrapper-v2 +``` + +Confirm that the working tree is clean and the selected revision contains the correction: + +```bash +git status --short --branch +git log -1 --oneline +``` + +Do not assume that upstream `main` contains the correction until the maintainer merges it. + +## 4. Supply the local Apple Music build input + +The runtime profiles target Apple Music package `com.apple.android.music`, version `3.6.0-beta`, build `1109`. Supply your own authorized local package for the selected ABI. The build script accepts either: + +- A standalone APK containing the required manifest and architecture-specific native libraries. +- A split APKM bundle containing `base.apk` and the matching architecture split. + +A base APK extracted by itself from a split package may not contain the required native libraries. The package must match the profile selected by `--arch`. This repository does not host the package and this runbook does not identify third-party download sources. + +Set a shell variable to the local file you already possess: + +```bash +APPLE_MUSIC_PACKAGE="/absolute/path/to/your/authorized-Apple-Music-build-1109.apk" +test -f "$APPLE_MUSIC_PACKAGE" +``` + +The path may point to an `.apkm` file instead. Do not place the package in Git, a shared build context, or an image layer. + +**What the build verifies:** `tools/prepare_rootfs.py` checks the expected base/split Android manifest digest, the selected ABI, the ELF machine type, and the SHA-256 hash of each required Apple native library. It stages only the allowlisted files. The helper also calculates the complete input archive's SHA-256 and passes that value through BuildKit; this preserves input consistency and cache invalidation, but it is not a publisher-authenticity check or a comparison to a trusted, hard-coded whole-archive checksum. + +## 5. Build the tested x86_64 image + +```bash +./tools/build-docker.sh "$APPLE_MUSIC_PACKAGE" --arch x86_64 +``` + +The multi-stage Docker build installs the pinned NDK and Rust toolchain, compiles the native worker and namespace launcher, builds the Rust HTTP service, validates the selected runtime files, and assembles the Android root filesystem inside the image. + +The build must complete without manifest, hash, architecture, missing-library, or compilation errors. Do not start an image produced by an interrupted or failed build. + +An ARM64 build can be requested with: + +```bash +./tools/build-docker.sh "$APPLE_MUSIC_PACKAGE" --arch arm64-v8a +``` + +This command is present in the build scripts, but it is not validated by the live reproduction documented here. Cross-building may require binfmt/QEMU support in Buildx or a remote multi-platform builder. Do not treat a successful image build alone as proof of ARM64 authentication or playback. + +## 6. Start Wrapper and check the service + +A normal clean installation does not need a `.env` file: + +```bash +docker compose up -d +docker compose ps +docker compose logs -f wrapper +``` + +The service binds to `127.0.0.1:8080` on the Linux host and stores session data in the persistent `wrapper_data` volume by default. + +Check liveness, runtime profile, and session state: + +```bash +curl -fsS http://127.0.0.1:8080/health +curl -fsS http://127.0.0.1:8080/info +curl -fsS http://127.0.0.1:8080/session +``` + +- `/health` confirms that the HTTP server is responding. It does not prove the native worker is authenticated. +- `/info` reports the version, architecture, and selected runtime profile. +- `/session` reports the session/worker state. + +A new volume has no cached Apple Music session. An initial restore attempt may report `no_cached_session` or `session_expired`; continue through a fresh login. + +## 7. Connect Windows Gamdl to Wrapper under WSL + +The validated arrangement ran Wrapper inside WSL and installed Gamdl separately on Windows. With WSL localhost forwarding enabled and the default Compose port mapping, Windows can reach the service at: + +```text +http://127.0.0.1:8080 +``` + +Check from PowerShell: + +```powershell +curl.exe -fsS http://127.0.0.1:8080/health +``` + +Configure Gamdl to use Wrapper as its authentication provider and supply the endpoint when prompted. Complete Apple Account login and any 2FA challenge in the client. Keep the WSL distribution, Docker daemon, and Wrapper container running while Gamdl uses the service. + +If Windows cannot reach the endpoint, check WSL localhost forwarding and the Compose port mapping first. Do not expose the unauthenticated HTTP service on all host interfaces as a workaround. + +## 8. Expected authentication and runtime sequence + +The validated x86_64 run exercised this sequence: + +1. The API and native worker start. +2. A fresh `POST /session/login` returns HTTP 202 while the 2FA challenge is pending. +3. Challenge submission returns HTTP 200 and Wrapper logs `session.authenticated`. +4. `GET /session` and `GET /session/credentials` return HTTP 200. +5. After worker replacement, Wrapper logs `session.recovered`. +6. Playback and `/key` requests return HTTP 200. + +These results confirm the exercised x86_64 routes. They do not validate every catalog item, codec, playback edge case, internal context-byte correctness, or ARM64. + +## 9. Preserve session state + +Stop the service without deleting the persistent volume: + +```bash +docker compose down +``` + +Rebuild and restart while keeping the same Compose project and volume: + +```bash +./tools/build-docker.sh "$APPLE_MUSIC_PACKAGE" --arch x86_64 +docker compose up -d +``` + +**Destructive reset — use only when intentionally deleting the saved device identity and Apple Music session:** + +```bash +docker compose down -v +``` + +The `-v` option removes the Compose-managed named volume. Never use it as a routine update command. For installations using the legacy `WRAPPER_DATA_DIR=./data` bind mount, preserve that directory and its original `WRAPPER_DEVICE_INFO`; do not silently switch to the named volume. + +## 10. Security + +- Keep the host binding on loopback. The HTTP API has no built-in authentication or TLS. +- Do not expose port 8080 directly to the Internet; use a separately authenticated TLS gateway for deliberate remote access. +- Treat Docker daemon access, the session volume, `.env`, and operational logs as sensitive. +- Do not commit the Apple Music package, extracted proprietary libraries, credentials, or session state. +- Do not publish or redistribute the locally built image: it contains extracted proprietary Apple libraries. +- Keep the generated device identity paired with its session volume across restarts and image upgrades. diff --git a/docs/source-audit-2026-11.md b/docs/source-audit-2026-11.md new file mode 100644 index 0000000..852bd03 --- /dev/null +++ b/docs/source-audit-2026-11.md @@ -0,0 +1,370 @@ +# Source audit and reverse-engineering notes — November 2026 + +## Review identity and limits + +- Repository: `TuPapaPendejo/wrapper-v2-Tests` +- Reviewed baseline: `main` at `9a6f29f493b1bac5325105ab6edf5dbd8caaae8c` +- Scope: Rust HTTP API and supervisor; native C++ worker, session and playback + paths; x86-64 and ARM64 context-capture hooks; launcher and namespaces; + runtime profiles and binary pins; APK/APKM staging; Docker/Compose; tests, + CI and operational documentation. +- Method: source and configuration review through the GitHub repository + contents API, comparison against the upstream Wrapper Lite device-identity + implementation, and review of the supplied reproduction in + [glomatico/wrapper-v2 issue 23](https://github.com/glomatico/wrapper-v2/issues/23). +- This document records the **source-level review**; that review did not itself + execute Apple's proprietary code. A separate clean x86_64 Docker deployment, + login, 2FA, session recovery, playback, and key-route reproduction was later + supplied and is documented near the end. CI's synthetic worker still cannot + validate Apple's proprietary `AuthenticateFlow`. + +## Executive findings + +1. **Confirmed fresh-install authentication compatibility defect — fixed in this + change.** The auto-generated device identity used an obsolete client tuple + (`Music/4.9`, Samsung S9, build 7663313) and generated a 128-bit suffix + (32 hex characters). Issue 23 comment + [7162866962](https://github.com/glomatico/wrapper-v2/issues/23#issuecomment-7162866962) + reports a controlled successful login after changing only + `WRAPPER_DEVICE_INFO` to the `Music/5.0.2` / Pixel 8 / build 7663314 tuple + with an eight-byte random Android ID. The author did not isolate the two + fields experimentally. The new default adopts the complete tested tuple + and ID representation, and adds tests for that exact shape. +2. **Persisted sessions are deliberately not migrated.** The Rust identity file + and native `.worker-device` hash form a pair. Silently regenerating either + value can make an existing Apple Music cache unusable. The patch changes + only identities generated for new installations and explicitly tests that + an existing 1.0.0 identity is left byte-for-byte unchanged. +3. **The API is not an internet-facing authenticated service.** There is no + built-in HTTP authentication or TLS. In particular, + `GET /session/credentials` exports session tokens. Compose publishes the + host port on loopback by default; changing that binding or exposing the + container port without an authenticated TLS gateway exposes account + material and session-control operations. +4. **The native implementation is highly version- and ABI-specific by design.** + Symbols, object layouts, linker behavior, capture hook addresses, register + states, byte offsets and expected context sizes are coupled to exact + Apple/Android binaries. SHA-256 pins and runtime handshakes fail closed, but + they do not replace real integration testing against the pinned APKM. +5. **The HTTP and lifecycle tests are synthetic.** They give useful coverage of + routing, IPC, retry behavior, 2FA orchestration, redaction, staging and + namespace teardown. They do not execute Apple's native authentication or + prove that a real Apple account can log in. + +## Detailed findings + +### F-01 — Fresh-install device identity did not match the working client profile + +**Severity:** High for first-login availability +**Status:** Fixed and exercised in the supplied clean x86_64 reproduction. ARM64 and broader native/media behavior remain unverified. + +Baseline implementation in `src/device_info.rs` used: + +- `Music/4.9/Android/10/Samsung S9/7663313/en-US/en-US` +- 16 random bytes, formatted as a 32-character hexadecimal suffix. + +The issue 23 reproduction records the same native failure on a fresh x86-64 +build-1109 install and then a successful 2FA login after changing only the +device-info override to: + +```text +Music/5.0.2/Android/10/Pixel 8/7663314/en-US/en-US/<16 lowercase hex chars> +``` + +The upstream [WorldObservationLog Wrapper Lite source](https://github.com/WorldObservationLog/wrapper/blob/lite/lite/lite_main.cpp) +also documents the nine-field device tuple and computes Android ID as a +64-bit FNV-1a value formatted to 16 hexadecimal characters. The issue's +successful test uses a random 64-bit value instead; this project continues +to use cryptographically random bytes rather than deriving an ID from the +account username. + +**Change:** new installations now use that known-working client tuple and +eight random bytes (64 bits). The random ID is persisted atomically with mode +0600. Temporary-file names retain their independent 128-bit randomness. + +**Compatibility:** explicit `WRAPPER_DEVICE_INFO` overrides remain supported. +Existing `.wrapper-device-info` files are read as-is, including old 32-hex +suffixes. No old identity, native hash, or saved session is rewritten. + +**Unresolved experimental distinction:** the report changed both the client +tuple and the ID length at once. The evidence proves the combined value works +in that reporter's environment; it does not establish which individual field +Apple rejected. A later controlled test can vary one field at a time, but a +new installation should use the already demonstrated working combination. + +### F-02 — Runtime API-level documentation disagreed with the build profiles + +**Severity:** Low +**Status:** Fixed in this change. + +The README described the ARM64 Android system image as API 22. Both pinned +profiles declare API 21, and the Docker/CMake build configures and enforces +Android platform 21. The requirement table now reports API 21 for both ABIs. + +### F-03 — Unauthenticated HTTP API and credential export + +**Severity:** High if reachable by an untrusted client +**Status:** Existing documented design limitation; no protocol change made. + +The HTTP service has no authentication middleware or TLS termination. +`GET /session/credentials` returns developer and media-user tokens; login, +session close, playback and context routes are also directly callable. +Compose's published port is bound to `127.0.0.1` by default, and the README +warns against exposing the service directly. + +**Operational control:** keep the host binding on loopback, do not publish the +container port to an untrusted network, restrict Docker/network access, and +put any remote access behind an independently authenticated TLS gateway. +Do not treat a private container network as a substitute for application +authentication when other tenants or workloads can join it. + +### F-04 — Human 2FA wait has no server-side deadline + +**Severity:** Medium when an untrusted client can reach the API +**Status:** Deliberate behavior, retained to avoid expiring legitimate 2FA. + +The Rust supervisor holds the single-worker lock while waiting for a human +challenge response. The native protocol pauses its operation timer only during +that wait. This prevents a short fixed timeout from killing a valid interactive +login, but also means one abandoned challenge can keep the worker occupied and +cause other worker-dependent calls to return `503 worker_busy`. + +**Operational control:** restrict access to the API and cancel abandoned +challenges with an empty code. A future configurable idle timeout would need +explicit product behavior and regression tests for long-running 2FA. + +### F-05 — Native ABI and capture hooks are pinned to exact binary layouts + +**Severity:** High impact if pins or offsets drift +**Status:** Guarded by hashes and fail-closed checks; requires ongoing review. + +The native worker uses mangled Apple C++ symbols, hand-declared ABI return +types, shared-pointer control-block adoption, hard-coded object storage sizes, +and a fixed offset to read a response payload. The capture implementations +also use architecture-specific instruction addresses, byte prefixes, register +predicates, stack ranges, pointer remapping and hundreds of fixed state offsets. +The runtime verifies Apple shared-library SHA-256 values and hook instruction +prefixes before use; profile metadata and HTTP response contracts validate +captured context sizes. + +These guards are valuable: do not relax them to make a different APK appear +compatible. Any Apple Music version, library, NDK, Dobby, linker or ABI change +must be treated as a separate reverse-engineering target and tested on both +architectures. A successful compile alone does not prove that native object +sizes or capture state are correct. + +### F-06 — CI does not exercise the proprietary Apple authentication path + +**Severity:** Medium +**Status:** Test-environment limitation. + +The current workflow builds the Rust API and launcher, runs Rust/C++ unit +tests, Linux namespace tests, and Python integration tests using +`tests/mock_worker.py`. APK staging tests use synthetic archives. The +workflow does not receive the proprietary APKM or Apple credentials and does +not execute the native Apple libraries. + +Consequently, green CI can validate the HTTP/supervisor contracts but cannot +confirm `AuthenticateFlow`, live 2FA, token validation, playback, or actual +Temari context capture. Keep real-device tests private and report their +architecture, APKM digest, profile, and sanitized result separately. + +### F-07 — Builder inputs are not fully reproducible + +**Severity:** Medium for supply-chain/rebuild reproducibility +**Status:** Not changed in this authentication patch. + +The Android NDK archive is checksum-verified and external native source +dependencies are pinned to Git commits. However, the Docker base image is +referenced by a mutable tag, Debian packages are installed from the current +repository state, and Rust is installed using the moving `stable` channel. +Two builds from the same source commit can therefore use different build +toolchains or base layers over time. + +**Recommendation:** pin the Docker base by digest, pin a tested Rust toolchain, +use a controlled package snapshot, and record toolchain versions in build +metadata. Keep the existing artifact hash verification. + +### F-08 — Authentication validation uses a separately hard-coded request header + +**Severity:** Low / investigation item +**Status:** Not changed; no evidence it caused the reported failure. + +`native/session.cpp` constructs a POST header identifying +`Music/4.9 Android/10 model/Samsung S9 build/7663313`, while the tested +working `WRAPPER_DEVICE_INFO` tuple is Music 5.0.2 / Pixel 8 / 7663314. +This header is used by the later signed session-validation request, not to +construct the nine-field `RequestContext` identity itself. The issue reporter's +working override shows that this mismatch did not prevent the reported login +from completing. It should nevertheless be tested during private session +restore and token validation before changing it; blindly deriving or changing +the header could introduce a second variable. + +### F-09 — Certificate trust is build-host dependent + +**Severity:** Medium when the worker must reach an Apple endpoint whose root is +absent from the builder's CA bundle +**Status:** Not changed; separate from the demonstrated device-identity fix. + +`tools/prepare_rootfs.py` stages the CA bundle supplied by the build +environment. The issue 23 report separately found that one staged bundle did +not contain the Apple Root CA needed by `gsa.apple.com`; appending that root +made `curl` verification succeed, but did not change the native +`AuthenticateFlow` result. Do not conflate this trust-store correction with +the device-identity fix. Any future CA addition must be obtained from an +authoritative Apple certificate source and checked against a published +fingerprint before being bundled. + +### F-10 — Sensitive data is intentionally omitted from logs, but runtime access +still matters + +**Severity:** Medium +**Status:** Existing controls retained. + +The HTTP layer logs allowlisted route names rather than raw paths or query +strings. Credentials, challenge values, key URIs, tokens and contexts are +excluded from ordinary logs. Native authentication diagnostics accept only +bounded enums and numeric fields. However, Docker logs, the data volume, +`.env`, the Docker socket and the final image remain security-sensitive. +The image contains extracted proprietary Apple libraries, and the session +volume contains persistent authentication state. Keep all of them private. + +## Architecture map + +1. **Build/staging:** `tools/build-docker.sh` supplies the operator's APK/APKM + to a named BuildKit context. `tools/prepare_rootfs.py` verifies the selected + profile's manifests and Apple library hashes, verifies vendored Android + system files, and stages the root filesystem. +2. **Rust HTTP facade:** `src/main.rs`, `src/http.rs`, `src/config.rs`, + `src/profile.rs` parse configuration and expose the unversioned API. +3. **Supervisor:** `src/worker.rs` serializes operations, frames IPC, + enforces timeouts and response limits, handles worker recycling, and + coordinates 2FA. +4. **Namespace launcher:** `native/launcher.cpp` creates mount/PID namespaces, + chroots into the staged Android rootfs, starts the Android worker, reaps + children and tears down the namespace when IPC closes. +5. **Native worker:** `native/main.cpp`, `runtime.cpp`, `session.cpp`, + `playback.cpp` and `context.cpp` call the pinned Apple libraries. +6. **Context capture:** `capture_x86_64.cpp` and `capture_arm64.cpp` use + different, profile-specific hooks and memory layouts. The Rust profile + contract checks the serialized context before it is returned to a client. + +## Verification matrix + +| Area | Source/test coverage reviewed | Live validation still required | +| --- | --- | --- | +| Device identity | persistence, atomic creation, concurrent startup, explicit override and legacy identity tests | clean x86_64 fresh login/2FA succeeded; ARM64 live test remains outstanding | +| HTTP API | synthetic routes, validation, error mapping, and redaction | x86_64 login, challenge, session, credential, playback, and key routes returned expected HTTP responses | +| Supervisor | mock worker recycle/recovery, cancellation, 2FA, and client disconnect | x86_64 worker replacement and session recovery exercised; failure-mode matrix not exhausted | +| Native protocol | framing, size/depth checks, 2FA continuation validation, SHA-256/base64 tests | x86_64 Apple authentication and worker IPC exercised; every native edge case remains unverified | +| Launcher | disposable PID/mount namespaces, orphan reaping, and teardown | clean x86_64 Docker deployment exercised; other kernels and security profiles remain environment-dependent | +| APK/APKM staging | synthetic package fixtures, manifest/hash/ELF and duplicate-library rejection | the supplied x86_64 deployment completed a private image build; ARM64 build remains unverified | +| x86-64/ARM64 capture | static profiles, offsets, hashes and context length contracts | x86_64 playback and /key returned HTTP 200; context bytes were not independently validated, and ARM64 was not tested | + +## Private build-input and verification boundary + +The selected profiles target Apple Music package `com.apple.android.music`, +version `3.6.0-beta`, build `1109`, with architecture-specific manifest and +native-library hashes. The operator supplies an authorized local standalone +APK or supported split APKM; the repository does not distribute that package +or identify a third-party download source. + +`tools/prepare_rootfs.py` verifies the required base/split manifest digest, +selects the expected architecture split, checks the ELF machine type, and +compares every extracted Apple native library against the selected profile's +SHA-256 value. It stages only the allowlisted native libraries and the +separately pinned Android system files. + +The build helper also computes the SHA-256 of the complete local APK/APKM and +passes it to BuildKit. The Dockerfile recomputes that same value inside the +builder. This verifies that the supplied build input remains unchanged across +the BuildKit hand-off and participates in cache invalidation. It is **not** a +publisher-authenticity check and is not a comparison against a trusted, +hard-coded whole-archive checksum. Obsolete profile metadata that implied +archive-level validation was removed because the staging code does not +perform that check. + +Do not commit the input package, extracted proprietary libraries, account +credentials, tokens, or session data. The resulting local image contains +extracted Apple libraries and must remain private. + +## Successful clean-install reproduction — 25 November 2026 local time + +A subsequent clean installation confirmed the identity correction on x86_64. +The log timestamps below were emitted in UTC on 26 November 2026; the test took +place on 25 November local time (UTC-06:00). + +### Environment + +- Windows host: Windows 10 IoT Enterprise LTSC 2021. +- Linux runtime: openSUSE Tumbleweed under an updated WSL installation. +- Wrapper deployment: Docker Compose in the Linux environment. +- Wrapper version: 1.0.0. +- Native worker: x86_64. +- Apple Music: pinned 3.6.0-beta, build 1109. +- Gamdl: freshly installed separately on Windows. +- Test scope: x86_64 only. + +### Authentication evidence + +The sanitized log shows: + +- The Rust API started successfully. +- The x86_64 worker initialized successfully. +- A previous-session restore returned `session_expired` (HTTP 403), which + preceded a new interactive login and did not prevent it. +- `POST /session/login` returned HTTP 202, the expected pending-2FA response. +- The challenge completed with HTTP 200 and Wrapper emitted + `session.authenticated`. +- `GET /session` and `GET /session/credentials` returned HTTP 200. + +### Session-recovery and playback evidence + +Later, after the native worker was stopped and replaced: + +- The replacement x86_64 worker started. +- Wrapper emitted `session.recovered`. +- `GET /session/credentials` returned HTTP 200. +- Two playback requests returned HTTP 200. +- Two `/key` requests returned HTTP 200. + +This validates the fresh-login/2FA path and the exercised x86_64 session-recovery, +playback, and key/context HTTP paths in the reported environment. It does not +validate every catalog item, every media codec, all playback edge cases, or +the internal correctness of context bytes beyond the successful endpoint +responses in this test. + +### ARM64 qualification + +The identity generation and validation reside in shared Rust code, not in +architecture-specific native capture files. Thus, the device-info change is +expected to apply identically on ARM64. However, this reproduction did not +build or run an ARM64 image and did not test ARM64 authentication, playback, +or context capture. ARM64 must remain marked unverified until those steps are +performed on an ARM64-capable or emulated Buildx/runtime environment. + +### Sanitized log evidence (relevant events) + +```jsonl +{"timestamp":"2026-11-26T01:52:54.580290Z","level":"INFO","event":"server.started","version":"1.0.0","protocol":1,"architecture":"x86_64","host":"0.0.0.0","port":80} +{"timestamp":"2026-11-26T01:53:31.644440Z","level":"INFO","event":"http.request","request_id":2,"method":"GET","path":"/session","status":200,"duration_ms":1013} +{"timestamp":"2026-11-26T01:58:32.479258Z","level":"WARN","event":"worker.error","operation":"session.restore","code":"session_expired","restart_required":false} +{"timestamp":"2026-11-26T01:58:32.479323Z","level":"WARN","event":"http.request","request_id":6,"method":"POST","path":"/session/restore","status":403,"duration_ms":1,"code":"session_expired"} +{"timestamp":"2026-11-26T01:58:33.853034Z","level":"INFO","event":"http.request","request_id":8,"method":"GET","path":"/session","status":200,"duration_ms":0} +{"timestamp":"2026-11-26T01:58:46.069488Z","level":"INFO","event":"http.request","request_id":9,"method":"POST","path":"/session/login","status":202,"duration_ms":6311} +{"timestamp":"2026-11-26T01:59:10.838309Z","level":"INFO","event":"session.authenticated"} +{"timestamp":"2026-11-26T01:59:10.838357Z","level":"INFO","event":"http.request","request_id":10,"method":"POST","path":"/session/challenge","status":200,"duration_ms":4444} +{"timestamp":"2026-11-26T01:59:10.846869Z","level":"INFO","event":"http.request","request_id":11,"method":"GET","path":"/session","status":200,"duration_ms":0} +{"timestamp":"2026-11-26T01:59:10.853881Z","level":"INFO","event":"http.request","request_id":12,"method":"GET","path":"/session/credentials","status":200,"duration_ms":0} +{"timestamp":"2026-11-26T02:14:39.596825Z","level":"INFO","event":"worker.started","architecture":"x86_64"} +{"timestamp":"2026-11-26T02:14:43.461339Z","level":"INFO","event":"session.recovered"} +{"timestamp":"2026-11-26T02:14:43.461481Z","level":"INFO","event":"http.request","request_id":17,"method":"GET","path":"/session","status":200,"duration_ms":4540} +{"timestamp":"2026-11-26T02:14:43.471588Z","level":"INFO","event":"http.request","request_id":18,"method":"GET","path":"/session/credentials","status":200,"duration_ms":0} +{"timestamp":"2026-11-26T02:14:45.062051Z","level":"INFO","event":"http.request","request_id":19,"method":"GET","path":"/playback","status":200,"duration_ms":356} +{"timestamp":"2026-11-26T02:14:45.388081Z","level":"INFO","event":"http.request","request_id":20,"method":"GET","path":"/playback","status":200,"duration_ms":317} +{"timestamp":"2026-11-26T02:14:47.230518Z","level":"INFO","event":"http.request","request_id":21,"method":"GET","path":"/key","status":200,"duration_ms":321} +{"timestamp":"2026-11-26T02:14:47.609184Z","level":"INFO","event":"http.request","request_id":22,"method":"GET","path":"/key","status":200,"duration_ms":309} +``` + +No username, password, 2FA code, cookie, token value, signed URL, or account +identifier appears in this event excerpt. diff --git a/profiles/apple-music-1109-arm64-v8a.json b/profiles/apple-music-1109-arm64-v8a.json index 535a08b..fe3e0dc 100644 --- a/profiles/apple-music-1109-arm64-v8a.json +++ b/profiles/apple-music-1109-arm64-v8a.json @@ -5,7 +5,6 @@ "architecture": "arm64-v8a", "base_manifest_sha256": "9aef5c901453199ddfbca184eabd5237b0a287dc1af4fbdad56368bfd3c9c5f3", "split_manifest_sha256": "d13b9dc7e896ce4c1427f56b2f8216f5c9e2223ea1fcf66d09c046348bb57f2e", - "bundle_sha256": "5be907af370a7f6bd73344e646dcfebe2e64c2da3b9ad71192110c91950f3f67", "apple_libraries": { "libBlocksRuntime.so": "f7ebfdcf5115c6bf2073c79c498bcf6652f2501a697774a053cab4f6cf3e638a", "libCoreADI.so": "db8779a9e1b026a087cd9a35c7d69f8af51418a29249ef325e6391ec560f6f47", diff --git a/profiles/apple-music-1109-x86_64.json b/profiles/apple-music-1109-x86_64.json index 1c4b9f6..7ca5ff2 100644 --- a/profiles/apple-music-1109-x86_64.json +++ b/profiles/apple-music-1109-x86_64.json @@ -5,7 +5,6 @@ "architecture": "x86_64", "base_manifest_sha256": "9aef5c901453199ddfbca184eabd5237b0a287dc1af4fbdad56368bfd3c9c5f3", "split_manifest_sha256": "ffec778d2e997ea8ff9852f1d2ba08b8c82ee6cb12e3ef2621ecf1f31da17a2f", - "bundle_sha256": "5be907af370a7f6bd73344e646dcfebe2e64c2da3b9ad71192110c91950f3f67", "apple_libraries": { "libBlocksRuntime.so": "9814b756ae173a546eb12bf1019746f14b17a6546806445ff67f75b0aba8856a", "libCoreADI.so": "b5b971cea0bbe828bdcfaf219fd91fc1e37cf8daee84001ef917d0b1c2b985ed", diff --git a/src/device_info.rs b/src/device_info.rs index 7936fb7..b9d09b7 100644 --- a/src/device_info.rs +++ b/src/device_info.rs @@ -13,7 +13,10 @@ use crate::error::ApiError; const FILE_NAME: &str = ".wrapper-device-info"; const LEGACY_FILE_NAME: &str = ".worker-device"; -const DEVICE_PREFIX: &str = "Music/4.9/Android/10/Samsung S9/7663313/en-US/en-US/"; +// Use the combined client fingerprint reported to complete fresh login +// and 2FA in issue #23. That report changed the client tuple and Android-ID +// length together, so the independent effect of each change is not isolated. +const DEVICE_PREFIX: &str = "Music/5.0.2/Android/10/Pixel 8/7663314/en-US/en-US/"; fn invalid() -> ApiError { ApiError::bad_config("WRAPPER_DEVICE_INFO") @@ -30,18 +33,23 @@ fn validate(value: &str) -> Result<(), ApiError> { Ok(()) } -fn random_suffix() -> Result { - let mut random = [0u8; 16]; +fn random_hex() -> Result { + let mut random = [0u8; N]; File::open("/dev/urandom") .and_then(|mut file| file.read_exact(&mut random)) .map_err(|_| invalid())?; - let mut suffix = String::with_capacity(32); + let mut suffix = String::with_capacity(N * 2); for byte in random { write!(suffix, "{byte:02x}").map_err(|_| invalid())?; } Ok(suffix) } +fn random_android_id() -> Result { + // The native Android client fingerprint uses an eight-byte / 64-bit ID. + random_hex::<8>() +} + fn read_identity(path: &Path) -> Result { if path .symlink_metadata() @@ -84,8 +92,13 @@ pub fn resolve( return Err(invalid()); } - let identity = format!("{DEVICE_PREFIX}{}", random_suffix()?); - let temp_path = directory.join(format!(".wrapper-device-info-{}.tmp", random_suffix()?)); + let identity = format!("{DEVICE_PREFIX}{}", random_android_id()?); + // Keep the temporary filename's entropy at 128 bits; it is independent + // of the 64-bit Android ID format required by the client fingerprint. + let temp_path = directory.join(format!( + ".wrapper-device-info-{}.tmp", + random_hex::<16>()? + )); let write_result = (|| -> Result<(), ApiError> { let mut temp = OpenOptions::new() .write(true) @@ -116,7 +129,7 @@ mod tests { fn directory() -> std::path::PathBuf { let base = - std::env::temp_dir().join(format!("wrapper-identity-{}", random_suffix().unwrap())); + std::env::temp_dir().join(format!("wrapper-identity-{}", random_hex::<8>().unwrap())); fs::create_dir(&base).unwrap(); base } @@ -142,6 +155,38 @@ mod tests { fs::remove_dir_all(another).unwrap(); } + #[test] + fn fresh_identity_uses_known_client_prefix_and_64_bit_android_id() { + let base = directory(); + let generated = resolve(&base, "/", None).unwrap(); + let android_id = generated + .strip_prefix(DEVICE_PREFIX) + .expect("generated identity must use the pinned client prefix"); + + assert_eq!(android_id.len(), 16); + assert!(android_id + .bytes() + .all(|byte| byte.is_ascii_digit() || (b'a'..=b'f').contains(&byte))); + + fs::remove_dir_all(base).unwrap(); + } + + #[test] + fn existing_generated_identity_is_never_migrated_or_rotated() { + let base = directory(); + // Existing 1.0.0 installations may have the previous 32-hex suffix. + let legacy = "Music/4.9/Android/10/Samsung S9/7663313/en-US/en-US/00112233445566778899aabbccddeeff"; + fs::write(base.join(FILE_NAME), format!("{legacy}\n")).unwrap(); + + assert_eq!(resolve(&base, "/", None).unwrap(), legacy); + assert_eq!( + fs::read_to_string(base.join(FILE_NAME)).unwrap(), + format!("{legacy}\n") + ); + + fs::remove_dir_all(base).unwrap(); + } + #[test] fn concurrent_initialization_keeps_a_single_identity() { let base = directory(); diff --git a/tools/build-docker.sh b/tools/build-docker.sh old mode 100755 new mode 100644 index 44434ce..f529ec2 --- a/tools/build-docker.sh +++ b/tools/build-docker.sh @@ -41,7 +41,8 @@ apk=$(realpath -- "$apk_input") apk_sha256=$(sha256sum "$apk" | cut -d ' ' -f 1) image=${WRAPPER_IMAGE:-wrapper-v2:1.0.0-local-${platform#linux/}} -echo "Building $image ($platform) with the verified APK supplied privately to BuildKit." +echo "Building $image ($platform) with the local Apple Music package supplied privately to BuildKit." +echo "The builder checks the selected profile manifests and native-library hashes." echo "NOTE: The resulting image contains Apple's proprietary libraries; do not publish it." # BuildKit limits the size of --secret inputs on some builders. Use an isolated