-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNougatHybridAttestationChecker.kt
65 lines (56 loc) · 2.91 KB
/
NougatHybridAttestationChecker.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package at.asitplus.attestation.android
import at.asitplus.attestation.android.exceptions.AndroidAttestationException
import at.asitplus.attestation.android.exceptions.AttestationValueException
import com.google.android.attestation.ParsedAttestationRecord
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.cache.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
import io.ktor.serialization.kotlinx.json.*
import java.time.Instant
import java.util.*
class NougatHybridAttestationChecker @JvmOverloads constructor(
attestationConfiguration: AndroidAttestationConfiguration,
verifyChallenge: (expected: ByteArray, actual: ByteArray) -> Boolean = { expected, actual -> expected contentEquals actual }
) : AndroidAttestationChecker(attestationConfiguration, verifyChallenge) {
init {
if (!attestationConfiguration.enableNougatAttestation) throw object :
AndroidAttestationException("Nougat attestation is disabled!", null) {}
if (attestationConfiguration.hardwareAttestationTrustAnchors.isEmpty()) throw object :
AndroidAttestationException("No Nougat (Software) attestation trust anchors configured", null) {}
}
@Throws(AttestationValueException::class)
override fun ParsedAttestationRecord.verifySecurityLevel() {
if (attestationConfiguration.requireStrongBox) {
if (keymasterSecurityLevel() != ParsedAttestationRecord.SecurityLevel.STRONG_BOX) throw AttestationValueException(
"Keymaster security level not StrongBox", reason = AttestationValueException.Reason.SEC_LEVEL
)
} else {
if (keymasterSecurityLevel() == ParsedAttestationRecord.SecurityLevel.SOFTWARE) throw AttestationValueException(
"Keymaster security level software", reason = AttestationValueException.Reason.SEC_LEVEL
)
}
if (attestationSecurityLevel() != ParsedAttestationRecord.SecurityLevel.SOFTWARE) {
throw AttestationValueException(
"Attestation security level not software", reason = AttestationValueException.Reason.SEC_LEVEL
)
}
}
override val trustAnchors = attestationConfiguration.softwareAttestationTrustAnchors
@Throws(AttestationValueException::class)
override fun ParsedAttestationRecord.verifyAndroidVersion(versionOverride: Int?, osPatchLevel: PatchLevel?) {
//impossible
}
@Throws(AttestationValueException::class)
override fun ParsedAttestationRecord.verifyBootStateAndSystemImage() {
//impossible
}
@Throws(AttestationValueException::class)
override fun ParsedAttestationRecord.verifyRollbackResistance() = teeEnforced().verifyRollbackResistance()
override fun ParsedAttestationRecord.verifyAttestationTime(verificationDate: Instant) {
//impossible
}
}