From d3f16b317782aaeb403d1584695944f659178b0b Mon Sep 17 00:00:00 2001 From: Vlasta Hajek Date: Sat, 4 Sep 2021 19:34:00 +0200 Subject: [PATCH] Allow manually setting MD5 checksum for HTTP update (#8204) --- .../ESP8266httpUpdate/src/ESP8266httpUpdate.cpp | 12 +++++++++--- libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp index f3d67b40ea..a0a7104282 100755 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp @@ -211,8 +211,14 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String& DEBUG_HTTP_UPDATE("[httpUpdate] - code: %d\n", code); DEBUG_HTTP_UPDATE("[httpUpdate] - len: %d\n", len); - if(http.hasHeader("x-MD5")) { - DEBUG_HTTP_UPDATE("[httpUpdate] - MD5: %s\n", http.header("x-MD5").c_str()); + String md5; + if (_md5Sum.length()) { + md5 = _md5Sum; + } else if(http.hasHeader("x-MD5")) { + md5 = http.header("x-MD5"); + } + if(md5.length()) { + DEBUG_HTTP_UPDATE("[httpUpdate] - MD5: %s\n", md5.c_str()); } DEBUG_HTTP_UPDATE("[httpUpdate] ESP8266 info:\n"); @@ -298,7 +304,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String& } } } - if(runUpdate(*tcp, len, http.header("x-MD5"), command)) { + if(runUpdate(*tcp, len, md5, command)) { ret = HTTP_UPDATE_OK; DEBUG_HTTP_UPDATE("[httpUpdate] Update ok\n"); http.end(); diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h index c825d8abab..6c6b140f39 100755 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h @@ -108,6 +108,11 @@ class ESP8266HTTPUpdate _ledOn = ledOn; } + void setMD5sum(const String &md5Sum) + { + _md5Sum = md5Sum; + } + void setAuthorization(const String& user, const String& password); void setAuthorization(const String& auth); @@ -142,7 +147,7 @@ class ESP8266HTTPUpdate String _user; String _password; String _auth; - + String _md5Sum; private: int _httpClientTimeout; followRedirects_t _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;