Browse Source

support auth_simple

dev
BreakWa11 9 years ago
parent
commit
59105f6e64
  1. 22
      shadowsocks/obfsplugin/verify_simple.py
  2. 4
      shadowsocks/tcprelay.py

22
shadowsocks/obfsplugin/verify_simple.py

@ -338,7 +338,9 @@ 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 self.startup_time = int(time.time() - 30) & 0xFFFFFFFF
self.local_client_id = b''
self.connection_id = 0
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:
@ -404,8 +406,26 @@ class auth_simple(verify_base):
data += struct.pack('<I', crc) data += struct.pack('<I', crc)
return data return data
def auth_data(self):
utc_time = int(time.time()) & 0xFFFFFFFF
if self.server_info.data.connection_id > 0xFF000000:
self.server_info.data.local_client_id = b''
if not self.server_info.data.local_client_id:
self.server_info.data.local_client_id = os.urandom(4)
logging.debug("local_client_id %s" % (binascii.hexlify(self.server_info.data.local_client_id),))
self.server_info.data.connection_id = struct.unpack('<I', os.urandom(4))[0] & 0xFFFFFF
self.server_info.data.connection_id += 1
return b''.join([struct.pack('<I', utc_time),
self.server_info.data.local_client_id,
struct.pack('<I', self.server_info.data.connection_id)])
def client_pre_encrypt(self, buf): def client_pre_encrypt(self, buf):
ret = b'' ret = b''
if not self.has_sent_header:
datalen = max(len(buf), common.ord(os.urandom(1)[0]) % 32 + 4)
ret += self.pack_data(self.auth_data() + buf[:datalen])
buf = buf[datalen:]
self.has_sent_header = True
while len(buf) > self.unit_len: while len(buf) > self.unit_len:
ret += self.pack_data(buf[:self.unit_len]) ret += self.pack_data(buf[:self.unit_len])
buf = buf[self.unit_len:] buf = buf[self.unit_len:]

4
shadowsocks/tcprelay.py

@ -263,8 +263,8 @@ class TCPRelayHandler(object):
if sock == self._local_sock and self._encrypt_correct: if sock == self._local_sock and self._encrypt_correct:
obfs_encode = self._obfs.server_encode(data) obfs_encode = self._obfs.server_encode(data)
data = obfs_encode data = obfs_encode
l = len(data) if data:
if l > 0: l = len(data)
s = sock.send(data) s = sock.send(data)
if s < l: if s < l:
data = data[s:] data = data[s:]

Loading…
Cancel
Save