X Tutup
Skip to content

Commit f7cec29

Browse files
authored
fix OTA bug
1 parent 134d1d4 commit f7cec29

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

pproxy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pproxy import proto
33

44
__title__ = 'pproxy'
5-
__version__ = "1.3"
5+
__version__ = "1.3.1"
66
__description__ = "Proxy server that can tunnel among remote servers by regex rules."
77
__author__ = "Qian Wenjie"
88
__license__ = "MIT License"

pproxy/cipher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ def feed_data(s, o=reader.feed_data):
145145
else:
146146
o(reader_cipher.decrypt(s))
147147
def write(s, o=writer.write):
148-
if not s:
149-
return
150148
if not writer_cipher.iv:
151149
writer_cipher.setup_iv()
152150
o(writer_cipher.iv)
151+
if not s:
152+
return
153153
return o(writer_cipher.encrypt(s))
154154
reader.feed_data = feed_data
155155
writer.write = write

pproxy/proto.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
X Tutup