Browse Source

add startup time in auth_simple

dev
BreakWa11 9 years ago
parent
commit
83c8b50ea2
  1. 3
      shadowsocks/obfsplugin/verify_simple.py
  2. 4
      shadowsocks/tcprelay.py

3
shadowsocks/obfsplugin/verify_simple.py

@ -338,6 +338,7 @@ class obfs_auth_data(object):
def __init__(self): def __init__(self):
self.sub_obfs = None self.sub_obfs = None
self.client_id = {} self.client_id = {}
self.startup_time = int(time.time() - 30) & 0xffffffff
def update(self, client_id, connection_id): def update(self, client_id, connection_id):
if client_id in self.client_id: if client_id in self.client_id:
@ -491,7 +492,7 @@ class auth_simple(verify_base):
client_id = struct.unpack('<I', out_buf[4:8])[0] client_id = struct.unpack('<I', out_buf[4:8])[0]
connection_id = struct.unpack('<I', out_buf[8:12])[0] connection_id = struct.unpack('<I', out_buf[8:12])[0]
time_dif = common.int32((int(time.time()) & 0xffffffff) - utc_time) time_dif = common.int32((int(time.time()) & 0xffffffff) - utc_time)
if time_dif < 60 * -3 or time_dif > 60 * 3: if time_dif < 60 * -3 or time_dif > 60 * 3 or common.int32(utc_time - self.server_info.data.startup_time) < 0:
self.raw_trans = True self.raw_trans = True
self.recv_buf = b'' self.recv_buf = b''
logging.info('auth_simple: wrong timestamp, time_dif %d, data %s' % (time_dif, binascii.hexlify(out_buf),)) logging.info('auth_simple: wrong timestamp, time_dif %d, data %s' % (time_dif, binascii.hexlify(out_buf),))

4
shadowsocks/tcprelay.py

@ -115,8 +115,6 @@ class TCPRelayHandler(object):
config['method']) config['method'])
self._encrypt_correct = True self._encrypt_correct = True
self._obfs = obfs.obfs(config['obfs']) self._obfs = obfs.obfs(config['obfs'])
if server.obfs_data is None:
server.obfs_data = self._obfs.init_data()
server_info = obfs.server_info(server.obfs_data) server_info = obfs.server_info(server.obfs_data)
server_info.host = config['server'] server_info.host = config['server']
server_info.port = server._listen_port server_info.port = server._listen_port
@ -769,7 +767,7 @@ class TCPRelay(object):
self.server_transfer_ul = 0 self.server_transfer_ul = 0
self.server_transfer_dl = 0 self.server_transfer_dl = 0
self.server_connections = 0 self.server_connections = 0
self.obfs_data = None self.obfs_data = obfs.obfs(config['obfs']).init_data()
self._timeout = config['timeout'] self._timeout = config['timeout']
self._timeouts = [] # a list for all the handlers self._timeouts = [] # a list for all the handlers

Loading…
Cancel
Save