Repository navigation
Add MbedTLS example - #653
padelsbach wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Non-blocking TLS I/O mishandles retryable results and partial writes, while CI dependency fetching fails for SHA inputs and uses unpinned or potentially mismatched commits.
4 open issues
What changed in this PR
Adds an Mbed TLS 4.x client example using wolfPSA’s compatibility layer over wolfSSL, integrated with the repository’s example build and CI infrastructure.
Changes:
- Adds a TLS client with certificate verification and a non-blocking socket option.
- Adds build instructions and checks for TLS 1.2, TLS 1.3, and expected error cases.
- Registers the example in CI and adds dependency-fetch configuration.
| File | Description |
|---|---|
README.md |
Introduces and links the compatibility example. |
mbedtls-compat/README.md |
Documents building, running, testing, and compatibility limitations. |
mbedtls-compat/Makefile |
Builds the client and test servers and exposes check targets. |
mbedtls-compat/client-tls-mbedtls.c |
Implements the client using Mbed TLS APIs. |
mbedtls-compat/check.sh |
Checks protocol versions, socket modes, and error results. |
.gitignore |
Excludes generated example binaries. |
.github/workflows/examples.yml |
Passes the wolfSSL ref to dependency-fetch steps. |
.github/examples-manifest.yml |
Registers the example and its dependency builds. |
Review effort: Balanced
1fc1481 to
18ef181
Compare
18ef181 to
392995e
Compare
Frauschi
left a comment
There was a problem hiding this comment.
Builds and passes make check locally; a few comments on the test script and the client.
| while IFS='|' read -r name server opts expect; do | ||
| [ -z "$name" ] && continue | ||
| "$BIN_DIR/$server" >/dev/null 2>&1 & | ||
| srv=$! |
There was a problem hiding this comment.
If an earlier server still holds port 11111 (e.g. from the README steps), this server fails to bind and the client tests the old one, so the TLS 1.2 cases pass against a TLS 1.3 server. Check kill -0 $srv after the client runs and fail the case if the server is gone.
| ret = mbedtls_ssl_read(&ssl, buf, sizeof(buf) - 1); | ||
| } while (tls_want(ret) || | ||
| ret == MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET); | ||
| if (ret > 0) { |
There was a problem hiding this comment.
mbedtls_ssl_read() returns 0 when the peer closes without sending data, so this reports success with no response read. Treat ret == 0 as a failure; checking the server's reply in check.sh would also catch it.
| } | ||
| mbedtls_ssl_set_bio(&ssl, &net, mbedtls_net_send, mbedtls_net_recv, NULL); | ||
|
|
||
| while ((ret = mbedtls_ssl_handshake(&ssl)) != 0) { |
There was a problem hiding this comment.
With -N these loops retry WANT_READ/WANT_WRITE immediately and spin a core. Since this is meant to be copied, wait on the fd with poll() (POLLIN/POLLOUT) before retrying.
|
|
||
| ``` | ||
| make check-server-tls13 | ||
| ./check-server-tls13 & |
There was a problem hiding this comment.
The client can run before the server is listening, and the server keeps running afterwards and holds port 11111. Add a short sleep before the client and a kill %1 at the end.
| run_client() { | ||
| i=0 | ||
| while :; do | ||
| out=$($WRAP "$BIN_DIR/client-tls-mbedtls" $opts 127.0.0.1 2>&1) |
There was a problem hiding this comment.
Comparing out by exact string breaks with any WRAP that prints (valgrind banner, sanitizer reports): no retry happens and every case fails. Match only the last line of out instead.
| } | ||
| /* tls_get() retries on MBEDTLS_ERR_SSL_WANT_READ/WANT_WRITE */ | ||
| if (nonBlock && | ||
| fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL) | O_NONBLOCK) != 0) { |
There was a problem hiding this comment.
If F_GETFL fails this sets -1 | O_NONBLOCK, and F_SETFL only guarantees -1 on failure. Store the flags, check them for -1, and compare the F_SETFL result against -1.

Add the example from the docs repo to the examples repo