From e13858e06816f94fd4e8316609662cccfd52e98c Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 1 Jun 2024 20:47:36 +0900 Subject: [PATCH] wip --- .../interfaces/api/auth/AuthController.kt | 1 - .../core/service/auth/RecaptchaResult.kt | 25 -------- .../core/service/auth/RegisterAccountDto.kt | 23 ------- .../core/service/user/RemoteUserCreateDto.kt | 33 ---------- .../core/service/user/UpdateUserDto.kt | 28 --------- .../core/service/user/UserAuthService.kt | 29 --------- .../core/service/user/UserAuthServiceImpl.kt | 61 ------------------- 7 files changed, 200 deletions(-) delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RecaptchaResult.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RegisterAccountDto.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/RemoteUserCreateDto.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UpdateUserDto.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserAuthService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserAuthServiceImpl.kt diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt index bd61adac..22b6fd61 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt @@ -18,7 +18,6 @@ package dev.usbharu.hideout.core.interfaces.api.auth import dev.usbharu.hideout.application.config.ApplicationConfig import dev.usbharu.hideout.application.config.CaptchaConfig -import dev.usbharu.hideout.core.service.auth.RegisterAccountDto import org.springframework.stereotype.Controller import org.springframework.ui.Model import org.springframework.validation.annotation.Validated diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RecaptchaResult.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RecaptchaResult.kt deleted file mode 100644 index 956fbcd9..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RecaptchaResult.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.core.service.auth - -data class RecaptchaResult( - val success: Boolean, - val challenge_ts: String, - val hostname: String, - val score: Float, - val action: String -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RegisterAccountDto.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RegisterAccountDto.kt deleted file mode 100644 index c44c291c..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RegisterAccountDto.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.core.service.auth - -data class RegisterAccountDto( - val username: String, - val password: String, - val recaptchaResponse: String, -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/RemoteUserCreateDto.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/RemoteUserCreateDto.kt deleted file mode 100644 index e02c259c..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/RemoteUserCreateDto.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.core.service.user - -data class RemoteUserCreateDto( - val name: String, - val domain: String, - val screenName: String, - val description: String, - val inbox: String, - val outbox: String, - val url: String, - val publicKey: String, - val keyId: String, - val followers: String?, - val following: String?, - val sharedInbox: String?, - val locked: Boolean? -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UpdateUserDto.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UpdateUserDto.kt deleted file mode 100644 index 93e4959c..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UpdateUserDto.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.core.service.user - -import dev.usbharu.hideout.core.domain.model.media.Media - -data class UpdateUserDto( - val screenName: String, - val description: String, - val avatarMedia: Media?, - val headerMedia: Media?, - val locked: Boolean, - val autoAcceptFolloweeFollowRequest: Boolean -) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserAuthService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserAuthService.kt deleted file mode 100644 index ee69cca9..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserAuthService.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.core.service.user - -import org.springframework.stereotype.Service -import java.security.KeyPair - -@Service -interface UserAuthService { - fun hash(password: String): String - - suspend fun usernameAlreadyUse(username: String): Boolean - - suspend fun generateKeyPair(): KeyPair -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserAuthServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserAuthServiceImpl.kt deleted file mode 100644 index 77c90ace..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserAuthServiceImpl.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.core.service.user - -import dev.usbharu.hideout.application.config.ApplicationConfig -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder -import org.springframework.stereotype.Service -import java.security.* -import java.util.* - -@Service -class UserAuthServiceImpl( - private val actorRepository: ActorRepository, - private val applicationConfig: ApplicationConfig -) : UserAuthService { - - override fun hash(password: String): String = BCryptPasswordEncoder().encode(password) - - override suspend fun usernameAlreadyUse(username: String): Boolean { - actorRepository.findByNameAndDomain(username, applicationConfig.url.host) ?: return false - return true - } - - override suspend fun generateKeyPair(): KeyPair { - val keyPairGenerator = KeyPairGenerator.getInstance("RSA") - keyPairGenerator.initialize(keySize) - return keyPairGenerator.generateKeyPair() - } - - companion object { - val sha256: MessageDigest = MessageDigest.getInstance("SHA-256") - const val keySize: Int = 2048 - const val pemSize: Int = 64 - } -} - -fun PublicKey.toPem(): String { - return "-----BEGIN PUBLIC KEY-----\n" + - Base64.getEncoder().encodeToString(encoded).chunked(UserAuthServiceImpl.pemSize).joinToString("\n") + - "\n-----END PUBLIC KEY-----\n" -} - -fun PrivateKey.toPem(): String { - return "-----BEGIN PRIVATE KEY-----\n" + - Base64.getEncoder().encodeToString(encoded).chunked(UserAuthServiceImpl.pemSize).joinToString("\n") + - "\n-----END PRIVATE KEY-----\n" -}