java: CertHacker: Handle attest and keymaster version gracefully

Signed-off-by: Dakkshesh <beakthoven@gmail.com>
This commit is contained in:
Dakkshesh
2025-08-13 12:06:24 +05:30
parent e768569ed6
commit 10c1a41981
2 changed files with 21 additions and 3 deletions
@@ -130,6 +130,24 @@ private val osVersionMap = mapOf(
private fun getOsVersion(sdkVersion: Int): Int = osVersionMap[sdkVersion] ?: 160000
private val attestVersionMap = mapOf(
Build.VERSION_CODES.Q to 4, // Keymaster 4.1
Build.VERSION_CODES.R to 4, // Keymaster 4.1
Build.VERSION_CODES.S to 100, // KeyMint 1.0
Build.VERSION_CODES.S_V2 to 100, // KeyMint 1.0
Build.VERSION_CODES.TIRAMISU to 200, // KeyMint 2.0
Build.VERSION_CODES.UPSIDE_DOWN_CAKE to 300, // KeyMint 3.0
Build.VERSION_CODES.VANILLA_ICE_CREAM to 300, // KeyMint 3.0
Build.VERSION_CODES.BAKLAVA to 400 // KeyMint 4.0
)
val attestVersion: Int
get() = attestVersionMap[Build.VERSION.SDK_INT] ?: 400
val keymasterVersion: Int
get() = if (attestVersion == 4) 41 else attestVersion
fun String.convertPatchLevel(isLong: Boolean): Int = runCatching {
val parts = split("-")
when {
@@ -723,7 +723,7 @@ object CertificateHacker {
DERTaggedObject(true, 719, bootPatchLevel),
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (io.github.beakthoven.TrickyStoreOSS.attestVersion >= 400) {
teeEnforcedObjects.add(DERTaggedObject(true, 724, moduleHash))
}
@@ -763,9 +763,9 @@ object CertificateHacker {
softwareEnforcedEncodables: Array<ASN1Encodable>,
params: KeyGenParameters
): ASN1OctetString {
val attestationVersion = ASN1Integer(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) 400L else 300L)
val attestationVersion = ASN1Integer(io.github.beakthoven.TrickyStoreOSS.attestVersion.toLong())
val attestationSecurityLevel = ASN1Enumerated(1)
val keymasterVersion = ASN1Integer(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) 400L else 300L)
val keymasterVersion = ASN1Integer(io.github.beakthoven.TrickyStoreOSS.keymasterVersion.toLong())
val keymasterSecurityLevel = ASN1Enumerated(1)
val attestationChallenge = DEROctetString(params.attestationChallenge ?: ByteArray(0))
val uniqueId = DEROctetString(ByteArray(0))