Skip to content

Commit 330beb4

Browse files
zinkettlucasssvazpre-commit-ci-lite[bot]
authored
Update lib - User can choose if calc MD5 from encrypted or decrypted file (#10510)
* User can choose if calc MD5 from decrypted file At the present moment, if user want use OTA, the function calculate MD5 of the decrypted file, but if file is encrypted from source, could be more useful to know the MD5 of the encrypted file. * md5 * Update Updater.cpp * Update libraries/Update/src/Update.h Co-authored-by: Lucas Saavedra Vaz <[email protected]> * Update libraries/Update/src/Update.h Co-authored-by: Lucas Saavedra Vaz <[email protected]> * Update libraries/Update/src/Updater.cpp Co-authored-by: Lucas Saavedra Vaz <[email protected]> * Update libraries/Update/src/Updater.cpp Co-authored-by: Lucas Saavedra Vaz <[email protected]> * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: Lucas Saavedra Vaz <[email protected]> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent cb83cda commit 330beb4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Diff for: libraries/Update/src/Update.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ class UpdateClass {
137137

138138
/*
139139
sets the expected MD5 for the firmware (hexString)
140+
If calc_post_decryption is true, the update library will calculate the MD5 after the decryption, if false the calculation occurs before the decryption
140141
*/
141-
bool setMD5(const char *expected_md5);
142+
bool setMD5(const char *expected_md5, bool calc_post_decryption = true);
142143

143144
/*
144145
returns the MD5 String of the successfully ended firmware
@@ -257,6 +258,7 @@ class UpdateClass {
257258
const esp_partition_t *_partition;
258259

259260
String _target_md5;
261+
bool _target_md5_decrypted = true;
260262
MD5Builder _md5;
261263

262264
int _ledPin;

Diff for: libraries/Update/src/Updater.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ bool UpdateClass::_writeBuffer() {
348348
log_d("Decrypting OTA Image");
349349
}
350350
}
351+
352+
if (!_target_md5_decrypted) {
353+
_md5.add(_buffer, _bufferLen);
354+
}
355+
351356
//check if data in buffer needs decrypting
352357
if (_cryptMode & U_AES_IMAGE_DECRYPTING_BIT) {
353358
if (!_decryptBuffer()) {
@@ -404,7 +409,9 @@ bool UpdateClass::_writeBuffer() {
404409
if (!_progress && _command == U_FLASH) {
405410
_buffer[0] = ESP_IMAGE_HEADER_MAGIC;
406411
}
407-
_md5.add(_buffer, _bufferLen);
412+
if (_target_md5_decrypted) {
413+
_md5.add(_buffer, _bufferLen);
414+
}
408415
_progress += _bufferLen;
409416
_bufferLen = 0;
410417
if (_progress_callback) {
@@ -446,12 +453,13 @@ bool UpdateClass::_verifyEnd() {
446453
return false;
447454
}
448455

449-
bool UpdateClass::setMD5(const char *expected_md5) {
456+
bool UpdateClass::setMD5(const char *expected_md5, bool calc_post_decryption) {
450457
if (strlen(expected_md5) != 32) {
451458
return false;
452459
}
453460
_target_md5 = expected_md5;
454461
_target_md5.toLowerCase();
462+
_target_md5_decrypted = calc_post_decryption;
455463
return true;
456464
}
457465

0 commit comments

Comments
 (0)