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

Update AddNOC/UpdateNOC to follow final error handling spec text #18861

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Expand Up @@ -73,8 +73,15 @@ constexpr uint8_t kDACCertificate = 1;
constexpr uint8_t kPAICertificate = 2;

CHIP_ERROR CreateAccessControlEntryForNewFabricAdministrator(const Access::SubjectDescriptor & subjectDescriptor,
FabricIndex fabricIndex, NodeId subject)
FabricIndex fabricIndex, uint64_t subject)
{
NodeId subjectAsNodeID = static_cast<NodeId>(subject);

if (!IsOperationalNodeId(subjectAsNodeID) && !IsCASEAuthTag(subjectAsNodeID))
{
return CHIP_ERROR_INVALID_ADMIN_SUBJECT;
}

Access::AccessControl::Entry entry;
ReturnErrorOnFailure(Access::GetAccessControl().PrepareEntry(entry));
ReturnErrorOnFailure(entry.SetFabricIndex(fabricIndex));
Expand Down Expand Up @@ -607,6 +614,10 @@ OperationalCertStatus ConvertToNOCResponseStatus(CHIP_ERROR err)
{
return OperationalCertStatus::kInvalidFabricIndex;
}
if (err == CHIP_ERROR_INVALID_ADMIN_SUBJECT)
{
return OperationalCertStatus::kInvalidAdminSubject;
}

return OperationalCertStatus::kInvalidNOC;
}
Expand All @@ -631,7 +642,8 @@ bool emberAfOperationalCredentialsClusterAddNOCCallback(app::CommandHandler * co
Credentials::GroupDataProvider::KeySet keyset;
FabricInfo * newFabricInfo = nullptr;

auto * secureSession = commandObj->GetExchangeContext()->GetSessionHandle()->AsSecureSession();
auto * secureSession = commandObj->GetExchangeContext()->GetSessionHandle()->AsSecureSession();
FailSafeContext & failSafeContext = DeviceControlServer::DeviceControlSvr().GetFailSafeContext();

uint8_t compressed_fabric_id_buffer[sizeof(uint64_t)];
MutableByteSpan compressed_fabric_id(compressed_fabric_id_buffer);
Expand All @@ -644,17 +656,17 @@ bool emberAfOperationalCredentialsClusterAddNOCCallback(app::CommandHandler * co
return true;
}

FailSafeContext & failSafeContext = DeviceControlServer::DeviceControlSvr().GetFailSafeContext();
VerifyOrExit(NOCValue.size() <= 400, nonDefaultStatus = Status::InvalidCommand);

VerifyOrExit(!ICACValue.HasValue() || ICACValue.Value().size() <= 400, nonDefaultStatus = Status::InvalidCommand);

VerifyOrExit(ipkValue.size() == Crypto::CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES, nonDefaultStatus = Status::InvalidCommand);

VerifyOrExit(failSafeContext.IsFailSafeArmed(commandObj->GetAccessingFabricIndex()),
HodgertA marked this conversation as resolved.
Show resolved Hide resolved
nonDefaultStatus = Status::UnsupportedAccess);

VerifyOrExit(!failSafeContext.NocCommandHasBeenInvoked(), nonDefaultStatus = Status::ConstraintError);

VerifyOrExit(NOCValue.size() <= 400, nonDefaultStatus = Status::InvalidCommand);
VerifyOrExit(ICACValue.HasValue() && ICACValue.Value().size() <= 400, nonDefaultStatus = Status::InvalidCommand);
VerifyOrExit(ipkValue.size() == Crypto::CHIP_CRYPTO_SYMMETRIC_KEY_LENGTH_BYTES, nonDefaultStatus = Status::InvalidCommand);

err = gFabricBeingCommissioned.SetNOCCert(NOCValue);
VerifyOrExit(err == CHIP_NO_ERROR, nocResponse = ConvertToNOCResponseStatus(err));

Expand Down Expand Up @@ -690,7 +702,7 @@ bool emberAfOperationalCredentialsClusterAddNOCCallback(app::CommandHandler * co
* . If the current secure session was established with CASE, subsequent configuration
* of the newly installed Fabric requires the opening of a new CASE session from the
* Administrator from the Fabric just installed. This Administrator is the one listed
* in the `CaseAdminNode` argument.
* in the `caseAdminSubject` argument.
*
*/
if (secureSession->GetSecureSessionType() == SecureSession::Type::kPASE)
Expand Down Expand Up @@ -722,17 +734,17 @@ bool emberAfOperationalCredentialsClusterAddNOCCallback(app::CommandHandler * co
gFabricBeingCommissioned.Reset();
if (nonDefaultStatus == Status::Success)
{
// We have an NOC response and did not have IM failures before on field validations
// We have an NOC response but had IM failures before on field validations
HodgertA marked this conversation as resolved.
Show resolved Hide resolved
SendNOCResponse(commandObj, commandPath, nocResponse, fabricIndex, CharSpan());
if (nocResponse != OperationalCertStatus::kSuccess)
{
ChipLogError(Zcl, "OpCreds: Failed AddNOC request (err=%" CHIP_ERROR_FORMAT ") with OperationalCert error %d",
err.Format(), to_underlying(nocResponse));
}
// We have an NOC response but had IM failures before on field validations
// Success
else
{
ChipLogProgress(Zcl, "OpCreds: successfully created fabric index 0x%x via AddNOC", fabricIndex);
ChipLogProgress(Zcl, "OpCreds: successfully created fabric index 0x%x via AddNOC", static_cast<unsigned>(fabricIndex));
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved
}
}
else
Expand Down Expand Up @@ -774,7 +786,8 @@ bool emberAfOperationalCredentialsClusterUpdateNOCCallback(app::CommandHandler *
VerifyOrExit(!failSafeContext.NocCommandHasBeenInvoked(), nonDefaultStatus = Status::ConstraintError);

VerifyOrExit(NOCValue.size() <= 400, nonDefaultStatus = Status::InvalidCommand);
VerifyOrExit(ICACValue.HasValue() && ICACValue.Value().size() <= 400, nonDefaultStatus = Status::InvalidCommand);

VerifyOrExit(!ICACValue.HasValue() || ICACValue.Value().size() <= 400, nonDefaultStatus = Status::InvalidCommand);
HodgertA marked this conversation as resolved.
Show resolved Hide resolved

err = fabric->SetNOCCert(NOCValue);
VerifyOrExit(err == CHIP_NO_ERROR, nocResponse = ConvertToNOCResponseStatus(err));
Expand Down
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ CHIP_ERROR DeviceCommissioner::ConvertFromOperationalCertStatus(OperationalCrede
case OperationalCertStatus::kTableFull:
return CHIP_ERROR_NO_MEMORY;
case OperationalCertStatus::kInvalidAdminSubject:
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved
return CHIP_IM_GLOBAL_STATUS(InvalidCommand);
return CHIP_ERROR_INVALID_ADMIN_SUBJECT;
case OperationalCertStatus::kFabricConflict:
return CHIP_ERROR_FABRIC_EXISTS;
case OperationalCertStatus::kInsufficientPrivilege:
Expand Down
3 changes: 3 additions & 0 deletions src/lib/core/CHIPError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, CHIP_ERROR err)
case CHIP_ERROR_MISSING_SECURE_SESSION.AsInteger():
desc = "Missing secure session";
break;
case CHIP_ERROR_INVALID_ADMIN_SUBJECT.AsInteger():
desc = "CaseAdminSubject is not valid";
break;
case CHIP_ERROR_INVALID_PATH_LIST.AsInteger():
desc = "Invalid TLV path list";
break;
Expand Down
9 changes: 8 additions & 1 deletion src/lib/core/CHIPError.h
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,14 @@ using CHIP_ERROR = ::chip::ChipError;
*/
#define CHIP_ERROR_MISSING_SECURE_SESSION CHIP_CORE_ERROR(0x77)

// unused CHIP_CORE_ERROR(0x78)
/**
* @def CHIP_ERROR_INVALID_ADMIN_SUBJECT
*
* @brief
* The CaseAdminSubject field is not valid.
HodgertA marked this conversation as resolved.
Show resolved Hide resolved
*
*/
#define CHIP_ERROR_INVALID_ADMIN_SUBJECT CHIP_CORE_ERROR(0x78)

// unused CHIP_CORE_ERROR(0x79)

Expand Down