From ede0e94ca3f110efa117dc4ce25f4551895c0a9e Mon Sep 17 00:00:00 2001 From: Robert Mathew Date: Fri, 30 Aug 2024 19:52:22 +0530 Subject: [PATCH] fix: fixed verify function --- .../kotlin/com/sphereon/oid/fed/kms/local/LocalKms.kt | 5 ++++- .../kotlin/com/sphereon/oid/fed/kms/local/jwt/JoseJwt.kt | 2 +- .../kotlin/com/sphereon/oid/fed/kms/local/jwt/JoseJwt.jvm.kt | 5 ++--- .../kotlin/com/sphereon/oid/fed/services/LocalKmsClient.kt | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/LocalKms.kt b/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/LocalKms.kt index 5b3d6e08..79b41024 100644 --- a/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/LocalKms.kt +++ b/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/LocalKms.kt @@ -4,6 +4,7 @@ import com.sphereon.oid.fed.kms.local.database.LocalKmsDatabase import com.sphereon.oid.fed.kms.local.jwk.generateKeyPair import com.sphereon.oid.fed.openapi.models.JWTHeader import com.sphereon.oid.fed.kms.local.jwt.sign +import com.sphereon.oid.fed.kms.local.jwt.verify import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObject @@ -23,6 +24,8 @@ class LocalKms { } fun verify(token: String, keyId: String): Boolean { - TODO("Pending") + val jwk = database.getKey(keyId) + + return verify(jwt = token, key = Json.decodeFromString(jwk.private_key)) } } \ No newline at end of file diff --git a/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/jwt/JoseJwt.kt b/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/jwt/JoseJwt.kt index 717dd0b7..a4032967 100644 --- a/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/jwt/JoseJwt.kt +++ b/modules/local-kms/src/commonMain/kotlin/com/sphereon/oid/fed/kms/local/jwt/JoseJwt.kt @@ -5,4 +5,4 @@ import com.sphereon.oid.fed.openapi.models.Jwk import kotlinx.serialization.json.JsonObject expect fun sign(payload: JsonObject, header: JWTHeader, key: Jwk): String -expect fun verify(jwt: String, key: Any, opts: Map): Boolean +expect fun verify(jwt: String, key: Jwk): Boolean diff --git a/modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/jwt/JoseJwt.jvm.kt b/modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/jwt/JoseJwt.jvm.kt index 3936c803..9b871668 100644 --- a/modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/jwt/JoseJwt.jvm.kt +++ b/modules/local-kms/src/jvmMain/kotlin/com/sphereon/oid/fed/kms/local/jwt/JoseJwt.jvm.kt @@ -31,11 +31,10 @@ actual fun sign( actual fun verify( jwt: String, - key: Any, - opts: Map + key: Jwk ): Boolean { try { - val rsaKey = key as RSAKey + val rsaKey = key.toRsaKey() val verifier: JWSVerifier = RSASSAVerifier(rsaKey) val signedJWT = SignedJWT.parse(jwt) val verified = signedJWT.verify(verifier) diff --git a/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/LocalKmsClient.kt b/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/LocalKmsClient.kt index 993c5eed..7f03fb0a 100644 --- a/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/LocalKmsClient.kt +++ b/modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/LocalKmsClient.kt @@ -17,6 +17,6 @@ class LocalKmsClient : KmsClient { } override fun verify(token: String, keyId: String): Boolean { - TODO("Not yet implemented") + return localKms.verify(token, keyId) } } \ No newline at end of file