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

oc_ace: refactor and add tests #622

Merged
merged 9 commits into from
Aug 5, 2024
Merged

Conversation

Danielius1922
Copy link
Member

No description provided.

Copy link

coderabbitai bot commented Apr 19, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The updates significantly enhance access control management within the security framework by restructuring the oc_ace_res_t type, introducing new functions for handling Access Control Entries (ACEs), and adding extensive unit tests. These improvements streamline ACE management, refine access control mechanisms, and bolster test coverage, thereby reinforcing the overall security module.

Changes

File Path Change Summary
include/oc_acl.h Modified oc_ace_res_t struct by replacing its definition with a forward declaration and removing interfaces and types.
security/oc_ace.c, security/oc_ace_internal.h Added and modified functions for ACE management, including creation, encoding, decoding, and resource handling.
security/oc_acl.c Renamed and reorganized functions to improve clarity and alignment with new ACE management protocols.
security/unittest/acetest.cpp Introduced a comprehensive suite of unit tests for validating ACE functionalities, including various test cases for encoding and decoding.
security/unittest/acltest.cpp Transitioned from oc_ace_subject_t to oc_ace_subject_view_t, enhancing subject representation in tests and adding checks for ACL behavior.
onboarding_tool/obtmain.c, python/oc_python.c Integrated access control functionalities by including oc_ace_internal.h.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ocf-conformance-test-tool
Copy link

🎉 Thank you for your code contribution! To guarantee the change/addition is conformant to the OCF Specification, we would like to ask you to execute OCF Conformance Testing of your change ☝️ when your work is ready to be reviewed.


ℹ️ To verify your latest change (5731b43), label this PR with OCF Conformance Testing.

⚠️ Label is removed with every code change.

@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch 4 times, most recently from 9585357 to 5ea3443 Compare April 20, 2024 14:42
@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch from 62b54e8 to 83b8b22 Compare May 13, 2024 17:40
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Out of diff range and nitpick comments (1)
security/unittest/acetest.cpp (1)

41-41: Remove or replace the TODO comment with a more descriptive or actionable item.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4dd98e5 and 83b8b22.
Files selected for processing (15)
  • api/oc_collection.c (1 hunks)
  • port/android/Makefile (1 hunks)
  • port/arduino/adapter/Makefile (1 hunks)
  • port/esp32/main/CMakeLists.txt (1 hunks)
  • port/linux/Makefile (1 hunks)
  • port/openthread/Makefile (1 hunks)
  • port/windows/vs2015/IoTivity-lite.vcxproj (2 hunks)
  • port/windows/vs2015/IoTivity-lite.vcxproj.filters (2 hunks)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/oc_acl.c (17 hunks)
  • security/oc_acl_internal.h (2 hunks)
  • security/oc_acl_util.c (7 hunks)
  • security/unittest/acetest.cpp (1 hunks)
  • security/unittest/acltest.cpp (12 hunks)
Files not reviewed due to errors (1)
  • port/windows/vs2015/IoTivity-lite.vcxproj (no review received)
Additional comments not posted (43)
port/openthread/Makefile (1)

60-60: Security source files correctly added under conditional compilation for enhanced security features.

security/oc_acl_internal.h (1)

27-27: Include directive for oc_ace_internal.h correctly added to support ACE functionalities in ACL.

port/arduino/adapter/Makefile (1)

42-42: Security source files correctly added under conditional compilation for enhanced security features.

security/oc_ace_internal.h (1)

1-108: New file oc_ace_internal.h correctly defines necessary functionalities for ACE management.

port/esp32/main/CMakeLists.txt (1)

189-189: Security source files correctly added under conditional compilation for enhanced security features.

port/android/Makefile (1)

272-272: Security source files correctly added under conditional compilation for enhanced security features.

security/unittest/acetest.cpp (12)

48-67: The test NewUUID correctly initializes and checks various properties of an ACE object. The use of assertions and expectations is appropriate for unit testing.


69-114: The test NewRole effectively handles different role scenarios, including roles with and without authority. The assertions ensure that the ACE properties are set correctly.


116-130: The test NewAnonConn is concise and checks the properties of an ACE object for anonymous connections. The use of ASSERT_NE and EXPECT_EQ is appropriate.


132-146: The test NewCryptConn verifies the ACE properties for authenticated and encrypted connections. The test structure is consistent with other tests in the file.


148-187: The test GetOrAddResource covers scenarios for adding and retrieving resources in an ACE. It includes checks for resource creation and retrieval, which are crucial for correct ACE behavior.


189-280: The test FindResource thoroughly tests the resource finding functionality in various configurations, including wildcards. The detailed assertions ensure the robustness of the resource handling.


282-305: The test EncodeUUID checks the encoding of an ACE with a UUID subject. It uses the RepPool for handling CBOR encoding and decoding, which is crucial for data interchange in IoTivity-lite.


307-329: The test EncodeRole ensures that ACEs with role subjects are correctly encoded into CBOR format. The use of RepPool and assertions about the encoding process are appropriate.


331-350: The test EncodeAnonConn validates the CBOR encoding of an ACE for anonymous connections. The structure and assertions are consistent with other encoding tests.


352-371: The test EncodeCryptConn checks the CBOR encoding for authenticated and encrypted connections. This is important for ensuring secure data transmission.


373-411: The test EncodeWithResources handles the encoding of an ACE with multiple resources, including wildcards. This test is crucial for verifying the correct encoding of complex ACE configurations.


413-438: The test EncodeWithWCAllResource focuses on encoding an ACE with a wildcard-all resource. This scenario is important for applications needing broad access control configurations.

security/oc_acl_util.c (5)

29-29: The inclusion of oc_ace_internal.h is appropriate as it likely provides necessary definitions for handling ACEs within ACL utilities.


Line range hint 123-142: The function oc_ace_get_permission correctly handles wildcard permissions based on resource properties. The use of bitwise operations for permissions is appropriate and efficient.


156-164: The function get_role_permissions effectively retrieves and applies permissions based on role credentials. The structured initialization of role_subject is clean and avoids errors.


Line range hint 346-369: The function get_conn_permissions handles permissions for authenticated, encrypted, and anonymous connections. The repeated pattern of finding and applying permissions is consistent and logical.


393-399: The function oc_sec_check_acl_by_permissions manages permissions based on UUID subjects. The use of a loop to find and apply permissions ensures that all relevant ACEs are considered.

security/oc_acl.c (6)

32-32: Added import for oc_ace_internal.h is appropriate given the new ACE-related functionalities being integrated.


73-87: Renaming and modification of oc_sec_acl_find_subject align with the PR's objectives to enhance ACL handling.


103-108: Implementation of acl_get_new_aceid correctly ensures the generation of a unique ACE ID.


146-166: Enhancements in oc_sec_acl_update_res for better resource management and error handling are well-implemented.


260-273: Correct implementation of oc_sec_acl_add_created_resource_ace to handle permissions for newly created resources.


467-476: Implementation of oc_sec_acl_anon_connection correctly handles ACEs for anonymous connections.

security/oc_ace.c (4)

21-30: Includes and constants are correctly defined and organized, facilitating future maintenance and readability.


102-138: Implementation of oc_sec_new_ace correctly handles the creation of new ACEs with comprehensive subject type handling.


184-206: Enhancements in oc_sec_ace_get_or_add_res for better resource management and error handling are well-implemented.


219-229: Correct implementation of oc_sec_free_ace to ensure thorough cleanup of ACEs and associated resources.

port/windows/vs2015/IoTivity-lite.vcxproj.filters (2)

359-361: The addition of oc_ace.c to the 'Security' filter is correctly placed and aligns with the project's security enhancements.


736-738: The addition of oc_ace_internal.h to the 'Security' filter is appropriately categorized and supports the internal handling of ACE functionalities.

port/linux/Makefile (1)

294-294: Addition of oc_ace.c to security sources aligns with PR objectives.

api/oc_collection.c (1)

551-551: Ensure proper handling of collection creation in security ACLs.

security/unittest/acltest.cpp (6)

30-30: Include of oc_ace_internal.h aligns with the PR's objective to enhance ACE handling.


189-189: Test case oc_sec_acl_add_bootstrap_acl effectively checks the addition of a bootstrap ACL.


189-289: Comprehensive testing of oc_sec_acl_find_subject function covering various scenarios.


Line range hint 672-703: Tests for ACL updates using UUID subjects are well-implemented and check various permissions.


Line range hint 750-792: Tests for ACL updates using role-based subjects are well-implemented and check various permissions.


1014-1018: Tests for ACL updates using anonymous connections are well-implemented and check various permissions.

@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch from 83b8b22 to bdcec0c Compare May 14, 2024 07:22
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Out of diff range and nitpick comments (1)
security/oc_acl.c (1)

Line range hint 290-336: Ensure proper error handling for oc_sec_decode_ace.

In the function oc_sec_decode_acl, if oc_sec_decode_ace fails, the function returns false without freeing any previously allocated resources. This could lead to memory leaks.

-        if (!oc_sec_decode_ace(aclist2->value.object, &ace_decode)) {
-          OC_ERR("oc_acl: error decoding ACE");
-          return false;
-        }
+        if (!oc_sec_decode_ace(aclist2->value.object, &ace_decode)) {
+          OC_ERR("oc_acl: error decoding ACE");
+          // Free any previously allocated resources
+          if (upd_ace != NULL) {
+            oc_sec_free_ace(upd_ace);
+          }
+          return false;
+        }
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 83b8b22 and 9adcfdd.
Files selected for processing (7)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/oc_acl.c (17 hunks)
  • security/oc_acl_internal.h (2 hunks)
  • security/oc_acl_util.c (7 hunks)
  • security/unittest/acetest.cpp (1 hunks)
  • security/unittest/acltest.cpp (12 hunks)
