@@ -140,7 +140,9 @@ def send_invitation_and_get_auth_challenge(remote_addr, remote_port, message):
140140 return True , data , None
141141
142142
143- def authenticate (remote_addr , remote_port , password , use_md5_password , use_old_protocol , filename , content_size , file_md5 , nonce ):
143+ def authenticate (
144+ remote_addr , remote_port , password , use_md5_password , use_old_protocol , filename , content_size , file_md5 , nonce
145+ ):
144146 """
145147 Perform authentication with the ESP device.
146148
@@ -173,7 +175,9 @@ def authenticate(remote_addr, remote_port, password, use_md5_password, use_old_p
173175 # The password can be hashed with either MD5 or SHA256
174176 if use_md5_password :
175177 # Use MD5 for password hash (for devices that stored MD5 hashes)
176- logging .warning ("Using insecure MD5 hash for password due to legacy device support. Please upgrade devices to ESP32 Arduino Core 3.3.1+ for improved security." )
178+ logging .warning (
179+ "Using insecure MD5 hash for password due to legacy device support. Please upgrade devices to ESP32 Arduino Core 3.3.1+ for improved security."
180+ )
177181 password_hash = hashlib .md5 (password .encode ()).hexdigest ()
178182 else :
179183 # Use SHA256 for password hash (recommended)
@@ -253,9 +257,15 @@ def serve(
253257 sys .stderr .write ("Authenticating (MD5 protocol)..." )
254258 sys .stderr .flush ()
255259 auth_success , auth_error = authenticate (
256- remote_addr , remote_port , password ,
257- use_md5_password = True , use_old_protocol = True ,
258- filename = filename , content_size = content_size , file_md5 = file_md5 , nonce = nonce
260+ remote_addr ,
261+ remote_port ,
262+ password ,
263+ use_md5_password = True ,
264+ use_old_protocol = True ,
265+ filename = filename ,
266+ content_size = content_size ,
267+ file_md5 = file_md5 ,
268+ nonce = nonce ,
259269 )
260270
261271 if not auth_success :
@@ -279,18 +289,30 @@ def serve(
279289 sys .stderr .write ("Authenticating (SHA256 protocol with MD5 password)..." )
280290 sys .stderr .flush ()
281291 auth_success , auth_error = authenticate (
282- remote_addr , remote_port , password ,
283- use_md5_password = True , use_old_protocol = False ,
284- filename = filename , content_size = content_size , file_md5 = file_md5 , nonce = nonce
292+ remote_addr ,
293+ remote_port ,
294+ password ,
295+ use_md5_password = True ,
296+ use_old_protocol = False ,
297+ filename = filename ,
298+ content_size = content_size ,
299+ file_md5 = file_md5 ,
300+ nonce = nonce ,
285301 )
286302 else :
287303 # Try SHA256 password hash first
288304 sys .stderr .write ("Authenticating..." )
289305 sys .stderr .flush ()
290306 auth_success , auth_error = authenticate (
291- remote_addr , remote_port , password ,
292- use_md5_password = False , use_old_protocol = False ,
293- filename = filename , content_size = content_size , file_md5 = file_md5 , nonce = nonce
307+ remote_addr ,
308+ remote_port ,
309+ password ,
310+ use_md5_password = False ,
311+ use_old_protocol = False ,
312+ filename = filename ,
313+ content_size = content_size ,
314+ file_md5 = file_md5 ,
315+ nonce = nonce ,
294316 )
295317
296318 # Scenario 3: If SHA256 fails, try MD5 password hash (for devices with stored MD5 passwords)
@@ -315,17 +337,27 @@ def serve(
315337 nonce = data .split ()[1 ]
316338
317339 auth_success , auth_error = authenticate (
318- remote_addr , remote_port , password ,
319- use_md5_password = True , use_old_protocol = False ,
320- filename = filename , content_size = content_size , file_md5 = file_md5 , nonce = nonce
340+ remote_addr ,
341+ remote_port ,
342+ password ,
343+ use_md5_password = True ,
344+ use_old_protocol = False ,
345+ filename = filename ,
346+ content_size = content_size ,
347+ file_md5 = file_md5 ,
348+ nonce = nonce ,
321349 )
322350
323351 if auth_success :
324352 logging .warning ("====================================================================" )
325353 logging .warning ("WARNING: Device authenticated with MD5 password hash (deprecated)" )
326354 logging .warning ("MD5 is cryptographically broken and should not be used." )
327- logging .warning ("Please update your sketch to use either setPassword() or setPasswordHash()" )
328- logging .warning ("with SHA256, then upload again to migrate to the new secure SHA256 protocol." )
355+ logging .warning (
356+ "Please update your sketch to use either setPassword() or setPasswordHash()"
357+ )
358+ logging .warning (
359+ "with SHA256, then upload again to migrate to the new secure SHA256 protocol."
360+ )
329361 logging .warning ("======================================================================" )
330362
331363 if not auth_success :
0 commit comments