Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
slav-at-attachix committed Mar 23, 2021
1 parent dfbf8c1 commit 237fa66
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Sming/Libraries/OtaUpgradeMqtt/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ endif

# If enabled (set to 1) then we can use unlimited number of patch versions
COMPONENT_VARS += ENABLE_OTA_VARINT_VERSION
ENABLE_OTA_VARINT_VERSION ?= 1
ENABLE_OTA_VARINT_VERSION ?= 1

COMPONENT_CXXFLAGS := -DENABLE_OTA_ADVANCED=$(ENABLE_OTA_ADVANCED) \
-DENABLE_OTA_VARINT_VERSION=$(ENABLE_OTA_VARINT_VERSION)
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void otaUpdate()
#ifdef ENABLE_SSL
mqtt.setSslInitHandler([](Ssl::Session& session) {
// These fingerprints change very frequently.
static const Ssl::Fingerprint::Cert::Sha1 sha1Fingerprint PROGMEM = { MQTT_FINGERPRINT_SHA1 };
static const Ssl::Fingerprint::Cert::Sha1 sha1Fingerprint PROGMEM = {MQTT_FINGERPRINT_SHA1};

// Trust certificate only if it matches the SHA1 fingerprint...
session.validators.pin(sha1Fingerprint);
Expand Down
13 changes: 9 additions & 4 deletions Sming/Libraries/OtaUpgradeMqtt/src/PayloadParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Mqtt
{
int PayloadParser::parse(MqttPayloadParserState& state, mqtt_message_t* message, const char* buffer, int length)
{
if(message == nullptr || buffer == nullptr) {
if(message == nullptr) {
debug_e("Invalid MQTT message");
return ERROR_INVALID_MQTT_MESSAGE;
}
Expand Down Expand Up @@ -46,16 +46,21 @@ int PayloadParser::parse(MqttPayloadParserState& state, mqtt_message_t* message,
delete updateState->stream;
delete updateState;
if(success) {
debug_d("Swtiching was successful. Restarting...");
debug_d("Switching was successful. Restarting...");
System.restart();
} else {
debug_e("Swtiching failed!");
debug_e("Switching failed!");
}
}

return 0;
}

if(buffer == nullptr) {
debug_e("Invalid MQTT message");
return ERROR_INVALID_MQTT_MESSAGE;
}

if(!updateState->started) {
size_t offset = 0;
int patchVersion = getPatchVersion(buffer, length, offset, updateState->version);
Expand Down Expand Up @@ -104,7 +109,7 @@ int PayloadParser::getPatchVersion(const char* buffer, int length, size_t& offse
do {
version += (buffer[offset] & 0x7f);
useNextByte = (buffer[offset++] & 0x80);
} while(useNextByte && (offset < length));
} while(useNextByte && (offset < size_t(length)));

if(useNextByte) {
// all the data is consumed and we still don't have a version number?!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ namespace Mqtt
class RbootPayloadParser : public PayloadParser
{
public:
RbootPayloadParser(Storage::Partition part, size_t currentVersion) : PayloadParser(currentVersion), part(part)
RbootPayloadParser(Storage::Partition part, size_t currentVersion, size_t allowedVersionBytes = 24)
: PayloadParser(currentVersion, allowedVersionBytes), part(part)
{
}

Expand Down

0 comments on commit 237fa66

Please sign in to comment.