Skip to content

Commit cc42b9b

Browse files
committed
feat: algorithm in initial keys
1 parent 7417459 commit cc42b9b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/main/kotlin/no/nav/security/mock/oauth2/token/KeyGenerator.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data class KeyGenerator(
2323
if (keyGenerator.algorithm != KeyType.RSA.value) {
2424
return keyGenerator.generateECKey(keyId, algorithm)
2525
}
26-
return keyGenerator.generateRSAKey(keyId)
26+
return keyGenerator.generateRSAKey(keyId, algorithm)
2727
}
2828

2929
private fun KeyPairGenerator.generateECKey(keyId: String, algorithm: JWSAlgorithm): JWK =
@@ -33,6 +33,7 @@ data class KeyGenerator(
3333
.privateKey(it.private as ECPrivateKey)
3434
.keyUse(KeyUse.SIGNATURE)
3535
.keyID(keyId)
36+
.algorithm(algorithm)
3637
.build()
3738
}
3839

@@ -44,13 +45,14 @@ data class KeyGenerator(
4445
}
4546
}
4647

47-
private fun KeyPairGenerator.generateRSAKey(keyId: String): JWK =
48+
private fun KeyPairGenerator.generateRSAKey(keyId: String, algorithm: JWSAlgorithm): JWK =
4849
generateKeyPair()
4950
.let {
5051
RSAKey.Builder(it.public as RSAPublicKey)
5152
.privateKey(it.private as RSAPrivateKey)
5253
.keyUse(KeyUse.SIGNATURE)
5354
.keyID(keyId)
55+
.algorithm(algorithm)
5456
.build()
5557
}
5658

src/test/kotlin/no/nav/security/mock/oauth2/token/KeyGeneratorTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.nimbusds.jwt.JWTClaimsSet
1111
import com.nimbusds.jwt.SignedJWT
1212
import com.nimbusds.oauth2.sdk.id.Issuer
1313
import io.kotest.assertions.throwables.shouldNotThrow
14+
import io.kotest.matchers.collections.shouldBeIn
1415
import io.kotest.matchers.shouldBe
1516
import no.nav.security.mock.oauth2.extensions.verifySignatureAndIssuer
1617
import no.nav.security.mock.oauth2.token.KeyGenerator.Companion.ecAlgorithmFamily
@@ -34,6 +35,7 @@ class KeyGeneratorTest {
3435
keys.keyID shouldBe keyId
3536
keys.keyType.toString() shouldBe KeyType.RSA.value
3637
keys.keyUse.toString() shouldBe "sig"
38+
keys.algorithm shouldBeIn rsaAlgorithmFamily
3739

3840
val issuer = Issuer("issuer$index")
3941
val jwt = jwtWith(issuer.value, keyId, JOSEObjectType.JWT.type, jwsAlgorithm)
@@ -61,6 +63,7 @@ class KeyGeneratorTest {
6163
keys.keyID shouldBe keyId
6264
keys.keyType.toString() shouldBe KeyType.EC.value
6365
keys.keyUse.toString() shouldBe "sig"
66+
keys.algorithm shouldBeIn ecAlgorithmFamily
6467

6568
val issuer = Issuer("issuer$index")
6669
val jwt = jwtWith(issuer.value, keyId, JOSEObjectType.JWT.type, jwsAlgorithm)

0 commit comments

Comments
 (0)