Browse Source

fix error return

dev
破娃酱 8 years ago
parent
commit
efea3e08cc
  1. 9
      shadowsocks/obfsplugin/auth.py
  2. 2
      shadowsocks/obfsplugin/verify.py

9
shadowsocks/obfsplugin/auth.py

@ -313,8 +313,7 @@ class auth_sha1(verify_base):
pos = common.ord(self.recv_buf[6]) + 6 pos = common.ord(self.recv_buf[6]) + 6
out_buf = self.recv_buf[pos:length - 10] out_buf = self.recv_buf[pos:length - 10]
if len(out_buf) < 12: if len(out_buf) < 12:
self.recv_buf = b'' logging.info('auth_sha1: too short, data %s' % (binascii.hexlify(self.recv_buf),))
logging.info('auth_sha1: too short')
return self.not_match_return(self.recv_buf) return self.not_match_return(self.recv_buf)
utc_time = struct.unpack('<I', out_buf[:4])[0] utc_time = struct.unpack('<I', out_buf[:4])[0]
client_id = struct.unpack('<I', out_buf[4:8])[0] client_id = struct.unpack('<I', out_buf[4:8])[0]
@ -322,7 +321,6 @@ class auth_sha1(verify_base):
time_dif = common.int32(utc_time - (int(time.time()) & 0xffffffff)) time_dif = common.int32(utc_time - (int(time.time()) & 0xffffffff))
if time_dif < -self.max_time_dif or time_dif > self.max_time_dif \ if time_dif < -self.max_time_dif or time_dif > self.max_time_dif \
or common.int32(utc_time - self.server_info.data.startup_time) < -self.max_time_dif / 2: or common.int32(utc_time - self.server_info.data.startup_time) < -self.max_time_dif / 2:
self.recv_buf = b''
logging.info('auth_sha1: wrong timestamp, time_dif %d, data %s' % (time_dif, binascii.hexlify(out_buf),)) logging.info('auth_sha1: wrong timestamp, time_dif %d, data %s' % (time_dif, binascii.hexlify(out_buf),))
return self.not_match_return(self.recv_buf) return self.not_match_return(self.recv_buf)
elif self.server_info.data.insert(client_id, connection_id): elif self.server_info.data.insert(client_id, connection_id):
@ -331,7 +329,6 @@ class auth_sha1(verify_base):
self.client_id = client_id self.client_id = client_id
self.connection_id = connection_id self.connection_id = connection_id
else: else:
self.recv_buf = b''
logging.info('auth_sha1: auth fail, data %s' % (binascii.hexlify(out_buf),)) logging.info('auth_sha1: auth fail, data %s' % (binascii.hexlify(out_buf),))
return self.not_match_return(self.recv_buf) return self.not_match_return(self.recv_buf)
self.recv_buf = self.recv_buf[length:] self.recv_buf = self.recv_buf[length:]
@ -551,8 +548,7 @@ class auth_sha1_v2(verify_base):
pos = struct.unpack('>H', self.recv_buf[7:9])[0] + 6 pos = struct.unpack('>H', self.recv_buf[7:9])[0] + 6
out_buf = self.recv_buf[pos:length - 10] out_buf = self.recv_buf[pos:length - 10]
if len(out_buf) < 12: if len(out_buf) < 12:
self.recv_buf = b'' logging.info('auth_sha1_v2: too short, data %s' % (binascii.hexlify(self.recv_buf),))
logging.info('auth_sha1_v2: too short, data %s' % (binascii.hexlify(out_buf),))
return self.not_match_return(self.recv_buf) return self.not_match_return(self.recv_buf)
client_id = struct.unpack('<Q', out_buf[:8])[0] client_id = struct.unpack('<Q', out_buf[:8])[0]
connection_id = struct.unpack('<I', out_buf[8:12])[0] connection_id = struct.unpack('<I', out_buf[8:12])[0]
@ -562,7 +558,6 @@ class auth_sha1_v2(verify_base):
self.client_id = client_id self.client_id = client_id
self.connection_id = connection_id self.connection_id = connection_id
else: else:
self.recv_buf = b''
logging.info('auth_sha1_v2: auth fail, data %s' % (binascii.hexlify(out_buf),)) logging.info('auth_sha1_v2: auth fail, data %s' % (binascii.hexlify(out_buf),))
return self.not_match_return(self.recv_buf) return self.not_match_return(self.recv_buf)
self.recv_buf = self.recv_buf[length:] self.recv_buf = self.recv_buf[length:]

2
shadowsocks/obfsplugin/verify.py

@ -245,7 +245,7 @@ class verify_deflate(verify_base):
self.raw_trans = True self.raw_trans = True
self.recv_buf = b'' self.recv_buf = b''
if self.decrypt_packet_num == 0: if self.decrypt_packet_num == 0:
return None return (b'E'*64, False)
else: else:
raise Exception('server_post_decrype data error') raise Exception('server_post_decrype data error')
if length > len(self.recv_buf): if length > len(self.recv_buf):

Loading…
Cancel
Save