From 115389243828523cc3da995c574670499b93b726 Mon Sep 17 00:00:00 2001 From: joonhaengHeo <85541460+joonhaengHeo@users.noreply.github.com> Date: Mon, 27 Mar 2023 23:13:39 +0900 Subject: [PATCH] Fix Android Attestation error (#25837) --- .../ExampleAttestationTrustStoreDelegate.kt | 3 ++- .../DeviceProvisioningFragment.kt | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/attestation/ExampleAttestationTrustStoreDelegate.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/attestation/ExampleAttestationTrustStoreDelegate.kt index 4e723faeffecd3..c94a64d1b8d00f 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/attestation/ExampleAttestationTrustStoreDelegate.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/attestation/ExampleAttestationTrustStoreDelegate.kt @@ -1,6 +1,7 @@ package com.google.chip.chiptool.attestation import android.util.Base64 +import android.util.Log import chip.devicecontroller.AttestationTrustStoreDelegate import chip.devicecontroller.ChipDeviceController import java.util.* @@ -13,7 +14,7 @@ class ExampleAttestationTrustStoreDelegate(val chipDeviceController: ChipDeviceC override fun getProductAttestationAuthorityCert(skid: ByteArray): ByteArray? { return paaCerts .map { Base64.decode(it, Base64.DEFAULT) } - .firstOrNull { cert -> chipDeviceController.extractSkidFromPaaCert(cert) == skid } + .firstOrNull { cert -> Arrays.equals(chipDeviceController.extractSkidFromPaaCert(cert), skid) } } companion object { diff --git a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt index fa6c2bf7883db0..743f853acb9a38 100644 --- a/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt +++ b/examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/provisioning/DeviceProvisioningFragment.kt @@ -60,6 +60,8 @@ class DeviceProvisioningFragment : Fragment() { private lateinit var scope: CoroutineScope + private var dialog: AlertDialog? = null + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) deviceController = ChipClient.getDeviceController(requireContext()) @@ -87,6 +89,7 @@ class DeviceProvisioningFragment : Fragment() { override fun onStop() { super.onStop() gatt = null + dialog = null } override fun onDestroy() { @@ -104,7 +107,7 @@ class DeviceProvisioningFragment : Fragment() { private fun setAttestationDelegate() { deviceController.setDeviceAttestationDelegate(DEVICE_ATTESTATION_FAILED_TIMEOUT - ) { devicePtr, attestationInfo, errorCode -> + ) { devicePtr, _, errorCode -> Log.i(TAG, "Device attestation errorCode: $errorCode, " + "Look at 'src/credentials/attestation_verifier/DeviceAttestationVerifier.h' " + "AttestationVerificationResult enum to understand the errors") @@ -120,7 +123,11 @@ class DeviceProvisioningFragment : Fragment() { } activity.runOnUiThread(Runnable { - val dialog = AlertDialog.Builder(activity) + if (dialog != null && dialog?.isShowing == true) { + Log.d(TAG, "dialog is already showing") + return@Runnable + } + dialog = AlertDialog.Builder(activity) .setPositiveButton("Continue", DialogInterface.OnClickListener { dialog, id -> deviceController.continueCommissioning(devicePtr, true) @@ -131,9 +138,7 @@ class DeviceProvisioningFragment : Fragment() { }) .setTitle("Device Attestation") .setMessage("Device Attestation failed for device under commissioning. Do you wish to continue pairing?") - .create() - - dialog.show() + .show() }) } } @@ -230,6 +235,8 @@ class DeviceProvisioningFragment : Fragment() { ?.onCommissioningComplete(0) } else { showMessage(R.string.rendezvous_over_ble_pairing_failure_text) + FragmentUtil.getHost(this@DeviceProvisioningFragment, Callback::class.java) + ?.onCommissioningComplete(errorCode) } } @@ -238,6 +245,8 @@ class DeviceProvisioningFragment : Fragment() { if (code != STATUS_PAIRING_SUCCESS) { showMessage(R.string.rendezvous_over_ble_pairing_failure_text) + FragmentUtil.getHost(this@DeviceProvisioningFragment, Callback::class.java) + ?.onCommissioningComplete(code) } }