@@ -50,9 +50,10 @@ def start_https_server(ota_image_dir: str, server_ip: str, server_port: int) ->
5050 requestHandler = https_request_handler ()
5151 httpd = http .server .HTTPServer ((server_ip , server_port ), requestHandler )
5252
53- httpd .socket = ssl .wrap_socket (httpd .socket ,
54- keyfile = key_file ,
55- certfile = server_file , server_side = True )
53+ ssl_context = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
54+ ssl_context .load_cert_chain (certfile = server_file , keyfile = key_file )
55+
56+ httpd .socket = ssl_context .wrap_socket (httpd .socket , server_side = True )
5657 httpd .serve_forever ()
5758
5859
@@ -88,9 +89,10 @@ def start_redirect_server(ota_image_dir: str, server_ip: str, server_port: int,
8889
8990 httpd = http .server .HTTPServer ((server_ip , server_port ), redirectHandler )
9091
91- httpd .socket = ssl .wrap_socket (httpd .socket ,
92- keyfile = key_file ,
93- certfile = server_file , server_side = True )
92+ ssl_context = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
93+ ssl_context .load_cert_chain (certfile = server_file , keyfile = key_file )
94+
95+ httpd .socket = ssl_context .wrap_socket (httpd .socket , server_side = True )
9496 httpd .serve_forever ()
9597
9698
@@ -154,8 +156,8 @@ def test_examples_protocol_advanced_https_ota_example_truncated_bin(dut: Dut) ->
154156 truncated_bin_size = 64000
155157 binary_file = os .path .join (dut .app .binary_path , bin_name )
156158 with open (binary_file , 'rb+' ) as f :
157- with open (os .path .join (dut .app .binary_path , truncated_bin_name ), 'wb+' ) as fo :
158- fo .write (f .read (truncated_bin_size ))
159+ with open (os .path .join (dut .app .binary_path , truncated_bin_name ), 'wb+' ) as output_file :
160+ output_file .write (f .read (truncated_bin_size ))
159161 binary_file = os .path .join (dut .app .binary_path , truncated_bin_name )
160162 # Start server
161163 thread1 = multiprocessing .Process (target = start_https_server , args = (dut .app .binary_path , '0.0.0.0' , server_port ))
@@ -187,7 +189,7 @@ def test_examples_protocol_advanced_https_ota_example_truncated_bin(dut: Dut) ->
187189@pytest .mark .ethernet_ota
188190def test_examples_protocol_advanced_https_ota_example_truncated_header (dut : Dut ) -> None :
189191 """
190- Working of OTA if headers of binary file are truncated is vaildated in this test case.
192+ Working of OTA if headers of binary file are truncated is validated in this test case.
191193 Application should return with error message in this case.
192194 steps: |
193195 1. join AP/Ethernet
@@ -205,8 +207,8 @@ def test_examples_protocol_advanced_https_ota_example_truncated_header(dut: Dut)
205207 # check and log bin size
206208 binary_file = os .path .join (dut .app .binary_path , bin_name )
207209 with open (binary_file , 'rb+' ) as f :
208- with open (os .path .join (dut .app .binary_path , truncated_bin_name ), 'wb+' ) as fo :
209- fo .write (f .read (truncated_bin_size ))
210+ with open (os .path .join (dut .app .binary_path , truncated_bin_name ), 'wb+' ) as output_file :
211+ output_file .write (f .read (truncated_bin_size ))
210212 binary_file = os .path .join (dut .app .binary_path , truncated_bin_name )
211213 # Start server
212214 thread1 = multiprocessing .Process (target = start_https_server , args = (dut .app .binary_path , '0.0.0.0' , server_port ))
@@ -249,16 +251,16 @@ def test_examples_protocol_advanced_https_ota_example_random(dut: Dut) -> None:
249251 server_port = 8001
250252 # Random binary file to be generated
251253 random_bin_name = 'random.bin'
252- # Size of random binary file. 32000 is choosen , to reduce the time required to run the test-case
254+ # Size of random binary file. 32000 is chosen , to reduce the time required to run the test-case
253255 random_bin_size = 32000
254256 # check and log bin size
255257 binary_file = os .path .join (dut .app .binary_path , random_bin_name )
256- with open (binary_file , 'wb+' ) as fo :
258+ with open (binary_file , 'wb+' ) as output_file :
257259 # First byte of binary file is always set to zero. If first byte is generated randomly,
258260 # in some cases it may generate 0xE9 which will result in failure of testcase.
259- fo .write (struct .pack ('B' , 0 ))
261+ output_file .write (struct .pack ('B' , 0 ))
260262 for i in range (random_bin_size - 1 ):
261- fo .write (struct .pack ('B' , random .randrange (0 ,255 ,1 )))
263+ output_file .write (struct .pack ('B' , random .randrange (0 ,255 ,1 )))
262264 # Start server
263265 thread1 = multiprocessing .Process (target = start_https_server , args = (dut .app .binary_path , '0.0.0.0' , server_port ))
264266 thread1 .daemon = True
@@ -302,16 +304,16 @@ def test_examples_protocol_advanced_https_ota_example_invalid_chip_id(dut: Dut)
302304 # Random binary file to be generated
303305 random_bin_name = 'random.bin'
304306 random_binary_file = os .path .join (dut .app .binary_path , random_bin_name )
305- # Size of random binary file. 2000 is choosen , to reduce the time required to run the test-case
307+ # Size of random binary file. 2000 is chosen , to reduce the time required to run the test-case
306308 random_bin_size = 2000
307309
308310 binary_file = os .path .join (dut .app .binary_path , bin_name )
309311 with open (binary_file , 'rb+' ) as f :
310312 data = list (f .read (random_bin_size ))
311313 # Changing Chip id
312314 data [13 ] = 0xfe
313- with open (random_binary_file , 'wb+' ) as fo :
314- fo .write (bytearray (data ))
315+ with open (random_binary_file , 'wb+' ) as output_file :
316+ output_file .write (bytearray (data ))
315317 # Start server
316318 thread1 = multiprocessing .Process (target = start_https_server , args = (dut .app .binary_path , '0.0.0.0' , server_port ))
317319 thread1 .daemon = True
@@ -452,11 +454,11 @@ def test_examples_protocol_advanced_https_ota_example_anti_rollback(dut: Dut) ->
452454 binary_file = os .path .join (dut .app .binary_path , bin_name )
453455 file_size = os .path .getsize (binary_file )
454456 with open (binary_file , 'rb+' ) as f :
455- with open (os .path .join (dut .app .binary_path , anti_rollback_bin_name ), 'wb+' ) as fo :
456- fo .write (f .read (file_size ))
457+ with open (os .path .join (dut .app .binary_path , anti_rollback_bin_name ), 'wb+' ) as output_file :
458+ output_file .write (f .read (file_size ))
457459 # Change security_version to 0 for negative test case
458- fo .seek (36 )
459- fo .write (b'\x00 ' )
460+ output_file .seek (36 )
461+ output_file .write (b'\x00 ' )
460462 binary_file = os .path .join (dut .app .binary_path , anti_rollback_bin_name )
461463 # Start server
462464 thread1 = multiprocessing .Process (target = start_https_server , args = (dut .app .binary_path , '0.0.0.0' , server_port ))
@@ -666,10 +668,10 @@ def test_examples_protocol_advanced_https_ota_example_openssl_aligned_bin(dut: D
666668 # Dummy data required to align binary size to 289 bytes boundary
667669 dummy_data_size = 289 - (bin_size % 289 )
668670 with open (binary_file , 'rb+' ) as f :
669- with open (os .path .join (dut .app .binary_path , aligned_bin_name ), 'wb+' ) as fo :
670- fo .write (f .read (bin_size ))
671+ with open (os .path .join (dut .app .binary_path , aligned_bin_name ), 'wb+' ) as output_file :
672+ output_file .write (f .read (bin_size ))
671673 for _ in range (dummy_data_size ):
672- fo .write (struct .pack ('B' , random .randrange (0 ,255 ,1 )))
674+ output_file .write (struct .pack ('B' , random .randrange (0 ,255 ,1 )))
673675 # Start server
674676 chunked_server = start_chunked_server (dut .app .binary_path , 8070 )
675677 try :
0 commit comments