Skip to content

TLS support for esp32 using AsyncTCP/mbed-tls of fremouw #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

COMPONENT_ADD_INCLUDEDIRS := src/
COMPONENT_SRCDIRS := src/
COMPONENT_SRCDIRS += src/AsyncMqttClient
COMPONENT_SRCDIRS += src/AsyncMqttClient/Packets
17 changes: 16 additions & 1 deletion src/AsyncMqttClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -118,7 +124,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);
Expand Down Expand Up @@ -178,6 +191,7 @@ void AsyncMqttClient::_onConnect(AsyncClient* client) {
(void)client;

#if ASYNC_TCP_SSL_ENABLED
#ifndef ESP32
if (_secure && _secureServerFingerprints.size() > 0) {
SSL* clientSsl = _client.getSSL();

Expand All @@ -195,6 +209,7 @@ void AsyncMqttClient::_onConnect(AsyncClient* client) {
return;
}
}
#endif
#endif

char fixedHeader[5];
Expand Down
7 changes: 7 additions & 0 deletions src/AsyncMqttClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#endif

#if ASYNC_TCP_SSL_ENABLED
#ifdef ESP32
#include <tcp_mbedtls.h>
#else
#include <tcp_axtls.h>
#endif
#define SHA1_SIZE 20
#endif

Expand Down Expand Up @@ -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);
Expand Down