Skip to content

Commit

Permalink
Fix Android Attestation error
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo committed Mar 27, 2023
1 parent c6cdc9e commit 522dd23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -87,6 +89,7 @@ class DeviceProvisioningFragment : Fragment() {
override fun onStop() {
super.onStop()
gatt = null
dialog = null
}

override fun onDestroy() {
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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()
})
}
}
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}

Expand Down

0 comments on commit 522dd23

Please sign in to comment.