From e5e5e8573a80c9402736596cd80a6f9832909965 Mon Sep 17 00:00:00 2001 From: Kevin Deus Date: Tue, 19 Nov 2024 13:27:55 -0800 Subject: [PATCH] Fix the detected vct when parsing the input detector for claim descriptions. This fixes a bug where the new naturalization_date field wasn't showing its display name correctly because we weren't detecting the credential type correctly. Tested by: - Manual testing. - ./gradlew check Signed-off-by: Kevin Deus --- .../OpenID4VPPresentationActivity.kt | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/wallet/src/main/java/com/android/identity_credential/wallet/presentation/OpenID4VPPresentationActivity.kt b/wallet/src/main/java/com/android/identity_credential/wallet/presentation/OpenID4VPPresentationActivity.kt index 1807bf0c4..856c9ad60 100644 --- a/wallet/src/main/java/com/android/identity_credential/wallet/presentation/OpenID4VPPresentationActivity.kt +++ b/wallet/src/main/java/com/android/identity_credential/wallet/presentation/OpenID4VPPresentationActivity.kt @@ -443,7 +443,8 @@ class OpenID4VPPresentationActivity : FragmentActivity() { inputDescriptor: JsonObject ): Pair> { val requestedClaims = mutableListOf() - val vct = EUPersonalID.EUPID_VCT // TODO: extract from `inputDescriptor` + // Set the default vct if we don't detect it below. + var vct = EUPersonalID.EUPID_VCT val constraints = inputDescriptor["constraints"]!!.jsonObject val fields = constraints["fields"]!!.jsonArray @@ -453,6 +454,11 @@ class OpenID4VPPresentationActivity : FragmentActivity() { val parsed = parsePathItem(path) val claimName = parsed.second requestedClaims.add(claimName) + + if (path == "\"\$.vct\"") { + val filter = fieldObj["filter"]!!.jsonObject + vct = filter["const"]!!.toString().run { substring(1, this.length - 1) } + } } return Pair(vct, requestedClaims) } @@ -490,18 +496,10 @@ class OpenID4VPPresentationActivity : FragmentActivity() { inputDescriptorObj["id"]!!.toString().run { substring(1, this.length - 1) } } else { try { - var vct = "" - val constraints = inputDescriptorObj["constraints"]!!.jsonObject - for (field in constraints["fields"]!!.jsonArray) { - if (field.jsonObject["path"]!!.jsonArray[0].toString() == "\"\$.vct\"") { - val vctField = field.jsonObject - val filter = vctField["filter"]!!.jsonObject - vct = filter["const"]!!.toString().run { substring(1, this.length - 1) } - } - } + val (vct, _) = parseInputDescriptorForVc(inputDescriptorObj) vct } catch (e: NullPointerException) { - Logger.d(TAG, "Error: Could not find const filter field: ${e.message}") + Logger.d(TAG, "Error: Expected input descriptor field is missing: ${e.message}") "" } }