Browse Source

fix http_simple calc 'head_size'

add 'iv', 'key', 'head_len' in server_info
dev
BreakWa11 9 years ago
parent
commit
8826629741
  1. 2
      shadowsocks/common.py
  2. 2
      shadowsocks/encrypt.py
  3. 2
      shadowsocks/local.py
  4. 2
      shadowsocks/obfsplugin/http_simple.py
  5. 25
      shadowsocks/tcprelay.py

2
shadowsocks/common.py

@ -204,7 +204,7 @@ def parse_header(data):
elif addrtype == ADDRTYPE_HOST: elif addrtype == ADDRTYPE_HOST:
if len(data) > 2: if len(data) > 2:
addrlen = ord(data[1]) addrlen = ord(data[1])
if len(data) >= 2 + addrlen: if len(data) >= 4 + addrlen:
dest_addr = data[2:2 + addrlen] dest_addr = data[2:2 + addrlen]
dest_port = struct.unpack('>H', data[2 + addrlen:4 + dest_port = struct.unpack('>H', data[2 + addrlen:4 +
addrlen])[0] addrlen])[0]

2
shadowsocks/encrypt.py

@ -78,6 +78,7 @@ class Encryptor(object):
self.iv_sent = False self.iv_sent = False
self.cipher_iv = b'' self.cipher_iv = b''
self.iv_buf = b'' self.iv_buf = b''
self.cipher_key = b''
self.decipher = None self.decipher = None
method = method.lower() method = method.lower()
self._method_info = self.get_method_info(method) self._method_info = self.get_method_info(method)
@ -109,6 +110,7 @@ class Encryptor(object):
if op == 1: if op == 1:
# this iv is for cipher not decipher # this iv is for cipher not decipher
self.cipher_iv = iv[:m[1]] self.cipher_iv = iv[:m[1]]
self.cipher_key = key
return m[2](method, key, iv, op) return m[2](method, key, iv, op)
def encrypt(self, buf): def encrypt(self, buf):

2
shadowsocks/local.py

@ -47,6 +47,8 @@ def main():
asyncdns.IPV6_CONNECTION_SUPPORT = False asyncdns.IPV6_CONNECTION_SUPPORT = False
daemon.daemon_exec(config) daemon.daemon_exec(config)
logging.info("local start with protocol[%s] password [%s] method [%s] obfs [%s] obfs_param [%s]" %
(config['protocol'], config['password'], config['method'], config['obfs'], config['obfs_param']))
try: try:
logging.info("starting local at %s:%d" % logging.info("starting local at %s:%d" %

2
shadowsocks/obfsplugin/http_simple.py

@ -90,7 +90,7 @@ class http_simple(plain.plain):
def client_encode(self, buf): def client_encode(self, buf):
if self.has_sent_header: if self.has_sent_header:
return buf return buf
head_size = self.get_head_size(buf, 30) head_size = len(self.server_info.iv) + self.server_info.head_len
if len(buf) - head_size > 64: if len(buf) - head_size > 64:
headlen = head_size + random.randint(0, 64) headlen = head_size + random.randint(0, 64)
else: else:

25
shadowsocks/tcprelay.py

@ -118,16 +118,22 @@ class TCPRelayHandler(object):
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
server_info.tcp_mss = 1440
server_info.param = config['obfs_param'] server_info.param = config['obfs_param']
server_info.iv = self._encryptor.cipher_iv
server_info.key = self._encryptor.cipher_key
server_info.head_len = 30
server_info.tcp_mss = 1440
self._obfs.set_server_info(server_info) self._obfs.set_server_info(server_info)
self._protocol = obfs.obfs(config['protocol']) self._protocol = obfs.obfs(config['protocol'])
server_info = obfs.server_info(server.protocol_data) server_info = obfs.server_info(server.protocol_data)
server_info.host = config['server'] server_info.host = config['server']
server_info.port = server._listen_port server_info.port = server._listen_port
server_info.tcp_mss = 1440
server_info.param = '' server_info.param = ''
server_info.iv = self._encryptor.cipher_iv
server_info.key = self._encryptor.cipher_key
server_info.head_len = 30
server_info.tcp_mss = 1440
self._protocol.set_server_info(server_info) self._protocol.set_server_info(server_info)
self._redir_list = config.get('redirect', ["0.0.0.0:0"]) self._redir_list = config.get('redirect', ["0.0.0.0:0"])
@ -386,6 +392,18 @@ class TCPRelayHandler(object):
traceback.print_exc() traceback.print_exc()
self.destroy() self.destroy()
def _get_head_size(self, buf, def_value):
if len(buf) < 2:
return def_value
head_type = ord(buf[0]) & 0xF
if head_type == 1:
return 7
if head_type == 4:
return 19
if head_type == 3:
return 4 + ord(buf[1])
return def_value
def _handle_stage_addr(self, ogn_data, data): def _handle_stage_addr(self, ogn_data, data):
try: try:
if self._is_local: if self._is_local:
@ -439,6 +457,9 @@ class TCPRelayHandler(object):
self._write_to_sock((b'\x05\x00\x00\x01' self._write_to_sock((b'\x05\x00\x00\x01'
b'\x00\x00\x00\x00\x10\x10'), b'\x00\x00\x00\x00\x10\x10'),
self._local_sock) self._local_sock)
head_len = self._get_head_size(data, 30)
self._obfs.obfs.server_info.head_len = head_len
self._protocol.obfs.server_info.head_len = head_len
if CLIENT_NEW_PROTOCOL: if CLIENT_NEW_PROTOCOL:
rnd_len = random.randint(1, 32) rnd_len = random.randint(1, 32)
total_len = 7 + rnd_len + len(data) total_len = 7 + rnd_len + len(data)

Loading…
Cancel
Save