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

Link to system mbedtls #356

Merged
merged 3 commits into from
Jan 31, 2023
Merged

Conversation

Oxymoron79
Copy link
Collaborator

This PR adds a BUILD_MBEDTLS CMake option:

  • If set to ON (default) the mbedtls library is patched and built by the iotivity-lite build system.
  • If set to OFF, the iotivity-lite build system searches for the mbedtls library using CMake's find_package function and verifies that the library has been built with the OCF patches applied.

To test this feature, I used patched, built and installed the mbedtls library from the deps/mbedtls submodule before building iotivity-lite:
To patch mbedtls I used the deps/mbedtls-patch.cmake script:

$ cmake -DOC_DYNAMIC_ALLOCATION_ENABLED=ON -DOC_PKI_ENABLED=ON -P deps/mbedtls-patch.cmake

Then I configured, built and installed mbedtls as a shared library:

$ cd deps/mbedtls
$ cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=ON .
$ make install

After that, with BUILD_MBEDTLS=OFF iotivity-lite was able to

  • find the mbedtls shared library with the find_package function
  • verify that mbedtls was patched by checking for the mbedtls_x509write_crt_set_subject_alt_names function
  • compile iotivity-lite and link to the mbedtls shared library

But to make the patched mbedtls library compile successfully, I had to modify the OCF patches and remove the generic entropy pool setting, since that requires parts of the iotivity-lite sources.

I am not sure what impact this modification of the OCF patches for mbedtls has and whether that would be acceptable.
I also haven't tested whether BUILD_MBEDTLS=OFF works on all platforms and with different build configurations.

@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 (4be1348), label this PR with OCF Conformance Testing.

⚠️ Label is removed with every code change.

@Danielius1922
Copy link
Member

Nice job, Martin!

We've talked with @jkralik and if we understand the problem with the MBEDTLS_ENTROPY_C correct, the issue is that mbedtls_platform_entropy_poll is added by the patch. Which includes port/oc_random.h and uses oc_random_value from iotivity-lite. So we decided that instead of directly using oc_random_value I will update the patch and add a function pointer and a setter for this pointer to mbedtls and this pointer will be used instead of oc_random_value. Iotivity lite will set this function to oc_random_value() when it initializes mbedtls.
Similar issue might be with MBEDTLS_PLATFORM_STD_EXIT which is defined as oc_exit, but we will solve it the same way. And this should allow us to keep MBEDTLS_ENTROPY_C enabled. I'll add commits to this PR if that's OK.

Also to test the various compilation options I'm thinking about modifying the GH workflows. In most workflows we have workflow_dispatch enabled, so one can run a workflow manually. And dispatching can be parameterized. I'll add a bool, which controls whether preinstalled or submodule mbedtls should be used. The workflows will need to be modified to add an mbedtls installation step, but that shouldn't be complicated.

@Danielius1922 Danielius1922 force-pushed the Oxymoron79/feature/use-system-mbedtls branch 14 times, most recently from 19f0495 to af387f0 Compare January 27, 2023 12:43
@Danielius1922 Danielius1922 marked this pull request as ready for review January 30, 2023 13:42
@Danielius1922 Danielius1922 force-pushed the Oxymoron79/feature/use-system-mbedtls branch from af387f0 to fc0827a Compare January 31, 2023 10:00
@Danielius1922 Danielius1922 added the OCF Conformance Testing OCF Conformance Testing required label Jan 31, 2023
Oxymoron79 and others added 3 commits January 31, 2023 11:30
If set to ON (default) the mbedtls library is patched and built by the
iotivity-lite build system.
If set to OFF, the iotivity-lite build system searches for the mbedtls
library using CMake's find_package function and verifies that the library
has been built with the OCF patches applied.
- Allow compilation will clang
- Make tests that use CMake to build configurable, so they can be
built in such a way that they preinstall mbedTLS and then use the
preinstalled libraries.
- remove patched in implementation of mbedtls_platform_entropy_poll using oc_random_value
- remove obsolete __OC_RANDOM
- implement mbedtls entropy source using oc_entropy_value and use public API
mbedtls_entropy_add_source to add it to mbedTLS

- add mbedtls_oc_platform-standalone.h.in when building mbedtls with standalone programs
which don't link with iotivity-lite. This file is processed by CMake, which then creates
mbedtls_oc_platform.h. This header is included by mbedtls_config.h and defines some of the
defines needed by mbedTLS configuration which otherwise would be defined from included
iotivity-lite headers.
@Danielius1922 Danielius1922 force-pushed the Oxymoron79/feature/use-system-mbedtls branch from fc0827a to 7bd43e4 Compare January 31, 2023 10:33
@ocf-conformance-test-tool ocf-conformance-test-tool bot removed the OCF Conformance Testing OCF Conformance Testing required label Jan 31, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

90.5% 90.5% Coverage
0.0% 0.0% Duplication

@Danielius1922 Danielius1922 added the OCF Conformance Testing OCF Conformance Testing required label Jan 31, 2023
@Danielius1922 Danielius1922 merged commit 88b27e0 into master Jan 31, 2023
@Danielius1922 Danielius1922 deleted the Oxymoron79/feature/use-system-mbedtls branch January 31, 2023 21:22
@github-actions github-actions bot locked and limited conversation to collaborators Jan 31, 2023
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.

3 participants