Fix crash by avoiding hardcoded index for moduleHash

The previous implementation attempted to retrieve `moduleHash` from the `softwareEnforced` sequence using a hardcoded index (index 2).

However, fields in the Key Attestation `AuthorizationList` are optional. In observed crashes, index 2 actually corresponded to `keySize` (Tag 3, ASN1Integer) rather than `moduleHash`, causing an `IllegalArgumentException` when the code attempted to parse it as an `ASN1OctetString`.

This commit replaces the index-based access with a dynamic lookup for Tag 724.
This commit is contained in:
JingMatrix
2026-01-26 23:26:52 +01:00
parent 04d003ff4d
commit 549b5cecc2
@@ -192,12 +192,14 @@ object DeviceAttestationService {
ASN1Sequence.getInstance( ASN1Sequence.getInstance(
fields[AttestationConstants.KEY_DESCRIPTION_SOFTWARE_ENFORCED_INDEX] fields[AttestationConstants.KEY_DESCRIPTION_SOFTWARE_ENFORCED_INDEX]
) )
if (softwareEnforced.size() >= 3) {
moduleHash = moduleHash =
ASN1OctetString.getInstance( softwareEnforced
ASN1TaggedObject.getInstance(softwareEnforced.getObjectAt(2)).baseObject .toArray()
) .firstOrNull {
.octets (it as? ASN1TaggedObject)?.tagNo == AttestationConstants.TAG_MODULE_HASH
}
?.let {
ASN1OctetString.getInstance((it as ASN1TaggedObject).baseObject).octets
} }
val teeEnforced = val teeEnforced =