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

Address testing feedback from opcert callbacks, and re-commissioning #22369

Merged
merged 9 commits into from
Sep 14, 2022
38 changes: 35 additions & 3 deletions src/controller/AutoCommissioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,41 @@ CHIP_ERROR AutoCommissioner::CommissioningStepFinished(CHIP_ERROR err, Commissio
SetDAC(report.Get<RequestedCertificate>().certificate);
break;
case CommissioningStage::kSendAttestationRequest:
// These don't need to be deep copied to local memory because they are used in this one step then never again.
mParams.SetAttestationElements(report.Get<AttestationResponse>().attestationElements)
.SetAttestationSignature(report.Get<AttestationResponse>().signature);
if (report.Get<AttestationResponse>().attestationElements.size() > kAttestationElementsLength)
chrisdecenzo marked this conversation as resolved.
Show resolved Hide resolved
{
ChipLogError(Controller, "AutoCommissioner attestationElements buffer size %d larger than cache size %d",
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved
static_cast<int>(report.Get<AttestationResponse>().attestationElements.size()),
static_cast<int>(kAttestationElementsLength));
chrisdecenzo marked this conversation as resolved.
Show resolved Hide resolved
mParams.SetAttestationElements(report.Get<AttestationResponse>().attestationElements);
chrisdecenzo marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
memcpy(mAttestationElements, report.Get<AttestationResponse>().attestationElements.data(),
report.Get<AttestationResponse>().attestationElements.size());
mParams.SetAttestationElements(
ByteSpan(mAttestationElements, report.Get<AttestationResponse>().attestationElements.size()));
}

if (report.Get<AttestationResponse>().signature.size() > kAttestationSignatureLength)
chrisdecenzo marked this conversation as resolved.
Show resolved Hide resolved
{
ChipLogError(Controller,
"AutoCommissioner attestationSignature buffer size %d larger than "
"cache size %d",
static_cast<int>(report.Get<AttestationResponse>().signature.size()),
static_cast<int>(kAttestationSignatureLength));
chrisdecenzo marked this conversation as resolved.
Show resolved Hide resolved
mParams.SetAttestationSignature(report.Get<AttestationResponse>().signature);
}
else
{
memcpy(mAttestationSignature, report.Get<AttestationResponse>().signature.data(),
report.Get<AttestationResponse>().signature.size());
mParams.SetAttestationSignature(
ByteSpan(mAttestationSignature, report.Get<AttestationResponse>().signature.size()));
}
// ? These don't need to be deep copied to local memory because they are used in this one step then never again.
chrisdecenzo marked this conversation as resolved.
Show resolved Hide resolved
// mParams.SetAttestationElements(report.Get<AttestationResponse>().attestationElements)
// .SetAttestationSignature(report.Get<AttestationResponse>().signature);
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved

// TODO: Does this need to be done at runtime? Seems like this could be done earlier and we wouldn't need to hold a
// reference to the operational credential delegate here
if (mOperationalCredentialsDelegate != nullptr)
Expand Down
6 changes: 6 additions & 0 deletions src/controller/AutoCommissioner.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
namespace chip {
namespace Controller {

constexpr size_t kAttestationElementsLength = 900;
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved
constexpr size_t kAttestationSignatureLength = 64;
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved

class DeviceCommissioner;

class AutoCommissioner : public CommissioningDelegate
Expand Down Expand Up @@ -86,6 +89,9 @@ class AutoCommissioner : public CommissioningDelegate
uint8_t mCSRNonce[kCSRNonceLength];
uint8_t mNOCertBuffer[Credentials::kMaxCHIPCertLength];
uint8_t mICACertBuffer[Credentials::kMaxCHIPCertLength];

uint8_t mAttestationElements[kAttestationElementsLength];
uint8_t mAttestationSignature[kAttestationSignatureLength];
};
} // namespace Controller
} // namespace chip
4 changes: 3 additions & 1 deletion src/controller/java/AndroidOperationalCredentialsIssuer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ CHIP_ERROR AndroidOperationalCredentialsIssuer::CallbackGenerateNOCChain(const B
jmethodID method;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
err = JniReferences::GetInstance().FindMethod(env, mJavaObjectRef, "onNOCChainGenerationNeeded", "([B[B[B[B[B[B[B[B[B)V",

err = JniReferences::GetInstance().FindMethod(env, mJavaObjectRef, "onNOCChainGenerationNeeded",
"(Lchip/devicecontroller/CSRInfo;Lchip/devicecontroller/AttestationInfo;)V",
&method);
if (err != CHIP_NO_ERROR)
{
Expand Down