Skip to content

Commit

Permalink
feat: added KmsService and local KMS module
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmathew committed Aug 23, 2024
1 parent cf6d37d commit ba581e3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
23 changes: 23 additions & 0 deletions modules/local-kms/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
kotlin("jvm") version "2.0.0"
}

group = "com.sphereon.oid.fed.kms.local"
version = "0.1.0"

repositories {
mavenCentral()
mavenLocal()
google()
}

dependencies {
testImplementation(kotlin("test"))
}

tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(21)
}
5 changes: 5 additions & 0 deletions modules/local-kms/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.sphereon.oid.fed.kms.local

fun main() {
println("Hello World!")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.sphereon.oid.fed.services

import com.sphereon.oid.fed.persistence.models.Jwk

class KmsService(private val provider: String) {

private val kmsClient: KmsClient by lazy {
when (provider) {
//"local" -> LocalKmsClient()
//"aws" -> AwsKmsClient()
else -> throw IllegalArgumentException("Unsupported KMS provider: $provider")
}
}

fun generateKeyPair(keyId: String): Jwk {
return kmsClient.generateKeyPair(keyId)
}

fun sign(data: String, keyId: String): String {
return kmsClient.sign(data, keyId)
}

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

interface KmsClient {
fun generateKeyPair(keyId: String): Jwk
fun sign(data: String, keyId: String): String
fun verify(token: String, keyId: String): Boolean
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ include(":modules:federation-server")
include(":modules:openapi")
include(":modules:persistence")
include(":modules:services")
include("modules:local-kms")

0 comments on commit ba581e3

Please sign in to comment.