Skip to content

Commit

Permalink
setMD5 has now returns bool
Browse files Browse the repository at this point in the history
handle setMD5 failed in HTTP update
reset UpdaterClass when MD5 check failed
see: esp8266#1244
  • Loading branch information
Links2004 committed Dec 18, 2015
1 parent 727b6b1 commit 02e6b2f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions cores/esp8266/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ bool UpdaterClass::begin(size_t size, int command) {
return true;
}

void UpdaterClass::setMD5(const char * expected_md5){
if(strlen(expected_md5) != 32) return;
bool UpdaterClass::setMD5(const char * expected_md5){
if(strlen(expected_md5) != 32)
{
return false;
}
_target_md5 = expected_md5;
return true;
}

bool UpdaterClass::end(bool evenIfRemaining){
Expand Down Expand Up @@ -160,6 +164,7 @@ bool UpdaterClass::end(bool evenIfRemaining){
#ifdef DEBUG_UPDATER
DEBUG_UPDATER.printf("MD5 Failed: expected:%s, calculated:%s\n", _target_md5.c_str(), _md5.toString().c_str());
#endif
_reset();
return false;
}
#ifdef DEBUG_UPDATER
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class UpdaterClass {
/*
sets the expected MD5 for the firmware (hexString)
*/
void setMD5(const char * expected_md5);
bool setMD5(const char * expected_md5);

/*
returns the MD5 String of the sucessfully ended firmware
Expand Down
6 changes: 5 additions & 1 deletion libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ bool ESP8266HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int com
}

if(md5.length()) {
Update.setMD5(md5.c_str());
if(!Update.setMD5(md5.c_str())) {
lastError = HTTP_UE_SERVER_FAULTY_MD5;
DEBUG_HTTP_UPDATE("[httpUpdate] Update.setMD5 failed! (%s)\n", md5.c_str());
return false;
}
}

if(Update.writeStream(in) != size) {
Expand Down
1 change: 1 addition & 0 deletions libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#define HTTP_UE_SERVER_FILE_NOT_FOUND (-102)
#define HTTP_UE_SERVER_FORBIDDEN (-103)
#define HTTP_UE_SERVER_WRONG_HTTP_CODE (-104)
#define HTTP_UE_SERVER_FAULTY_MD5 (-105)

typedef enum {
HTTP_UPDATE_FAILED,
Expand Down

0 comments on commit 02e6b2f

Please sign in to comment.