Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Fix Attestation crash #25837

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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