Skip to main content

Attestation

Why attestation matters​

The shyconfig declares runtime fallback rules that gate receipt confirmation:

{
"deployment": {
"default_posture": "recoverable",
"runtime_fallbacks": {
"write_only_on_missing_play_integrity": false,
"write_only_on_untrusted_device_attestation": true,
"write_only_on_hostile_network": true
}
}
}

When write_only_on_untrusted_device_attestation: true and the device cannot be attested, resolveEffectivePosture returns effectivePosture = "write_only". The ballot can be submitted but the receipt nonce is not persisted — the voter has no offline proof of their direction.

For unknown networks, pass network.hostile = true and enable write_only_on_hostile_network. App Attest establishes a device signal; it does not establish network safety. OS VPN or location checks alone cannot establish that a network is trustworthy. Populist treats every unassessed network as unknown. The trusted proxy supplies Cloudflare IP-country evidence; fixed-size cover responses update the SDK’s network policy before new receipt retention. Recovery requires an assessed network exit outside the configured country set and valid request-bound App Attest. This assesses network exit location, not the user’s physical location.


App Attest lifecycle​

1. Create the provider​

let attester = AppAttestProvider(
storageKey: "com.example.shyware.attest.keyId",
registrationURL: URL(string: "https://vote.example.com/attest/register"),
registrationTokenProvider: { try await firebaseIDToken() }
)

firebaseIDToken() is the host app's callback returning a fresh Firebase ID token. Enable Firebase write authentication and the server's App Attest team, bundle, production environment, and durable key store explicitly; manifest fields alone do not enable enforcement.

The provider persists its key ID in UserDefaults using storageKey. If registrationURL is set, attestKey() performs the App Attest ceremony and POSTs the attestation payload to your backend for verification and registration.

2. Resolve runtime signals​

guard attester.isSupported else {
await client.setRuntimeSignals(.untrusted)
return
}

let signals = await attester.resolveSignals(
network: .init(hostile: true)
)
await client.setRuntimeSignals(signals)

resolveSignals calls attestKey() internally. On success it returns deviceAttestation.trusted = true. On unsupported devices or attestation failure it returns .untrusted.

3. Fetch posture override (optional)​

If your deployment config includes deployment.posture_endpoint, fetch it after setting runtime signals:

await client.fetchOperatorPosture()

4. Assert per request​

After initial attestation, you can bind individual requests to the attested key:

let requestData = Data(txJson.utf8)
let assertion = try await attester.assert(requestData: requestData)
// Include assertion in your request headers for server-side per-request binding

Or wrap it as the client's assertion provider:

let client = try VotingClient.from(
config,
assertionProvider: attester.assertionProvider(),
firebaseIDTokenProvider: { try await firebaseIDToken() },
storageScope: firebaseUID
)

Posture resolution​

After setting signals, check posture before showing the ballot UI:

let posture = await client.effectivePosture()

switch posture.effectivePosture {
case "recoverable":
// Full receipt flow: ballot + nonce persisted to Keychain
showFullBallotUI()
case "write_only":
// Reasons tell you why
if posture.fallbackReasons.contains("untrusted_device_attestation") {
showWriteOnlyUI(reason: "Device attestation unavailable on this device.")
}
default:
break
}

The fallbackReasons array mirrors the web SDK exactly:

  • "missing_play_integrity" — Play Integrity not available or failed (Android-only; mapped on iOS to device attestation)
  • "untrusted_device_attestation" — App Attest failed or not supported
  • "hostile_network" — network signal flagged hostile
  • "hsm_unavailable" — the runtime signaled HSM unavailability
  • "user_preference" — local user posture override forced write-only
  • "operator_override" — server-pushed posture forced write-only

Simulator behavior​

DCAppAttestService.shared.isSupported returns false on simulators. AppAttestProvider.attest returns .untrusted without making any API calls. For development:

#if targetEnvironment(simulator)
await client.setRuntimeSignals(.trusted) // dev override
#else
let signals = await attester.resolveSignals(network: .init(hostile: true))
await client.setRuntimeSignals(signals)
#endif

Do not ship the .trusted override to production.


Receipt storage​

When posture is recoverable, castSubmission persists a SubmissionReceipt to the iOS Keychain under kSecAttrAccessibleWhenUnlockedThisDeviceOnly. The receipt survives:

  • App updates
  • Reinstallation on the same device may preserve entries, but must be tested and cannot be promised as the recovery mechanism

The receipt is device-bound and does not sync through iCloud. Renewed Didit verification can re-derive the document-scoped identity, but cannot reconstruct a lost receipt nonce or voter key. Cross-device recovery requires explicit integration with the authenticated recovery service; test this flow separately from local receipt loading.

When the deployment starts a new ledger​

When a chain is retired and the deployment relaunches on a new chain ID (the relay's /health reports a different node_info.network), the device's receipts and per-poll voter keys belong to ballots that no longer count, and an old per-poll key makes a new vote on the same poll look like a replay. Clear them, but keep the device's enclave enrollment:

KeychainReceiptStore(appId: appId, storageScope: uid).deleteAll()
KeychainVoterKeyStore(appId: appId, storageScope: uid).deleteLedgerKeys() // SDK 0.3.9+

Do not call KeychainVoterKeyStore.deleteAll() for a ledger change. The voter key store also holds the device's enclave enrollment (device-secret:<uid>), which belongs to the identity verification, not to any ledger. The enclave enrolls a verification only once (a reused session gets 409 session_used), so deleting the enrollment makes every participant verify with Didit again. Keep deleteAll() for a privacy wipe or sign-out. holdsLedgerKeys tells you whether a device has per-poll keys to clear.

Keyless additional-device voting recovery​

SDK patch 0.3.3 exposes startVoteRecovery(pollId:enrollmentSessionId:) and setVoteRecoverySession(pollId:sessionId:). The new device creates its own per-poll Ed25519 key locally and sends only the public key. Start a fresh liveness/face-match session using the previously verified enrollment portrait, then set that session after the provider callback and retry the reconciled operation. The authority independently checks Didit's actual decision; a callback alone is not authorization.

Current request-bound App Attest and trusted location policy gate recovery. Identity and reconciliation authorities co-authorize the exact target and typed action. The new device is added, keeping the original authorization valid; no original private key or old receipt is required. A temporary write-only vote retains the protected off-canonical authority lookup while suppressing local receipts and analytics. Recovery eligibility is assessed now rather than from that original fallback. Permanent coercion-resistant deployments keep recovery disabled. Real-device biometric acceptance is separate from simulator tests.

The Populist country-level policy is configurable (CU, IR, KP); unknown network exits fail closed. It does not implement regional or designated-person sanctions screening. See OFAC's distinction between jurisdiction and targeted sanctions.