Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding possibility to manually set MD5 checksum for HTTP update #8204

Merged
merged 2 commits into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -142,7 +147,7 @@ class ESP8266HTTPUpdate
String _user;
String _password;
String _auth;

String _md5Sum;
private:
int _httpClientTimeout;
followRedirects_t _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
Expand Down