Files skipped from review as they are similar to previous changes (4)
  • security/oc_ace_internal.h
  • security/oc_acl_internal.h
  • security/oc_acl_util.c
  • security/unittest/acetest.cpp
Additional comments not posted (14)
security/unittest/acltest.cpp (14)

30-30: Inclusion of security/oc_ace_internal.h is appropriate for accessing new ACE management functions.


189-239: Initialization of subjects and updates to ACL resources using oc_ace_subject_view_t and oc_sec_acl_update_res are correctly implemented.


240-244: Clearing the ACL and verifying the count of ACEs is correctly implemented.


247-281: Finding subjects in the ACL and verifying their properties is correctly implemented.


Line range hint 288-312: Clearing specific ACL entries and verifying the count of remaining ACEs is correctly implemented.


Line range hint 672-703: Initialization of a subject and updates to ACL resources with various permissions using oc_ace_subject_view_t and oc_sec_acl_update_res are correctly implemented.


704-704: Verification of access to the resource based on the updated permissions is correctly implemented.


Line range hint 750-792: Initialization of a subject and updates to ACL resources with various permissions using oc_ace_subject_view_t and oc_sec_acl_update_res are correctly implemented.


793-793: Verification of access to the resource based on the updated permissions is correctly implemented.


Line range hint 880-901: Initialization of a subject and updates to ACL resources with various permissions using oc_ace_subject_view_t and oc_sec_acl_update_res are correctly implemented.


902-902: Verification of access to the resource based on the updated permissions is correctly implemented.


942-946: Initialization of a subject and updates to ACL resources with various permissions using oc_ace_subject_view_t and oc_sec_acl_update_res are correctly implemented.


947-947: Verification of access to the resource based on the updated permissions is correctly implemented.


948-948: Clearing the ACL and verifying the count of remaining ACEs is correctly implemented.

security/oc_acl.c Outdated Show resolved Hide resolved
@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch from 9adcfdd to e96fce1 Compare May 14, 2024 10:04
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 9adcfdd and e96fce1.
Files selected for processing (8)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/oc_acl.c (16 hunks)
  • security/oc_acl_internal.h (2 hunks)
  • security/oc_acl_util.c (8 hunks)
  • security/oc_tls.c (1 hunks)
  • security/unittest/acetest.cpp (1 hunks)
  • security/unittest/acltest.cpp (12 hunks)
Files skipped from review due to trivial changes (1)
  • security/oc_tls.c
Files skipped from review as they are similar to previous changes (4)
  • security/oc_ace_internal.h
  • security/oc_acl_internal.h
  • security/oc_acl_util.c
  • security/unittest/acetest.cpp
Additional comments not posted (25)
security/oc_acl.c (7)

330-335: Proper error handling in oc_sec_decode_acl.

The function oc_sec_decode_acl properly handles errors when decoding ACEs. Ensure that all resources are freed in case of failure.


260-274: Proper error handling in oc_sec_acl_add_created_resource_ace.

The function oc_sec_acl_add_created_resource_ace properly handles errors when adding a new ACE for a created resource.


213-213: Proper error handling in oc_sec_remove_ace.

The function oc_sec_remove_ace properly handles errors when removing an ACE and freeing its resources.


222-222: Proper error handling in oc_sec_remove_ace_by_aceid.

The function oc_sec_remove_ace_by_aceid properly handles errors when removing an ACE by its ID and freeing its resources.


237-237: Proper error handling in oc_sec_acl_clear.

The function oc_sec_acl_clear properly handles errors when clearing all ACEs for a device.


237-237: Proper error handling in oc_sec_acl_free.

The function oc_sec_acl_free properly handles errors when freeing all ACL resources.


512-515: Proper error handling in oc_sec_apply_acl.

The function oc_sec_apply_acl properly handles errors when applying an ACL to a device.

security/oc_ace.c (6)

263-282: Proper error handling in oc_sec_ace_find_subject.

The function oc_sec_ace_find_subject properly handles errors when finding an ACE by its subject.


326-337: Proper error handling in oc_sec_ace_find_resource.

The function oc_sec_ace_find_resource properly handles errors when finding a resource in an ACE.


184-206: Proper error handling in oc_sec_ace_get_or_add_res.

The function oc_sec_ace_get_or_add_res properly handles errors when adding a new resource to an ACE.


263-282: Proper error handling in oc_sec_ace_find_subject.

The function oc_sec_ace_find_subject properly handles errors when finding an ACE by its subject.


326-337: Proper error handling in oc_sec_ace_find_resource.

The function oc_sec_ace_find_resource properly handles errors when finding a resource in an ACE.


184-206: Proper error handling in oc_sec_ace_get_or_add_res.

The function oc_sec_ace_get_or_add_res properly handles errors when adding a new resource to an ACE.

security/unittest/acltest.cpp (12)

30-30: New includes for internal security headers are appropriate and necessary for accessing the new ACE management functions.


189-239: The initial setup of the oc_sec_acl_find_subject test case is comprehensive and covers various types of subjects and permissions. This thorough setup ensures robust testing of the ACL functionalities.


240-281: The assertions in the oc_sec_acl_find_subject test case are well-structured and cover various scenarios, including matching and non-matching aceid and tags. This ensures comprehensive validation of the functionality.


Line range hint 282-312: The cleanup and final assertions in the oc_sec_acl_find_subject test case are necessary and correctly implemented. They ensure no side effects for subsequent tests and confirm the correct behavior after clearing the ACL.


672-673: The initial setup of the oc_sec_check_acl_AccessToSVRBySubject test case is appropriate and necessary for testing access control based on UUID.


Line range hint 678-703: The assertions in the oc_sec_check_acl_AccessToSVRBySubject test case are well-structured and cover various permissions, ensuring comprehensive validation of access control.


750-755: The initial setup of the oc_sec_check_acl_AccessToSVRByPSK test case is appropriate and necessary for testing access control based on PSK.


Line range hint 761-792: The assertions in the oc_sec_check_acl_AccessToSVRByPSK test case are well-structured and cover various permissions, ensuring comprehensive validation of access control.


880-883: The initial setup of the oc_sec_check_acl_AccessToSVRByNonOwnerRoleCred test case is appropriate and necessary for testing access control based on non-owner role credentials.


897-901: The assertions in the oc_sec_check_acl_AccessToSVRByNonOwnerRoleCred test case are well-structured and cover various permissions, ensuring comprehensive validation of access control.


942-946: The initial setup of the oc_sec_check_acl_AccessToNonSVRByCryptConn test case is appropriate and necessary for testing access control based on secure connections.


1014-1018: The assertions in the oc_sec_check_acl_AccessToNonSVRByCryptConn test case are well-structured and cover various permissions, ensuring comprehensive validation of access control.

security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between e96fce1 and 7f90bc5.
Files selected for processing (6)
  • include/oc_acl.h (1 hunks)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/oc_acl.c (15 hunks)
  • security/oc_acl_util.c (8 hunks)
  • security/unittest/acetest.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • security/oc_ace_internal.h
  • security/oc_acl_util.c
  • security/unittest/acetest.cpp
Additional comments not posted (6)
include/oc_acl.h (1)

83-85: Ensure that the removal of interfaces and types fields from oc_ace_res_t does not break any existing functionality.

Verification successful

Let's verify if the removed fields interfaces and types from oc_ace_res_t are referenced elsewhere in the codebase.


The removed fields interfaces and types from oc_ace_res_t are not referenced elsewhere in the codebase.

  • The search results for interfaces and types showed numerous references, but none were related to the oc_ace_res_t structure.
  • The search results for oc_ace_res_t did not show any references to the removed fields interfaces and types.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the removed fields `interfaces` and `types` are not referenced elsewhere in the codebase.

# Test: Search for references to `interfaces` and `types` in the codebase.
rg --type c 'interfaces'
rg --type c 'types'

Length of output: 42720



Script:

#!/bin/bash
# Description: Verify if the removed fields `interfaces` and `types` from `oc_ace_res_t` are referenced elsewhere in the codebase.

# Test: Search for references to `oc_ace_res_t` in the codebase.
rg --type c 'oc_ace_res_t'

Length of output: 3376

security/oc_acl.c (5)

73-87: Ensure that oc_sec_acl_find_subject correctly handles the new type oc_ace_subject_view_t.

Verification successful

The function oc_sec_acl_find_subject correctly handles the new type oc_ace_subject_view_t, and all usages in the codebase have been updated accordingly.

  • security/oc_acl.c: Function definition is correct.
  • security/oc_acl_util.c: Usages are updated to use oc_ace_subject_view_t.
  • security/unittest/acltest.cpp: Usages are updated to use oc_ace_subject_view_t.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of `oc_sec_acl_find_subject` with the new type `oc_ace_subject_view_t`.

# Test: Search for the function definition and its usage in the codebase.
ast-grep --lang c --pattern $'oc_sec_acl_find_subject($_, $_, $_, $_, $_, $_, $_)' 

Length of output: 83



Script:

#!/bin/bash
# Description: Verify the correctness of `oc_sec_acl_find_subject` with the new type `oc_ace_subject_view_t`.

# Search for the function definition in the codebase.
ast-grep --lang c --pattern $'oc_sec_ace_t *oc_sec_acl_find_subject($_, $_, $_, $_, $_, $_, $_, $_)'

