Skip to content

ports/esp32: Enable mbedtls cert time validation. - #13100

Merged
dpgeorge merged 1 commit into
micropython:masterfrom
Carglglz:esp32_mbedtls_time
Dec 3, 2023
Merged

dpgeorge merged 1 commit into
micropython:masterfrom
Carglglz:esp32_mbedtls_time

Conversation

@Carglglz

@Carglglz Carglglz commented Nov 30, 2023 •

Copy link
Copy Markdown
Contributor

WIP

Comment thread ports/esp32/main.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you want to include #include "mbedtls/platform.h" instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

mbedtls/platform.h includes mbedtls/platform_time.h, since this only requires mbedtls_platform_set_time I think it's simpler to include platform_time directly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yep, sounds good!

Comment thread ports/esp32/main.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this set of includes is needed??

Comment thread ports/esp32/esp32_common.cmake Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This line should not be needed.

Comment thread ports/esp32/mbedtls/mbedtls_port.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't you use #ifdef MBEDTLS_PLATFORM_TIME_ALT here instead?

@Carglglz
Carglglz force-pushed the esp32_mbedtls_time branch 3 times, most recently from 8407d27 to 93aff62 Compare December 3, 2023 00:15
@Carglglz
Carglglz marked this pull request as ready for review December 3, 2023 00:23
Comment thread ports/esp32/mbedtls/mbedtls_config.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see that this file is indeed included in the build. But that seems to be by accident: esp-idf/components/mbedtls/port/include/mbedtls/esp_config.h includes mbedtls/mbedtls_config.h which is intended to pick up the default mbedtls_config.h from the mbedtls component of the IDF.

So having this file here will completely override the default set of settings.

Why is this file needed? I don't think the MBEDTLS_HAVE_ASM option does anything, that seems to only be needed for x84 architectures.

Comment thread ports/esp32/mbedtls/mbedtls_port.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To keep things simple, you could just put this function in main.c, before the mp_task() function. Then this separate file is not needed, nor are any additional headers like mbedtls_config.h.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, I've just tested this and it is in fact the simplest option, thanks for the help again 🙏🏼 !!

@dpgeorge

dpgeorge commented Dec 3, 2023

Copy link
Copy Markdown
Member

This looks much better now. Is it ready to be merged?

@Carglglz

Carglglz commented Dec 3, 2023

Copy link
Copy Markdown
Contributor Author

Yes I've been testing this and it works as expected 👍🏼 .

With this commit now all ports that use mbedtls have cert time validation enabled, so I think a note should be added to SSL/TLS documentation for ssl.CERT_REQUIRED option e.g.

ssl.CERT_REQUIRED

This option requires RTC to be properly set

otherwise MBEDTLS_ERR_X509_CERT_VERIFY_FAILED will be raised or after #13098

ValueError:
The certificate validity starts in the future

@dpgeorge
dpgeorge merged commit 30b0ee3 into micropython:master Dec 3, 2023
@dpgeorge

dpgeorge commented Dec 4, 2023

Copy link
Copy Markdown
Member

Thanks for testing. Now merged.

@Carglglz
Carglglz deleted the esp32_mbedtls_time branch December 4, 2023 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants