From f88bf83f27e69cc7909e88c0996a2dd1e1c22ce5 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Wed, 9 Feb 2022 19:10:35 +0800 Subject: [PATCH] feat: builder test of shadowsocksr --- ProxyBuilder/test/Shadowsocks.py | 109 -------------------------- ProxyBuilder/test/__init__.py | 4 - test.py | 41 ++++++++++ test/Shadowsocks.py | 4 +- test/ShadowsocksR.py | 128 +++++++++++++++++++++++++++++++ test/__init__.py | 1 + test/entry.py | 4 + 7 files changed, 176 insertions(+), 115 deletions(-) delete mode 100644 ProxyBuilder/test/Shadowsocks.py delete mode 100644 ProxyBuilder/test/__init__.py create mode 100644 test.py create mode 100644 test/ShadowsocksR.py diff --git a/ProxyBuilder/test/Shadowsocks.py b/ProxyBuilder/test/Shadowsocks.py deleted file mode 100644 index 95fc4df..0000000 --- a/ProxyBuilder/test/Shadowsocks.py +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/python -# -*- coding:utf-8 -*- - -ssMethodList = [ - 'aes-128-gcm', - 'aes-192-gcm', - 'aes-256-gcm', - 'aes-128-ctr', - 'aes-192-ctr', - 'aes-256-ctr', - 'aes-128-ocb', - 'aes-192-ocb', - 'aes-256-ocb', - 'aes-128-ofb', - 'aes-192-ofb', - 'aes-256-ofb', - 'aes-128-cfb', - 'aes-192-cfb', - 'aes-256-cfb', - 'aes-128-cfb1', - 'aes-192-cfb1', - 'aes-256-cfb1', - 'aes-128-cfb8', - 'aes-192-cfb8', - 'aes-256-cfb8', - 'aes-128-cfb128', - 'aes-192-cfb128', - 'aes-256-cfb128', - 'camellia-128-cfb', - 'camellia-192-cfb', - 'camellia-256-cfb', - 'camellia-128-cfb128', - 'camellia-192-cfb128', - 'camellia-256-cfb128', - 'plain', - 'none', - 'table', - 'rc4', - 'rc4-md5', - 'rc2-cfb', - 'bf-cfb', - 'cast5-cfb', - 'des-cfb', - 'idea-cfb', - 'seed-cfb', - 'salsa20', - 'salsa20-ctr', - 'xchacha20', - 'chacha20', - 'chacha20-ietf', - 'chacha20-poly1305', - 'chacha20-ietf-poly1305', - 'xchacha20-ietf-poly1305' -] - -def test(port, password): - testList = [] - for method in ssMethodList: - proxyInfo = { - 'type': 'ss', - 'server': '127.0.0.1', - 'port': str(port), - 'password': password, - 'method': method, - 'plugin': '', - 'pluginArg': '', - } - testInfo = 'test for ' + method - if method == 'plain' or method == 'none': - serverCommand = [ - 'ss-rust-server', '-U', - '-s', '0.0.0.0:' + str(port), - '-k', password, - '-m', method - ] - elif method == 'salsa20-ctr': - serverCommand = [ - 'ss-bootstrap-server', - '--shadowsocks', 'ss-python-legacy-server', - '-p', str(port), - '-k', password, - '-m', method - ] - else: - specialMethods = [ - 'aes-128-cfb128', - 'aes-192-cfb128', - 'aes-256-cfb128', - 'camellia-128-cfb128', - 'camellia-192-cfb128', - 'camellia-256-cfb128', - ] - if method in specialMethods: - method = 'mbedtls:' + method - serverCommand = [ - 'ss-bootstrap-server', - '--shadowsocks', 'ss-python-server', - '-p', str(port), - '-k', password, - '-m', method - ] - if method == 'idea-cfb' or method == 'seed-cfb': - serverCommand.append('--libopenssl=libcrypto.so.1.0.0') - testList.append({ - 'caption': testInfo, - 'proxyInfo': proxyInfo, - 'serverCommand': serverCommand - }) - return testList diff --git a/ProxyBuilder/test/__init__.py b/ProxyBuilder/test/__init__.py deleted file mode 100644 index b3ef4ca..0000000 --- a/ProxyBuilder/test/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/python -# -*- coding:utf-8 -*- - -from ProxyBuilder.test import Shadowsocks diff --git a/test.py b/test.py new file mode 100644 index 0000000..ff8bc1b --- /dev/null +++ b/test.py @@ -0,0 +1,41 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- + +import time +import subprocess + +import test as Tester +import ProxyBuilder as Builder +import ProxyChecker as Checker + +# print(dir(Tester)) + +# data = Tester.Shadowsocks(1081, 'dnomd343') +data = Tester.ShadowsocksR(1081, 'dnomd343') + +# for field in data: +# print(field['proxyInfo']) +# print(field['serverCommand']) +# print('') + +for field in data: + serverProcess = subprocess.Popen( + field['serverCommand'], + stdout = subprocess.DEVNULL, + stderr = subprocess.DEVNULL) + time.sleep(0.1) # 等待进程启动 + if serverProcess.poll() != None: # 服务端启动失败 + print("server unexpected exit") + continue + print(field['caption'] + ' => ', end = '') + client = Builder.build(field['proxyInfo'], '/tmp/ProxyC') + time.sleep(0.5) # 等待初始化完成 + if not Builder.check(client): + print("client unexpected exit") # 客户端启动失败 + else: + print(format(Checker.httpPing(client['port']), '.2f') + 'ms') + Builder.destroy(client) # 关闭客户端 + time.sleep(0.1) + serverProcess.terminate() # 关闭服务端 + time.sleep(0.1) + print() diff --git a/test/Shadowsocks.py b/test/Shadowsocks.py index e039764..322e162 100644 --- a/test/Shadowsocks.py +++ b/test/Shadowsocks.py @@ -59,13 +59,13 @@ def test(port, password): proxyInfo = { 'type': 'ss', 'server': '127.0.0.1', - 'port': str(port), + 'port': int(port), 'password': password, 'method': method, 'plugin': '', 'pluginArg': '', } - testInfo = 'Shadowsocks ' + method + testInfo = 'Shadowsocks method ' + method if method == 'plain' or method == 'none': serverCommand = [ 'ss-rust-server', '-U', diff --git a/test/ShadowsocksR.py b/test/ShadowsocksR.py new file mode 100644 index 0000000..75dbf7a --- /dev/null +++ b/test/ShadowsocksR.py @@ -0,0 +1,128 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- + + +ssrMethodList = [ + "aes-128-cfb", + "aes-192-cfb", + "aes-256-cfb", + "aes-128-cfb1", + "aes-192-cfb1", + "aes-256-cfb1", + "aes-128-cfb8", + "aes-192-cfb8", + "aes-256-cfb8", + "aes-128-ctr", + "aes-192-ctr", + "aes-256-ctr", + "aes-128-gcm", + "aes-192-gcm", + "aes-256-gcm", + "aes-128-ofb", + "aes-192-ofb", + "aes-256-ofb", + "camellia-128-cfb", + "camellia-192-cfb", + "camellia-256-cfb", + "none", + "table", + "rc4", + "rc4-md5", + "rc4-md5-6", + "bf-cfb", + "cast5-cfb", + "des-cfb", + "idea-cfb", + "seed-cfb", + "rc2-cfb", + "salsa20", + "xsalsa20", + "chacha20", + "xchacha20", + "chacha20-ietf", +] + +ssrProtocolList = [ + "origin", + "verify_sha1", + "verify_simple", + "verify_deflate", + "auth_simple", + "auth_sha1", + "auth_sha1_v2", + "auth_sha1_v4", + "auth_aes128", + "auth_aes128_md5", + "auth_aes128_sha1", + "auth_chain_a", + "auth_chain_b", + "auth_chain_c", + "auth_chain_d", + "auth_chain_e", + "auth_chain_f", +] + +ssrObfsList = [ + "plain", + "http_post", + "http_simple", + "tls_simple", + "tls1.2_ticket_auth", + "tls1.2_ticket_fastauth", + "random_head", +] + +def test(port, password): + testList = [] + for method in ssrMethodList: + proxyInfo = { + 'type': 'ssr', + 'server': '127.0.0.1', + 'port': int(port), + 'password': password, + 'method': method, + 'protocol': 'origin', + 'protocolParam': '', + 'obfs': 'plain', + 'obfsParam': '' + } + serverCommand = [ + 'ssr-server', + '-p', str(port), + '-k', password, + '-m', method, + '-O', 'origin', + '-o', 'plain' + ] + testList.append({ + 'caption': 'ShadowsocksR method ' + method, + 'proxyInfo': proxyInfo, + 'serverCommand': serverCommand + }) + for protocol in ssrProtocolList: + for obfs in ssrObfsList: + proxyInfo = { + 'type': 'ssr', + 'server': '127.0.0.1', + 'port': int(port), + 'password': password, + 'method': 'table', + 'protocol': protocol, + 'protocolParam': '', + 'obfs': obfs, + 'obfsParam': '' + } + serverCommand = [ + 'ssr-server', + '-p', str(port), + '-k', password, + '-m', 'table', + '-O', protocol, + '-o', obfs + ] + testList.append({ + 'caption': 'ShadowsocksR protocol ' + protocol + ' obfs ' + obfs, + 'proxyInfo': proxyInfo, + 'serverCommand': serverCommand + }) + return testList diff --git a/test/__init__.py b/test/__init__.py index 7d9ba6b..fb7418d 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -2,3 +2,4 @@ # -*- coding:utf-8 -*- from test.entry import Shadowsocks +from test.entry import ShadowsocksR diff --git a/test/entry.py b/test/entry.py index d782d44..e23d7c6 100644 --- a/test/entry.py +++ b/test/entry.py @@ -2,6 +2,10 @@ # -*- coding:utf-8 -*- import test.Shadowsocks as ss +import test.ShadowsocksR as ssr def Shadowsocks(port, password): return ss.test(port, password) + +def ShadowsocksR(port, password): + return ssr.test(port, password)