# Search for all usages of the function in the codebase.
rg 'oc_sec_acl_find_subject'

Length of output: 1666



Script:

#!/bin/bash
# Extract the function definition from `security/oc_acl.c`.
ast-grep --lang c --pattern $'oc_sec_ace_t *oc_sec_acl_find_subject($_, $_, $_, $_, $_, $_, $_, $_)' security/oc_acl.c

# Extract the relevant lines from `security/oc_acl_util.c`.
rg -A 3 -B 3 'oc_sec_acl_find_subject' security/oc_acl_util.c

# Extract the relevant lines from `security/unittest/acltest.cpp`.
rg -A 3 -B 3 'oc_sec_acl_find_subject' security/unittest/acltest.cpp

Length of output: 4145


103-108: LGTM! The changes ensure unique ACE IDs.


146-166: Ensure comprehensive error handling in oc_sec_acl_update_res.

Verification successful

Ensure comprehensive error handling in oc_sec_acl_update_res.

The function oc_sec_acl_update_res and its usages have been reviewed. The function is defined in security/oc_acl.c and is used in multiple places within the same file and in security/unittest/acltest.cpp. The error handling within the function appears to be comprehensive, and the return values are properly checked in the calling code.

  • security/oc_acl.c:

    • The function checks if ace is NULL and handles the error by returning false.
    • The return value of oc_sec_acl_update_res is checked in multiple places, and appropriate actions are taken if the function returns false.
  • security/unittest/acltest.cpp:

    • The return value of oc_sec_acl_update_res is checked using assertions (EXPECT_EQ and ASSERT_EQ), ensuring that the function behaves as expected during tests.

Based on the provided context and the extracted code segments, the error handling in oc_sec_acl_update_res is comprehensive and consistent.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the error handling in `oc_sec_acl_update_res`.

# Test: Search for the function definition and its usage in the codebase.
ast-grep --lang c --pattern $'oc_sec_acl_update_res($_, $_, $_, $_, $_, $_, $_, $_)' 

Length of output: 85



Script:

#!/bin/bash
# Locate the function definition of `oc_sec_acl_update_res`.
ast-grep --lang c --pattern $'oc_sec_acl_update_res($_, $_, $_, $_, $_, $_, $_, $_, $_, $_)' 

# Search for all usages of `oc_sec_acl_update_res` in the codebase.
rg 'oc_sec_acl_update_res'

Length of output: 1935



Script:

#!/bin/bash
# Extract the function definition of `oc_sec_acl_update_res` from `security/oc_acl.c`.
ast-grep --lang c --pattern $'oc_sec_acl_update_res($_, $_, $_, $_, $_, $_, $_, $_, $_, $_)' security/oc_acl.c

# Extract the relevant code segments where `oc_sec_acl_update_res` is used in `security/oc_acl.c`.
rg -A 5 -B 5 'oc_sec_acl_update_res' security/oc_acl.c

# Extract the relevant code segments where `oc_sec_acl_update_res` is used in `security/unittest/acltest.cpp`.
rg -A 5 -B 5 'oc_sec_acl_update_res' security/unittest/acltest.cpp

Length of output: 9306


330-370: Ensure comprehensive error handling and correct decoding logic in oc_sec_decode_acl.

Verification successful

The function oc_sec_decode_acl in security/oc_acl.c includes comprehensive error handling and decoding logic. The function checks for invalid states and decoding errors, returning false when an error is encountered. This ensures that errors are appropriately handled during the decoding process.

  • The function verifies the state of the device and prevents operations in invalid states.
  • It checks for errors during the decoding of ACEs and ACE resources, logging errors and returning false when an error occurs.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the error handling and decoding logic in `oc_sec_decode_acl`.

# Test: Search for the function definition and its usage in the codebase.
ast-grep --lang c --pattern $'oc_sec_decode_acl($_, $_, $_, $_, $_)' 

Length of output: 69



Script:

#!/bin/bash
# Description: Search for the definition of the function `oc_sec_decode_acl` in the codebase.
ast-grep --lang c --pattern $'void oc_sec_decode_acl($_, $_, $_, $_, $_)' 

# Description: Search for the usage of the function `oc_sec_decode_acl` in the codebase.
rg 'oc_sec_decode_acl'

Length of output: 890



Script:

#!/bin/bash
# Description: Extract the definition of the function `oc_sec_decode_acl` from `security/oc_acl.c`.
ast-grep --lang c --pattern $'bool oc_sec_decode_acl(const oc_rep_t *rep, bool from_storage, size_t device, $_, $_) {
  $$$
}' security/oc_acl.c

Length of output: 145



Script:

#!/bin/bash
# Description: Search for the definition of the function `oc_sec_decode_acl` in `security/oc_acl.c` using `rg`.
rg 'bool oc_sec_decode_acl' security/oc_acl.c -A 20

Length of output: 53



Script:

#!/bin/bash
# Description: Search for the definition of the function `oc_sec_decode_acl` in `security/oc_acl.c` using `rg` with a broader pattern.
rg 'oc_sec_decode_acl' security/oc_acl.c -A 50

Length of output: 3549


426-436: Ensure comprehensive error handling in oc_sec_acl_anon_connection.

Verification successful

Comprehensive error handling in oc_sec_acl_anon_connection

The function oc_sec_acl_anon_connection in security/oc_acl.c includes error handling for the oc_sec_acl_update_res function call. If the call fails, an error message is logged, and the function returns false. This ensures that any failure in updating the ACL resource is properly handled.

  • The function definition and its usage have been verified.
  • Error handling is present and appears to be comprehensive.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the error handling in `oc_sec_acl_anon_connection`.

# Test: Search for the function definition and its usage in the codebase.
ast-grep --lang c --pattern $'oc_sec_acl_anon_connection($_, $_, $_)' 

Length of output: 70



Script:

#!/bin/bash
# Description: Verify the error handling in `oc_sec_acl_anon_connection`.

# Search for the function definition in the codebase.
ast-grep --lang c --pattern $'oc_sec_acl_anon_connection(size_t device, oc_string_view_t href, uint16_t permission) {
  $$$
}' 

# Search for the function usage in the codebase.
rg 'oc_sec_acl_anon_connection\('

Length of output: 1060



Script:

#!/bin/bash
# Description: Display the relevant lines from `security/oc_acl.c` to verify the error handling in `oc_sec_acl_anon_connection`.

# Display the function definition and its usage in `security/oc_acl.c`.
sed -n '420,460p' security/oc_acl.c

Length of output: 1430

@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch from 7f90bc5 to f1894d6 Compare May 14, 2024 11:42
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7f90bc5 and f1894d6.
Files selected for processing (6)
  • include/oc_acl.h (1 hunks)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/oc_acl.c (15 hunks)
  • security/oc_acl_util.c (8 hunks)
  • security/unittest/acetest.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • include/oc_acl.h
  • security/oc_ace_internal.h
  • security/oc_acl_util.c
  • security/unittest/acetest.cpp
Additional comments not posted (6)
security/oc_acl.c (6)

103-108: LGTM! The function acl_get_new_aceid correctly generates a new unique ACE ID.


112-122: LGTM! The function acl_encode_subjects correctly encodes the subjects of an ACL.


330-370: LGTM! The function oc_sec_decode_acl correctly decodes an ACL from a CBOR representation.


472-475: LGTM! The function oc_sec_apply_acl correctly applies an ACL.


Line range hint 478-487: LGTM! The function acl_resource_post correctly handles POST requests for ACL resources.


Line range hint 490-515: LGTM! The function acl_resource_delete correctly handles DELETE requests for ACL resources.

@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch from f1894d6 to 8758fea Compare May 14, 2024 12:42
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between f1894d6 and 8758fea.
Files selected for processing (6)
  • include/oc_acl.h (1 hunks)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/oc_acl.c (14 hunks)
  • security/oc_acl_util.c (8 hunks)
  • security/unittest/acetest.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • include/oc_acl.h
  • security/oc_ace_internal.h
  • security/oc_acl_util.c
  • security/unittest/acetest.cpp
Additional comments not posted (13)
security/oc_acl.c (7)

103-108: LGTM! The function acl_get_new_aceid correctly generates a new ACE ID.


112-122: LGTM! The function acl_encode_subjects correctly encodes subjects into a CBOR array.


135-137: LGTM! The function oc_sec_encode_acl correctly encodes the ACL into a CBOR object.


213-213: LGTM! The function oc_sec_remove_ace correctly removes an ACE from the device.


222-222: LGTM! The function oc_sec_remove_ace_by_aceid correctly removes an ACE by its ID.


260-274: LGTM! The function oc_sec_acl_add_created_resource_ace correctly adds a created resource ACE.


295-343: LGTM! The function acl_decode_ace_resources correctly decodes ACE resources.

security/oc_ace.c (6)

174-197: LGTM! The function oc_sec_add_new_ace_res is well-implemented.


277-298: LGTM! The function oc_sec_ace_find_subject is well-implemented.


340-352: LGTM! The function oc_sec_ace_find_resource is well-implemented.


457-484: LGTM! The function oc_sec_encode_ace is well-implemented.


654-700: LGTM! The function oc_sec_decode_ace_res is well-implemented.


702-715: LGTM! The function oc_sec_decode_ace_resources is well-implemented.

