mirror of https://github.com/usbharu/Hideout.git
fix: Inbox処理のトランザクションを修正
This commit is contained in:
parent
be7bd590eb
commit
158cd3a6df
|
@ -34,25 +34,37 @@ class InboxJobProcessor(
|
|||
private val transaction: Transaction
|
||||
) : JobProcessor<InboxJobParam, InboxJob> {
|
||||
|
||||
private suspend fun verifyHttpSignature(httpRequest: HttpRequest, signature: Signature): Boolean {
|
||||
private suspend fun verifyHttpSignature(
|
||||
httpRequest: HttpRequest,
|
||||
signature: Signature,
|
||||
transaction: Transaction
|
||||
): Boolean {
|
||||
val requiredHeaders = when (httpRequest.method) {
|
||||
HttpMethod.GET -> getRequiredHeaders
|
||||
HttpMethod.POST -> postRequiredHeaders
|
||||
}
|
||||
if (signature.headers.containsAll(requiredHeaders).not()) {
|
||||
logger.warn("FAILED Invalid signature. require: {}", requiredHeaders)
|
||||
return false
|
||||
}
|
||||
|
||||
val user = try {
|
||||
val user = transaction.transaction {
|
||||
try {
|
||||
userQueryService.findByKeyId(signature.keyId)
|
||||
} catch (_: FailedToGetResourcesException) {
|
||||
apUserService.fetchPersonWithEntity(signature.keyId).second
|
||||
}
|
||||
}
|
||||
|
||||
val verify = signatureVerifier.verify(
|
||||
val verify = try {
|
||||
signatureVerifier.verify(
|
||||
httpRequest,
|
||||
PublicKey(RsaUtil.decodeRsaPublicKeyPem(user.publicKey), signature.keyId)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
logger.warn("FAILED Verify Http Signature", e)
|
||||
return false
|
||||
}
|
||||
|
||||
return verify.success
|
||||
}
|
||||
|
@ -60,6 +72,7 @@ class InboxJobProcessor(
|
|||
@Suppress("TooGenericExceptionCaught")
|
||||
private fun parseSignatureHeader(httpHeaders: HttpHeaders): Signature? {
|
||||
return try {
|
||||
println("Signature Header =" + httpHeaders.get("Signature").single())
|
||||
signatureHeaderParser.parse(httpHeaders)
|
||||
} catch (e: RuntimeException) {
|
||||
logger.trace("FAILED parse signature header", e)
|
||||
|
@ -67,7 +80,8 @@ class InboxJobProcessor(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun process(param: InboxJobParam) = transaction.transaction {
|
||||
override suspend fun process(param: InboxJobParam) {
|
||||
|
||||
val jsonNode = objectMapper.readTree(param.json)
|
||||
|
||||
logger.info("START Process inbox. type: {}", param.type)
|
||||
|
@ -83,8 +97,9 @@ class InboxJobProcessor(
|
|||
|
||||
logger.debug("Has signature? {}", signature != null)
|
||||
|
||||
val verify = signature?.let { verifyHttpSignature(httpRequest, it) } ?: false
|
||||
val verify = signature?.let { verifyHttpSignature(httpRequest, it, transaction) } ?: false
|
||||
|
||||
transaction.transaction {
|
||||
logger.debug("Is verifying success? {}", verify)
|
||||
|
||||
val activityPubProcessor =
|
||||
|
@ -100,6 +115,7 @@ class InboxJobProcessor(
|
|||
|
||||
logger.info("SUCCESS Process inbox. type: {}", param.type)
|
||||
}
|
||||
}
|
||||
|
||||
override fun job(): InboxJob = InboxJob
|
||||
|
||||
|
|
Loading…
Reference in New Issue