test(core): tamper decoded ciphertext deterministically
这个提交包含在:
父节点
fcdc94b309
当前提交
f32e281081
@ -4,6 +4,7 @@ import org.junit.Assert.assertEquals
|
|||||||
import org.junit.Assert.assertThrows
|
import org.junit.Assert.assertThrows
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import java.util.Base64
|
||||||
import javax.crypto.KeyGenerator
|
import javax.crypto.KeyGenerator
|
||||||
|
|
||||||
class AesGcmCodecTest {
|
class AesGcmCodecTest {
|
||||||
@ -27,7 +28,11 @@ class AesGcmCodecTest {
|
|||||||
assertThrows(Exception::class.java) {
|
assertThrows(Exception::class.java) {
|
||||||
AesGcmCodec.decrypt(key, encoded, "scope-b".toByteArray())
|
AesGcmCodec.decrypt(key, encoded, "scope-b".toByteArray())
|
||||||
}
|
}
|
||||||
val tampered = encoded.dropLast(1) + if (encoded.last() == 'A') "B" else "A"
|
val parts = encoded.split(".").toMutableList()
|
||||||
|
val cipherText = Base64.getUrlDecoder().decode(parts[2])
|
||||||
|
cipherText[cipherText.lastIndex] = (cipherText.last().toInt() xor 1).toByte()
|
||||||
|
parts[2] = Base64.getUrlEncoder().withoutPadding().encodeToString(cipherText)
|
||||||
|
val tampered = parts.joinToString(".")
|
||||||
assertThrows(Exception::class.java) {
|
assertThrows(Exception::class.java) {
|
||||||
AesGcmCodec.decrypt(key, tampered, "scope-a".toByteArray())
|
AesGcmCodec.decrypt(key, tampered, "scope-a".toByteArray())
|
||||||
}
|
}
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户