@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch from 8758fea to 96f11a9 Compare May 14, 2024 13:15
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8758fea and 96f11a9.
Files selected for processing (6)
  • include/oc_acl.h (1 hunks)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/oc_acl.c (14 hunks)
  • security/oc_acl_util.c (8 hunks)
  • security/unittest/acetest.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • include/oc_acl.h
  • security/oc_ace_internal.h
  • security/oc_acl_util.c
  • security/unittest/acetest.cpp
Additional comments not posted (6)
security/oc_acl.c (6)

103-110: LGTM! The function acl_get_new_aceid correctly generates a new ACE ID.


112-122: LGTM! The function acl_encode_subjects correctly encodes subjects into a CBOR array.


211-213: LGTM! The function oc_sec_remove_ace correctly removes an ACE from the device.


260-274: LGTM! The function oc_sec_acl_add_created_resource_ace correctly adds an ACE for a created resource.


295-343: LGTM! The function acl_decode_ace_resources correctly decodes ACE resources.


Line range hint 344-425: LGTM! The function oc_sec_decode_acl correctly decodes an ACL from a CBOR representation.

@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch from 96f11a9 to cf13af4 Compare May 15, 2024 15:51
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 96f11a9 and cf13af4.
Files selected for processing (6)
  • include/oc_acl.h (1 hunks)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/oc_acl.c (14 hunks)
  • security/oc_acl_util.c (8 hunks)
  • security/unittest/acetest.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • include/oc_acl.h
  • security/oc_ace_internal.h
  • security/oc_acl_util.c
  • security/unittest/acetest.cpp
Additional comments not posted (5)
security/oc_acl.c (5)

103-108: The function acl_get_new_aceid looks good and follows best practices.


112-122: The function acl_encode_subjects looks good and follows best practices.


260-274: The function oc_sec_acl_add_created_resource_ace looks good and follows best practices.


Line range hint 344-423: The function oc_sec_decode_acl looks good and follows best practices.


482-485: The function oc_sec_apply_acl looks good and follows best practices.

security/oc_ace.c Outdated Show resolved Hide resolved
@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch from cf13af4 to acc3331 Compare May 15, 2024 16:25
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 13

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between cf13af4 and acc3331.
Files selected for processing (6)
  • include/oc_acl.h (1 hunks)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/oc_acl.c (14 hunks)
  • security/oc_acl_util.c (8 hunks)
  • security/unittest/acetest.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • include/oc_acl.h
  • security/oc_ace_internal.h
  • security/oc_acl_util.c
  • security/unittest/acetest.cpp
Additional comments not posted (2)
security/oc_ace.c (2)

379-418: LGTM! The function ace_encode_subject is well-implemented.


441-455: LGTM! The function ace_encode_subject_resources is well-implemented.

security/oc_acl.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
security/oc_acl.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Outdated Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
Copy link

github-actions bot commented May 16, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between acc3331 and 913192f.
Files selected for processing (3)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/unittest/acetest.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • security/oc_ace_internal.h
  • security/unittest/acetest.cpp
Additional comments not posted (2)
security/oc_ace.c (2)

265-285: LGTM! The function oc_sec_ace_find_subject is well-implemented and follows best practices.


329-340: LGTM! The function oc_sec_ace_find_resource is well-implemented and follows best practices.

security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
security/oc_ace.c Show resolved Hide resolved
Copy link

sonarqubecloud bot commented May 16, 2024

@Danielius1922
Copy link
Member Author

~format

@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch from 913192f to 4fbd0d2 Compare July 30, 2024 16:32
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Outside diff range, codebase verification and nitpick comments (9)
security/oc_ace_internal.h (8)

34-36: Consider adding documentation for wildcard constants.

Adding brief comments explaining the purpose of each wildcard constant can improve code readability and maintainability.

#define OC_ACE_WC_ALL_STR "*" // Matches all resources
#define OC_ACE_WC_ALL_SECURED_STR "+" // Matches all secured resources
#define OC_ACE_WC_ALL_PUBLIC_STR "-" // Matches all public resources

38-39: Consider adding documentation for connection type constants.

Adding brief comments explaining the purpose of each connection type constant can improve code readability and maintainability.

#define OC_CONN_AUTH_CRYPT_STR "auth-crypt" // Authenticated and encrypted connection
#define OC_CONN_ANON_CLEAR_STR "anon-clear" // Unauthenticated and unencrypted connection

66-70: Consider adding documentation for oc_ace_subject_role_view_t.

Adding brief comments explaining the purpose of each field can improve code readability and maintainability.

typedef struct
{
  oc_string_view_t role; // Role name
  oc_string_view_t authority; // Authority name
} oc_ace_subject_role_view_t;

72-76: Consider adding documentation for oc_ace_subject_view_t.

Adding brief comments explaining the purpose of each field can improve code readability and maintainability.

typedef union {
  oc_uuid_t uuid; // UUID of the subject
  oc_ace_subject_role_view_t role; // Role of the subject
  oc_ace_connection_type_t conn; // Connection type of the subject
} oc_ace_subject_view_t;

103-107: Consider adding documentation for oc_ace_res_data_t.

Adding brief comments explaining the purpose of each field can improve code readability and maintainability.

typedef struct oc_ace_res_data_t
{
  oc_ace_res_t *res; // Pointer to the ACE resource
  bool created; // Indicates if the resource was created
} oc_ace_res_data_t;

125-133: Consider adding documentation for oc_sec_ace_decode_t.

Adding brief comments explaining the purpose of each field can improve code readability and maintainability.

typedef struct
{
  int aceid; // ACE identifier
  uint16_t permission; // Permissions
  oc_ace_subject_view_t subject; // Subject information
  oc_ace_subject_type_t subject_type; // Subject type
  const oc_rep_t *resources; // Resources
  const oc_string_t *tag; // Custom user tag
} oc_sec_ace_decode_t;

139-148: Consider adding documentation for oc_sec_ace_res_decode_t.

Adding brief comments explaining the purpose of each field can improve code readability and maintainability.

typedef struct
{
  oc_ace_wildcard_t wildcard; // Wildcard information
  const oc_string_t *href; // Href
#if 0
#ifdef OC_SERVER
  oc_resource_properties_t wc_r; // Resource properties
#endif /* OC_SERVER */
#endif
} oc_sec_ace_res_decode_t;

53-55: Ensure all wildcard enum values are handled.

The oc_ace_wildcard_to_string function does not handle the OC_ACE_NO_WC value from the oc_ace_wildcard_t enum. This could lead to undefined behavior if this value is passed to the function. Please add a case to handle the OC_ACE_NO_WC value.

  • security/oc_ace.c: Update the oc_ace_wildcard_to_string function to handle OC_ACE_NO_WC.
Analysis chain

Ensure all wildcard enum values are handled.

Verify that oc_ace_wildcard_to_string handles all possible values of oc_ace_wildcard_t to avoid undefined behavior.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all enum values are handled in oc_ace_wildcard_to_string.

# Test: Search for the function implementation. Expect: All enum values are handled.
rg --type-add 'c' --type c -A 10 'oc_ace_wildcard_to_string'

Length of output: 118


Script:

#!/bin/bash
# Description: Verify all enum values are handled in oc_ace_wildcard_to_string.

# Test: Search for the function implementation. Expect: All enum values are handled.
rg -t c -A 10 'oc_ace_wildcard_to_string'

Length of output: 2421


Script:

#!/bin/bash
# Description: Find the definition of the oc_ace_wildcard_t enum and verify if all its values are handled in oc_ace_wildcard_to_string.

# Search for the definition of the oc_ace_wildcard_t enum.
rg -t c 'typedef enum' -A 10 | rg 'oc_ace_wildcard_t'

# Verify if all enum values are handled in oc_ace_wildcard_to_string.
rg -t c -A 10 'oc_ace_wildcard_to_string'

Length of output: 2513


Script:

#!/bin/bash
# Description: Retrieve the full definition of the oc_ace_wildcard_t enum and verify if all its values are handled in oc_ace_wildcard_to_string.

# Retrieve the full definition of the oc_ace_wildcard_t enum.
rg -A 10 'typedef enum' include/oc_acl.h

# Verify if all enum values are handled in oc_ace_wildcard_to_string.
rg -t c -A 10 'oc_ace_wildcard_to_string'

Length of output: 3288

include/oc_acl.h (1)

85-89: Issues found due to active usage of interfaces and types fields.

The fields interfaces and types are actively used in various parts of the codebase, including headers, source files, and test files. Excluding these fields from the oc_ace_res_t struct might lead to potential issues or broken functionality.

  • Files with active usage of interfaces:

    • python/oc_python.h
    • swig/java_lang/oc_iotivity_lite_jni.h
    • tests/itc/ri/helper/RIHelper.cpp
    • port/linux/oc_config.h
    • include/oc_ri.h
    • include/oc_link.h
    • include/oc_endpoint.h
    • include/oc_api.h
    • apps/client_arduino.cpp
    • api/unittest/resourcetest.cpp
    • api/unittest/coreresourcetest.cpp
    • api/unittest/discovery/discovery.h
    • api/unittest/RITest.cpp
    • api/oc_resource_factory_internal.h
    • api/oc_link_internal.h
    • api/unittest/linktest.cpp
    • api/oc_core_res_internal.h
  • Files with active usage of types:

    • security/oc_obt_internal.h
    • security/oc_sp_internal.h
    • python/unittest/pythontest.cpp
    • security/unittest/credutiltest.cpp
    • security/unittest/sptest.cpp
    • python/oc_python.h
    • swig/java_lang/oc_iotivity_lite_jni.h
    • tests/itc/ri/helper/RIHelper.cpp
    • include/oc_acl.h
    • include/oc_ri.h
    • include/oc_api.h
    • apps/client_arduino.cpp
    • api/oc_resource_factory_internal.h
    • api/unittest/discovery/discovery.cpp
    • api/oc_core_res_internal.h
    • api/oc_collection_internal.h

