From fc4a14f7ac7282984b5e8717c7aab27ec112719c Mon Sep 17 00:00:00 2001 From: Franz Auernigg Date: Thu, 1 Oct 2020 01:48:32 +0200 Subject: [PATCH 1/3] add component.mk to simplify esp32 usage --- component.mk | 5 +++++ 1 file changed, 5 insertions(+) create mode 100755 component.mk diff --git a/component.mk b/component.mk new file mode 100755 index 0000000..b530e56 --- /dev/null +++ b/component.mk @@ -0,0 +1,5 @@ + +COMPONENT_ADD_INCLUDEDIRS := src/ +COMPONENT_SRCDIRS := src/ +COMPONENT_SRCDIRS += src/AsyncMqttClient +COMPONENT_SRCDIRS += src/AsyncMqttClient/Packets From 0c35ea688e979fe4a76f01d2c4ffe2020dfba59e Mon Sep 17 00:00:00 2001 From: Franz Auernigg Date: Thu, 1 Oct 2020 01:50:50 +0200 Subject: [PATCH 2/3] add esp32 tls support using AsyncTCP mbedtls branch Verify server using setRootCa instead of using a fingerprint. Use AsyncTCP mbedtls branch forked by fremouw --- src/AsyncMqttClient.cpp | 9 +++++++++ src/AsyncMqttClient.hpp | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/AsyncMqttClient.cpp b/src/AsyncMqttClient.cpp index 8fa959d..38af3e3 100644 --- a/src/AsyncMqttClient.cpp +++ b/src/AsyncMqttClient.cpp @@ -118,7 +118,14 @@ AsyncMqttClient& AsyncMqttClient::addServerFingerprint(const uint8_t* fingerprin _secureServerFingerprints.push_back(newFingerprint); return *this; } +#ifdef ESP32 +AsyncMqttClient& AsyncMqttClient::setRootCa(const char* rootca, const size_t len) { + _client.setRootCa(rootca, len); + return *this; +} #endif +#endif + AsyncMqttClient& AsyncMqttClient::onConnect(AsyncMqttClientInternals::OnConnectUserCallback callback) { _onConnectUserCallbacks.push_back(callback); @@ -178,6 +185,7 @@ void AsyncMqttClient::_onConnect(AsyncClient* client) { (void)client; #if ASYNC_TCP_SSL_ENABLED +#ifndef ESP32 if (_secure && _secureServerFingerprints.size() > 0) { SSL* clientSsl = _client.getSSL(); @@ -195,6 +203,7 @@ void AsyncMqttClient::_onConnect(AsyncClient* client) { return; } } +#endif #endif char fixedHeader[5]; diff --git a/src/AsyncMqttClient.hpp b/src/AsyncMqttClient.hpp index 4f41210..f06c7a3 100644 --- a/src/AsyncMqttClient.hpp +++ b/src/AsyncMqttClient.hpp @@ -15,7 +15,11 @@ #endif #if ASYNC_TCP_SSL_ENABLED +#ifdef ESP32 +#include +#else #include +#endif #define SHA1_SIZE 20 #endif @@ -62,6 +66,9 @@ class AsyncMqttClient { #if ASYNC_TCP_SSL_ENABLED AsyncMqttClient& setSecure(bool secure); AsyncMqttClient& addServerFingerprint(const uint8_t* fingerprint); +#ifdef ESP32 + AsyncMqttClient& setRootCa(const char* rootca, const size_t len); + #endif #endif AsyncMqttClient& onConnect(AsyncMqttClientInternals::OnConnectUserCallback callback); From dd00c78cd0adc4709a5a662cbff70a613e325ea2 Mon Sep 17 00:00:00 2001 From: Franz Auernigg Date: Thu, 1 Oct 2020 01:53:10 +0200 Subject: [PATCH 3/3] fix compiler warning parsingInformation not initialized --- src/AsyncMqttClient.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/AsyncMqttClient.cpp b/src/AsyncMqttClient.cpp index 38af3e3..86041d8 100644 --- a/src/AsyncMqttClient.cpp +++ b/src/AsyncMqttClient.cpp @@ -24,7 +24,13 @@ AsyncMqttClient::AsyncMqttClient() , _willPayloadLength(0) , _willQos(0) , _willRetain(false) -, _parsingInformation { .bufferState = AsyncMqttClientInternals::BufferState::NONE } +, _parsingInformation { .bufferState = AsyncMqttClientInternals::BufferState::NONE, + .maxTopicLength = 0, + .topicBuffer = NULL, + .packetType = 0, + .packetFlags = 0, + .remainingLength = 0 + } , _currentParsedPacket(nullptr) , _remainingLengthBufferPosition(0) , _nextPacketId(1) {