Skip to content

Commit

Permalink
fix: changed verify parameters and created new directory for kms
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmathew committed Sep 5, 2024
1 parent cd43681 commit ee2457f
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion modules/amazon-kms/src/main/kotlin/AmazonKms.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AmazonKms {
}

private fun createKey(): String {
val request = CreateKeyRequest.builder().keyUsage(KeyUsageType.SIGN_VERIFY) // Or adjust based on your needs
val request = CreateKeyRequest.builder().keyUsage(KeyUsageType.SIGN_VERIFY)
.build()

val response = kmsClient.createKey(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LocalKms {
return sign(header = mHeader, payload = payload, key = jwkObject)
}

fun verify(token: String, keyId: String): Boolean {
return verify(jwt = token, key = Jwk(kty = keyId))
fun verify(token: String, jwk: Jwk): Boolean {
return verify(jwt = token, key =jwk)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.nimbusds.jose.jwk.gen.ECKeyGenerator
import com.sphereon.oid.fed.openapi.models.EntityConfigurationStatement
import com.sphereon.oid.fed.openapi.models.JWTHeader
import com.sphereon.oid.fed.openapi.models.Jwk
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.encodeToJsonElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.sphereon.oid.fed.openapi.models.FederationEntityMetadata
import com.sphereon.oid.fed.openapi.models.JWTHeader
import com.sphereon.oid.fed.persistence.Persistence
import com.sphereon.oid.fed.services.extensions.toJwkDto
import com.sphereon.oid.fed.services.kms.KmsService
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.sphereon.oid.fed.services
import com.sphereon.oid.fed.openapi.models.JwkAdminDTO
import com.sphereon.oid.fed.persistence.Persistence
import com.sphereon.oid.fed.services.extensions.toJwkAdminDTO
import com.sphereon.oid.fed.services.kms.KmsService
import kotlinx.serialization.json.Json

class KeyService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.sphereon.oid.fed.persistence.Persistence
import com.sphereon.oid.fed.persistence.models.Subordinate
import com.sphereon.oid.fed.persistence.models.SubordinateJwk
import com.sphereon.oid.fed.services.extensions.toJwkDTO
import com.sphereon.oid.fed.services.kms.KmsService
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonObject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.sphereon.oid.fed.services
package com.sphereon.oid.fed.services.kms

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

Expand All @@ -17,7 +18,7 @@ class AmazonKmsClient : KmsClient {
return amazonKms.sign(header, payload, keyId)
}

override fun verify(token: String, keyId: String): Boolean {
return amazonKms.verify(token, keyId)
override fun verify(token: String, keyId: String?, jwk: Jwk?): Boolean {
return amazonKms.verify(token, keyId!!)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sphereon.oid.fed.services
package com.sphereon.oid.fed.services.kms

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

Expand All @@ -19,5 +20,5 @@ object KmsService {
interface KmsClient {
fun generateKeyPair(): JwkAdminDTO
fun sign(header: JWTHeader, payload: JsonObject, keyId: String): String
fun verify(token: String, keyId: String): Boolean
fun verify(token: String, keyId: String?, jwk: Jwk?): Boolean
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sphereon.oid.fed.services
package com.sphereon.oid.fed.services.kms

import com.sphereon.oid.fed.kms.local.LocalKms
import com.sphereon.oid.fed.openapi.models.JWTHeader
Expand All @@ -20,7 +20,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, keyId: String?, jwk: Jwk?): Boolean {
return localKms.verify(token, jwk!!)
}
}

0 comments on commit ee2457f

Please sign in to comment.