Hardware-backed RFC 9449 DPoP & ECDSA P-256 device-bound signing for Kotlin Multiplatform.
Kothless gives Android, iOS, and JVM backend targets a focused, zero-bloat Kotlin API for generating non-extractable NIST P-256 (secp256r1) keys inside hardware security modules (Android Keystore StrongBox/TEE and Apple Secure Enclave), issuing RFC 9449 DPoP (dpop+jwt, ES256) proofs or challenge signatures, and verifying them identically on your JVM server.
- vs. Passkeys (
CredentialManager/AuthenticationServices): Passkeys sync across devices via iCloud Keychain or Google Password Manager and present OS sheets. Kothless keys stay bound to one physical device (ThisDeviceOnly/AndroidKeyStore) and sign HTTP requests silently without UI prompts (or viaBiometricPrompt.CryptoObjectwhen step-up auth is required). - vs.
a-sit-plus/signum: Use Signum if you need a full PKI/eID suite (COSE, X.509 certificate builders, Verifiable Credentials, key agreement). Use Kothless if you want a minimal, zero-dependency ECDSA P-256 hardware signer + RFC 9449 DPoP with an optional drop-in Ktor Client plugin.
| Module | Purpose | Dependencies |
|---|---|---|
:library (io.yavero:kothless) |
DeviceKeyStore (StrongBox/TEE & Secure Enclave), P-256 SPKI/X9.63/JWK/DER/P1363 codecs, pure-Kotlin SHA-256 + RFC 7638 jkt, RFC 9449 DpopProofGenerator & DpopProofVerifier, RequestSigner, ChallengeAuthenticator |
kotlinx-coroutines-core only |
:kothless-ktor (io.yavero:kothless-ktor) |
KothlessDpop Ktor 3 ClientPlugin with automatic ath token binding, per-origin DPoP-Nonce caching, and transparent 401/400 nonce challenge-retry |
:library + ktor-client-core |
| Artifact | Android Keystore | Apple Secure Enclave | Normalized by Kothless |
|---|---|---|---|
| Public Key | X.509 SPKI DER (91 B) | Uncompressed X9.63 (65 B) | spkiDer(), x963Raw(), toPem(), toJwkJson(), jwkThumbprint() (RFC 7638 jkt) |
| Signature | ASN.1 DER SHA256withECDSA |
ASN.1 DER kSecKeyAlgorithmECDSASignatureMessageX962SHA256 |
der(), p1363() (64 B r || s for JWS ES256), derBase64Url(), p1363Base64Url() |
// Android: AndroidKeyStoreDeviceKeyStore(context.packageManager)
// iOS: SecureEnclaveDeviceKeyStore()
val keyStore: DeviceKeyStore = /* platform instance */
val keyId = KeyId("device-dpop-v1")
val generated = keyStore.generateKey(
keyId = keyId,
config = KeyConfig(
hardwarePolicy = HardwarePolicy.REQUIRE_HARDWARE, // fails closed if no TEE/StrongBox/Secure Enclave
userPresence = UserPresence.NONE,
attestationChallenge = serverChallengeBytes, // optional Android Key Attestation
),
)
// Register generated.publicKey.jwkThumbprint() or generated.publicKey.toJwkJson() on your auth server.val client = HttpClient {
install(KothlessDpop) {
this.keyStore = keyStore
this.keyId = keyId
}
}
// Automatically attaches DPoP JWT (with ath = base64url(SHA-256(accessToken))),
// caches DPoP-Nonce per origin, and retries once on a fresh 401/400 DPoP-Nonce challenge.
val response = client.post("https://api.example.com/v1/transfers") {
header(HttpHeaders.Authorization, "DPoP $accessToken")
setBody(payload)
}// Client
val generator = DpopProofGenerator(keyStore)
val proof = generator.generate(
keyId,
DpopProofRequest(
httpMethod = "POST",
httpTargetUri = "https://api.example.com/v1/transfers?dryRun=true",
accessToken = accessToken,
nonce = serverNonce,
),
)
// Server (JVM / Ktor / Spring)
val verifier = DpopProofVerifier(JvmSignatureVerifier())
when (val res = verifier.verify(
proof.jwt,
DpopVerificationPolicy(
expectedHttpMethod = "POST",
expectedHttpTargetUri = "https://api.example.com/v1/transfers",
expectedAccessToken = accessToken,
expectedNonce = serverNonce,
expectedJkt = tokenBoundJkt,
isJtiFresh = { jti -> replayCache.markIfAbsent(jti) },
),
)) {
is DpopVerificationResult.Valid -> { /* authenticated & proof-of-possession verified */ }
is DpopVerificationResult.Invalid -> { /* reject with res.reason */ }
}val androidStore = AndroidKeyStoreDeviceKeyStore(context.packageManager)
val sig = androidStore.createBiometricSignature(keyId)
// Pass BiometricPrompt.CryptoObject(sig) to BiometricPrompt.authenticate(...)
// Inside onAuthenticationSucceeded(result):
val signatureBytes = androidStore.completeSignature(
requireNotNull(result.cryptoObject?.signature),
payload,
)- Fail-closed hardware enforcement: Under
HardwarePolicy.REQUIRE_HARDWARE, Android attempts StrongBox (API 28+) and falls back to TEE if unavailable, then inspectsKeyInfo— if software-backed, Kothless deletes the key and throwsKothlessException.HardwareUnavailable. Physical iOS devices usekSecAttrTokenIDSecureEnclavewithkSecAttrAccessibleAfterFirstUnlockThisDeviceOnly; the iOS Simulator has no Secure Enclave and fails closed unlessALLOW_SOFTWARE_FALLBACKis explicitly passed for tests. - RFC 9449 Section 4.3 enforcement:
DpopProofVerifiervalidatestyp: "dpop+jwt",alg: "ES256", rejects any"d"private key parameter injwk, verifiesES256signatures in constant time where applicable, normalizeshtuwithout query/fragment, and enforcesiatskew,ath,nonce,cnf.jkt, andjtireplay hooks. - Server policy: Your backend must store per-token
cnf.jktbindings, enforcejtiuniqueness across the skew window, rotateDPoP-Noncevalues, and verify Android Key Attestation chains against Google's hardware root CA when attestation is required.
# Run all unit, DPoP, and real localhost TCP Ktor HTTP end-to-end tests + Android & iOS compilation
./gradlew :library:jvmTest :library:testAndroidHostTest :library:compileAndroidMain \
:library:compileKotlinIosArm64 :library:compileTestKotlinIosSimulatorArm64 \
:kothless-ktor:jvmTest :kothless-ktor:testAndroidHostTest :kothless-ktor:compileAndroidMain \
:kothless-ktor:compileKotlinIosArm64
# On macOS: execute Security.framework & DPoP tests on iOS Simulator
./gradlew :library:iosSimulatorArm64Test :kothless-ktor:compileTestKotlinIosSimulatorArm64Apache License 2.0. See LICENSE.