Skip to content

Commit

Permalink
fix: Fixed verify parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmathew committed Sep 2, 2024
1 parent 5228299 commit 282aadf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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 com.sphereon.oid.fed.openapi.models.Jwk
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject

Expand All @@ -23,9 +24,7 @@ class LocalKms {
return sign(header = header, payload = payload, key = Json.decodeFromString(jwk.private_key))
}

fun verify(token: String, keyId: String): Boolean {
val jwk = database.getKey(keyId)

return verify(jwt = token, key = Json.decodeFromString(jwk.private_key))
fun verify(token: String, jwk: Jwk): Boolean {
return verify(jwt = token, key = jwk)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sphereon.oid.fed.services

import com.sphereon.oid.fed.openapi.models.JWTHeader
import com.sphereon.oid.fed.openapi.models.Jwk
import kotlinx.serialization.json.JsonObject

class KmsService(private val provider: String) {
Expand All @@ -18,13 +19,13 @@ class KmsService(private val provider: String) {
return kmsClient.sign(header, payload, keyId)
}

fun verify(token: String, keyId: String): Boolean {
return kmsClient.verify(token, keyId)
fun verify(token: String, jwk: Jwk): Boolean {
return kmsClient.verify(token, jwk)
}
}

interface KmsClient {
fun generateKeyPair(keyId: String)
fun sign(header: JWTHeader, payload: JsonObject, keyId: String): String
fun verify(token: String, keyId: String): Boolean
fun verify(token: String, jwk: Jwk): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.sphereon.oid.fed.services

import com.sphereon.oid.fed.kms.local.LocalKms
import com.sphereon.oid.fed.openapi.models.JWTHeader
import com.sphereon.oid.fed.openapi.models.Jwk
import kotlinx.serialization.json.JsonObject

class LocalKmsClient : KmsClient {

val localKms = LocalKms()
private val localKms = LocalKms()

override fun generateKeyPair(keyId: String) {
return localKms.generateKey(keyId)
Expand All @@ -16,7 +17,7 @@ class LocalKmsClient : KmsClient {
return localKms.sign(header, payload, keyId)
}

override fun verify(token: String, keyId: String): Boolean {
return localKms.verify(token, keyId)
override fun verify(token: String, jwk: Jwk): Boolean {
return localKms.verify(token, jwk)
}
}

0 comments on commit 282aadf

Please sign in to comment.