seal now allows up to 45s in future to tolerate some time difference

This commit is contained in:
Sergey Chernov 2025-02-03 17:13:28 +03:00
parent 242cc7d0f5
commit 7fa3ab1ca8
2 changed files with 3 additions and 2 deletions

View File

@ -9,7 +9,7 @@ plugins {
}
group = "net.sergeych"
version = "0.7.1-SNAPSHOT"
version = "0.7.2-SNAPSHOT"
repositories {
mavenCentral()

View File

@ -6,6 +6,7 @@ import net.sergeych.bipack.BipackEncoder
import net.sergeych.bipack.decodeFromBipack
import net.sergeych.crypto2.Seal.Companion.create
import net.sergeych.utools.now
import kotlin.time.Duration.Companion.seconds
/**
* Extended public-key signature.
@ -67,7 +68,7 @@ class Seal(
*/
fun verify(message: UByteArray) {
val n = now()
if (createdAt > n) throw IllegalSignatureException("signature's timestamp in the future")
if (createdAt - 45.seconds > n) throw IllegalSignatureException("signature's timestamp in the future: $createdAt / $n")
expiresAt?.let {
if (n >= it) throw ExpiredSignatureException("signature expired at $it")
}