diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt index cd4051d9..f4aed6c5 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt @@ -16,7 +16,14 @@ package dev.usbharu.hideout.core.config +import com.nimbusds.jose.jwk.JWKSet +import com.nimbusds.jose.jwk.RSAKey +import com.nimbusds.jose.jwk.source.ImmutableJWKSet +import com.nimbusds.jose.jwk.source.JWKSource +import com.nimbusds.jose.proc.SecurityContext import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.HideoutUserDetails +import dev.usbharu.hideout.util.RsaUtil +import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.core.annotation.Order @@ -118,6 +125,19 @@ class SecurityConfig { } } + @Bean + fun loadJwkSource(jwkConfig: JwkConfig): JWKSource { + val rsaKey = RSAKey.Builder(RsaUtil.decodeRsaPublicKey(jwkConfig.publicKey)) + .privateKey(RsaUtil.decodeRsaPrivateKey(jwkConfig.privateKey)).keyID(jwkConfig.keyId).build() + return ImmutableJWKSet(JWKSet(rsaKey)) + } + + @ConfigurationProperties("hideout.security.jwt") + data class JwkConfig( + val keyId: String, + val publicKey: String, + val privateKey: String, + ) @Bean fun roleHierarchy(): RoleHierarchy { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt index 574ea476..b02351d7 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ExposedPostRepository.kt @@ -199,6 +199,7 @@ object Posts : Table("posts") { val deleted = bool("deleted") val hide = bool("hide") val moveTo = long("move_to").references(id).nullable() + override val primaryKey: PrimaryKey = PrimaryKey(id) } object PostsMedia : Table("posts_media") { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt index 1c4acd6c..7ee64d0a 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/factory/PostFactoryImpl.kt @@ -47,7 +47,7 @@ class PostFactoryImpl( mediaIds: List, ): Post { val id = idGenerateService.generateId() - val url = URI.create(applicationConfig.url.toString() + "/users/" + actorName + "/posts/" + id) + val url = URI.create(applicationConfig.url.toString() + "/users/" + actorName.name + "/posts/" + id) return Post.create( PostId(id), actorId, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/RsaUtil.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/RsaUtil.kt index 3460a515..8efbd8b0 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/RsaUtil.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/util/RsaUtil.kt @@ -17,7 +17,9 @@ package dev.usbharu.hideout.util import java.security.KeyFactory +import java.security.interfaces.RSAPrivateKey import java.security.interfaces.RSAPublicKey +import java.security.spec.PKCS8EncodedKeySpec import java.security.spec.X509EncodedKeySpec object RsaUtil { @@ -36,4 +38,11 @@ object RsaUtil { return decodeRsaPublicKey(replace) } + fun decodeRsaPrivateKey(byteArray: ByteArray): RSAPrivateKey { + val pkcS8EncodedKeySpec = PKCS8EncodedKeySpec(byteArray) + return KeyFactory.getInstance("RSA").generatePrivate(pkcS8EncodedKeySpec) as RSAPrivateKey + } + + fun decodeRsaPrivateKey(encoded: String): RSAPrivateKey = decodeRsaPrivateKey(Base64Util.decode(encoded)) + } diff --git a/hideout-core/src/main/resources/log4j2.xml b/hideout-core/src/main/resources/log4j2.xml index 834d3910..195006c3 100644 --- a/hideout-core/src/main/resources/log4j2.xml +++ b/hideout-core/src/main/resources/log4j2.xml @@ -11,5 +11,6 @@ + \ No newline at end of file