Skip to content

Commit 73b3293

Browse files
authored
Merge pull request #610 from david-cermak/feat/mosq_tls
[mosq]: Added TLS transport to mosquitto port
2 parents f5dc07f + f613c70 commit 73b3293

19 files changed

+673
-24
lines changed

.github/workflows/mosq__build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
- name: Run Test
6565
working-directory: ${{ env.TEST_DIR }}
6666
run: |
67+
python -m pip install pytest-embedded-serial-esp pytest-embedded-idf pytest-rerunfailures pytest-timeout pytest-ignore-test-results
6768
unzip ci/artifacts.zip -d ci
6869
for dir in `ls -d ci/build_*`; do
6970
rm -rf build sdkconfig.defaults

.github/workflows/publish-docs-component.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ jobs:
9999
components/console_cmd_ifconfig;
100100
components/console_cmd_wifi;
101101
components/mbedtls_cxx;
102+
components/mosquitto;
102103
namespace: "espressif"
103104
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@ Please refer to instructions in [ESP-IDF](https://github.com/espressif/esp-idf)
5757
### mbedtls_cxx
5858

5959
* Brief introduction [README](components/mbedtls_cxx/README.md)
60+
61+
### mosquitto
62+
63+
* Brief introduction [README](components/mosquitto/README.md)
64+
* API documentation [api.md](components/mosquitto/api.md)

ci/check_copyright_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ mosquitto_component:
5353
allowed_licenses:
5454
- EPL-2.0
5555
- Apache-2.0
56+
- BSD-3-Clause
5657

5758
slim_modem_examples:
5859
include:

components/mosquitto/.cz.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
---
12
commitizen:
23
bump_message: 'bump(mosq): $current_version -> $new_version'
3-
pre_bump_hooks: python ../../ci/changelog.py mosq
4+
pre_bump_hooks: python ../../ci/changelog.py mosquitto
45
tag_format: mosq-v$version
5-
version: 2.0.27
6+
version: 2.0.28~0
67
version_files:
7-
- idf_component.yml
8+
- idf_component.yml

components/mosquitto/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## [2.0.28~0](https://github.com/espressif/esp-protocols/commits/mosq-v2.0.28_0)
2+
3+
### Features
4+
5+
- Added support for TLS transport using ESP-TLS ([1af4bbe1](https://github.com/espressif/esp-protocols/commit/1af4bbe1))
6+
- Add API docs, memory consideration and tests ([a20c0c9d](https://github.com/espressif/esp-protocols/commit/a20c0c9d))
7+
- Add target tests with localhost broker-client ([5c850cda](https://github.com/espressif/esp-protocols/commit/5c850cda))
8+
- Initial moquitto v2.0.18 port (TCP only) ([de4531e8](https://github.com/espressif/esp-protocols/commit/de4531e8))
9+
10+
### Bug Fixes
11+
12+
- Fix clean compilation addressing _GNU_SOURCE redefined ([e2392c36](https://github.com/espressif/esp-protocols/commit/e2392c36))
13+
14+
### Updated
15+
16+
- docs(mosq): Prepare mosquitto component for publishing ([c2c4bf83](https://github.com/espressif/esp-protocols/commit/c2c4bf83))

components/mosquitto/CMakeLists.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ set(m_deps_dir ${m_dir}/deps)
77
set(m_srcs
88
${m_lib_dir}/memory_mosq.c
99
${m_lib_dir}/util_mosq.c
10-
${m_lib_dir}/net_mosq.c
1110
${m_lib_dir}/will_mosq.c
1211
${m_lib_dir}/alias_mosq.c
1312
${m_lib_dir}/send_mosq.c
@@ -46,7 +45,6 @@ set(m_srcs
4645
${m_src_dir}/mux.c
4746
${m_src_dir}/mux_epoll.c
4847
${m_src_dir}/mux_poll.c
49-
${m_src_dir}/net.c
5048
${m_src_dir}/password_mosq.c
5149
${m_src_dir}/persist_read.c
5250
${m_src_dir}/persist_read_v234.c
@@ -73,20 +71,26 @@ set(m_srcs
7371
${m_src_dir}/xtreport.c)
7472

7573
idf_component_register(SRCS ${m_srcs}
76-
port/callbacks.c port/config.c port/signals.c port/ifaddrs.c port/broker.c port/files.c
74+
port/callbacks.c
75+
port/config.c
76+
port/signals.c
77+
port/ifaddrs.c
78+
port/broker.c
79+
port/files.c
80+
port/net__esp_tls.c
7781
PRIV_INCLUDE_DIRS port/priv_include port/priv_include/sys ${m_dir} ${m_src_dir}
7882
${m_incl_dir} ${m_lib_dir} ${m_deps_dir}
7983
INCLUDE_DIRS ${m_incl_dir} port/include
80-
PRIV_REQUIRES newlib
84+
PRIV_REQUIRES newlib esp-tls
8185
)
8286

8387
target_compile_definitions(${COMPONENT_LIB} PRIVATE "WITH_BROKER")
8488
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
8589

86-
# Some mosquittos source unconditionally define `_GNU_SOURCE` which collides with IDF build system
90+
# Some mosquitto source unconditionally define `_GNU_SOURCE` which collides with IDF build system
8791
# producing warning: "_GNU_SOURCE" redefined
8892
# This workarounds this issue by undefining the macro for the selected files
89-
set(sources_that_define_gnu_source ${m_lib_dir}/net_mosq.c ${m_src_dir}/loop.c ${m_src_dir}/mux_poll.c)
93+
set(sources_that_define_gnu_source ${m_src_dir}/loop.c ${m_src_dir}/mux_poll.c)
9094
foreach(offending_src ${sources_that_define_gnu_source})
9195
set_source_files_properties(${offending_src} PROPERTIES COMPILE_OPTIONS "-U_GNU_SOURCE")
9296
endforeach()

components/mosquitto/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# ESP32 Mosquitto Port
22

3-
This is a lightweight port of the Mosquitto broker designed to run on the ESP32. It currently supports a single listener and TCP transport only.
3+
This is a lightweight port of the Mosquitto broker designed to run on the ESP32. It currently supports a single listener with TCP transport or TLS transport based on ESP-TLS library.
44

55
## Supported Options
66

7-
The Espressif port supports a limited set of options (with plans to add more in future releases). These options can be configured through a structure passed to the `mosq_broker_start()` function. For detailed information on available configuration options, refer to the [API documentation](api.md).
7+
The Espressif port supports a limited set of options (with plans to add more in future releases). These options can be configured through a structure passed to the `mosq_broker_run()` function. For detailed information on available configuration options, refer to the [API documentation](api.md).
88

99
## API
1010

1111
### Starting the Broker
1212

13-
To start the broker, call the `mosq_broker_start()` function with a properly configured settings structure. The broker operates in the context of the calling task and does not create a separate task.
13+
To start the broker, call the `mosq_broker_run()` function with a properly configured settings structure. The broker operates in the context of the calling task and does not create a separate task.
1414

1515
It's recommended to analyze the stack size needed for the task, but in general, the broker requires at least 4 kB of stack size.
1616

1717
```c
18-
mosq_broker_start(&config);
18+
mosq_broker_run(&config);
1919
```
2020
2121
## Memory Footprint Considerations

components/mosquitto/api.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
| Type | Name |
2222
| ---: | :--- |
23-
| int | [**mosq\_broker\_start**](#function-mosq_broker_start) (struct [**mosq\_broker\_config**](#struct-mosq_broker_config) \*config) <br>_Start mosquitto broker._ |
23+
| int | [**mosq\_broker\_run**](#function-mosq_broker_run) (struct [**mosq\_broker\_config**](#struct-mosq_broker_config) \*config) <br>_Start mosquitto broker._ |
24+
| void | [**mosq\_broker\_stop**](#function-mosq_broker_stop) (void) <br>_Stops running broker._ |
2425

2526

2627
## Structures and Types Documentation
@@ -37,14 +38,16 @@ Variables:
3738

3839
- int port <br>Port number of the broker to listen to
3940

41+
- esp\_tls\_cfg\_server\_t \* tls_cfg <br>ESP-TLS configuration (if TLS transport used) Please refer to the ESP-TLS official documentation for more details on configuring the TLS options. You can open the respective docs with this idf.py command: `idf.py docs -sp api-reference/protocols/esp_tls.html`
42+
4043

4144
## Functions Documentation
4245

43-
### function `mosq_broker_start`
46+
### function `mosq_broker_run`
4447

4548
_Start mosquitto broker._
4649
```c
47-
int mosq_broker_start (
50+
int mosq_broker_run (
4851
struct mosq_broker_config *config
4952
)
5053
```
@@ -63,3 +66,16 @@ This API runs the broker in the calling thread and blocks until the mosquitto ex
6366
**Returns:**
6467

6568
int Exit code (0 on success)
69+
### function `mosq_broker_stop`
70+
71+
_Stops running broker._
72+
```c
73+
void mosq_broker_stop (
74+
void
75+
)
76+
```
77+
78+
79+
**Note:**
80+
81+
After calling this API, function mosq\_broker\_run() unblocks and returns.

components/mosquitto/examples/broker/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Overview
44

5-
This example runs a TCP broker on a specified host and port.
5+
This example runs a broker on TLS or TCP transport, specified host and port.
66

77
### How to use this example
88

@@ -13,6 +13,19 @@ If you enabled also the mqtt client, this example will connect to the local brok
1313

1414
You can connect to the ESP32 mosquitto broker using some other client using the ESP32 IPv4 address and the port specified in the project configuration menu.
1515

16+
> [!IMPORTANT]
17+
> The certificates and keys provided in this example are intended for testing purposes only. They are self-signed, single-use, and configured with a common name of "127.0.0.1". Do not reuse these credentials in any production or real-world applications, as they are not secure for such environments.
18+
19+
For more information on setting up TLS configuration (including certificates and keys), please refer to the ESP-TLS documentation:
20+
```bash
21+
idf.py docs -sp api-reference/protocols/esp_tls.html
22+
```
23+
24+
Configuring the TLS option for the broker is quite similar to setting it up for an HTTPS server, as both involve server-side security configuration. Refer to the HTTPS server documentation for details:
25+
```bash
26+
idf.py docs -sp api-reference/protocols/esp_https_server.html
27+
```
28+
1629
### Test version
1730

1831
This example is also used for testing on loopback interface only, disabling any actual connection, just using the local mqtt client to the loopback interface.

0 commit comments

Comments
 (0)