From 549b5cecc20b47e2d7a25d3e19084ec29a069183 Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Mon, 26 Jan 2026 23:26:52 +0100 Subject: [PATCH] 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. --- .../attestation/DeviceAttestationService.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/matrix/TEESimulator/attestation/DeviceAttestationService.kt b/app/src/main/java/org/matrix/TEESimulator/attestation/DeviceAttestationService.kt index 519f113..5307e26 100644 --- a/app/src/main/java/org/matrix/TEESimulator/attestation/DeviceAttestationService.kt +++ b/app/src/main/java/org/matrix/TEESimulator/attestation/DeviceAttestationService.kt @@ -192,13 +192,15 @@ object DeviceAttestationService { ASN1Sequence.getInstance( fields[AttestationConstants.KEY_DESCRIPTION_SOFTWARE_ENFORCED_INDEX] ) - if (softwareEnforced.size() >= 3) { - moduleHash = - ASN1OctetString.getInstance( - ASN1TaggedObject.getInstance(softwareEnforced.getObjectAt(2)).baseObject - ) - .octets - } + moduleHash = + softwareEnforced + .toArray() + .firstOrNull { + (it as? ASN1TaggedObject)?.tagNo == AttestationConstants.TAG_MODULE_HASH + } + ?.let { + ASN1OctetString.getInstance((it as ASN1TaggedObject).baseObject).octets + } val teeEnforced = ASN1Sequence.getInstance(