From c644a660714243e4b109f7caf802b04b8fa5b509 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 29 Apr 2023 17:10:58 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Signature=E3=83=98=E3=83=83=E3=83=80?= =?UTF-8?q?=E3=83=BC=E3=81=AE=E5=BD=A2=E5=BC=8F=E3=82=92=E5=A4=89=E6=9B=B4?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/usbharu/hideout/plugins/ActivityPub.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/plugins/ActivityPub.kt b/src/main/kotlin/dev/usbharu/hideout/plugins/ActivityPub.kt index 312c38e0..af7c4b86 100644 --- a/src/main/kotlin/dev/usbharu/hideout/plugins/ActivityPub.kt +++ b/src/main/kotlin/dev/usbharu/hideout/plugins/ActivityPub.kt @@ -44,10 +44,10 @@ suspend fun HttpClient.postAp(urlString: String, username: String, jsonLd: JsonL } } -suspend fun HttpClient.getAp(urlString: String,username: String):HttpResponse { - return this.get(urlString){ - header("Accept",ContentType.Application.Activity) - header("Signature","keyId=\"$username\",algorithm=\"rsa-sha256\",headers=\"(request-target) host date\"") +suspend fun HttpClient.getAp(urlString: String, username: String): HttpResponse { + return this.get(urlString) { + header("Accept", ContentType.Application.Activity) + header("Signature", "keyId=\"$username\",algorithm=\"rsa-sha256\",headers=\"(request-target) host date\"") } } @@ -111,9 +111,11 @@ val httpSignaturePlugin = createClientPlugin("HttpSign", ::HttpSignaturePluginCo "date" -> { "Date" } + "host" -> { "Host" } + else -> { it } @@ -152,7 +154,8 @@ val httpSignaturePlugin = createClientPlugin("HttpSign", ::HttpSignaturePluginCo val signatureHeader = request.headers.getAll("Signature").orEmpty() request.headers.remove("Signature") - signatureHeader.map { it.replace("; ",",").replace(";",",") }.joinToString().let { request.header("Signature", it)} + signatureHeader.map { it.replace("; ", ",").replace(";", ",") }.joinToString(",") + .let { request.header("Signature", it) } } } @@ -164,7 +167,7 @@ class KtorKeyMap(private val userAuthRepository: IUserRepository) : KeyMap { .substringAfterLast("/") val publicBytes = Base64.getDecoder().decode( userAuthRepository.findByNameAndDomain( - username,Config.configData.domain + username, Config.configData.domain )?.publicKey?.replace("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----")?.replace("", "") ?.replace("\n", "") ) @@ -177,7 +180,7 @@ class KtorKeyMap(private val userAuthRepository: IUserRepository) : KeyMap { .substringAfterLast("/") val publicBytes = Base64.getDecoder().decode( userAuthRepository.findByNameAndDomain( - username,Config.configData.domain + username, Config.configData.domain )?.privateKey?.replace("-----BEGIN PRIVATE KEY-----", "")?.replace("-----END PRIVATE KEY-----", "") ?.replace("\n", "") )