diff --git a/mujson_mgr.py b/mujson_mgr.py index bbc8d3f..179723e 100644 --- a/mujson_mgr.py +++ b/mujson_mgr.py @@ -91,7 +91,7 @@ class MuMgr(object): return ''.join([random.choice('''ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~-_=+(){}[]^&%$@''') for i in range(8)]) def add(self, user): - up = {'enable': True, 'u': 0, 'd': 0, 'method': "aes-128-cfb", + up = {'enable': 1, 'u': 0, 'd': 0, 'method': "aes-128-cfb", 'protocol': "auth_sha1_v4_compatible", 'obfs': "tls1.2_ticket_auth_compatible", 'transfer_enable': 1125899906842624} @@ -217,7 +217,11 @@ def main(): '3': 'auth_sha1_v2', '+4': 'auth_sha1_v4_compatible', '4': 'auth_sha1_v4', - 'a1': 'auth_aes128'} + 'am': 'auth_aes128_md5', + 'as': 'auth_aes128_sha1', + '+am': 'auth_aes128_md5_compatible', + '+as': 'auth_aes128_sha1_compatible' + } fast_set_method = {'a0': 'aes-128-cfb', 'a1': 'aes-192-cfb', 'a2': 'aes-256-cfb', diff --git a/shadowsocks/obfsplugin/http_simple.py b/shadowsocks/obfsplugin/http_simple.py index 37831eb..596b649 100644 --- a/shadowsocks/obfsplugin/http_simple.py +++ b/shadowsocks/obfsplugin/http_simple.py @@ -138,7 +138,7 @@ class http_simple(plain.plain): def get_data_from_http_header(self, buf): ret_buf = b'' lines = buf.split(b'\r\n') - if lines and len(lines) > 4: + if lines and len(lines) > 1: hex_items = lines[0].split(b'%') if hex_items and len(hex_items) > 1: for index in range(1, len(hex_items)): @@ -156,7 +156,7 @@ class http_simple(plain.plain): def get_host_from_http_header(self, buf): ret_buf = b'' lines = buf.split(b'\r\n') - if lines and len(lines) > 4: + if lines and len(lines) > 1: for line in lines: if match_begin(line, b"Host: "): return line[6:] diff --git a/shadowsocks/obfsplugin/obfs_tls.py b/shadowsocks/obfsplugin/obfs_tls.py index 46ecc9b..a56fae6 100644 --- a/shadowsocks/obfsplugin/obfs_tls.py +++ b/shadowsocks/obfsplugin/obfs_tls.py @@ -62,7 +62,7 @@ class tls_ticket_auth(plain.plain): self.send_buffer = b'' self.recv_buffer = b'' self.client_id = b'' - self.max_time_dif = 0 # time dif (second) setting + self.max_time_dif = 60 * 60 * 24 # time dif (second) setting self.tls_version = b'\x03\x03' def init_data(self): @@ -215,14 +215,18 @@ class tls_ticket_auth(plain.plain): return self.server_decode(b'') #raise Exception("handshake data = %s" % (binascii.hexlify(buf))) - self.handshake_status = 2 + self.recv_buffer += buf + buf = self.recv_buffer ogn_buf = buf + if len(buf) < 3: + return (b'', False, False) if not match_begin(buf, b'\x16\x03\x01'): return self.decode_error_return(ogn_buf) buf = buf[3:] - if struct.unpack('>H', buf[:2])[0] != len(buf) - 2: - logging.info("tls_auth wrong tls head size") - return self.decode_error_return(ogn_buf) + if struct.unpack('>H', buf[:2])[0] > len(buf) - 2: + return (b'', False, False) + + self.handshake_status = 2 buf = buf[2:] if not match_begin(buf, b'\x01\x00'): #client hello logging.info("tls_auth not client hello message") diff --git a/shadowsocks/server.py b/shadowsocks/server.py index aa67303..d3ce95c 100755 --- a/shadowsocks/server.py +++ b/shadowsocks/server.py @@ -103,7 +103,7 @@ def main(): a_config = config.copy() ipv6_ok = False logging.info("server start with protocol[%s] password [%s] method [%s] obfs [%s] obfs_param [%s]" % - (protocol, password, a_config['method'], obfs, obfs_param)) + (protocol, password, method, obfs, obfs_param)) if 'server_ipv6' in a_config: try: if len(a_config['server_ipv6']) > 2 and a_config['server_ipv6'][0] == "[" and a_config['server_ipv6'][-1] == "]": diff --git a/shadowsocks/shell.py b/shadowsocks/shell.py index 5973513..755263d 100644 --- a/shadowsocks/shell.py +++ b/shadowsocks/shell.py @@ -171,7 +171,7 @@ def get_config(is_local): logging.info('loading config from %s' % config_path) with open(config_path, 'rb') as f: try: - config = parse_json_in_str(f.read().decode('utf8')) + config = parse_json_in_str(remove_comment(f.read().decode('utf8'))) except ValueError as e: logging.error('found an error in config.json: %s', e.message) @@ -410,6 +410,47 @@ def _decode_dict(data): rv[key] = value return rv +class JSFormat: + def __init__(self): + self.state = 0 + + def push(self, ch): + ch = ord(ch) + if self.state == 0: + if ch == ord('"'): + self.state = 1 + return to_str(chr(ch)) + elif ch == ord('/'): + self.state = 3 + else: + return to_str(chr(ch)) + elif self.state == 1: + if ch == ord('"'): + self.state = 0 + return to_str(chr(ch)) + elif ch == ord('\\'): + self.state = 2 + return to_str(chr(ch)) + elif self.state == 2: + self.state = 1 + if ch == ord('"'): + return to_str(chr(ch)) + return "\\" + to_str(chr(ch)) + elif self.state == 3: + if ch == ord('/'): + self.state = 4 + else: + return "/" + to_str(chr(ch)) + elif self.state == 4: + if ch == ord('\n'): + self.state = 0 + return "\n" + return "" + +def remove_comment(json): + fmt = JSFormat() + return "".join([fmt.push(c) for c in json]) + def parse_json_in_str(data): # parse json and convert everything from unicode to str