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

This commit is contained in:
sergeych committed 2025-02-03 17:13:28 +03:00
1 parent 242cc7d0f5
commit 7fa3ab1ca8
2 files changed
+3 -2

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ plugins {
}
group = "net.sergeych"
version = "0.7.1-SNAPSHOT"
version = "0.7.2-SNAPSHOT"
repositories {
mavenCentral()
@@ -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")
}