Skip to content

Commit

Permalink
Refactor SSL to only compile when enabled (#if ASYNC_TCP_SSL_ENABLED)
Browse files Browse the repository at this point in the history
(cherry picked from commit 2a8a8f1)
  • Loading branch information
timpur authored and kleini committed Mar 24, 2019
1 parent c63aeb6 commit 050cc8b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Homie/Boot/BootNormal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void BootNormal::setup() {
Interface::get().getLogger() << "SSL is: " << Interface::get().getConfig().get().mqtt.server.ssl.enabled << endl;
Interface::get().getMqttClient().setSecure(Interface::get().getConfig().get().mqtt.server.ssl.enabled);
if (Interface::get().getConfig().get().mqtt.server.ssl.enabled && Interface::get().getConfig().get().mqtt.server.ssl.hasFingerprint) {
char hexBuf[MAX_FINGERPRINT_SIZE * 2 + 1];
char hexBuf[MAX_FINGERPRINT_STRING_LENGTH];
Helpers::byteArrayToHexString(Interface::get().getConfig().get().mqtt.server.ssl.fingerprint, hexBuf, MAX_FINGERPRINT_SIZE);
Interface::get().getLogger() << "Using fingerprint: " << hexBuf << endl;
Interface::get().getMqttClient().addServerFingerprint((const uint8_t*)Interface::get().getConfig().get().mqtt.server.ssl.fingerprint);
Expand Down
6 changes: 5 additions & 1 deletion src/Homie/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ bool Config::load() {
strlcpy(_configStruct.wifi.dns1, reqWifiDns1, MAX_IP_STRING_LENGTH);
strlcpy(_configStruct.wifi.dns2, reqWifiDns2, MAX_IP_STRING_LENGTH);
strlcpy(_configStruct.mqtt.server.host, reqMqttHost, MAX_HOSTNAME_LENGTH);
#if ASYNC_TCP_SSL_ENABLED
_configStruct.mqtt.server.ssl.enabled = reqMqttSsl;
if (strcmp_P(reqMqttFingerprint, PSTR("")) != 0) {
_configStruct.mqtt.server.ssl.hasFingerprint = true;
Helpers::hexStringToByteArray(reqMqttFingerprint, _configStruct.mqtt.server.ssl.fingerprint, MAX_FINGERPRINT_SIZE);
}
#endif
_configStruct.mqtt.server.port = reqMqttPort;
strlcpy(_configStruct.mqtt.baseTopic, reqMqttBaseTopic, MAX_MQTT_BASE_TOPIC_LENGTH);
_configStruct.mqtt.auth = reqMqttAuth;
Expand Down Expand Up @@ -352,12 +354,14 @@ void Config::log() const {
Interface::get().getLogger() << F(" • MQTT: ") << endl;
Interface::get().getLogger() << F(" ◦ Host: ") << _configStruct.mqtt.server.host << endl;
Interface::get().getLogger() << F(" ◦ Port: ") << _configStruct.mqtt.server.port << endl;
#if ASYNC_TCP_SSL_ENABLED
Interface::get().getLogger() << F(" ◦ SSL enabled: ") << (_configStruct.mqtt.server.ssl.enabled ? "true" : "false") << endl;
if (_configStruct.mqtt.server.ssl.enabled && _configStruct.mqtt.server.ssl.hasFingerprint) {
char hexBuf[MAX_FINGERPRINT_SIZE * 2 + 1];
char hexBuf[MAX_FINGERPRINT_STRING_LENGTH];
Helpers::byteArrayToHexString(Interface::get().getConfig().get().mqtt.server.ssl.fingerprint, hexBuf, MAX_FINGERPRINT_SIZE);
Interface::get().getLogger() << F(" ◦ Fingerprint: ") << hexBuf << endl;
}
#endif
Interface::get().getLogger() << F(" ◦ Base topic: ") << _configStruct.mqtt.baseTopic << endl;
Interface::get().getLogger() << F(" ◦ Auth? ") << (_configStruct.mqtt.auth ? F("yes") : F("no")) << endl;
if (_configStruct.mqtt.auth) {
Expand Down
2 changes: 2 additions & 0 deletions src/Homie/Datatypes/ConfigStruct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ struct ConfigStruct {
struct Server {
char host[MAX_HOSTNAME_LENGTH];
uint16_t port;
#if ASYNC_TCP_SSL_ENABLED
struct {
bool enabled;
bool hasFingerprint;
uint8_t fingerprint[MAX_FINGERPRINT_SIZE];
} ssl;
#endif
} server;
char baseTopic[MAX_MQTT_BASE_TOPIC_LENGTH];
bool auth;
Expand Down
1 change: 1 addition & 0 deletions src/Homie/Limits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace HomieInternals {
const uint8_t MAX_WIFI_PASSWORD_LENGTH = 64 + 1;
const uint16_t MAX_HOSTNAME_LENGTH = 255 + 1;
const uint8_t MAX_FINGERPRINT_SIZE = 20;
const uint8_t MAX_FINGERPRINT_STRING_LENGTH = (MAX_FINGERPRINT_SIZE *2) + 1;

const uint8_t MAX_MQTT_CREDS_LENGTH = 32 + 1;
const uint8_t MAX_MQTT_BASE_TOPIC_LENGTH = 48 + 1;
Expand Down

0 comments on commit 050cc8b

Please sign in to comment.