Skip to content

Commit 38ef6a2

Browse files
committed
add auth_chain_b
1 parent ab236ff commit 38ef6a2

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

shadowsocks/obfsplugin/auth_chain.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import zlib
3232
import hmac
3333
import hashlib
34+
import bisect
3435

3536
import shadowsocks
3637
from shadowsocks import common, lru_cache, encrypt
@@ -40,9 +41,12 @@
4041
def create_auth_chain_a(method):
4142
return auth_chain_a(method)
4243

44+
def create_auth_chain_b(method):
45+
return auth_chain_b(method)
4346

4447
obfs_map = {
4548
'auth_chain_a': (create_auth_chain_a,),
49+
'auth_chain_b': (create_auth_chain_b,),
4650
}
4751

4852
class xorshift128plus(object):
@@ -630,3 +634,46 @@ def server_udp_post_decrypt(self, buf):
630634
def dispose(self):
631635
self.server_info.data.remove(self.user_id, self.client_id)
632636

637+
class auth_chain_b(auth_chain_a):
638+
def __init__(self, method):
639+
super(auth_chain_b, self).__init__(method)
640+
self.salt = b"auth_chain_b"
641+
self.no_compatible_method = 'auth_chain_b'
642+
self.data_size_list = []
643+
644+
def init_data_size(self, key):
645+
if self.data_size_list:
646+
self.data_size_list = []
647+
random = xorshift128plus()
648+
random.init_from_bin(key)
649+
list_len = random.next() % 32 + 8;
650+
for i in range(0, list_len):
651+
self.data_size_list.append((int)(random.next() % 1440))
652+
self.data_size_list.sort()
653+
654+
def set_server_info(self, server_info):
655+
self.server_info = server_info
656+
try:
657+
max_client = int(server_info.protocol_param.split('#')[0])
658+
except:
659+
max_client = 64
660+
self.server_info.data.set_max_client(max_client)
661+
self.init_data_size(self.server_info.key)
662+
663+
def rnd_data_len(self, buf_size, last_hash, random):
664+
if buf_size >= 1440:
665+
return 0
666+
random.init_from_bin_len(last_hash, buf_size)
667+
pos = bisect.bisect_left(self.data_size_list, buf_size)
668+
final_pos = pos + random.next() % (len(self.data_size_list) + 1 - pos)
669+
if final_pos < len(self.data_size_list):
670+
return self.data_size_list[final_pos] - buf_size
671+
672+
if buf_size > 1300:
673+
return random.next() % 31
674+
if buf_size > 900:
675+
return random.next() % 127
676+
if buf_size > 400:
677+
return random.next() % 521
678+
return random.next() % 1021
679+

0 commit comments

Comments
 (0)