feat: Digestヘッダーのパースを行うように

This commit is contained in:
usbharu 2024-02-20 23:00:27 +09:00
parent 0a38c8155c
commit 5c2128704c
1 changed files with 5 additions and 1 deletions

View File

@ -41,14 +41,18 @@ class HttpSignatureHeaderChecker(private val applicationConfig: ApplicationConfi
}
fun checkDigest(byteArray: ByteArray, digest: String) {
val find = regex.find(digest)
val sha256 = MessageDigest.getInstance("SHA-256")
if (Base64Util.encode(sha256.digest(byteArray)).equals(digest, true).not()) {
val other = find?.groups?.get(2)?.value.orEmpty()
if (Base64Util.encode(sha256.digest(byteArray)).equals(other, true).not()) {
throw IllegalArgumentException("リクエストボディが違う")
}
}
companion object {
private val dateFormat = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
private val regex = Regex("^([a-zA-Z0-9\\-]+)=(.+)$")
}
}