fix: Signatureヘッダーの形式を変更2

This commit is contained in:
usbharu 2023-04-29 17:10:58 +09:00
parent 7b45451dca
commit c644a66071
1 changed files with 10 additions and 7 deletions

View File

@ -44,10 +44,10 @@ suspend fun HttpClient.postAp(urlString: String, username: String, jsonLd: JsonL
} }
} }
suspend fun HttpClient.getAp(urlString: String,username: String):HttpResponse { suspend fun HttpClient.getAp(urlString: String, username: String): HttpResponse {
return this.get(urlString){ return this.get(urlString) {
header("Accept",ContentType.Application.Activity) header("Accept", ContentType.Application.Activity)
header("Signature","keyId=\"$username\",algorithm=\"rsa-sha256\",headers=\"(request-target) host date\"") header("Signature", "keyId=\"$username\",algorithm=\"rsa-sha256\",headers=\"(request-target) host date\"")
} }
} }
@ -111,9 +111,11 @@ val httpSignaturePlugin = createClientPlugin("HttpSign", ::HttpSignaturePluginCo
"date" -> { "date" -> {
"Date" "Date"
} }
"host" -> { "host" -> {
"Host" "Host"
} }
else -> { else -> {
it it
} }
@ -152,7 +154,8 @@ val httpSignaturePlugin = createClientPlugin("HttpSign", ::HttpSignaturePluginCo
val signatureHeader = request.headers.getAll("Signature").orEmpty() val signatureHeader = request.headers.getAll("Signature").orEmpty()
request.headers.remove("Signature") 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("/") .substringAfterLast("/")
val publicBytes = Base64.getDecoder().decode( val publicBytes = Base64.getDecoder().decode(
userAuthRepository.findByNameAndDomain( userAuthRepository.findByNameAndDomain(
username,Config.configData.domain username, Config.configData.domain
)?.publicKey?.replace("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----")?.replace("", "") )?.publicKey?.replace("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----")?.replace("", "")
?.replace("\n", "") ?.replace("\n", "")
) )
@ -177,7 +180,7 @@ class KtorKeyMap(private val userAuthRepository: IUserRepository) : KeyMap {
.substringAfterLast("/") .substringAfterLast("/")
val publicBytes = Base64.getDecoder().decode( val publicBytes = Base64.getDecoder().decode(
userAuthRepository.findByNameAndDomain( userAuthRepository.findByNameAndDomain(
username,Config.configData.domain username, Config.configData.domain
)?.privateKey?.replace("-----BEGIN PRIVATE KEY-----", "")?.replace("-----END PRIVATE KEY-----", "") )?.privateKey?.replace("-----BEGIN PRIVATE KEY-----", "")?.replace("-----END PRIVATE KEY-----", "")
?.replace("\n", "") ?.replace("\n", "")
) )