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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user