Skip to content

Commit 58e310e

Browse files
silabs-borislrzr
authored andcommitted
UIC-3222: Better handling of rejection of credential due to security rules
Works both when adding a credential and modifying it
1 parent 9a66734 commit 58e310e

File tree

2 files changed

+81
-12
lines changed

2 files changed

+81
-12
lines changed

applications/zpc/components/zwave_command_classes/src/zwave_command_class_user_credential.cpp

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -601,17 +601,41 @@ sl_status_t zwave_command_class_user_credential_credential_handle_report(
601601

602602
// Helper function to clean up pending credentials slot nodes
603603
auto clean_up_pending_credentials_slot_nodes = [&]() {
604-
auto nodes = get_credential_identifier_nodes(
605-
endpoint_node,
606-
{user_id, REPORTED_ATTRIBUTE},
607-
{credential_type, DESIRED_OR_REPORTED_ATTRIBUTE},
608-
{credential_slot, DESIRED_ATTRIBUTE});
609-
610-
nodes.slot_node.delete_node();
611-
sl_log_debug(LOG_TAG, "Cleaning temporary credential slot node : %d (credential type %d, user %d)",
612-
credential_slot,
613-
credential_type,
614-
user_id);
604+
try {
605+
auto nodes = get_credential_identifier_nodes(
606+
endpoint_node,
607+
{user_id, REPORTED_ATTRIBUTE},
608+
{credential_type, DESIRED_OR_REPORTED_ATTRIBUTE},
609+
{credential_slot, DESIRED_ATTRIBUTE});
610+
611+
nodes.slot_node.delete_node();
612+
sl_log_debug(LOG_TAG,
613+
"Cleaning temporary credential slot node : %d (credential "
614+
"type %d, user %d)",
615+
credential_slot,
616+
credential_type,
617+
user_id);
618+
} catch (const std::exception &e) {
619+
// Try again with reported attribute
620+
// That should not trigger an error, but if it does it means that something went wrong
621+
auto nodes = get_credential_identifier_nodes(
622+
endpoint_node,
623+
{user_id, REPORTED_ATTRIBUTE},
624+
{credential_type, DESIRED_OR_REPORTED_ATTRIBUTE},
625+
{credential_slot, REPORTED_ATTRIBUTE});
626+
627+
sl_log_debug(
628+
LOG_TAG,
629+
"Cleaning desired values of credential slot node : %d (credential "
630+
"type %d, user %d)",
631+
credential_slot,
632+
credential_type,
633+
user_id);
634+
635+
for (auto child: nodes.slot_node.children()) {
636+
child.clear_desired();
637+
}
638+
}
615639
};
616640

617641
// We should have a valid user id if we receive this report

applications/zpc/components/zwave_command_classes/test/zwave_command_class_user_credential_test.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2550,11 +2550,56 @@ void test_user_credential_credential_set_error_report_cred_duplicate_happy_case(
25502550
helper_test_credential_rejected_case(0x07);
25512551
}
25522552

2553-
void test_user_credential_credential_set_error_report_cred_security_rule_happy_case()
2553+
void test_user_credential_credential_set_error_report_cred_security_rule_add_happy_case()
25542554
{
25552555
helper_test_credential_rejected_case(0x08);
25562556
}
25572557

2558+
void test_user_credential_credential_set_error_report_cred_security_rule_modify_happy_case()
2559+
{
2560+
user_credential_user_unique_id_t user_id = 12;
2561+
user_credential_type_t credential_type = 1;
2562+
user_credential_slot_t credential_slot = 1;
2563+
uint8_t crb = 1;
2564+
auto credential_data = string_to_uint8_vector("1212");
2565+
2566+
auto valid_user_node
2567+
= cpp_endpoint_id_node.emplace_node(ATTRIBUTE(USER_UNIQUE_ID), user_id);
2568+
auto valid_cred_type_node
2569+
= valid_user_node.emplace_node(ATTRIBUTE(CREDENTIAL_TYPE), credential_type);
2570+
auto valid_cred_slot_node
2571+
= valid_cred_type_node.emplace_node(ATTRIBUTE(CREDENTIAL_SLOT),
2572+
credential_slot,
2573+
REPORTED_ATTRIBUTE);
2574+
2575+
auto crb_node
2576+
= valid_cred_slot_node.emplace_node(ATTRIBUTE(CREDENTIAL_READ_BACK),
2577+
crb,
2578+
DESIRED_ATTRIBUTE);
2579+
auto credential_data_node
2580+
= valid_cred_slot_node.emplace_node(ATTRIBUTE(CREDENTIAL_DATA),
2581+
credential_data,
2582+
DESIRED_ATTRIBUTE);
2583+
2584+
helper_simulate_credential_report_frame(0x08,
2585+
user_id,
2586+
credential_type,
2587+
credential_slot,
2588+
crb,
2589+
credential_data,
2590+
0,
2591+
2,
2592+
0,
2593+
0);
2594+
2595+
// Check if the rejected report has cleared all desired values
2596+
TEST_ASSERT_FALSE_MESSAGE(crb_node.desired_exists(),
2597+
"CRB desired value should NOT exist");
2598+
2599+
TEST_ASSERT_FALSE_MESSAGE(credential_data_node.desired_exists(),
2600+
"Credential data desired value should NOT exist");
2601+
}
2602+
25582603
void test_user_credential_remove_all_users_happy_case()
25592604
{
25602605
helper_set_version(1);

0 commit comments

Comments
 (0)