Skip to content

Commit eb1855e

Browse files
bakadavehasenradball
authored andcommitted
Updater - fixed signature verification for compressed binaries (esp8266#9109)
Previously, Arduino Core attempted to read from flash memory without proper consideration for the 4-byte alignment requirement when calculating the hash for the signature verification. This did not present an issue when uncompressed binaries are checked as all compiled binaries are 4-aligned (unconfirmed, just an educated guess), and signature verification appears to work well in these cases. When uploading a compressed binary (based on this) the gzip algorithm makes no attempt to produce a 4-aligned file. The rest of the signing results in a valid signed binary regardless, however when calculating the hash for the verification process there is a ~75% chance that the hash will include some bytes from the signature, thus compromising the whole signature verification process. editorial note: ESP.flashRead for u8 arrays (aka byte arrays) was already updated to properly handle both aligned and unaligned target buffer and / or length, while u32 expects that its arguments are already aligned. Since array pointer in Updater is already aligned, this properly handles unaligned size case.
1 parent d851344 commit eb1855e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

cores/esp8266/Updater.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ bool UpdaterClass::end(bool evenIfRemaining){
284284
_hash->begin();
285285
for (uint32_t offset = 0; offset < binSize; offset += sizeof(buff)) {
286286
auto len = std::min(sizeof(buff), binSize - offset);
287-
ESP.flashRead(_startAddress + offset, reinterpret_cast<uint32_t *>(&buff[0]), len);
287+
ESP.flashRead(_startAddress + offset, buff, len);
288288
_hash->add(buff, len);
289289
}
290290
_hash->end();

0 commit comments

Comments
 (0)