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

Issue 628: Fix inconsistent ownership validation in IoTivity-Lite. #630

Merged
merged 2 commits into from
May 31, 2024

Conversation

sp-milos
Copy link
Collaborator

@sp-milos sp-milos commented May 31, 2024

A new ownership check was added to oc_main.c. If the device is not owned based upon that check, all of its existing resources are reset before attempting to load them again.

Fixes #628

@sp-milos sp-milos requested a review from jkralik May 31, 2024 08:06
Copy link

coderabbitai bot commented May 31, 2024

Walkthrough

The changes introduce a function to clear security-related data when device ownership cannot be established, ensuring consistent ownership validation. Additionally, hardcoded strings in security-related functions are replaced with defined constants for better maintainability and readability.

Changes

File(s) Change Summary
api/oc_main.c Added main_sec_clear_resources function to clear security-related storage data when ownership cannot be established.
security/oc_acl_internal.h Added constant OCF_SEC_ACL_STORE_NAME with value "acl".
security/oc_ael_internal.h Added macro OCF_SEC_AEL_STORE_NAME with value "ael".
security/oc_cred_internal.h Added constant OCF_SEC_CRED_STORE_NAME with value "cred".
security/oc_pstat_internal.h Added constant OCF_SEC_PSTAT_STORE_NAME with value "pstat".
security/oc_u_ids_internal.h Added constant OCF_SEC_U_IDS_STORE_NAME with value "u_ids".
security/oc_store.c Replaced hardcoded strings with corresponding defined constants in functions related to loading and dumping security data.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant Device
    participant Storage
    participant SecurityManager

    Device->>SecurityManager: Check Ownership
    SecurityManager-->>Device: Ownership not established
    SecurityManager->>Storage: Clear pstat, cred, acl, u_ids, ael data
    Storage-->>SecurityManager: Data cleared
    SecurityManager-->>Device: Security data cleared
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Validate ownership and reset all resource storages if the device is not owned (#628)
Replace hardcoded strings with defined constants for better maintainability and readability (#628)

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 Configration 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 (c27a4a6), label this PR with OCF Conformance Testing.

⚠️ Label is removed with every code change.

Copy link

github-actions bot commented May 31, 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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4dd98e5 and c27a4a6.

Files selected for processing (1)
  • api/oc_main.c (3 hunks)
Additional comments not posted (1)
api/oc_main.c (1)

303-308: Verify the implementation of oc_sec_get_doxm and the owned property.

Ensure that the new conditional logic in main_load_resources correctly handles the device's ownership status without unintended side effects.

Verification successful

The verification process has provided the following insights:

  1. The oc_sec_get_doxm function definition was not found, indicating it might be defined differently or in a different pattern than expected.
  2. The owned property is widely used across the codebase, including in the security/oc_doxm.c file, which seems to handle the ownership status of devices.
  3. The main_set_resource_defaults function was found, confirming its existence and usage.

Given these findings, we need to ensure that the oc_sec_get_doxm function is correctly implemented and that the owned property is appropriately used within this function. Additionally, we should verify that the conditional logic in main_load_resources correctly handles the device's ownership status without unintended side effects.

To proceed, let's refine our search for the oc_sec_get_doxm function and ensure its correct implementation.


The refined search has provided the following insights:

  1. The oc_sec_get_doxm function is defined in security/oc_doxm.c.
  2. The owned property is used within the oc_sec_get_doxm function and other parts of the codebase.

Given these findings, we can confirm that the oc_sec_get_doxm function and the owned property are correctly implemented and used. The conditional logic in main_load_resources that checks the owned status and calls main_set_resource_defaults if the device is not owned appears to be correctly handling the device's ownership status.

Therefore, the review comment regarding the conditional logic in main_load_resources is verified to be correct.

  • oc_sec_get_doxm function is defined in security/oc_doxm.c.
  • The owned property is used appropriately within the codebase.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation and usage of `oc_sec_get_doxm` and the `owned` property.

# Test: Search for the function and property usage. Expect: Correct implementation and usage patterns.
ast-grep --lang c --pattern $'oc_sec_get_doxm($_) {
  $$$
  owned
  $$$
}'

Length of output: 75



Script:

#!/bin/bash
# Description: Verify the implementation and usage of `oc_sec_get_doxm` and the `owned` property.

# Step 1: Search for the definition of the `oc_sec_get_doxm` function.
ast-grep --lang c --pattern 'oc_sec_doxm_t *oc_sec_get_doxm($_) {
  $$$
}' 

# Step 2: Search for the usage of the `owned` property within the codebase.
rg --word-regexp 'owned'

# Step 3: Verify the usage of `main_set_resource_defaults` function.
ast-grep --lang c --pattern 'void main_set_resource_defaults($_) {
  $$$
}'

