Browse Source

auth package size not less than head size

dev
BreakWa11 9 years ago
parent
commit
011415f710
  1. 14
      shadowsocks/obfsplugin/verify_simple.py

14
shadowsocks/obfsplugin/verify_simple.py

@ -110,6 +110,17 @@ class verify_base(plain.plain):
return self.sub_obfs.server_decode(buf) return self.sub_obfs.server_decode(buf)
return (buf, True, False) 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): class verify_simple(verify_base):
def __init__(self, method): def __init__(self, method):
super(verify_simple, self).__init__(method) super(verify_simple, self).__init__(method)
@ -422,7 +433,8 @@ class auth_simple(verify_base):
def client_pre_encrypt(self, buf): def client_pre_encrypt(self, buf):
ret = b'' ret = b''
if not self.has_sent_header: if not self.has_sent_header:
datalen = min(len(buf), common.ord(os.urandom(1)[0]) % 32 + 4) head_size = self.get_head_size(buf, 30)
datalen = min(len(buf), random.randint(0, 31) + head_size)
ret += self.pack_data(self.auth_data() + buf[:datalen]) ret += self.pack_data(self.auth_data() + buf[:datalen])
buf = buf[datalen:] buf = buf[datalen:]
self.has_sent_header = True self.has_sent_header = True

Loading…
Cancel
Save