Skip to content

Commit b0fd41f

Browse files
fix(ota): Show MD5 warning only when connection is successful (#12272)
* fix(ota): Show MD5 warning only when connection is successful * change(tools): Push generated binaries to PR --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 879cc37 commit b0fd41f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

tools/espota.exe

2.37 KB
Binary file not shown.

tools/espota.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,6 @@ def authenticate(
175175
# The password can be hashed with either MD5 or SHA256
176176
if use_md5_password:
177177
# Use MD5 for password hash (for devices that stored MD5 hashes)
178-
logging.warning(
179-
"Using insecure MD5 hash for password due to legacy device support. "
180-
"Please upgrade devices to ESP32 Arduino Core 3.3.1+ for improved security."
181-
)
182178
password_hash = hashlib.md5(password.encode()).hexdigest()
183179
else:
184180
# Use SHA256 for password hash (recommended)
@@ -272,6 +268,7 @@ def serve( # noqa: C901
272268
if not auth_success:
273269
sys.stderr.write("FAIL\n")
274270
logging.error("Authentication Failed: %s", auth_error)
271+
logging.error("Please check your password and try again")
275272
return 1
276273

277274
sys.stderr.write("OK\n")
@@ -300,9 +297,13 @@ def serve( # noqa: C901
300297
file_md5=file_md5,
301298
nonce=nonce,
302299
)
300+
301+
if auth_success:
302+
logging.warning("Using insecure MD5 hash for password due to legacy device support")
303+
logging.warning("Please upgrade devices to ESP32 Arduino Core 3.3.1+ for improved security")
303304
else:
304305
# Try SHA256 password hash first
305-
sys.stderr.write("Authenticating...")
306+
sys.stderr.write("Authenticating (PBKDF2-HMAC-SHA256)...\n")
306307
sys.stderr.flush()
307308
auth_success, auth_error = authenticate(
308309
remote_addr,
@@ -318,8 +319,9 @@ def serve( # noqa: C901
318319

319320
# Scenario 3: If SHA256 fails, try MD5 password hash (for devices with stored MD5 passwords)
320321
if not auth_success:
322+
sys.stderr.write("FAIL\n")
321323
logging.info("SHA256 password failed, trying MD5 password hash")
322-
sys.stderr.write("Retrying with MD5 password...")
324+
sys.stderr.write("Retrying with MD5 password...\n")
323325
sys.stderr.flush()
324326

325327
# Device is back in OTA_IDLE after auth failure, need to send new invitation
@@ -337,6 +339,9 @@ def serve( # noqa: C901
337339
# Get new nonce for second attempt
338340
nonce = data.split()[1]
339341

342+
sys.stderr.write("Authenticating (MD5)...\n")
343+
sys.stderr.flush()
344+
340345
auth_success, auth_error = authenticate(
341346
remote_addr,
342347
remote_port,
@@ -364,6 +369,7 @@ def serve( # noqa: C901
364369
if not auth_success:
365370
sys.stderr.write("FAIL\n")
366371
logging.error("Authentication Failed: %s", auth_error)
372+
logging.error("Please check your password and try again")
367373
return 1
368374

369375
sys.stderr.write("OK\n")

0 commit comments

Comments
 (0)