Skip to content

Commit

Permalink
Merge pull request #824 from mr-sebbo/bugfix/internal-error-when-JWK-…
Browse files Browse the repository at this point in the history
…contains-a-time

update JWKKey exporting to handle timestamp (double) attributes
  • Loading branch information
philpotisk authored Nov 15, 2024
2 parents a89e6e8 + 156cbb7 commit c053ac8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,23 @@ actual class JWKKey actual constructor(
actual override suspend fun getPublicKeyRepresentation(): ByteArray = when (keyType) {
KeyType.Ed25519 -> _internalJwk.toOctetKeyPair().decodedX
KeyType.RSA -> getRsaPublicKeyBytes(_internalJwk.toRSAKey().toPublicKey())
KeyType.secp256k1, KeyType.secp256r1 -> getECPublicKeyBytes(_internalJwk.toECKey().toECPublicKey())
KeyType.secp256k1, KeyType.secp256r1 -> getECPublicKeyBytes(_internalJwk.toECKey().toECPublicKey())
}

actual override suspend fun getMeta(): JwkKeyMeta = JwkKeyMeta(getKeyId())

actual override suspend fun exportJWK(): String = _internalJwk.toJSONString()

actual override suspend fun exportJWKObject(): JsonObject =
JsonObject(_internalJwk.toJSONObject().mapValues { JsonPrimitive(it.value as String) })
JsonObject(_internalJwk.toJSONObject().mapValues {
val value = it.value
when (value) {
is String -> JsonPrimitive(value)
is Number -> JsonPrimitive(value)
else -> throw IllegalArgumentException("Unsupported value type: ${value::class.simpleName} in field ${it.key}")

}
})

actual override suspend fun exportPEM(): String {
val pemObjects = ArrayList<PemObject>()
Expand Down Expand Up @@ -343,7 +351,8 @@ actual class JWKKey actual constructor(
val curveName = Curve.forECParameterSpec(key.params).name
return ECNamedCurveTable.getParameterSpec(curveName)
.curve.createPoint(key.w.affineX, key.w.affineY)
.getEncoded(true) }
.getEncoded(true)
}

private fun getPrivateKey() = when (keyType) {
KeyType.secp256r1, KeyType.secp256k1 -> _internalJwk.toECKey().toPrivateKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"p": "0bN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cea8ceNqhbB_y6L7RQA2uKp2EQrIgcwMfcYe8d1G3eQFXP2qW7XvJHj9Q92ZQiE",
"dq": "E7TDOpfQE5nT10f-8n7Gy6yi1GBbIEhiZewmIoPlpYEGnAfzUlAjj1GbWkBwkBNYgFcg2FjvFjZyKO8QOYh4cL5vbXGBUSq8MVfs9b2p4Gdervr9kGhsVR5jJkfP7gzcMlzkiDoliAopQmFVDzuBCjbTM4M-inglEo8b508SKRU",
"n": "qV-fGqTo8r6L52sIJpt44bxLkODaF0_wvIL_eYYDL55H-Ap-b1q4pd4YyZb7pARor_1mob6sMRnnAr5htmO1XucmKBEiNY-12zza0q9smjLm3-eNqq-8PgsEqBz4lU1YIBeQzsCR0NTa3J3OHfr-bADVystQeonSPoRLqSoO78oAtonQWLX1MUfS9778-ECcxlM21-JaUjqMD0nQR6wl8L6oWGcR7PjcjPQAyuS_ASTy7MO0SqunpkGzj_H7uFbK9Np_dLIOr9ZqrkCSdioA_PgDyk36E8ayuMnN1HDy4ak_Q7yEX4R_C75T0JxuuYio06hugwyREgOQNID-DVUoLw"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"kty": "RSA",
"nbf" : 1672571260,
"e": "AQAB",
"kid": "288WlRQvku-zrHFmvcAW86jnTF3qsMoEUKEbteI2K4A",
"exp" : 1672574860,
"n": "qV-fGqTo8r6L52sIJpt44bxLkODaF0_wvIL_eYYDL55H-Ap-b1q4pd4YyZb7pARor_1mob6sMRnnAr5htmO1XucmKBEiNY-12zza0q9smjLm3-eNqq-8PgsEqBz4lU1YIBeQzsCR0NTa3J3OHfr-bADVystQeonSPoRLqSoO78oAtonQWLX1MUfS9778-ECcxlM21-JaUjqMD0nQR6wl8L6oWGcR7PjcjPQAyuS_ASTy7MO0SqunpkGzj_H7uFbK9Np_dLIOr9ZqrkCSdioA_PgDyk36E8ayuMnN1HDy4ak_Q7yEX4R_C75T0JxuuYio06hugwyREgOQNID-DVUoLw"
}
Original file line number Diff line number Diff line change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FmdvazothWsvwuXYAWJbMGp2YASyytz1wehcea8ceNqhbB_y6L7RQA2uKp2EQrIgcwMfcYe8d1G3eQFXP2qW7XvJHj9Q92ZQiE",
"dq": "E7TDOpfQE5nT10f-8n7Gy6yi1GBbIEhiZewmIoPlpYEGnAfzUlAjj1GbWkBwkBNYgFcg2FjvFjZyKO8QOYh4cL5vbXGBUSq8MVfs9b2p4Gdervr9kGhsVR5jJkfP7gzcMlzkiDoliAopQmFVDzuBCjbTM4M-inglEo8b508SKRU",
"n": "qV-fGqTo8r6L52sIJpt44bxLkODaF0_wvIL_eYYDL55H-Ap-b1q4pd4YyZb7pARor_1mob6sMRnnAr5htmO1XucmKBEiNY-12zza0q9smjLm3-eNqq-8PgsEqBz4lU1YIBeQzsCR0NTa3J3OHfr-bADVystQeonSPoRLqSoO78oAtonQWLX1MUfS9778-ECcxlM21-JaUjqMD0nQR6wl8L6oWGcR7PjcjPQAyuS_ASTy7MO0SqunpkGzj_H7uFbK9Np_dLIOr9ZqrkCSdioA_PgDyk36E8ayuMnN1HDy4ak_Q7yEX4R_C75T0JxuuYio06hugwyREgOQNID-DVUoLw"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"jwk":
{
"kty": "RSA",
"nbf" : 1672571260,
"e": "AQAB",
"kid": "288WlRQvku-zrHFmvcAW86jnTF3qsMoEUKEbteI2K4A",
"exp" : 1672574860,
"n": "qV-fGqTo8r6L52sIJpt44bxLkODaF0_wvIL_eYYDL55H-Ap-b1q4pd4YyZb7pARor_1mob6sMRnnAr5htmO1XucmKBEiNY-12zza0q9smjLm3-eNqq-8PgsEqBz4lU1YIBeQzsCR0NTa3J3OHfr-bADVystQeonSPoRLqSoO78oAtonQWLX1MUfS9778-ECcxlM21-JaUjqMD0nQR6wl8L6oWGcR7PjcjPQAyuS_ASTy7MO0SqunpkGzj_H7uFbK9Np_dLIOr9ZqrkCSdioA_PgDyk36E8ayuMnN1HDy4ak_Q7yEX4R_C75T0JxuuYio06hugwyREgOQNID-DVUoLw"
}
}

0 comments on commit c053ac8

Please sign in to comment.