Skip to content

Commit 0166ae3

Browse files
authored
md5
1 parent 7bfded6 commit 0166ae3

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

libraries/Update/src/Updater.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
*/
66

77
#include "Update.h"
8-
#include "Arduino.h"
9-
#include "spi_flash_mmap.h"
8+
#include "Arduino.h"
109
#include "esp_ota_ops.h"
1110
#include "esp_image_format.h"
1211
#include "mbedtls/aes.h"
@@ -124,7 +123,7 @@ bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn, con
124123
_reset();
125124
_error = 0;
126125
_target_md5 = emptyString;
127-
_md5 = MD5Builder();
126+
_md5 = MD5Builder();
128127

129128
if (size == 0) {
130129
_error = UPDATE_ERROR_SIZE;
@@ -171,7 +170,7 @@ bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn, con
171170
}
172171
_size = size;
173172
_command = command;
174-
_md5.begin();
173+
_md5.begin();
175174
return true;
176175
}
177176

@@ -348,6 +347,11 @@ bool UpdateClass::_writeBuffer() {
348347
log_d("Decrypting OTA Image");
349348
}
350349
}
350+
351+
if(!_target_md5_decrypted){
352+
_md5.add(_buffer, _bufferLen);
353+
}
354+
351355
//check if data in buffer needs decrypting
352356
if (_cryptMode & U_AES_IMAGE_DECRYPTING_BIT) {
353357
if (!_decryptBuffer()) {
@@ -404,7 +408,9 @@ bool UpdateClass::_writeBuffer() {
404408
if (!_progress && _command == U_FLASH) {
405409
_buffer[0] = ESP_IMAGE_HEADER_MAGIC;
406410
}
407-
_md5.add(_buffer, _bufferLen);
411+
if(_target_md5_decrypted){
412+
_md5.add(_buffer, _bufferLen);
413+
}
408414
_progress += _bufferLen;
409415
_bufferLen = 0;
410416
if (_progress_callback) {
@@ -446,12 +452,14 @@ bool UpdateClass::_verifyEnd() {
446452
return false;
447453
}
448454

449-
bool UpdateClass::setMD5(const char *expected_md5) {
455+
bool UpdateClass::setMD5(const char *expected_md5, bool calc_post_decryption=true) {
450456
if (strlen(expected_md5) != 32) {
451457
return false;
452458
}
453459
_target_md5 = expected_md5;
454460
_target_md5.toLowerCase();
461+
462+
_target_md5_decrypted=calc_post_decryption;
455463
return true;
456464
}
457465

@@ -473,7 +481,8 @@ bool UpdateClass::end(bool evenIfRemaining) {
473481
_size = progress();
474482
}
475483

476-
_md5.calculate();
484+
_md5.calculate();
485+
477486
if (_target_md5.length()) {
478487
if (_target_md5 != _md5.toString()) {
479488
_abort(UPDATE_ERROR_MD5);

0 commit comments

Comments
 (0)