Skip to content

Commit

Permalink
fix: fixed verify function
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmathew committed Aug 30, 2024
1 parent 08e5e16 commit ede0e94
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Any>): Boolean
expect fun verify(jwt: String, key: Jwk): Boolean
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ actual fun sign(

actual fun verify(
jwt: String,
key: Any,
opts: Map<String, Any>
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class LocalKmsClient : KmsClient {
}

override fun verify(token: String, keyId: String): Boolean {
TODO("Not yet implemented")
return localKms.verify(token, keyId)
}
}

0 comments on commit ede0e94

Please sign in to comment.