Apple's account bag now returns the authentication endpoint as
https://auth.itunes.apple.com/auth/v1/native/fast. That endpoint only
responds correctly when the path has a trailing slash; posting to it
without the slash makes Apple's edge return a 301/204 with an empty or
HTML body, so 'ipatool auth login' fails to parse the response and
silently dies (observed as the 'plist: unexpected hex digit' error or a
-5000 with no usable message).
Also improve http client diagnostics: when an XML response body is not a
property list, return 'unexpected response from Apple (HTTP <code>):
<snippet>' instead of the opaque plist parse error.
* Fix purchase retry to resolve auth endpoint via Bag() before re-login
The retry logic in purchase, download, get-version-metadata, and
list-versions called Login() without an Endpoint when re-authenticating
after a password token expiry. This caused silent failures because the
auth endpoint was empty.
- Add Bag() call before Login() in all retry blocks to resolve the auth
endpoint dynamically
- Fall back to hardcoded auth endpoint when bag.xml omits
authenticateAccount
- Detect "Your password has changed." customer message as a token expiry
trigger alongside failure type 2034
- Increase download retry attempts to 3 to handle license-required then
token-expired chain
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Address PR review: make auth path constant consistent, add password-changed test
- Rename PrivateAppStoreAPIPathAuthenticate to store only the path
(consistent with other *APIPath* constants), constructing the full
URL in the Bag() fallback
- Add test for CustomerMessagePasswordChanged triggering
ErrPasswordTokenExpired in purchaseWithParams
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix purchase "already purchased" detection for Apple API changes
Apple now returns HTTP 200 with FailureType "5002" for already-purchased
apps instead of HTTP 500. Also treat FailureType "1008" (device
verification failed) as a stale token that triggers re-authentication.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix download retry to handle new Apple failure types (5002, 1008)
Map FailureType "5002" (license already exists) and "1008" (device
verification failed) to ErrPasswordTokenExpired in the download flow,
triggering re-auth retry consistent with the purchase fix in 438e8e8.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix zip corruption on re-download when .ipa already exists
applyPatches opened the destination file with O_CREATE|O_WRONLY but no
O_TRUNC. On re-download, the existing .ipa (which includes sinf data
from ReplicateSinf) is larger than what applyPatches writes (zip entries
+ metadata, no sinf yet). The leftover bytes at the end corrupt the ZIP
end-of-central-directory record, causing ReplicateSinf's zip.OpenReader
to fail with "failed to open zip reader".
Fix: add O_TRUNC to truncate the file before writing, and add a missing
defer dstFile.Close() to prevent file descriptor leaks.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Treat "license already exists" as success in purchase and download
When the user already owns an app, purchase should report success
(with alreadyOwned=true) instead of failing with an error. Applied
to both the standalone purchase command and the --purchase flag in
the download command.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Remove Bag() fallback in retry paths, use DefaultAuthEndpoint directly
The bag response from init.itunes.apple.com/bag.xml does not contain
an authenticateAccount key, so the fallback was firing 100% of the time.
Replace the Bag()+Login() pattern in retry paths with Login() using a
DefaultAuthEndpoint constant directly, avoiding an unnecessary network
round-trip. The cmd/auth.go login flow still uses Bag() as before.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Use bag auth endpoint for retry login
---------
Co-authored-by: Barnabas Birmacher <birmacher@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
I though that the first attempt would not contain the 2fa code,
but I was wrong. This fixes the authentication when using 2fa enabled
accounts.
closesmajd/ipatool#326
Co-authored-by: Majd Alfhaily <majd@alfhaily.me>
login: increment 'attempt' while following redirects
Apple has introduced some dynamic GET parameters into their
redirects, forcing us to use the main domain ( no `p71-`
and such prefixes ) to obtain those parameters.
However, when following such redirects, we shall also increment
the `attempt` parameter (something that was hard-coded before).
- Move logging to command level.
- Simplify and unify interfaces for `appstore` package.
- Move sinf replication from "Download" API to "ReplicateSinf" API.
- Handle retries and command specific logic in the command level.
- Rename "Info" API to "AccountInfo".