Fix retrieval of attestation challenge in Java (#18867)
When not using the auto-commissioning flow, the mDeviceBeingCommissioned
proxy is no longer assigned, so the default behavior of retrieving the
attestation challenge fails.
Since at the time of use we already have a reference to the correct
DeviceProxy, added an overload to pass the proxy along to retrieve the
challenge.
diff --git a/src/app/DeviceProxy.h b/src/app/DeviceProxy.h
index 2b9bd0e..843ebd9 100644
--- a/src/app/DeviceProxy.h
+++ b/src/app/DeviceProxy.h
@@ -59,6 +59,25 @@
const ReliableMessageProtocolConfig & GetRemoteMRPConfig() const { return mRemoteMRPConfig; }
+ /**
+ * @brief
+ * This function returns the attestation challenge for the secure session.
+ *
+ * @param[out] attestationChallenge The output for the attestationChallenge
+ *
+ * @return CHIP_ERROR CHIP_NO_ERROR on success, or CHIP_ERROR_INVALID_ARGUMENT if no secure session is active
+ */
+ virtual CHIP_ERROR GetAttestationChallenge(ByteSpan & attestationChallenge)
+ {
+ Optional<SessionHandle> secureSessionHandle;
+
+ secureSessionHandle = GetSecureSession();
+ VerifyOrReturnError(secureSessionHandle.HasValue(), CHIP_ERROR_INCORRECT_STATE);
+
+ attestationChallenge = secureSessionHandle.Value()->AsSecureSession()->GetCryptoContext().GetAttestationChallenge();
+ return CHIP_NO_ERROR;
+ }
+
protected:
virtual bool IsSecureConnected() const = 0;