Please review the exclusion of these fields to ensure it does not affect the functionality of the code.

Analysis chain

Verify the exclusion of interfaces and types fields.

The fields interfaces and types have been excluded from compilation using preprocessor directives. Ensure that this exclusion is intentional and does not affect the functionality of the code.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `interfaces` and `types` fields in the codebase.

# Test: Search for the usage of `interfaces` and `types` fields. Expect: No active usage.
rg --type cpp -A 5 $'interfaces'
rg --type cpp -A 5 $'types'

Length of output: 36974

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 913192f and 4fbd0d2.

Files selected for processing (16)
  • api/oc_collection.c (1 hunks)
  • include/oc_acl.h (1 hunks)
  • port/android/Makefile (1 hunks)
  • port/arduino/adapter/Makefile (1 hunks)
  • port/esp32/main/CMakeLists.txt (1 hunks)
  • port/linux/Makefile (1 hunks)
  • port/openthread/Makefile (1 hunks)
  • port/windows/vs2015/IoTivity-lite.vcxproj (2 hunks)
  • port/windows/vs2015/IoTivity-lite.vcxproj.filters (2 hunks)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/oc_acl.c (14 hunks)
  • security/oc_acl_internal.h (2 hunks)
  • security/oc_acl_util.c (8 hunks)
  • security/unittest/acetest.cpp (1 hunks)
  • security/unittest/acltest.cpp (12 hunks)
Additional comments not posted (91)
port/openthread/Makefile (1)

60-60: LGTM!

The addition of oc_ace.c and other security-related files to SRC_COMMON when SECURE is set to 1 is consistent with the existing structure and ensures the necessary files are included in the build process.

security/oc_acl_internal.h (4)

27-28: New includes are appropriate.

The inclusion of oc_ace_internal.h and oc_features.h is appropriate for the added functionality.


60-63: Improved type safety and performance.

The function oc_sec_acl_add_created_resource_ace now uses oc_string_view_t for href, which improves type safety and performance.


64-68: Enhanced function signature.

The function oc_sec_acl_find_subject now uses oc_ace_subject_view_t and oc_string_view_t, enhancing type safety and performance.


77-80: Improved function signature.

The function oc_sec_acl_update_res now uses oc_ace_subject_view_t and oc_string_view_t, improving type safety and performance.

port/arduino/adapter/Makefile (1)

42-42: LGTM!

The addition of oc_ace.c and other security-related files to SEC_SRC when SECURE is set to 1 is consistent with the existing structure and ensures the necessary files are included in the build process.

security/oc_ace_internal.h (13)

87-89: Ensure proper tag comparison and error handling in oc_ace_has_matching_tag.

Verify that the tag comparison is correct and errors are properly handled in oc_ace_has_matching_tag.

Verification successful

The function oc_ace_has_matching_tag correctly handles tag comparison and potential errors.

  • The function checks if the tag is NULL and compares the tag using oc_string_is_cstr_equal.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify proper tag comparison and error handling in oc_ace_has_matching_tag.

# Test: Search for the function implementation. Expect: Correct tag comparison and error handling.
rg --type-add 'c' --type c -A 10 'oc_ace_has_matching_tag'

Length of output: 116


Script:

#!/bin/bash
# Description: Verify proper tag comparison and error handling in oc_ace_has_matching_tag.

# Test: Search for the function implementation. Expect: Correct tag comparison and error handling.
ast-grep --lang c --pattern $'bool oc_ace_has_matching_tag(const oc_sec_ace_t *ace, oc_string_view_t tag) {
  $$$
}'

Length of output: 510


109-113: Ensure proper resource handling and error handling in oc_sec_ace_get_or_add_res.

Verify that resource handling and error handling are correct in oc_sec_ace_get_or_add_res.

Verification successful

Let's correct the shell script to search for the implementation of the oc_sec_ace_get_or_add_res function and review its resource and error handling.


Resource and error handling in oc_sec_ace_get_or_add_res are correctly implemented.

The function oc_sec_ace_get_or_add_res in security/oc_ace.c handles resource creation and errors appropriately. The unit tests in security/unittest/acetest.cpp further confirm the correct behavior in various scenarios.

  • security/oc_ace.c: Implementation of oc_sec_ace_get_or_add_res
  • security/unittest/acetest.cpp: Unit tests verifying the function's behavior
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify proper resource handling and error handling in oc_sec_ace_get_or_add_res.

# Test: Search for the function implementation. Expect: Correct resource handling and error handling.
rg --type-add 'c' --type c -A 10 'oc_sec_ace_get_or_add_res'

Length of output: 118


Script:

#!/bin/bash
# Description: Verify proper resource handling and error handling in oc_sec_ace_get_or_add_res.

# Test: Search for the function implementation. Expect: Correct resource handling and error handling.
rg -A 20 'oc_sec_ace_get_or_add_res'

Length of output: 12679


91-94: Ensure proper subject comparison and error handling in oc_ace_has_matching_subject.

Verify that the subject comparison is correct and errors are properly handled in oc_ace_has_matching_subject.

Verification successful

The function oc_ace_has_matching_subject correctly handles subject comparison and error handling.

The function checks the subject_type and performs appropriate comparisons based on the type. It uses assertions and returns the result of the comparison functions.

  • File: security/oc_ace.c
  • Lines: 243-263
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify proper subject comparison and error handling in oc_ace_has_matching_subject.

# Test: Search for the function implementation. Expect: Correct subject comparison and error handling.
rg --type-add 'c' --type c -A 10 'oc_ace_has_matching_subject'

Length of output: 120


Script:

#!/bin/bash
# Description: Verify proper subject comparison and error handling in oc_ace_has_matching_subject.

# Test: Search for the function implementation. Expect: Correct subject comparison and error handling.
ast-grep --lang c --pattern $'bool oc_ace_has_matching_subject(const oc_sec_ace_t *ace, oc_ace_subject_type_t type, oc_ace_subject_view_t subject) {
  $$$
}'

Length of output: 1377


153-156: Ensure proper resource decoding and error handling in oc_sec_decode_ace_resources.

Verify that resource decoding and error handling are correct in oc_sec_decode_ace_resources.

Verification successful

Ensure proper resource decoding and error handling in oc_sec_decode_ace_resources.

The function oc_sec_decode_ace_resources correctly handles resource decoding and error handling by checking the return value of ace_decode_resource and returning false if any resource fails to decode.

  • security/oc_ace.c: oc_sec_decode_ace_resources
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify proper resource decoding and error handling in oc_sec_decode_ace_resources.

# Test: Search for the function implementation. Expect: Correct resource decoding and error handling.
rg --type-add 'c' --type c -A 10 'oc_sec_decode_ace_resources'

Length of output: 120


Script:

#!/bin/bash
# Description: Verify proper resource decoding and error handling in oc_sec_decode_ace_resources.

# Test: Search for the function implementation. Expect: Correct resource decoding and error handling.
rg --type c -A 10 'oc_sec_decode_ace_resources'

Length of output: 2003


78-82: Ensure proper initialization and error handling in oc_sec_new_ace.

Verify that all fields are correctly initialized and errors are properly handled in oc_sec_new_ace.

Verification successful

Let's correct the rg command to search for the implementation of the oc_sec_new_ace function and verify its proper initialization and error handling.


To ensure that all fields are initialized and errors are handled properly in the oc_sec_new_ace function, let's gather the complete implementation of the function.


The function oc_sec_new_ace correctly initializes all fields and handles errors properly.

  • The function initializes the resources list.
  • It sets the subject based on the type.
  • It handles memory allocation errors by checking if the allocation was successful and returning NULL if it wasn't.
  • It sets the aceid, subject_type, and permission.
  • It handles the tag if provided.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify proper initialization and error handling in oc_sec_new_ace.

# Test: Search for the function implementation. Expect: All fields are initialized and errors are handled.
rg --type-add 'c' --type c -A 10 'oc_sec_new_ace'

Length of output: 107


Script:

#!/bin/bash
# Description: Verify proper initialization and error handling in oc_sec_new_ace.

# Test: Search for the function implementation. Expect: All fields are initialized and errors are handled.
rg -A 20 'oc_sec_new_ace'

Length of output: 20844


Script:

#!/bin/bash
# Description: Retrieve the complete implementation of the oc_sec_new_ace function to verify proper initialization and error handling.

# Test: Search for the complete function implementation. Expect: All fields are initialized and errors are handled.
rg 'oc_sec_new_ace' -A 50

Length of output: 31300


84-85: Ensure proper resource deallocation in oc_sec_free_ace.

Verify that all allocated resources are correctly freed in oc_sec_free_ace.


96-101: Ensure proper list search and error handling in oc_sec_ace_find_subject.

Verify that the list search is correct and errors are properly handled in oc_sec_ace_find_subject.

Verification successful

Let's correct the rg command to search for the implementation of the oc_sec_ace_find_subject function directly.


To fully verify the list search and error handling in oc_sec_ace_find_subject, we need to extract the complete implementation of the function from security/oc_ace.c.


The function oc_sec_ace_find_subject correctly handles list search and error conditions.

