diff --git a/shadowsocks/obfsplugin/http_simple.py b/shadowsocks/obfsplugin/http_simple.py index 4dc8d49..926ba85 100644 --- a/shadowsocks/obfsplugin/http_simple.py +++ b/shadowsocks/obfsplugin/http_simple.py @@ -90,8 +90,9 @@ class http_simple(plain.plain): def client_encode(self, buf): if self.has_sent_header: return buf - if len(buf) > 64: - headlen = random.randint(1, 64) + head_size = self.get_head_size(buf, 30) + if len(buf) - head_size > 64: + headlen = head_size + random.randint(1, 64) else: headlen = len(buf) headdata = buf[:headlen] diff --git a/shadowsocks/obfsplugin/plain.py b/shadowsocks/obfsplugin/plain.py index 5450e7a..a99fb0b 100644 --- a/shadowsocks/obfsplugin/plain.py +++ b/shadowsocks/obfsplugin/plain.py @@ -22,6 +22,8 @@ import sys import hashlib import logging +from shadowsocks.common import ord + def create_obfs(method): return plain(method) @@ -70,3 +72,15 @@ class plain(object): def dispose(self): pass + 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 + diff --git a/shadowsocks/obfsplugin/verify_simple.py b/shadowsocks/obfsplugin/verify_simple.py index 03c73b2..16c8342 100644 --- a/shadowsocks/obfsplugin/verify_simple.py +++ b/shadowsocks/obfsplugin/verify_simple.py @@ -82,17 +82,6 @@ class verify_base(plain.plain): def server_decode(self, buf): return (buf, True, False) - def get_head_size(self, buf, def_value): - if len(buf) < 2: - return def_value - if ord(buf[0]) == 1: - return 7 - if ord(buf[0]) == 4: - return 19 - if ord(buf[0]) == 3: - return 4 + ord(buf[1]) - return def_value - class verify_simple(verify_base): def __init__(self, method): super(verify_simple, self).__init__(method)