Skip to content

Commit

Permalink
Merge pull request esp8266#1245 from Links2004/httpUpdate
Browse files Browse the repository at this point in the history
fix esp8266#1244 - MD5 handling
  • Loading branch information
Links2004 committed Dec 18, 2015
2 parents 727b6b1 + 8032f77 commit a07838a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
11 changes: 8 additions & 3 deletions cores/esp8266/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool UpdaterClass::begin(size_t size, int command) {
return false;
}

if(ESP.checkFlashConfig(false)) {
if(!ESP.checkFlashConfig(false)) {
_error = UPDATE_ERROR_FLASH_CONFIG;
#ifdef DEBUG_UPDATER
printError(DEBUG_UPDATER);
Expand Down 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 a07838a

Please sign in to comment.