Length of output: 22400



Script:

#!/bin/bash
# Description: Refine the search for the `oc_sec_get_doxm` function definition and verify its implementation.

# Step 1: Search for the definition of the `oc_sec_get_doxm` function using a broader pattern.
rg --word-regexp 'oc_sec_get_doxm'

# Step 2: Verify the usage of the `owned` property within the `oc_sec_get_doxm` function.
ast-grep --lang c --pattern 'oc_sec_doxm_t *oc_sec_get_doxm($_) {
  $$$
  owned
  $$$
}'

Length of output: 2156

api/oc_main.c Outdated Show resolved Hide resolved
@sp-milos sp-milos added the OCF Conformance Testing OCF Conformance Testing required label May 31, 2024
api/oc_main.c Outdated Show resolved Hide resolved
api/oc_main.c Outdated Show resolved Hide resolved
@sp-milos
Copy link
Collaborator Author

I have read the CLA Document and I hereby sign the CLA.

@jkralik
Copy link
Member

jkralik commented May 31, 2024

recheck

api/oc_main.c Outdated Show resolved Hide resolved
github-actions bot added a commit that referenced this pull request May 31, 2024
@sp-milos
Copy link
Collaborator Author

recheck

@ocf-conformance-test-tool ocf-conformance-test-tool bot removed the OCF Conformance Testing OCF Conformance Testing required label May 31, 2024
@sp-milos sp-milos added the OCF Conformance Testing OCF Conformance Testing required label May 31, 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 c27a4a6 and d8b1a7e.

Files selected for processing (7)
  • api/oc_main.c (4 hunks)
  • security/oc_acl_internal.h (1 hunks)
  • security/oc_ael_internal.h (1 hunks)
  • security/oc_cred_internal.h (1 hunks)
  • security/oc_pstat_internal.h (1 hunks)
  • security/oc_store.c (15 hunks)
  • security/oc_u_ids_internal.h (1 hunks)
Files skipped from review due to trivial changes (5)
  • security/oc_acl_internal.h
  • security/oc_ael_internal.h
  • security/oc_cred_internal.h
  • security/oc_pstat_internal.h
  • security/oc_u_ids_internal.h
Additional comments not posted (8)
api/oc_main.c (2)

276-298: The implementation and documentation of main_sec_clear_resources are clear and align well with the PR's objectives.


312-318: The usage of main_sec_clear_resources within the ownership check is appropriate and well-placed.

security/oc_store.c (6)

95-100: Replacing hardcoded strings with constants like OCF_SEC_PSTAT_STORE_NAME enhances maintainability and reduces error potential.


114-114: Using constants for storage names in oc_sec_dump_pstat is a good practice.


234-240: The consistent use of constants for storage names in oc_sec_load_cred is commendable.


Line range hint 262-279: Good use of constants for storage names in oc_sec_dump_cred, enhancing code maintainability.


291-297: The consistent use of constants for storage names in oc_sec_load_acl is commendable.


Line range hint 318-335: Good use of constants for storage names in oc_sec_dump_acl, enhancing code maintainability.

@ocf-conformance-test-tool ocf-conformance-test-tool bot removed the OCF Conformance Testing OCF Conformance Testing required label May 31, 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 d8b1a7e and 4d25f75.

Files selected for processing (7)
  • api/oc_main.c (4 hunks)
  • security/oc_acl_internal.h (1 hunks)
  • security/oc_ael_internal.h (1 hunks)
  • security/oc_cred_internal.h (1 hunks)
  • security/oc_pstat_internal.h (1 hunks)
  • security/oc_store.c (15 hunks)
  • security/oc_u_ids_internal.h (1 hunks)
Files skipped from review as they are similar to previous changes (7)
  • api/oc_main.c
  • security/oc_acl_internal.h
  • security/oc_ael_internal.h
  • security/oc_cred_internal.h
  • security/oc_pstat_internal.h
  • security/oc_store.c
  • security/oc_u_ids_internal.h

@sp-milos
Copy link
Collaborator Author

I have read the CLA Document and I hereby sign the CLA

@sp-milos
Copy link
Collaborator Author

recheck

@Danielius1922
Copy link
Member

~format

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 4d25f75 and fea7c6b.

Files selected for processing (1)
  • security/oc_store.c (15 hunks)
Files skipped from review as they are similar to previous changes (1)
  • security/oc_store.c

Copy link

sonarcloud bot commented May 31, 2024

@Danielius1922 Danielius1922 merged commit b79efb1 into master May 31, 2024
124 checks passed
@Danielius1922 Danielius1922 deleted the sp-milos/issue-628 branch May 31, 2024 18:47
@github-actions github-actions bot locked and limited conversation to collaborators May 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent Ownership Validation and resources reset in IoTivity-Lite
3 participants