pkg/mbedtls: add TLS support for LWIP#17519
Conversation
|
Please rebase. |
|
It should not be necessary to copy the mbedtls header files into pkg/mbedtls/include/ |
5db9d9f to
f31f73e
Compare
| #if !defined(unix) && !defined(__unix__) && !defined(__unix) && \ | ||
| !defined(__APPLE__) && !defined(_WIN32) && !defined(__QNXNTO__) && \ | ||
| - !defined(__HAIKU__) && !defined(__midipix__) | ||
| + !defined(__HAIKU__) && !defined(__midipix__) && defined(_RIOT_) |
There was a problem hiding this comment.
Shouldn't this be
| + !defined(__HAIKU__) && !defined(__midipix__) && defined(_RIOT_) | |
| + !defined(__HAIKU__) && !defined(__midipix__) && !defined(RIOT_VERSION) |
tests/mbedtls_test/Makefile
Outdated
| USEMODULE += shell_commands | ||
| USEMODULE += ps | ||
| # Add atwinc15x0 driver | ||
| USEMODULE += atwinc15x0 |
There was a problem hiding this comment.
No need to force the use of this driver, sam0_eth, netdev_tap or esp_wifi would work as well - just use netdev_default
tests/mbedtls_test/Makefile
Outdated
| -DATWINC15X0_PARAM_WAKE_PIN="GPIO_PIN(0, 7)" | ||
| CFLAGS += -DCONFIG_ENTROPY_SOURCE_ADC_HMIN="200" | ||
| CFLAGS += -DISR_STACK_SIZE=4096 | ||
| CFLAGS += -DHOST_SERVER="\"10.0.110.117\"" |
There was a problem hiding this comment.
Let's set this using a shell command. Then we also don't need a separate thread - just bump THREAD_STACKSIZE_MAIN if necessary.
static int cmd_tls_connect(int argc, char **argv)
{
if (argc < 3) {
printf("usage: %s <host> <port> [data]\n", argv[0]);
return -1;
}
return _lwip_mbedtls_client(argv[1], argv[2]);
}
static const shell_command_t shell_commands[] = {
{ "connect", "Perform a TLS connection", cmd_tls_connect },
{ NULL, NULL, NULL }
};
tests/mbedtls_test/main.c
Outdated
| (void)arg; | ||
| int status; | ||
|
|
||
| xtimer_sleep(20); |
There was a problem hiding this comment.
Then you can also drop the delay
tests/mbedtls_test/main.c
Outdated
| while(1) { | ||
| DEBUG_PUTS("_lwip_mbedtls_client_thread: sending encrypted hello world to server is DONE :) "); | ||
| xtimer_sleep(10); | ||
| } | ||
|
|
||
| error: | ||
| while(1) { | ||
| DEBUG_PUTS("FAILED"); | ||
| xtimer_sleep(20); | ||
| } | ||
| return NULL; |
There was a problem hiding this comment.
No need to loop here - just return
tests/mbedtls_test/main.c
Outdated
| DEBUG_PUTS("_lwip_mbedtls_client_thread: server connect succeeded"); | ||
|
|
||
| //verify certificate belongs to the server | ||
| status = mbedtls_ssl_set_hostname(&ssl, "mariem.com"); |
There was a problem hiding this comment.
example.com is usually used for this 😉
tests/mbedtls_test/main.c
Outdated
| mbedtls_net_context server_fd; | ||
| mbedtls_entropy_context entropy; | ||
| mbedtls_ctr_drbg_context ctr_drbg; | ||
| mbedtls_ssl_context ssl; | ||
| mbedtls_ssl_config conf; | ||
| mbedtls_x509_crt x509_certificate; |
There was a problem hiding this comment.
do those have to be global?
tests/mbedtls_test/main.c
Outdated
|
|
||
| // send hello world to the server | ||
| unsigned char write_buf[]="Hello world\n"; | ||
| size_t write_buf_len = sizeof(write_buf) -1; |
There was a problem hiding this comment.
We could also use data the user supplied as a shell command argument here
pkg/lwip/include/arch/sys_arch.h
Outdated
| /** | ||
| * @brief Use `random_uint32()` to generate random numbers, if available | ||
| */ | ||
| #if MBEDTLS_ENABLED == 0 |
There was a problem hiding this comment.
Please fix the trailing whitespaces and the horizontal tabs mentioned by the automatic checks.
| @@ -0,0 +1 @@ | |||
| #include "lwip/netdb.h" | |||
There was a problem hiding this comment.
Maybe this and the other one can be a symlink instead? It seems they are already used in the tree.
| /** @ingroup socket */ | ||
| #define close(s) lwip_close(s) | ||
| /** @ingroup socket */ | ||
| +#if MBEDTLS_ENABLED == 0 |
There was a problem hiding this comment.
Please edit the patch to explain why this is done.
67d7b3a to
15a9608
Compare
| #endif | ||
| /** @endcond */ | ||
|
|
||
| #if MBEDTLS_ENABLED == 1 |
pkg/lwip/include/arch/sys_arch.h
Outdated
| /** | ||
| * @brief Use `random_uint32()` to generate random numbers, if available | ||
| */ | ||
| #if MBEDTLS_ENABLED == 0 |
There was a problem hiding this comment.
This seems strange - it (LWIP_RAND) is set to the same value in lwipopts? Why is this needed?
There was a problem hiding this comment.
I added (LWIP_RAND) in lwipopts in order to be recognized in build/pkg/lwip/src/core/dns.c:103
But it is already defined in pkg/lwip/include/arch/sys_arch.h:133
=> This will create a redefiniton, therefore I added #if MBEDTLS_ENABLED == 0
There was a problem hiding this comment.
But you define it to the same thing there: random_uint32(). Why not just keep this and remove your extra definition? Make sure the random module is enabled and things should be fine.
6f6a3b7 to
a3fbe69
Compare
| * | ||
| * This module is required for SSL/TLS. | ||
| */ | ||
| #if CONFIG_MBEDTLS_SSL_TLS_C |
1570e1c to
a8092c4
Compare
tests/mbedtls_test/Kconfig
Outdated
| bool "Enable debug messages" | ||
| default y | ||
|
|
||
| endif #KCONFIG_USEMODULE_MBEDTLS_TEST |
There was a problem hiding this comment.
- Do you actually need all symbols? Please only add those that are required.
- It seem to me that these configs should go into this file which is the Kconfig based point to generate the traditional mbedtls configuration header file.
There was a problem hiding this comment.
- Yes, all of them are needed, mainly each module requires a few other modules to work correctly therefore it seems quite a lot.
- Do you mean all of them should be added in pkg/mbedtls/Kconfig?
There was a problem hiding this comment.
Sorry for responding so late, haven't seen this question. Yes, all of the configuration values that are needed. Please check the existing file Kconfig file (+ existing header file) that I pointed to earlier.
4876473 to
6c519d6
Compare
|
@mariemC thanks for cleaning up the configuration files. The implementation and its representation in menuconfig look good at first sight. I do, unfortunately, not have time for a full review + testing. Anyway, some thoughts on the rest of the PR:
|
Contribution description
Testing procedure
Issues/PRs references
-Depends on PR #15671