The function iterates over the list of ACEs, checks the specified conditions (aceid, permission, tag, and subject matching), and returns the matching ACE or NULL if no match is found.

  • The list search is correctly implemented using a loop.
  • Error handling is properly managed by returning NULL when no matching ACE is found.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify proper list search and error handling in oc_sec_ace_find_subject.

# Test: Search for the function implementation. Expect: Correct list search and error handling.
rg --type-add 'c' --type c -A 10 'oc_sec_ace_find_subject'

Length of output: 116


Script:

#!/bin/bash
# Description: Verify proper list search and error handling in oc_sec_ace_find_subject.

# Test: Search for the function implementation. Expect: Correct list search and error handling.
rg -A 10 'oc_sec_ace_find_subject'

Length of output: 1923


Script:

#!/bin/bash
# Description: Extract the complete implementation of oc_sec_ace_find_subject from security/oc_ace.c.

# Extract the function implementation.
rg -A 50 'oc_sec_ace_find_subject\(' security/oc_ace.c

Length of output: 1441


135-137: Ensure proper decoding and error handling in oc_sec_decode_ace.

Verify that decoding and error handling are correct in oc_sec_decode_ace.


56-58: Ensure all string values are handled.

Verify that oc_ace_wildcard_from_string handles all possible string values to avoid undefined behavior.

Verification successful

Verified: All string values are handled.

The function oc_ace_wildcard_from_string correctly handles specific known strings and returns -1 for any unrecognized input, ensuring all string values are managed appropriately.

  • security/oc_ace.c (implementation of oc_ace_wildcard_from_string)
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all string values are handled in oc_ace_wildcard_from_string.

# Test: Search for the function implementation. Expect: All string values are handled.
rg --type-add 'c' --type c -A 10 'oc_ace_wildcard_from_string'

Length of output: 120


Script:

#!/bin/bash
# Description: Verify all string values are handled in oc_ace_wildcard_from_string.

# Test: Search for the function implementation. Expect: All string values are handled.
rg -A 10 'int oc_ace_wildcard_from_string' --type c

Length of output: 654


Script:

#!/bin/bash
# Description: Locate the implementation of oc_ace_wildcard_from_string to verify it handles all string values.

# Search for the function implementation in C source files.
rg 'int oc_ace_wildcard_from_string' --type c

Length of output: 129


Script:

#!/bin/bash
# Description: Locate the implementation of oc_ace_wildcard_from_string to verify it handles all string values.

# Search for the function name across all files to find its implementation.
rg 'oc_ace_wildcard_from_string'

Length of output: 684


Script:

#!/bin/bash
# Description: Extract the implementation of oc_ace_wildcard_from_string from security/oc_ace.c to verify it handles all string values.

# Extract the lines around the function implementation in security/oc_ace.c.
rg -A 20 'oc_ace_wildcard_from_string' security/oc_ace.c

Length of output: 1292


59-62: Ensure all connection type enum values are handled.

Verify that oc_ace_connection_type_to_string handles all possible values of oc_ace_connection_type_t to avoid undefined behavior.


121-123: Ensure proper encoding and error handling in oc_sec_encode_ace.

Verify that encoding and error handling are correct in oc_sec_encode_ace.


63-65: Ensure all string values are handled.

Verify that oc_ace_connection_type_from_string handles all possible string values to avoid undefined behavior.


115-119: Ensure proper resource search and error handling in oc_sec_ace_find_resource.

Verify that the resource search is correct and errors are properly handled in oc_sec_ace_find_resource.

Verification successful

The resource search and error handling in oc_sec_ace_find_resource are correctly implemented.

  • The function oc_sec_ace_find_resource initializes the resource pointer and calls ace_res_find_resource to perform the search.
  • The ace_res_find_resource function correctly handles matching based on href and wildcard.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify proper resource search and error handling in oc_sec_ace_find_resource.

# Test: Search for the function implementation. Expect: Correct resource search and error handling.
rg --type-add 'c' --type c -A 10 'oc_sec_ace_find_resource'

Length of output: 117


Script:

#!/bin/bash
# Description: Verify proper resource search and error handling in oc_sec_ace_find_resource.

# Test: Search for the function implementation. Expect: Correct resource search and error handling.
rg -A 10 'oc_sec_ace_find_resource'

Length of output: 6015


Script:

#!/bin/bash
# Description: Verify the complete implementation of oc_sec_ace_find_resource and ace_res_find_resource.

# Search for the complete implementation of oc_sec_ace_find_resource
rg -A 20 'oc_sec_ace_find_resource' security/oc_ace.c

# Search for the implementation of ace_res_find_resource
rg -A 20 'ace_res_find_resource' security

Length of output: 3200

port/android/Makefile (1)

272-272: Verify the impact of replacing oc_cred.c with oc_ace.c.

Ensure that the functionalities provided by oc_cred.c are either deprecated or moved to oc_ace.c to avoid any unintended side effects.

security/oc_acl.c (3)

32-32: LGTM!

The new includes for oc_ace_internal.h and oc_acl_internal.h are appropriate for the added functionalities.


103-108: LGTM!

The acl_get_new_aceid function generates a unique ACE ID correctly.


146-166: Check for memory leaks when creating new ACE.

In the function oc_sec_acl_update_res, if oc_sec_new_ace fails to allocate memory, the function returns false without freeing any previously allocated resources. This could lead to memory leaks.

-    if (ace == NULL) {
-      return false;
-    }
+    if (ace == NULL) {
+      // Free any previously allocated resources
+      if (data != NULL) {
+        data->created = false;
+        data->created_resource = false;
+      }
+      return false;
+    }

Likely invalid or redundant comment.

security/oc_acl_util.c (6)

29-29: LGTM!

The new includes for oc_ace_internal.h, oc_acl_internal.h, and others are appropriate for the added functionalities.


Line range hint 123-142:
LGTM!

The oc_ace_get_permission function now uses oc_string_view2 for handling string data, improving performance and reducing memory overhead.


156-166: LGTM!

The get_role_permissions function now uses oc_ace_subject_view_t to encapsulate role information more efficiently.


Line range hint 348-373:
LGTM!

The get_conn_permissions function now uses oc_ace_subject_view_t to encapsulate connection information more efficiently.


396-403: LGTM!

The oc_sec_check_acl_by_permissions function now uses oc_ace_subject_view_t to encapsulate subject information more efficiently.


423-428: LGTM!

The addition of debugging output in the oc_sec_check_acl_by_permissions function provides better visibility into access evaluations, aiding in troubleshooting and monitoring access control decisions.

security/oc_ace.c (8)

105-142: Ensure proper error handling for oc_memb_alloc.

In the function oc_sec_new_ace, if oc_memb_alloc fails to allocate memory, the function logs a warning but does not handle the failure properly. This could lead to potential issues if the allocation fails.

-    OC_WRN("insufficient memory to add new ACE");
-    return NULL;
+    OC_WRN("insufficient memory to add new ACE");
+    // Handle the failure case
+    // Free any previously allocated resources if necessary
+    return NULL;

162-185: Ensure proper error handling for oc_memb_alloc.

In the function oc_sec_add_new_ace_res, if oc_memb_alloc fails to allocate memory, the function logs a warning but does not handle the failure properly. This could lead to potential issues if the allocation fails.

-    OC_WRN("insufficient memory to add new resource to ACE");
-    return NULL;
+    OC_WRN("insufficient memory to add new resource to ACE");
+    // Handle the failure case
+    // Free any previously allocated resources if necessary
+    return NULL;

187-209: Ensure proper error handling for oc_sec_add_new_ace_res.

In the function oc_sec_ace_get_or_add_res, if oc_sec_add_new_ace_res fails to allocate memory, the function logs an error but does not handle the failure properly. This could lead to potential issues if the allocation fails.

-    OC_ERR("could not %s resource for ACE", create ? "create" : "find");
-    return (oc_ace_res_data_t){ NULL, false };
+    OC_ERR("could not %s resource for ACE", create ? "create" : "find");
+    // Handle the failure case
+    // Free any previously allocated resources if necessary
+    return (oc_ace_res_data_t){ NULL, false };

222-232: Ensure proper error handling for oc_memb_free.

In the function oc_sec_free_ace, if oc_memb_free fails to free memory, the function does not handle the failure properly. This could lead to potential issues if the deallocation fails.

-    oc_memb_free(&g_ace_l, ace);
+    if (oc_memb_free(&g_ace_l, ace) != 0) {
+      // Handle the failure case
+      // Log an error or take appropriate action
+    }

579-641: Ensure proper error handling for ace_decode_property.

In the function oc_sec_decode_ace, if ace_decode_property fails, the function logs an error but does not handle the failure properly. This could lead to potential issues if the decoding fails.

-      OC_ERR("ACE decode: unknown property (name=%s, type=%d)",
-             oc_string(rep->name) != NULL ? oc_string(rep->name) : "(null)",
-             (int)rep->type);
-      return false;
+      OC_ERR("ACE decode: unknown property (name=%s, type=%d)",
+             oc_string(rep->name) != NULL ? oc_string(rep->name) : "(null)",
+             (int)rep->type);
+      // Handle the failure case
+      // Free any previously allocated resources if necessary
+      return false;

513-525: Ensure proper error handling for ace_decode_subject_string_property.

In the function ace_decode_subject, if ace_decode_subject_string_property fails, the function logs an error but does not handle the failure properly. This could lead to potential issues if the decoding fails.

