From 249146d56e3c90c55caf61bb1b16ababc29fa124 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Wed, 9 Feb 2022 18:04:14 +0800 Subject: [PATCH] feat: builder test of shadowsocks --- ProxyBuilder/__main__.py | 3 -- ProxyBuilder/builder.py | 41 --------------- test/Shadowsocks.py | 109 +++++++++++++++++++++++++++++++++++++++ test/__init__.py | 4 ++ test/entry.py | 7 +++ 5 files changed, 120 insertions(+), 44 deletions(-) delete mode 100644 ProxyBuilder/__main__.py create mode 100644 test/Shadowsocks.py create mode 100644 test/__init__.py create mode 100644 test/entry.py diff --git a/ProxyBuilder/__main__.py b/ProxyBuilder/__main__.py deleted file mode 100644 index b49f65e..0000000 --- a/ProxyBuilder/__main__.py +++ /dev/null @@ -1,3 +0,0 @@ -import ProxyBuilder.builder - -ProxyBuilder.builder.test() diff --git a/ProxyBuilder/builder.py b/ProxyBuilder/builder.py index 795c04e..a0ab8df 100644 --- a/ProxyBuilder/builder.py +++ b/ProxyBuilder/builder.py @@ -130,44 +130,3 @@ def destroy(taskInfo): # 结束客户端并清理 try: os.remove(taskInfo['file']) # 删除配置文件 except: pass - -def test(): - import requests - import ProxyBuilder.test as tester - - data = tester.Shadowsocks.test(1080, 'dnomd343') - - for field in data: - serverProcess = subprocess.Popen( - field['serverCommand'], - stdout = subprocess.DEVNULL, - stderr = subprocess.DEVNULL) - time.sleep(0.5) # 等待服务端启动完成 - if serverProcess.poll() != None: # 服务端启动失败 - print("server unexpected exit") - continue - print(field['caption']) - - client = build(field['proxyInfo'], '/tmp/ProxyC') - time.sleep(0.5) # 等待客户端启动完成 - if not check(client): - print("client unexpected exit") # 客户端启动失败 - else: - try: - startTime = time.time_ns() - r = requests.get('http://gstatic.com/generate_204', proxies = { - 'http': 'socks5://127.0.0.1:' + str(client['port']), - 'https': 'socks5://127.0.0.1:' + str(client['port']), - }) - if r.status_code == 204: - delay = (time.time_ns() - startTime) / (10 ** 6) - print(format(delay, '.2f') + 'ms') - else: - print("connect error") - except: - print("request error") - destroy(client) # 关闭客户端 - time.sleep(0.3) - serverProcess.terminate() # 关闭服务端 - time.sleep(0.3) - print() diff --git a/test/Shadowsocks.py b/test/Shadowsocks.py new file mode 100644 index 0000000..e039764 --- /dev/null +++ b/test/Shadowsocks.py @@ -0,0 +1,109 @@ +#!/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 = 'Shadowsocks ' + 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/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..7d9ba6b --- /dev/null +++ b/test/__init__.py @@ -0,0 +1,4 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- + +from test.entry import Shadowsocks diff --git a/test/entry.py b/test/entry.py new file mode 100644 index 0000000..d782d44 --- /dev/null +++ b/test/entry.py @@ -0,0 +1,7 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- + +import test.Shadowsocks as ss + +def Shadowsocks(port, password): + return ss.test(port, password)