java: CertHacker: Handle attest and keymaster version gracefully
Signed-off-by: Dakkshesh <beakthoven@gmail.com>
This commit is contained in:
@@ -130,6 +130,24 @@ private val osVersionMap = mapOf(
|
|||||||
|
|
||||||
private fun getOsVersion(sdkVersion: Int): Int = osVersionMap[sdkVersion] ?: 160000
|
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 {
|
fun String.convertPatchLevel(isLong: Boolean): Int = runCatching {
|
||||||
val parts = split("-")
|
val parts = split("-")
|
||||||
when {
|
when {
|
||||||
|
|||||||
@@ -723,7 +723,7 @@ object CertificateHacker {
|
|||||||
DERTaggedObject(true, 719, bootPatchLevel),
|
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))
|
teeEnforcedObjects.add(DERTaggedObject(true, 724, moduleHash))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -763,9 +763,9 @@ object CertificateHacker {
|
|||||||
softwareEnforcedEncodables: Array<ASN1Encodable>,
|
softwareEnforcedEncodables: Array<ASN1Encodable>,
|
||||||
params: KeyGenParameters
|
params: KeyGenParameters
|
||||||
): ASN1OctetString {
|
): 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 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 keymasterSecurityLevel = ASN1Enumerated(1)
|
||||||
val attestationChallenge = DEROctetString(params.attestationChallenge ?: ByteArray(0))
|
val attestationChallenge = DEROctetString(params.attestationChallenge ?: ByteArray(0))
|
||||||
val uniqueId = DEROctetString(ByteArray(0))
|
val uniqueId = DEROctetString(ByteArray(0))
|
||||||
|
|||||||
Reference in New Issue
Block a user