-    OC_ERR("ACE decode subject: unknown property (name=%s, type=%d)",
-           oc_string(rep->name) != NULL ? oc_string(rep->name) : "(null)",
-           (int)rep->type);
-    return -1;
+    OC_ERR("ACE decode subject: unknown property (name=%s, type=%d)",
+           oc_string(rep->name) != NULL ? oc_string(rep->name) : "(null)",
+           (int)rep->type);
+    // Handle the failure case
+    // Free any previously allocated resources if necessary
+    return -1;

682-697: Ensure proper error handling for ace_decode_resource_string_property.

In the function ace_decode_resource, if ace_decode_resource_string_property fails, the function logs an error but does not handle the failure properly. This could lead to potential issues if the decoding fails.

-    OC_ERR("ACE decode resource: unknown property (name=%s, type=%d)",
-           oc_string(rep->name) != NULL ? oc_string(rep->name) : "(null)",
-           (int)rep->type);
-    return false;
+    OC_ERR("ACE decode resource: unknown property (name=%s, type=%d)",
+           oc_string(rep->name) != NULL ? oc_string(rep->name) : "(null)",
+           (int)rep->type);
+      // Handle the failure case
+      // Free any previously allocated resources if necessary
+    return false;

717-729: Ensure proper error handling for ace_decode_resource.

In the function oc_sec_decode_ace_resources, if ace_decode_resource fails, the function does not handle the failure properly. This could lead to potential issues if the decoding fails.

-    if (!ace_decode_resource(rep->value.object, &aceres_decode)) {
-      return false;
-    }
+    if (!ace_decode_resource(rep->value.object, &aceres_decode)) {
+      // Handle the failure case
+      // Free any previously allocated resources if necessary
+      return false;
+    }
security/unittest/acetest.cpp (9)

104-123: LGTM!

The test case NewUUID is well-structured and verifies the expected properties of the created ACE.


125-170: LGTM!

The test case NewRole is well-structured and verifies the expected properties of the created ACE.


172-186: LGTM!

The test case NewAnonConn is well-structured and verifies the expected properties of the created ACE.


188-202: LGTM!

The test case NewCryptConn is well-structured and verifies the expected properties of the created ACE.


204-243: LGTM!

The test case GetOrAddResource is well-structured and verifies the expected properties of the retrieved or added resource.


245-336: LGTM!

The test case FindResource is well-structured and verifies the expected properties of the found resource.


338-350: LGTM!

The test case WildcardToString is well-structured and verifies the expected string representation of the wildcard.


352-362: LGTM!

The test case WildcardFromString is well-structured and verifies the expected wildcard representation of the string.


364-374: LGTM!

The test case ConnectionTypeToString is well-structured and verifies the expected string representation of the connection type.

port/windows/vs2015/IoTivity-lite.vcxproj (2)

282-282: Header file inclusion looks good.

The addition of oc_ace_internal.h to the <ClInclude> section is correctly placed and follows the project's structure.


465-465: Source file inclusion looks good.

The addition of oc_ace.c to the <ClCompile> section is correctly placed and follows the project's structure.

port/windows/vs2015/IoTivity-lite.vcxproj.filters (2)

359-361: Approved: Addition of oc_ace.c to the project.

The inclusion of oc_ace.c under the Security filter is correctly formatted and appropriately placed.


736-738: Approved: Addition of oc_ace_internal.h to the project.

The inclusion of oc_ace_internal.h under the Security filter is correctly formatted and appropriately placed.

port/linux/Makefile (1)

294-294: Approved: Addition of oc_ace.c to the Makefile.

The inclusion of oc_ace.c in the list of source files when the SECURE variable is not equal to zero is correctly formatted and appropriately placed.

api/oc_collection.c (1)

551-553: LGTM! But verify the function usage in the codebase.

The change to use oc_string_view2 instead of oc_string is approved. This change optimizes performance by avoiding unnecessary string allocations.

However, ensure that all function calls to oc_sec_acl_add_created_resource_ace are updated accordingly.

Verification successful

All occurrences of oc_sec_acl_add_created_resource_ace have been updated accordingly.

The function calls and definitions are consistent with the new signature using oc_string_view_t.

  • security/oc_acl.c: Function definition.
  • security/oc_acl_internal.h: Function declaration.
  • api/oc_collection.c: Updated function call.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `oc_sec_acl_add_created_resource_ace` are updated accordingly.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type c -A 5 $'oc_sec_acl_add_created_resource_ace'

Length of output: 1267

security/unittest/acltest.cpp (37)

189-189: Ensure test case name consistency.

The test case name oc_sec_acl_find_subject should reflect the new function name if it has changed.


191-193: Initialize anon_clear properly.

Ensure that the anon_clear object is correctly initialized to avoid potential issues.


194-197: Verify the tag usage.

Ensure that the tag is correctly used and validated in the oc_sec_acl_update_res function.


201-203: Initialize subject_uuid properly.

Ensure that the subject_uuid object is correctly initialized to avoid potential issues.


208-210: Initialize subject_role properly.

Ensure that the subject_role object is correctly initialized to avoid potential issues.


216-218: Initialize subject_role2 properly.

Ensure that the subject_role2 object is correctly initialized to avoid potential issues.


224-226: Initialize subject_role3 properly.

Ensure that the subject_role3 object is correctly initialized to avoid potential issues.


232-234: Initialize subject_role4 properly.

Ensure that the subject_role4 object is correctly initialized to avoid potential issues.


240-244: Verify the oc_sec_acl_clear function behavior.

Ensure that the oc_sec_acl_clear function behaves as expected with the new changes.


247-250: Verify the oc_sec_acl_find_subject function behavior.

Ensure that the oc_sec_acl_find_subject function behaves as expected with the new changes.


253-255: Check the aceid field.

Ensure that the aceid field is correctly set and validated.


256-259: Verify the oc_sec_acl_find_subject function behavior with aceid.

Ensure that the oc_sec_acl_find_subject function behaves as expected when aceid is provided.


261-266: Verify the oc_sec_acl_find_subject function behavior with non-matching aceid.

Ensure that the oc_sec_acl_find_subject function behaves as expected when a non-matching aceid is provided.


268-273: Verify the oc_sec_acl_find_subject function behavior with non-matching tag.

Ensure that the oc_sec_acl_find_subject function behaves as expected when a non-matching tag is provided.


275-280: Verify the oc_sec_acl_find_subject function behavior ignoring non-matching tag.

Ensure that the oc_sec_acl_find_subject function behaves as expected when ignoring a non-matching tag.


288-291: Verify the oc_sec_acl_find_subject function behavior after clearing ACL.

Ensure that the oc_sec_acl_find_subject function behaves as expected after clearing the ACL.


295-298: Verify the oc_sec_acl_find_subject function behavior with role subject.

Ensure that the oc_sec_acl_find_subject function behaves as expected with a role subject.


309-312: Verify the oc_sec_acl_find_subject function behavior after clearing specific ACE.

Ensure that the oc_sec_acl_find_subject function behaves as expected after clearing a specific ACE.


672-673: Initialize subject properly.

Ensure that the subject object is correctly initialized to avoid potential issues.


678-680: Verify the oc_sec_acl_update_res function behavior with UUID subject.

Ensure that the oc_sec_acl_update_res function behaves as expected with a UUID subject.


690-692: Verify the oc_sec_acl_update_res function behavior with create or update permissions.

Ensure that the oc_sec_acl_update_res function behaves as expected with create or update permissions.


700-703: Verify the oc_sec_acl_update_res function behavior with delete permission.

Ensure that the oc_sec_acl_update_res function behaves as expected with delete permission.


750-751: Verify the role and authority initialization.

Ensure that the role and authority are correctly initialized and used.


761-763: Verify the oc_sec_acl_update_res function behavior with role subject.

Ensure that the oc_sec_acl_update_res function behaves as expected with a role subject.


775-777: Verify the oc_sec_acl_update_res function behavior with create or update permissions.

Ensure that the oc_sec_acl_update_res function behaves as expected with create or update permissions.


787-789: Verify the oc_sec_acl_update_res function behavior with delete permission.

Ensure that the oc_sec_acl_update_res function behaves as expected with delete permission.


880-881: Verify the role and authority initialization.

Ensure that the role and authority are correctly initialized and used.


897-899: Verify the oc_sec_acl_update_res function behavior with role subject.

Ensure that the oc_sec_acl_update_res function behaves as expected with a role subject.


900-903: Verify the oc_sec_acl_update_res function behavior with update permission.

Ensure that the oc_sec_acl_update_res function behaves as expected with update permission.


942-944: Verify the oc_sec_acl_update_res function behavior with authenticated connection.

Ensure that the oc_sec_acl_update_res function behaves as expected with an authenticated connection.


945-948: Verify the oc_sec_acl_update_res function behavior with delete permission.

Ensure that the oc_sec_acl_update_res function behaves as expected with delete permission.


1014-1016: Verify the oc_sec_acl_update_res function behavior with anonymous connection.

Ensure that the oc_sec_acl_update_res function behaves as expected with an anonymous connection.


1017-1020: Verify the oc_sec_acl_update_res function behavior with retrieve permission.

Ensure that the oc_sec_acl_update_res function behaves as expected with retrieve permission.


1014-1016: Verify the oc_sec_acl_update_res function behavior with anonymous connection.

Ensure that the oc_sec_acl_update_res function behaves as expected with an anonymous connection.


1017-1020: Verify the oc_sec_acl_update_res function behavior with retrieve permission.

Ensure that the oc_sec_acl_update_res function behaves as expected with retrieve permission.


1014-1016: Verify the oc_sec_acl_update_res function behavior with anonymous connection.

Ensure that the oc_sec_acl_update_res function behaves as expected with an anonymous connection.


1017-1020: Verify the oc_sec_acl_update_res function behavior with retrieve permission.

Ensure that the oc_sec_acl_update_res function behaves as expected with retrieve permission.

include/oc_acl.h (1)

89-89: LGTM! The changes are approved.

The changes to the structure oc_ace_res_t are approved. The wildcard field remains active, indicating its relevance to the current implementation.

port/esp32/main/CMakeLists.txt (1)

189-189: LGTM! The addition of oc_ace.c is approved.

The addition of the new source file oc_ace.c to the sources list enhances the security features of the project. Ensure that the new file is correctly integrated and tested.

security/oc_acl.c Show resolved Hide resolved
security/oc_acl.c Show resolved Hide resolved
security/oc_acl.c Show resolved Hide resolved
@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch from 4fbd0d2 to 5b84154 Compare July 30, 2024 21:16
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
python/oc_python.c (1)

37-37: Unnecessary inclusion of oc_ace_internal.h in python/oc_python.c.

The header file oc_ace_internal.h is included in python/oc_python.c, but none of its definitions are used in this file. This inclusion should be removed to avoid unnecessary dependencies.

  • python/oc_python.c: Remove #include "security/oc_ace_internal.h"
Analysis chain

LGTM! But verify the usage of the included header.

The addition of the include directive for oc_ace_internal.h is consistent with the PR objectives to enhance access control management.

However, ensure that all usages of the included header are correct and necessary.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the included header `oc_ace_internal.h`.

# Test: Search for the usage of `oc_ace_internal.h`. Expect: Only necessary and correct usages.
rg --type c --type h --word-regexp 'oc_ace_internal'

Length of output: 467


Script:

#!/bin/bash
# Description: Verify the usage of definitions from `oc_ace_internal.h` in `python/oc_python.c`.

# Step 1: Extract all function and macro definitions from `oc_ace_internal.h`.
rg --type h --word-regexp '#define|^[a-zA-Z_][a-zA-Z0-9_]*\s*\(' security/oc_ace_internal.h > oc_ace_internal_definitions.txt

# Step 2: Search for these definitions in `python/oc_python.c`.
while read -r definition; do
  rg --type c --word-regexp "${definition%%(*}" python/oc_python.c
done < oc_ace_internal_definitions.txt

Length of output: 1973

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4fbd0d2 and 5b84154.

Files selected for processing (7)
  • include/oc_acl.h (2 hunks)
  • onboarding_tool/obtmain.c (1 hunks)
  • python/oc_python.c (1 hunks)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/oc_obt.c (1 hunks)
  • security/unittest/acetest.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • security/oc_ace.c
  • security/oc_ace_internal.h
  • security/unittest/acetest.cpp
Additional comments not posted (4)
include/oc_acl.h (2)

109-109: Forward declaration of oc_ace_res_t approved.

The forward declaration simplifies the structure and prepares for future modifications.


106-106: Verify the impact of excluding interfaces and types fields.

Excluding these fields from compilation may impact the functionality. Ensure that the codebase handles these exclusions appropriately.

Also applies to: 107-109

onboarding_tool/obtmain.c (1)

26-26: Include directive for oc_ace_internal.h approved.

The inclusion suggests an enhancement or modification in the security-related functionalities, potentially enabling access control features.

security/oc_obt.c (1)

41-41: Verify the usage of the newly included header file.

Ensure that the newly included header file security/oc_ace_internal.h is utilized appropriately within this file and that it doesn't introduce any unused dependencies.

Verification successful

The newly included header file security/oc_ace_internal.h is utilized appropriately within security/oc_obt.c through the usage of oc_ace_res_t.

  • oc_ace_res_t is used multiple times in security/oc_obt.c.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the newly included header file.

# Test: Search for the usage of functions, types, or macros defined in `oc_ace_internal.h`. Expect: At least one usage.
rg --type c -A 5 $'oc_ace_internal'

Length of output: 2206


Script:

#!/bin/bash
# Description: Verify the usage of specific functions, types, or macros defined in `security/oc_ace_internal.h` within `security/oc_obt.c`.

# Step 1: List all functions, types, and macros defined in `security/oc_ace_internal.h`.
# Step 2: Search for these functions, types, or macros in `security/oc_obt.c`.

# Step 1: Extract definitions from `security/oc_ace_internal.h`.
defs=$(rg --type c '^[a-zA-Z_][a-zA-Z0-9_]* ' security/oc_ace_internal.h | awk '{print $2}')

# Step 2: Search for these definitions in `security/oc_obt.c`.
for def in $defs; do
    rg --type c -n "$def" security/oc_obt.c
done

Length of output: 10088

@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch from 5b84154 to 48a7f83 Compare July 30, 2024 22:15
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5b84154 and 48a7f83.

Files selected for processing (6)
  • onboarding_tool/obtmain.c (1 hunks)
  • python/oc_python.c (1 hunks)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/oc_obt.c (1 hunks)
  • security/unittest/acetest.cpp (1 hunks)
Files skipped from review due to trivial changes (2)
  • python/oc_python.c
  • security/oc_ace_internal.h
Files skipped from review as they are similar to previous changes (4)
  • onboarding_tool/obtmain.c
  • security/oc_ace.c
  • security/oc_obt.c
  • security/unittest/acetest.cpp

@Danielius1922 Danielius1922 added the OCF Conformance Testing OCF Conformance Testing required label Aug 1, 2024
@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch from 48a7f83 to 6d446f5 Compare August 1, 2024 07:09
@ocf-conformance-test-tool ocf-conformance-test-tool bot removed the OCF Conformance Testing OCF Conformance Testing required label Aug 1, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 48a7f83 and 6d446f5.

Files selected for processing (3)
  • security/oc_ace.c (1 hunks)
  • security/oc_ace_internal.h (1 hunks)
  • security/unittest/acetest.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • security/oc_ace.c
  • security/oc_ace_internal.h
  • security/unittest/acetest.cpp

@Danielius1922 Danielius1922 marked this pull request as ready for review August 1, 2024 08:11
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6d446f5 and 429763d.

Files selected for processing (3)
  • security/oc_ace.c (1 hunks)
  • security/unittest/acetest.cpp (1 hunks)
  • security/unittest/acltest.cpp (13 hunks)
Files skipped from review as they are similar to previous changes (3)
  • security/oc_ace.c
  • security/unittest/acetest.cpp
  • security/unittest/acltest.cpp

@Danielius1922 Danielius1922 force-pushed the adam/bugfix/sc-fixes-16 branch from 429763d to cca06f3 Compare August 5, 2024 11:08
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 429763d and cca06f3.

Files selected for processing (3)
  • security/oc_ace.c (1 hunks)
  • security/unittest/acetest.cpp (1 hunks)
  • security/unittest/acltest.cpp (13 hunks)
Files skipped from review as they are similar to previous changes (2)
  • security/oc_ace.c
  • security/unittest/acetest.cpp
Additional comments not posted (8)
security/unittest/acltest.cpp (8)

30-30: Import statement approved.

The import of security/oc_ace_internal.h is necessary for the new oc_ace_subject_view_t structure.


71-71: Using declaration approved.

The use of std::chrono_literals simplifies time duration literals.


194-294: Refactoring and function signature updates approved.

The refactoring aligns with the new oc_ace_subject_view_t structure and updates function calls accordingly.


Line range hint 677-708:
Refactoring and function signature updates approved.

The refactoring aligns with the new oc_ace_subject_view_t structure and updates function calls accordingly.


Line range hint 755-797:
Refactoring and function signature updates approved.

The refactoring aligns with the new oc_ace_subject_view_t structure and updates function calls accordingly.


Line range hint 885-906:
Refactoring and function signature updates approved.

The refactoring aligns with the new oc_ace_subject_view_t structure and updates function calls accordingly.


947-951: Refactoring and function signature updates approved.

The refactoring aligns with the new oc_ace_subject_view_t structure and updates function calls accordingly.


1019-1023: Refactoring and function signature updates approved.

The refactoring aligns with the new oc_ace_subject_view_t structure and updates function calls accordingly.

@Danielius1922 Danielius1922 added the OCF Conformance Testing OCF Conformance Testing required label Aug 5, 2024
Copy link

sonarqubecloud bot commented Aug 5, 2024

@Danielius1922
Copy link
Member Author

@coderabbitai generate a description for this pull request about targeting to general developer audience, not familiar with the code in this repository.

Copy link

coderabbitai bot commented Aug 5, 2024

@Danielius1922:

This pull request aims to enhance the oc_ace module by refactoring the existing code and adding comprehensive tests. The primary goals are to improve the code's structure, functionality, and overall maintainability.

Key improvements include:

  • Code Refactoring: The code has been reorganized to adhere to best practices, making it more readable and easier to maintain. This restructuring helps developers understand the codebase more quickly and collaborate more effectively.
  • Enhanced Testing: New tests have been introduced to ensure the reliability of the oc_ace module. These tests cover various aspects of the module's functionality, helping to catch potential issues early and ensure that future changes do not introduce regressions.

Overall, these changes contribute to a more robust and maintainable codebase, facilitating future development and improving the quality of the software.

Actions performed

Comments resolved.

@Danielius1922 Danielius1922 merged commit 9120a25 into master Aug 5, 2024
132 checks passed
@Danielius1922 Danielius1922 deleted the adam/bugfix/sc-fixes-16 branch August 5, 2024 15:17
@github-actions github-actions bot locked and limited conversation to collaborators Aug 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
OCF Conformance Testing OCF Conformance Testing required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant