add random_head obfs
This commit is contained in:
parent
6f8fc5b77f
commit
f9e8af6358
1 changed files with 33 additions and 1 deletions
|
@ -24,7 +24,8 @@ import logging
|
||||||
import binascii
|
import binascii
|
||||||
import base64
|
import base64
|
||||||
import datetime
|
import datetime
|
||||||
from shadowsocks.common import to_bytes, to_str
|
from shadowsocks import common
|
||||||
|
from shadowsocks.common import to_bytes, to_str, ord
|
||||||
|
|
||||||
def create_http_obfs(method):
|
def create_http_obfs(method):
|
||||||
return http_simple(method)
|
return http_simple(method)
|
||||||
|
@ -35,10 +36,14 @@ def create_http2_obfs(method):
|
||||||
def create_tls_obfs(method):
|
def create_tls_obfs(method):
|
||||||
return tls_simple(method)
|
return tls_simple(method)
|
||||||
|
|
||||||
|
def create_random_head_obfs(method):
|
||||||
|
return random_head(method)
|
||||||
|
|
||||||
obfs = {
|
obfs = {
|
||||||
'http_simple': (create_http_obfs,),
|
'http_simple': (create_http_obfs,),
|
||||||
'http2_simple': (create_http2_obfs,),
|
'http2_simple': (create_http2_obfs,),
|
||||||
'tls_simple': (create_tls_obfs,),
|
'tls_simple': (create_tls_obfs,),
|
||||||
|
'random_head': (create_random_head_obfs,),
|
||||||
}
|
}
|
||||||
|
|
||||||
def match_begin(str1, str2):
|
def match_begin(str1, str2):
|
||||||
|
@ -215,3 +220,30 @@ class tls_simple(object):
|
||||||
return (buf, True, False)
|
return (buf, True, False)
|
||||||
# (buffer_to_recv, is_need_decrypt, is_need_to_encode_and_send_back)
|
# (buffer_to_recv, is_need_decrypt, is_need_to_encode_and_send_back)
|
||||||
return (b'', False, True)
|
return (b'', False, True)
|
||||||
|
|
||||||
|
class random_head(object):
|
||||||
|
def __init__(self, method):
|
||||||
|
self.method = method
|
||||||
|
self.has_sent_header = False
|
||||||
|
self.has_recv_header = False
|
||||||
|
|
||||||
|
def client_encode(self, buf):
|
||||||
|
return buf
|
||||||
|
|
||||||
|
def client_decode(self, buf):
|
||||||
|
# (buffer_to_recv, is_need_to_encode_and_send_back)
|
||||||
|
return (buf, False)
|
||||||
|
|
||||||
|
def server_encode(self, buf):
|
||||||
|
if self.has_sent_header:
|
||||||
|
return buf
|
||||||
|
self.has_sent_header = True
|
||||||
|
return os.urandom(common.ord(os.urandom(1)[0]) % 96)
|
||||||
|
|
||||||
|
def server_decode(self, buf):
|
||||||
|
if self.has_recv_header:
|
||||||
|
return (buf, True, False)
|
||||||
|
|
||||||
|
self.has_recv_header = True
|
||||||
|
# (buffer_to_recv, is_need_decrypt, is_need_to_encode_and_send_back)
|
||||||
|
return (b'', False, True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue