@@ -41,7 +41,7 @@ class Shadowsocks(BaseProtocol):
4141 name = 'ss'
4242 def correct_header (self , header , auth , ** kw ):
4343 return auth and header == auth [:1 ] or not auth and header and header [0 ] in (1 , 3 , 4 , 17 , 19 , 20 )
44- async def patch_ota_reader (self , cipher , reader ):
44+ def patch_ota_reader (self , cipher , reader ):
4545 chunk_id = 0
4646 async def patched_read ():
4747 nonlocal chunk_id
@@ -51,7 +51,7 @@ async def patched_read():
5151 return None
5252 checksum_client = await reader .readexactly (10 )
5353 data = await reader .readexactly (data_len )
54- checksum = hmac .new (cipher .iv + chunk_id .to_bytes (4 , 'big' ), data , hashlib .sha1 ). digest ( )
54+ checksum = hmac .digest (cipher .iv + chunk_id .to_bytes (4 , 'big' ), data , hashlib .sha1 )
5555 assert checksum [:10 ] == checksum_client
5656 chunk_id += 1
5757 return data
@@ -62,7 +62,7 @@ def patch_ota_writer(self, cipher, writer):
6262 def patched_write (data ):
6363 nonlocal chunk_id
6464 if not data : return
65- checksum = hmac .new (cipher .iv + chunk_id .to_bytes (4 , 'big' ), data , hashlib .sha1 ). digest ( )
65+ checksum = hmac .digest (cipher .iv + chunk_id .to_bytes (4 , 'big' ), data , hashlib .sha1 )
6666 chunk_id += 1
6767 return write (len (data ).to_bytes (2 , 'big' ) + checksum [:10 ] + data )
6868 writer .write = patched_write
@@ -76,15 +76,15 @@ async def parse(self, header, reader, auth, authtable, reader_cipher, **kw):
7676 host_name , port , data = await socks_address_process (reader , header [0 ])
7777 assert ota or not reader_cipher or not reader_cipher .ota , 'SS client must support OTA'
7878 if ota and reader_cipher :
79- checksum = hmac .new (reader_cipher .iv + reader_cipher .key , header + data , hashlib .sha1 ). digest ( )
79+ checksum = hmac .digest (reader_cipher .iv + reader_cipher .key , header + data , hashlib .sha1 )
8080 assert checksum [:10 ] == (await reader .read_n (10 )), 'Unknown OTA checksum'
8181 self .patch_ota_reader (reader_cipher , reader )
8282 return host_name , port , b''
8383 async def connect (self , reader_remote , writer_remote , rauth , host_name , port , initbuf , writer_cipher_r , ** kw ):
8484 writer_remote .write (rauth )
8585 if writer_cipher_r and writer_cipher_r .ota :
8686 rdata = b'\x13 ' + packstr (host_name .encode ()) + port .to_bytes (2 , 'big' )
87- checksum = hmac .new (writer_cipher_r .iv + writer_cipher_r .key , rdata , hashlib .sha1 ). digest ( )
87+ checksum = hmac .digest (writer_cipher_r .iv + writer_cipher_r .key , rdata , hashlib .sha1 )
8888 writer_remote .write (rdata + checksum [:10 ])
8989 self .patch_ota_writer (writer_cipher_r , writer_remote )
9090 else :
0 commit comments