-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9bc77dc
commit 7223ec4
Showing
5 changed files
with
148 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package at.asitplus.attestation.android | ||
|
||
import at.asitplus.attestation.android.exceptions.AndroidAttestationException | ||
import at.asitplus.attestation.android.exceptions.AttestationValueException | ||
import at.asitplus.attestation.data.AttestationData | ||
import at.asitplus.attestation.data.attestationCertChain | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.FreeSpec | ||
import io.kotest.datatest.withData | ||
import io.kotest.matchers.string.shouldContain | ||
import kotlinx.datetime.toJavaInstant | ||
import kotlinx.datetime.toKotlinInstant | ||
import java.util.* | ||
import kotlin.time.Duration.Companion.days | ||
import kotlin.time.Duration.Companion.minutes | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
class TemporalOffsetTest : FreeSpec() { | ||
|
||
private val exactStartOfValidity: Map<String, AttestationData> = mapOf( | ||
"KeyMint 200" to AttestationData( | ||
"Pixel 6", | ||
challengeB64 = "9w11c/H1kgfx+2Lqrqscug==", | ||
attestation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-14T14:30:22Z", //need to round up millis | ||
pubKeyB64 = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEqs5NcBOKN40tu/5+NLFvGRMRcYF6KRksYoUmiwlKhhzbGaALzE2PerEM5wzNKeC6ESruZJRoBPuHn5D+HfoMkA==" | ||
) | ||
) | ||
|
||
init { | ||
"Exact Time of Validity" - { | ||
withData(exactStartOfValidity) { | ||
attestationService().verifyAttestation( | ||
it.attestationCertChain, | ||
it.verificationDate, | ||
it.challenge | ||
) | ||
} | ||
} | ||
|
||
"Exact Time of Validity + 1D" - { | ||
withData(exactStartOfValidity) { | ||
attestationService( | ||
attestationStatementValiditiy = 1.days + 1.seconds | ||
).verifyAttestation( | ||
it.attestationCertChain, | ||
Date.from((it.verificationDate.toInstant().toKotlinInstant() + 1.days).toJavaInstant()), | ||
it.challenge, | ||
) | ||
} | ||
} | ||
|
||
"Exact Time of Validity - 1D" - { | ||
withData(exactStartOfValidity) { | ||
withData(exactStartOfValidity) { | ||
shouldThrow<AttestationValueException> { | ||
attestationService().verifyAttestation( | ||
it.attestationCertChain, | ||
Date.from((it.verificationDate.toInstant().toKotlinInstant() - 1.seconds).toJavaInstant()), | ||
it.challenge, | ||
) | ||
}.message!!.shouldContain("too far in the future") | ||
} | ||
|
||
|
||
withData(exactStartOfValidity) { | ||
shouldThrow<AttestationValueException> { | ||
attestationService().verifyAttestation( | ||
it.attestationCertChain, | ||
Date.from((it.verificationDate.toInstant().toKotlinInstant() + 10.minutes).toJavaInstant()), | ||
it.challenge, | ||
) | ||
}.message!!.shouldContain("too far in the past") | ||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
} | ||
|