Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

Support SHA1 verification in new versions of NodeMCU #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion nodemcu_uploader/luacode.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
on('data', '\0', recv_name, 0)
w(0, 'C')
end
function shafile(f) print(crypto.toHex(crypto.fhash('sha1', f))) end
function shafile(f)
if not crypto then print("unsupported") return end
local toHex = crypto.toHex and crypto.toHex or
(encoder and encoder.toHex or function() return "unsupported" end)
print(toHex(crypto.fhash('sha1', f)))
end
""" # noqa: E122

SEND_LUA = \
Expand Down
9 changes: 6 additions & 3 deletions nodemcu_uploader/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,17 @@ def verify_file(self, local, remote, verify='none'):
else:
log.info('Verification successful. Contents are identical.')
elif verify == 'sha1':
# Calculate SHA1 on remote file. Extract just hash from result
data = self.__exchange('shafile("'+remote+'")').splitlines()[1]
# Calculate SHA1 on remote file
data = self.__exchange('shafile("'+remote+'")')
log.info('Remote SHA1: %s', data)

# Calculate hash of local data
filehashhex = hashlib.sha1(content).hexdigest()
log.info('Local SHA1: %s', filehashhex)
if data != filehashhex:
if "unsupported" in data:
log.error('SHA1 verification unsupported - crypto and encoder modules not found in firmware.')
raise VerificationError('SHA1 verification unsupported - crypto and encoder modules not found in firmware.')
elif filehashhex not in data:
log.error('SHA1 verification failed.')
raise VerificationError('SHA1 Verification failed.')
else:
Expand Down