Browse Source

pack header in uri

dev
BreakWa11 9 years ago
parent
commit
2a03747e76
  1. 5
      shadowsocks/obfsplugin/http_simple.py
  2. 14
      shadowsocks/obfsplugin/plain.py
  3. 11
      shadowsocks/obfsplugin/verify_simple.py

5
shadowsocks/obfsplugin/http_simple.py

@ -90,8 +90,9 @@ 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
if len(buf) > 64: head_size = self.get_head_size(buf, 30)
headlen = random.randint(1, 64) if len(buf) - head_size > 64:
headlen = head_size + random.randint(1, 64)
else: else:
headlen = len(buf) headlen = len(buf)
headdata = buf[:headlen] headdata = buf[:headlen]

14
shadowsocks/obfsplugin/plain.py

@ -22,6 +22,8 @@ import sys
import hashlib import hashlib
import logging import logging
from shadowsocks.common import ord
def create_obfs(method): def create_obfs(method):
return plain(method) return plain(method)
@ -70,3 +72,15 @@ class plain(object):
def dispose(self): def dispose(self):
pass 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

11
shadowsocks/obfsplugin/verify_simple.py

@ -82,17 +82,6 @@ class verify_base(plain.plain):
def server_decode(self, buf): def server_decode(self, 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)

Loading…
Cancel
Save