5
5
*/
6
6
7
7
#include " Update.h"
8
- #include " Arduino.h"
9
- #include " spi_flash_mmap.h"
8
+ #include " Arduino.h"
10
9
#include " esp_ota_ops.h"
11
10
#include " esp_image_format.h"
12
11
#include " mbedtls/aes.h"
@@ -124,7 +123,7 @@ bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn, con
124
123
_reset ();
125
124
_error = 0 ;
126
125
_target_md5 = emptyString;
127
- _md5 = MD5Builder ();
126
+ _md5 = MD5Builder ();
128
127
129
128
if (size == 0 ) {
130
129
_error = UPDATE_ERROR_SIZE;
@@ -171,7 +170,7 @@ bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn, con
171
170
}
172
171
_size = size;
173
172
_command = command;
174
- _md5.begin ();
173
+ _md5.begin ();
175
174
return true ;
176
175
}
177
176
@@ -348,6 +347,11 @@ bool UpdateClass::_writeBuffer() {
348
347
log_d (" Decrypting OTA Image" );
349
348
}
350
349
}
350
+
351
+ if (!_target_md5_decrypted){
352
+ _md5.add (_buffer, _bufferLen);
353
+ }
354
+
351
355
// check if data in buffer needs decrypting
352
356
if (_cryptMode & U_AES_IMAGE_DECRYPTING_BIT) {
353
357
if (!_decryptBuffer ()) {
@@ -404,7 +408,9 @@ bool UpdateClass::_writeBuffer() {
404
408
if (!_progress && _command == U_FLASH) {
405
409
_buffer[0 ] = ESP_IMAGE_HEADER_MAGIC;
406
410
}
407
- _md5.add (_buffer, _bufferLen);
411
+ if (_target_md5_decrypted){
412
+ _md5.add (_buffer, _bufferLen);
413
+ }
408
414
_progress += _bufferLen;
409
415
_bufferLen = 0 ;
410
416
if (_progress_callback) {
@@ -446,12 +452,14 @@ bool UpdateClass::_verifyEnd() {
446
452
return false ;
447
453
}
448
454
449
- bool UpdateClass::setMD5 (const char *expected_md5) {
455
+ bool UpdateClass::setMD5 (const char *expected_md5, bool calc_post_decryption= true ) {
450
456
if (strlen (expected_md5) != 32 ) {
451
457
return false ;
452
458
}
453
459
_target_md5 = expected_md5;
454
460
_target_md5.toLowerCase ();
461
+
462
+ _target_md5_decrypted=calc_post_decryption;
455
463
return true ;
456
464
}
457
465
@@ -473,7 +481,8 @@ bool UpdateClass::end(bool evenIfRemaining) {
473
481
_size = progress ();
474
482
}
475
483
476
- _md5.calculate ();
484
+ _md5.calculate ();
485
+
477
486
if (_target_md5.length ()) {
478
487
if (_target_md5 != _md5.toString ()) {
479
488
_abort (UPDATE_ERROR_MD5);
0 commit comments