App attestation (Android)
For Android developers adding attestation to an app that already uses TrustPin pinning. At the end of this page, your requests carry a token your backend can verify, you can test it on an emulator, and you know what to check before release.
Using an AI coding agent? Install the TrustPin skill and let it wire this up for you.
How it works
kotlin-attest creates a device key and sends evidence about the app and the device to the attestation verifier you run: Android Key Attestation, Google Play Integrity, or both, as your policy asks. The verifier answers with a short-lived signed token, which the SDK renews cheaply with the same key. The SDK adds the token to requests for the hosts you choose, as the TrustPin-Attestation header, and your backend verifies it and decides what an unattested request may do.
The SDK never blocks or fails your requests. When no token is available within a short, bounded time, the request goes out without the header.
What your app calls, and when:
Requirements
| Item | Requirement |
|---|---|
| Android | minSdk 25 or later |
| Kotlin | 2.3.0 or later. The libraries target JVM 11 |
kotlin-sdk | Set up in your app, at the same version as kotlin-attest |
| Verifier | Deployed, reachable over HTTPS, with a published policy |
| Devices | Hardware-backed key attestation when the policy uses Key Attestation; emulators offer only software-level attestation, which is never accepted. Google Play services and the Play Store when the policy uses Play Integrity |
SDK and verifier compatibility
| SDK | Verifier |
|---|---|
kotlin-attest 7.1.x | Contract version 2 or newer: verifier 1.0.0 or later |
With an older verifier the state is Failed(VerifierIncompatible, …) and no header is sent until the verifier is upgraded. The app recovers on its own at the next attempt, with no update or reinstall.
Before you write code: the policy
Your verifier checks every attestation against a signed policy, which you manage on the project’s Attestation page and publish with Sign and publish (see Setting up apps and the policy). These settings matter for an Android app:
| Setting | What to set | What it does |
|---|---|---|
| Attest Android apps | Package name and every Signing certificate SHA-256 | An unlisted app or certificate is refused with app_not_allowed, in both modes |
| Evidence | Either, Both, Play Integrity only or Key Attestation only | Which evidence a device must provide (below) |
| Minimum security level | TRUSTED_ENVIRONMENT or STRONG_BOX | Software keys are never accepted |
| Require verified boot, Require a locked bootloader | On for consumer production | Devices that don’t meet them are refused |
| Require an app recognized by Google Play | On for production builds distributed through Play | Keep it off while testing builds installed from Android Studio or sideloaded |
| Require token binding | On to refuse tokens that are not bound to a session | See Bind tokens to the user’s session |
| Allow debug tokens | On if you test on simulators or emulators. Only your staging verifier, which has debug token hashes, accepts them | See Emulators and development |
| Mode | Monitor (recommended to start), then Enforce | Monitor issues a token even when a policy check fails and records the result in it |
Evidence decides which devices can attest:
| Option | The device must provide | Fails on |
|---|---|---|
| Key Attestation only | Key Attestation | Devices without hardware-backed key attestation, and emulators |
| Play Integrity only | Play Integrity | Devices without Google Play, and apps with no project number |
| Either | Every evidence it can provide: Key Attestation, plus Play Integrity when the app has a project number. Passes when at least one passes the policy | Devices without hardware attestation when the app has no project number, and devices that can provide neither |
| Both | Key Attestation and Play Integrity | Devices missing either one |
Key Attestation only is the simplest start, because it needs no Google Cloud setup. Under Either, an app configured with a project number spends one Play Integrity request on every attestation.
Signing certificates. List the SHA-256 of each certificate that signs a build you accept:
- your debug key, for builds run from Android Studio;
- your upload key, if you install builds signed with it;
- the Play app signing key, for installs from Play (Play Console, Protected with Play, Play Store protection, Manage Play app signing).
Read a digest with keytool, then paste it into the console as printed, or drop a certificate file (.pem, .der, .crt, .cer) onto the form:
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey \
-storepass android -keypass android | grep SHA256Register your verifier’s domain in your TrustPin project (how). Calls to the verifier are pinned by the TrustPin instance with the same identifier, and in strict mode an unregistered verifier host is never reached.
Install
Add both artifacts at the same version, plus the adapter for your HTTP client:
dependencies {
implementation("cloud.trustpin:kotlin-sdk:7.1.1")
implementation("cloud.trustpin:kotlin-attest:7.1.1")
// The adapter for your HTTP client:
implementation("cloud.trustpin:trustpin-okhttp:7.1.1") // OkHttp, Retrofit
// or
implementation("cloud.trustpin:trustpin-ktor:7.1.1") // Ktor with the OkHttp engine; includes trustpin-okhttp
}The adapters don’t bring OkHttp or Ktor with them, so your app supplies its own (they are built against OkHttp 4.12 and Ktor 3.2). kotlin-attest always brings the Play Integrity library. Both AARs ship their R8 and ProGuard consumer rules, so you add no keep rules, and kotlin-attest declares no permissions.
Configure
-
Verifier and hosts. Add the attestation keys to the
assets/trustpin.jsonthat already holds your pinning configuration:{ "organization_id": "<organization id>", "project_id": "<project id>", "public_key": "<project public key>", "mode": "strict", "attest_verifier_url": "https://attest.example.com", "attested_hosts": ["api.example.com"], "google_cloud_project_number": "123456789012" }Key Required Type Notes attest_verifier_urlYes String HTTPS base URL of your verifier, without a version segment. A path is allowed ( https://api.example.com/attest). No credentials, query, fragment or IP addressattested_hostsYes Array of string One to fifty hosts that receive the header, no duplicates. *.example.comcovers exactly one label. IP addresses are not acceptedgoogle_cloud_project_numberOnly for Play Integrity String or number Your Google Cloud project number. Leave it out when the policy doesn’t use Play Integrity Other keys are ignored.
TrustPinAttestConfiguration.fromAssets(context, fileName)reads another asset. -
Play Integrity, only if the policy uses it (Either, Both or Play Integrity only). The console admin enables the Play Integrity API in a Google Cloud project, links it to the app in Play Console and gives the verifier its credentials (Android apps). Put that project’s number, not its ID, in
google_cloud_project_number; it must match the policy’s Google Cloud project number.With a number configured, the app contacts Google Play services from setup on, whatever the evidence option, so configure it only when the policy uses Play Integrity. If Play Integrity is needed and the app has no number, the result is
EvidenceUnavailable.
To configure in code instead:
val configuration = TrustPinAttestConfiguration(
verifierUrl = "https://attest.example.com",
attestedHosts = listOf("api.example.com"),
googleCloudProjectNumber = 123456789012L, // null without Play Integrity
)An invalid value throws TrustPinAttestError.InvalidConfiguration, and the reason is written to logcat under the TrustPinAttest tag, whatever the log level.
Staging and production builds. Each environment has its own verifier URL. Give each build type or flavor its own trustpin.json in its source set, for example src/staging/assets/trustpin.json, which replaces src/main/assets/trustpin.json in that variant.
Set up
Set up pinning first, then attestation, once per process, for example in your Application:
import android.app.Application
import cloud.trustpin.kotlin.attest.TrustPinAttest
import cloud.trustpin.kotlin.attest.TrustPinAttestConfiguration
import cloud.trustpin.kotlin.attest.TrustPinAttestError
import cloud.trustpin.kotlin.attest.fromAssets
import cloud.trustpin.kotlin.sdk.TrustPin
import cloud.trustpin.kotlin.sdk.TrustPinConfiguration
import cloud.trustpin.kotlin.sdk.TrustPinError
import cloud.trustpin.kotlin.sdk.fromAssets
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
class MyApp : Application() {
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
override fun onCreate() {
super.onCreate()
appScope.launch {
try {
TrustPin.setup(TrustPinConfiguration.fromAssets(this@MyApp))
TrustPinAttest.setup(this@MyApp, TrustPinAttestConfiguration.fromAssets(this@MyApp))
TrustPinAttest.bindToHeader("Authorization")
TrustPinAttest.prefetch()
} catch (e: TrustPinError) {
// The pinning configuration is invalid.
} catch (e: TrustPinAttestError) {
// The attestation configuration is invalid.
}
}
}
}Register the class with android:name=".MyApp" on <application> in AndroidManifest.xml.
setupvalidates the configuration and loads any key attested in an earlier launch. It makes no call to your verifier.prefetch()starts attestation in the background, so your first request doesn’t wait. It never throws. Without it, the first attestation starts atsetTokenBinding,getToken()or the first request to an attested host.- A second
setupof one instance throwsAlreadyInitialized; one made while the first is still running throwsInvalidConfiguration. - Set up the pinning instance with the same identifier first. Without it, verifier calls fail with
VerifierUnavailable. - One process. Set attestation up in the process that does your networking. Two processes attesting at once are harmless but spend evidence quota twice.
- Named instances.
TrustPinAttest.instance("payments")pairs withTrustPin.instance("payments"), which must be set up first. The static calls use the default instance. - Java. Use
TrustPinAttest.getDefault().setupBlocking(context, TrustPinAttestConfigurationAssets.fromAssets(context))and the other blocking forms (getTokenBlocking,attestationHeadersBlocking,assertionHeadersBlocking,resetBlocking), from a background thread.setupBlockingthrowsIllegalStateExceptionon the main thread or a coroutine dispatcher thread.
Check. Turn on logging and watch the state while you develop, before setup:
import android.util.Log
import cloud.trustpin.kotlin.attest.TrustPinAttestLogLevel
TrustPinAttest.setLogLevel(TrustPinAttestLogLevel.INFO)
TrustPinAttest.setStateListener { state -> Log.i("MyApp", "Attestation: $state") }Run adb logcat -s TrustPinAttest MyApp. Within a few seconds of launch the state reaches Ready(expiresAtMillis=…). On an emulator this needs a debug token (Emulators and development). If it shows Failed, look the error up in Errors.
Bind tokens to the user’s session
A bound token is valid only with the session it was issued for, so a token copied out of one session is useless in another. Only a SHA-256 of the value travels: the value never leaves the device and is never logged.
| Mode | Call | Use it when |
|---|---|---|
| Header binding | TrustPinAttest.bindToHeader("Authorization") | Your requests carry the session in a header. Each request’s token is bound to that header’s value on that request |
| Fixed binding | TrustPinAttest.setTokenBinding(sessionValue) | You have one session value, or a client that sends no such header (gRPC, WebSockets) |
- Each mode clears the other.
- A binding change renews the token with the existing key; it is not a new attestation.
setTokenBindingrenews at once; with header binding, the next request carrying the new value renews it. - Sign-out. With header binding there is nothing to call: requests without the header get unbound tokens. With fixed binding, call
setTokenBinding(null)on sign-out andsetTokenBinding(newValue)on the next sign-in.bindToHeader(null)stops header binding and also clears a fixed binding. - Required binding. With Require token binding on, no token exists until a binding is known, and the state is
Failed(BindingRequired, Long.MAX_VALUE). That is expected before sign-in. With header binding, the first request carrying the header gets the token. With fixed binding, callsetTokenBindingbeforeprefetch(). prefetch()with header binding attests early but can’t bind, since there is no request yet. The first bound request renews the token once more, cheaply.- With header binding,
getToken()returns a token bound to the most recent request the instance saw.
Your API compares the token’s bind claim with the SHA-256 of the same header value (Verifying tokens in your API).
Send the header
Pick the path that matches your networking code. Build clients after TrustPin.setup.
A. OkHttp and Retrofit. The adapter that pins your client also adds the header:
import cloud.trustpin.kotlin.sdk.okhttp.trustPin
import okhttp3.OkHttpClient
import retrofit2.Retrofit
val client = OkHttpClient.Builder()
.trustPin()
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://api.example.com/")
.client(client)
.build()For a named instance, use .trustPin(TrustPin.instance("payments")).
B. Ktor with the OkHttp engine.
import cloud.trustpin.kotlin.sdk.ktor.trustPin
import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp
val ktor = HttpClient(OkHttp) {
engine { trustPin() }
}With a preconfigured OkHttpClient, call trustPin() in the same engine block, and don’t also pin that client with path A.
C. Your own client. Ask for the header and add it yourself. Turn off automatic redirects, so the token can’t follow a redirect to another host:
import cloud.trustpin.kotlin.attest.TrustPinAttest
import cloud.trustpin.kotlin.sdk.TrustPin
import java.net.URL
import javax.net.ssl.HttpsURLConnection
val url = "https://api.example.com/v1/items"
val auth = "Bearer $sessionToken"
// Pass the bound header, so the token is bound to it.
val headers = TrustPinAttest.attestationHeaders(url, mapOf("Authorization" to listOf(auth)))
val connection = (URL(url).openConnection() as HttpsURLConnection).apply {
sslSocketFactory = TrustPin.makeTlsPair().sslSocketFactory
instanceFollowRedirects = false
setRequestProperty("Authorization", auth)
headers.forEach { (name, value) -> setRequestProperty(name, value) }
}If your client must follow redirects, build each redirect’s headers with TrustPin.redirectedRequestHeaders(TrustPinAttestationRequest(newUrl, method, headers)), which returns the headers to send to the new URL.
D. Anything else (gRPC, WebSockets). Read the token and send it yourself:
val token = TrustPinAttest.getToken() // getTokenBlocking() from Java
// Send it in the TrustPinAttest.HEADER_NAME ("TrustPin-Attestation") header.getToken() throws the error that explains why no token is available (Errors).
These rules apply to every path:
- HTTPS only. The header is never added to a plain
http://request. - Attested hosts only. Other hosts never receive it.
- A header your app sets. On OkHttp it is kept: the SDK adds its own only when the request has none. With Ktor, the SDK replaces it on every request.
- Redirects. On paths A and B, a redirect gets the header only if it goes to an HTTPS URL on an attested host, and the header is requested again for the new URL. On OkHttp a header your app set is removed on a redirect to another URL.
- Bounded wait. If no token is ready, a request waits a short, bounded time, then goes out without the header. While the SDK is waiting after a failure, it goes out at once without the header.
- Adding the header yourself everywhere. Call
TrustPin.setAttestationProvider(null)afterTrustPinAttest.setup; then only paths C and D add it. On OkHttp the header is still removed on a redirect to another URL, or on every request if one of your interceptors rewrites the request’s URL.
Sensitive operations
For an operation your backend must not accept on a reused token alone (a payment, a change of beneficiary), send an assertion bound to that operation with the token:
import cloud.trustpin.kotlin.attest.TrustPinAttest
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import java.security.MessageDigest
val url = "https://api.example.com/v1/transfer"
val auth = "Bearer $sessionToken"
val body = transferJson.toByteArray() // the exact bytes you send
// With header binding, let the SDK see this request's Authorization value first.
val tokenHeaders = TrustPinAttest.attestationHeaders(url, mapOf("Authorization" to listOf(auth)))
val assertionHeaders = TrustPinAttest.assertionHeaders(MessageDigest.getInstance("SHA-256").digest(body))
val request = Request.Builder()
.url(url)
.header("Authorization", auth)
.apply { (tokenHeaders + assertionHeaders).forEach { (name, value) -> header(name, value) } }
.post(body.toRequestBody("application/json".toMediaType()))
.build()Send it with your pinned OkHttp client from path A, which keeps the headers you set.
- The result holds the
TrustPin-Attestationtoken and theTrustPin-Assertionheader (TrustPinAttest.ASSERTION_HEADER_NAME). Your backend passes both, with its own digest of the same bytes, to your verifier (Assertions for sensitive operations). - The token comes first. When no token is available, it throws the same error
getToken()would, and nothing is sent. - Digest. Anything but 32 bytes throws
InvalidDigestbefore any network activity. - Cost. Each call produces a new assertion and costs one round trip to your verifier besides your request. Java callers use
assertionHeadersBlocking. - Your verifier and your API decide which endpoints require an assertion. For endpoints that reuse the token, a short token lifetime and a required binding are the recommended configuration.
Verify the token in your API
Requests to the attested hosts carry TrustPin-Attestation: <token>, a JWT signed by your verifier. Your API checks its signature against the verifier’s published keys, its type, issuer, audience, expiry and project, and its binding, and refuses debug tokens in production. What to do with a request that has no valid token is your decision, per endpoint. See Verifying tokens in your API.
In the token, tp.plat is android and tp.app is the package name. sub identifies the device key. It changes when the device attests a new key, for example after a reset, a reinstall or a data wipe, so don’t use it as a stable device identifier.
Emulators and development
Emulators can’t provide device evidence your policy accepts. For development, your verifier’s operator can issue a debug token (how). The policy (Allow debug tokens) and the verifier must both allow it. Pass it from a debug-only build field, never from trustpin.json, which the SDK doesn’t read it from:
// build.gradle.kts
android {
buildFeatures { buildConfig = true }
buildTypes {
debug {
buildConfigField("String", "TRUSTPIN_DEBUG_TOKEN",
"\"${providers.gradleProperty("trustpinDebugToken").getOrElse("")}\"")
}
release {
buildConfigField("String", "TRUSTPIN_DEBUG_TOKEN", "\"\"")
}
}
}Keep the token itself in ~/.gradle/gradle.properties (trustpinDebugToken=…), not in the repository. Then build the configuration with it, in place of the fromAssets call in Set up:
val fromAssets = TrustPinAttestConfiguration.fromAssets(this@MyApp)
val configuration = TrustPinAttestConfiguration(
verifierUrl = fromAssets.verifierUrl,
attestedHosts = fromAssets.attestedHosts,
googleCloudProjectNumber = fromAssets.googleCloudProjectNumber,
debugToken = BuildConfig.TRUSTPIN_DEBUG_TOKEN.ifEmpty { null },
)
TrustPinAttest.setup(this@MyApp, configuration)- The debug token is used only when the app is debuggable. Every other build ignores it.
- In a debuggable build with a debug token and a policy that allows debug tokens, it is used on real devices too. To test real device evidence, build without it or turn Allow debug tokens off.
- A debug token presents the app by the package name the build runs as, including any
applicationIdSuffixof your debug build type, and the policy must list it. No signing-certificate or device check applies. - Debug tokens carry
tp.envdebug, which production APIs refuse.
On a real device, builds run from Android Studio are signed with your debug key: list its SHA-256 in the policy and keep Require an app recognized by Google Play off while you test them.
State, errors and logging
State
TrustPinAttest.state is one of four subclasses. setStateListener { state -> … } receives every change in order, on a background thread; it doesn’t replay the current state, so read state first.
| State | Meaning |
|---|---|
Unavailable | No token yet: after setup, before the first attestation, after reset(), or after a token expired with no renewal possible |
Attesting | An attestation or a renewal is in progress |
Ready(expiresAtMillis) | A token is available until that time (epoch milliseconds); it is renewed before then |
Failed(error, retryAtMillis) | The last attempt failed with a TrustPinAttestError |
Retry time. No timer runs after a failure. Nothing is tried before retryAtMillis; the next request, getToken() or prefetch() after it starts a new attempt. Long.MAX_VALUE means no new attempt in this process until reset() or a restart, and getToken() throws the same error until then. The exception is BindingRequired, which resumes as soon as a binding is set. Your verifier can set how long a device waits; the wait after a refusal survives a relaunch.
To act on the state, for example in a diagnostics screen:
import cloud.trustpin.kotlin.attest.TrustPinAttestError
import cloud.trustpin.kotlin.attest.TrustPinAttestState
when (val state = TrustPinAttest.state) {
is TrustPinAttestState.Ready -> Unit
is TrustPinAttestState.Failed ->
if (state.error != TrustPinAttestError.BindingRequired) { // expected before sign-in
Log.w("MyApp", "Attestation failed: ${state.error}, next attempt after ${state.retryAtMillis}")
}
else -> Unit
}Errors
setup, getToken() and assertionHeaders throw a TrustPinAttestError, and Failed carries one:
| Error | Meaning | What to do |
|---|---|---|
InvalidConfiguration | A trustpin.json key is missing or invalid, or another setup is in progress | Fix the configuration; read the TrustPinAttest logcat line. Set up once |
AlreadyInitialized | setup was called twice on one instance | Set up once per process |
NotSetUp | A call before setup | Call setup first |
UnsupportedDevice | New keys keep failing on this device | See Support flow |
EvidenceUnavailable | The policy asks for evidence this device can’t provide, or for Play Integrity without a project number | Review Evidence, or configure the project number |
BindingRequired | The policy requires a binding and none is known yet | Expected before sign-in. See Bind tokens |
AttestationFailed(reasons) | The verifier refused the attestation. reasons holds its reason codes, or one the SDK supplies (http_<status>, invalid_key, invalid_input) | Read reasons (Troubleshooting). The SDK waits before attesting again, as long as the verifier asks when it gives a time. The wait survives a relaunch, and an app update or reset() ends it |
VerifierUnavailable | The verifier couldn’t be reached securely | Check connectivity and the verifier’s health. In strict mode, register the verifier’s domain |
VerifierIncompatible | The verifier is older than contract version 2 | Upgrade the verifier to 1.0.0 or later. No app change is needed |
InvalidDigest | assertionHeaders was given something other than 32 bytes | Pass a SHA-256 digest |
TrustPinAttestState, TrustPinAttestError and TrustPinAttestEvent may gain subclasses in a minor release, so give when expressions over them an else branch.
Logging
Logging is off by default.
TrustPinAttest.setLogLevel(TrustPinAttestLogLevel.DEBUG) // NONE, ERROR, WARNING, INFO, DEBUG; per instance
TrustPinAttest.setLogSink { level, instanceId, message -> // process-wide; null restores logcat
myLogger.log("[attest/$instanceId] $level: $message")
}Without a sink, messages go to logcat under the TrustPinAttest tag (adb logcat -s TrustPinAttest). Whether a request got the header is logged at DEBUG. Log lines never contain tokens, key certificates, bound values or debug tokens. Use ERROR or NONE in release builds.
Events
TrustPinAttest.setEventListener { event -> … } or TrustPinAttest.events.collect { … } deliver TrustPinAttestEvent values for your metrics, in order and on a background thread. A slow or throwing listener never delays or fails attestation. A collector of events that falls behind may miss earlier events, so use setEventListener when every event matters.
import cloud.trustpin.kotlin.attest.TrustPinAttestEvent
TrustPinAttest.setEventListener { event ->
when (event) {
is TrustPinAttestEvent.AttestationSucceeded -> metrics.timing("attest", event.durationMillis)
is TrustPinAttestEvent.Refused -> metrics.count("attest.refused")
is TrustPinAttestEvent.WaitEntered -> metrics.gauge("attest.wait_until", event.untilMillis)
else -> Unit
}
}| Event | Carries |
|---|---|
KeyGenerated | Nothing |
KeyReplaced | count, recent replacements |
AttestationSucceeded, RefreshSucceeded, AssertionSucceeded | durationMillis |
AttestationFailed | reasons, retryAtMillis |
RefreshFailed, AssertionFailed | error |
Refused | retryAtMillis |
WaitEntered | untilMillis |
WaitCleared, DeviceUnsupported, VerifierUnavailable | Nothing |
Events never carry a token, a key or a device identifier.
Reset and backups
TrustPinAttest.reset() is a suspending call (resetBlocking() from Java). It discards the attested key and the token, ends any wait after a refusal, and returns once the discard is complete. The next request attests a new key, with a new sub. Use it for support flows, for example a “repair attestation” action, not routinely.
Keys and key certificates are never included in backups, and stored state doesn’t survive an uninstall, a clear-data or a transfer to another device. In each case the app attests a new key.
Before you release
- The release build’s
trustpin.jsonpoints at the production verifier, and its domain is registered in your TrustPin project. - The release build type has no debug token (
TRUSTPIN_DEBUG_TOKENempty, as above). - The production policy lists the package name and the Play app signing certificate, with Allow debug tokens off and Require an app recognized by Google Play on if you distribute only through Play.
- Your API refuses
tp.envdebugand checksbindif you bind tokens. - A build from a Play testing track reaches
Ready, and your API logs a verified token withtp.envproduction. - Your Play Console Data safety form declares the Play Integrity API if you configured a project number (Privacy).
- The log level is
ERRORorNONE.
Rolling out
Start in Monitor (recommended to start), test through a Play testing track, measure the requests without a header and the fail results by reason, then switch to Enforce. Remove certificates you no longer ship with. See Rolling out.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Requests arrive without the header | The host isn’t in attested_hosts, the URL is http://, the client doesn’t add headers, or there is no token yet | Read TrustPinAttest.state, turn on DEBUG logging, and check the paths |
AttestationFailed(reasons=[app_not_allowed]) | The package name the build runs as, or its signing certificate, isn’t in the policy | Add them. Builds from Play use the Play app signing key; debug builds may have an applicationIdSuffix |
AttestationFailed(reasons=[too_many_attestations]) | The verifier’s per-key limit was reached | The SDK keeps the key and waits as long as the verifier asks. Look for a loop calling assertionHeaders |
Failed(EvidenceUnavailable, …) | The device lacks the evidence the Evidence option needs, or the project number is missing | Check Evidence and google_cloud_project_number |
AttestationFailed or EvidenceUnavailable on an emulator | No debug token, or the build isn’t debuggable | Emulators and development |
Failed(BindingRequired, …) before sign-in | Require token binding is on | Expected. The first bound request gets the token |
Failed(VerifierUnavailable, …) every time | The verifier’s domain isn’t registered (strict mode), the verifier is down, or attest_verifier_url is wrong | Register the domain, then check the URL and the verifier’s health |
Failed(VerifierUnavailable, …) in a release build on an emulator or a non-OEM OS image | The pinning SDK refuses these images by default | Opt in with the cloud.trustpin.android.allowNonOemImages manifest entry if you support them |
Failed(VerifierIncompatible, …) | The verifier speaks a contract version below 2 | Upgrade the verifier to 1.0.0 or later |
| Play Integrity refused on a test build | The build was installed from Android Studio or sideloaded | Turn Require an app recognized by Google Play off while testing, or use a Play testing track |
| Key Attestation refused on a development phone | Unlocked bootloader or unverified boot, with those requirements on | Expected for such devices. Relax the setting only for testing |
| A real phone attests with a debug token | A debuggable build with a debug token, and Allow debug tokens on | Build without the token, or turn the setting off |
| Your API refuses an assertion | A header is missing, or your API’s digest isn’t over the bytes the app digested | Send both headers and digest the exact request bytes on both sides |
| Your API refuses a valid-looking token | Wrong audience or project in the check, a binding computed from a different header value, or clock skew | See Verifying tokens in your API |
Support flow
Failed(UnsupportedDevice, …) after repeated key failures, or a refusal that persists, is cleared by TrustPinAttest.reset() once the cause is fixed. The events and your verifier’s logs tell a throttled device from a refused one. Report a device that keeps failing after a reset to your verifier’s operator with the time of the attempt, which the verifier logs.
Privacy and Play Console Data safety
kotlin-attest sends attestation evidence and tokens only to your own verifier. It sends nothing to TrustPin and collects no device or user identifier. The device key stays in the device’s Android Keystore, and bound values never leave the device. Tokens identify a device key, not a person, and change when the key does.
With a project number configured, the app talks to Google Play services from setup on, so declare your use of the Play Integrity API. If you forward events to a third-party service, that disclosure is yours to make.
Next steps
- Verifying tokens in your API: the next step on the path to a verified token
- Rolling out: monitor to enforce
- Sample app and TrustPin Kotlin API reference