Skip to content
8 changes: 5 additions & 3 deletions libraries/Update/src/Update.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ class UpdateClass {

/*
sets the expected MD5 for the firmware (hexString)
calc_post_decryption if true che update library calc MD5 after decryption, if false the calc is before decryption
*/
bool setMD5(const char *expected_md5);
bool setMD5(const char *expected_md5, bool calc_post_decryption);

/*
returns the MD5 String of the successfully ended firmware
Expand Down Expand Up @@ -256,8 +257,9 @@ class UpdateClass {
uint32_t _command;
const esp_partition_t *_partition;

String _target_md5;
MD5Builder _md5;
String _target_md5;
bool _target_md5_decrypted=true;
MD5Builder _md5;

int _ledPin;
uint8_t _ledOn;
Expand Down
14 changes: 11 additions & 3 deletions libraries/Update/src/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

#include "Update.h"
#include "Arduino.h"
#include "Arduino.h"
#include "spi_flash_mmap.h"
#include "esp_ota_ops.h"
#include "esp_image_format.h"
Expand Down Expand Up @@ -348,6 +348,11 @@ bool UpdateClass::_writeBuffer() {
log_d("Decrypting OTA Image");
}
}

if(!_target_md5_decrypted){
_md5.add(_buffer, _bufferLen);
}

//check if data in buffer needs decrypting
if (_cryptMode & U_AES_IMAGE_DECRYPTING_BIT) {
if (!_decryptBuffer()) {
Expand Down Expand Up @@ -404,7 +409,9 @@ bool UpdateClass::_writeBuffer() {
if (!_progress && _command == U_FLASH) {
_buffer[0] = ESP_IMAGE_HEADER_MAGIC;
}
_md5.add(_buffer, _bufferLen);
if(_target_md5_decrypted){
_md5.add(_buffer, _bufferLen);
}
_progress += _bufferLen;
_bufferLen = 0;
if (_progress_callback) {
Expand Down Expand Up @@ -446,12 +453,13 @@ bool UpdateClass::_verifyEnd() {
return false;
}

bool UpdateClass::setMD5(const char *expected_md5) {
bool UpdateClass::setMD5(const char *expected_md5, bool calc_post_decryption=true) {
if (strlen(expected_md5) != 32) {
return false;
}
_target_md5 = expected_md5;
_target_md5.toLowerCase();
_target_md5_decrypted=calc_post_decryption;
return true;
}

Expand Down