mirror of https://github.com/usbharu/Hideout.git
wip
This commit is contained in:
parent
869ef1e111
commit
e13858e068
|
@ -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.ApplicationConfig
|
||||||
import dev.usbharu.hideout.application.config.CaptchaConfig
|
import dev.usbharu.hideout.application.config.CaptchaConfig
|
||||||
import dev.usbharu.hideout.core.service.auth.RegisterAccountDto
|
|
||||||
import org.springframework.stereotype.Controller
|
import org.springframework.stereotype.Controller
|
||||||
import org.springframework.ui.Model
|
import org.springframework.ui.Model
|
||||||
import org.springframework.validation.annotation.Validated
|
import org.springframework.validation.annotation.Validated
|
||||||
|
|
|
@ -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
|
|
||||||
)
|
|
|
@ -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,
|
|
||||||
)
|
|
|
@ -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?
|
|
||||||
)
|
|
|
@ -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
|
|
||||||
)
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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"
|
|
||||||
}
|
|
Loading…
Reference in New Issue