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
  • Loading branch information
timpur committed Jan 1, 2018
1 parent 3a15a2b commit 2a8a8f1
Show file tree
Hide file tree
Showing 3 changed files with 8 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 @@ -127,11 +127,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_STRING_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_STRING_LENGTH);
_configStruct.mqtt.auth = reqMqttAuth;
Expand Down Expand Up @@ -422,12 +424,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_STRING_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_STRING_LENGTH];
bool auth;
Expand Down

0 comments on commit 2a8a8f1

Please sign in to comment.