Testing App Attest end to end
What you are testing
There are two pieces of App Attest that need to work correctly:
- Registration, once per install: the app generates a key in the Secure Enclave, Apple attests it, and AIProxy checks the attestation against the team ID and bundle ID on your app's App Attest tab. The usual failure is a mismatch between those two values and the Xcode target.
- Assertion, on every request: the app signs the request's method, path, and body with that key, and AIProxy verifies the signature and the nonce. The usual failures are a body that changed after signing, a wrong path, or a device clock that is off.
Prerequisites
- Set your app to use App Attest in the AIProxy dashboard. In the dashboard, open your app's App Attest tab and enter the Apple team ID and bundle ID of the Xcode target. Note the resulting App URL, you'll need it later.
- Set your app's service to use App Attest, also in the AIProxy dashboard. To do this, tap on your service in the left sidebar and select Edit Settings > Request Verification > App Attest
- Add the App Attest capability to the Xcode target (Signing & Capabilities, + Capability).
- Have a physical device (iOS 14+, macOS 27+). The Simulator cannot attest.
Test App Attest with AIProxySwift
Copy and paste the following snippets into your app (remember to update <your-app-id>)
Stage 1: configure and register at launch
Configure the SDK with the app URL from the App Attest tab, then call attestIfNeeded() (which performs a one-time registration on a fresh install and is a no-op afterwards).
import AIProxy
AIProxy.configure(
logLevel: .debug,
printRequestBodies: false,
printResponseBodies: false,
resolveDNSOverTLS: true,
useStableID: true,
verificationMethod: .appAttest(appURL: "https://api.aiproxy.com/<your-app-id>")
)
// Leave this call in, even after you've verified the integration.
// It will shave off some overhead in your live app when your app needs to make AI calls.
Task {
do {
try await AIProxy.attestIfNeeded()
} catch {
// A team ID or bundle ID that does not match the dashboard, no network, or Apple refused.
// The app still works: the first request attests again. Log it, or show a message.
print("App Attest registration failed: \(error)")
}
}
Stage 2: verify (remove after integration)
Put this behind a debug button or in a UI test. It signs a request the way every service request is signed and has AIProxy verify it, without calling a provider. Once it reports assertion on a device, the integration is proven correct.
Task {
do {
let result = try await AIProxy.verifyAppAttest()
switch result.mode {
case "assertion":
print("App Attest verified. Key \(result.keyID ?? "?"), \(result.environment ?? "?") environment")
default:
print("Bypass token accepted; App Attest itself was not exercised (Simulator)")
}
} catch let error as AIProxyError {
print("App Attest failed: \(error.localizedDescription)")
}
}
What the result means:
| Field | Meaning |
|---|---|
mode | assertion: a real assertion verified, so registration and signing both work. bypass: the bypass token was accepted instead, which confirms the environment variable is set but exercises nothing else. |
environment | development for builds from Xcode, production for TestFlight and App Store builds. Both are accepted; this tells you which kind of key this install registered. |
keyID | The registered key. It stays the same for the life of the install. |
On the Simulator, set AIPROXY_APP_ATTEST_BYPASS in the scheme's environment variables to the bypass token from the App Attest tab. attestIfNeeded() then does nothing and verifyAppAttest() reports bypass. Never ship the token.
From any client
AIProxy has a route exposed so you can prove the integration without calling upstream to any AI provider (Anthropic, OpenAI, etc.):
POST https://api.aiproxy.com/<app>/aiproxy/v1/attest/verify
<app> is your app's id, shown as the App URL on the App Attest tab (if you are using AIProxySwift please see the instructions below instead of rolling your own calls to this endpoint). The route takes a request signed exactly like an AI service request and answers without forwarding upstream to Anthropic, OpenAI, etc.
If you built your own client from the contract, register as described there, then sign a request to the verify route the same way you sign any other: method POST, the path /<app>/aiproxy/v1/attest/verify, and whatever body you send (an empty JSON object is fine). Send the four aiproxy-appattest-* headers and aiproxy-client-id. No partial key is needed.
curl https://api.aiproxy.com/4f865a6d/aiproxy/v1/attest/verify \
-H "Content-Type: application/json" \
-H "aiproxy-client-id: some-stable-id-for-this-user" \
-H "aiproxy-appattest-key-id: <key id>" \
-H "aiproxy-appattest-assertion: <base64 assertion>" \
-H "aiproxy-appattest-nonce: <base64 nonce>" \
-H "aiproxy-appattest-timestamp: <unix seconds>" \
-d '{}'
{ "verified": true, "mode": "assertion", "key_id": "…", "environment": "development", "registered_at": 1760000000, "verify_ms": 4 }
To check only that a bypass token is wired up, send it instead of the four headers:
curl https://api.aiproxy.com/4f865a6d/aiproxy/v1/attest/verify \
-H "Content-Type: application/json" \
-H "aiproxy-client-id: some-stable-id-for-this-user" \
-H "aiproxy-appattest-bypass: <bypass token>" \
-d '{}'
{ "verified": true, "mode": "bypass", "note": "The bypass token was accepted; no assertion was checked. …" }
Each successful verify consumes the nonce it was signed with, like any request, so sign a fresh one each time. The route counts toward the app's registration limit of 30 calls per client ID per hour.
Reading a failure
A rejection is a 403 with the same error.type a real request would get, so what you learn here applies directly to production traffic. In AIProxySwift it surfaces as AIProxyError.unsuccessfulRequest with that body; a registration failure in attestIfNeeded() surfaces as AIProxyError.appAttestRegistrationFailed.
| What you see | What it means | Fix |
|---|---|---|
app_attest_registration_failed during registration | Apple's attestation is for a different app than the dashboard describes. | Make the team ID and bundle ID on the App Attest tab match the Xcode target exactly, including the bundle ID of the configuration you are running. |
incorrect_app_attest_configuration | The App Attest tab is empty. | Fill it in. |
app_attest_missing | One or more of the four headers was not sent. | In AIProxySwift, check that configure chose .appAttest(appURL:). In your own client, send all four. |
app_attest_unknown_key | The key is not registered with this app, for example after the App Attest configuration was removed and recreated, or the key was registered against a different app. | Register again. AIProxySwift does this on its own after this error. |
app_attest_failed | The signature did not match the request AIProxy received. Almost always a hash mismatch. | Sign the final bytes of the body, use the percent-encoded path without the query string, and send the nonce, timestamp, and key ID exactly as hashed. |
app_attest_stale | The timestamp is more than 300 seconds from AIProxy's clock. | Check the device clock. |
app_attest_replay | The nonce was used before. | Generate a fresh nonce for every signed request, including retries. |
incorrect_app_attest_bypass | The bypass token does not match the app's. | Copy it again from the App Attest tab; rotate it there if it may have leaked. |
appAttestIsUnavailable (SDK only) | The device cannot attest and no bypass token is set. | Run on a physical device, or set AIPROXY_APP_ATTEST_BYPASS for the Simulator. |
appAttestNotConfigured (SDK only) | attestIfNeeded() or verifyAppAttest() ran before configure chose App Attest. | Pass verificationMethod: .appAttest(appURL:) to configure. |
Then one real request
Once verify reports assertion, make a single request through a service whose verification method is App Attest and look at it in the dashboard's request log, or with recent_requests on the MCP server or the admin API. A provider status in the 2xx range means the whole path works. A 403 there carries the same error.type values as the table above, so the diagnosis is the same.