|
|
@ -4,6 +4,7 @@ |
|
|
|
import os |
|
|
|
import json |
|
|
|
from Tester import Plugin |
|
|
|
from Tester import Settings |
|
|
|
from Builder import TrojanGo |
|
|
|
from Basis.Logger import logging |
|
|
|
from Basis.Process import Process |
|
|
@ -12,48 +13,6 @@ from Basis.Functions import genFlag |
|
|
|
from Basis.Methods import trojanGoMethods |
|
|
|
from Basis.Functions import getAvailablePort |
|
|
|
|
|
|
|
settings = { |
|
|
|
'serverBind': '127.0.0.1', |
|
|
|
'clientBind': '127.0.0.1', |
|
|
|
# 'serverBind': '::1', |
|
|
|
# 'clientBind': '::1', |
|
|
|
'workDir': '/tmp/ProxyC', |
|
|
|
'host': '343.re', |
|
|
|
'cert': '/etc/ssl/certs/343.re/fullchain.pem', |
|
|
|
'key': '/etc/ssl/certs/343.re/privkey.pem', |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# def wsConfig(proxyInfo: dict) -> dict: |
|
|
|
# if proxyInfo['ws'] is None: |
|
|
|
# return {'enabled': False} |
|
|
|
# wsObject = { |
|
|
|
# 'enabled': True, |
|
|
|
# 'path': proxyInfo['ws']['path'] |
|
|
|
# } |
|
|
|
# if proxyInfo['ws']['host'] != '': |
|
|
|
# wsObject['host'] = proxyInfo['ws']['host'] |
|
|
|
# return wsObject |
|
|
|
# |
|
|
|
# |
|
|
|
# def ssConfig(proxyInfo: dict) -> dict: |
|
|
|
# return {**{ |
|
|
|
# 'enabled': False if proxyInfo['ss'] is None else True |
|
|
|
# }, **({} if proxyInfo['ss'] is None else { |
|
|
|
# 'method': proxyInfo['ss']['method'], |
|
|
|
# 'password': proxyInfo['ss']['passwd'], |
|
|
|
# })} |
|
|
|
# |
|
|
|
# |
|
|
|
# def pluginConfig(proxyInfo: dict) -> dict: |
|
|
|
# return {**{ |
|
|
|
# 'enabled': False if proxyInfo['plugin'] is None else True |
|
|
|
# }, **({} if proxyInfo['plugin'] is None else { |
|
|
|
# 'type': 'shadowsocks', |
|
|
|
# 'command': proxyInfo['plugin']['type'], |
|
|
|
# 'option': proxyInfo['plugin']['param'], |
|
|
|
# })} |
|
|
|
|
|
|
|
|
|
|
|
def loadServer(configFile: str, proxyInfo: dict) -> Process: |
|
|
|
trojanGoConfig = { |
|
|
@ -67,24 +26,24 @@ def loadServer(configFile: str, proxyInfo: dict) -> Process: |
|
|
|
], |
|
|
|
'disable_http_check': True, |
|
|
|
'ssl': { |
|
|
|
'cert': settings['cert'], |
|
|
|
'key': settings['key'] |
|
|
|
'cert': Settings['cert'], |
|
|
|
'key': Settings['key'] |
|
|
|
}, |
|
|
|
'websocket': TrojanGo.wsConfig(proxyInfo), |
|
|
|
'shadowsocks': TrojanGo.ssConfig(proxyInfo), |
|
|
|
'transport_plugin': TrojanGo.pluginConfig(proxyInfo), |
|
|
|
} |
|
|
|
serverFile = os.path.join(settings['workDir'], configFile) |
|
|
|
return Process(settings['workDir'], cmd = ['trojan-go', '-config', serverFile], file = { |
|
|
|
serverFile = os.path.join(Settings['workDir'], configFile) |
|
|
|
return Process(Settings['workDir'], cmd = ['trojan-go', '-config', serverFile], file = { |
|
|
|
'path': serverFile, |
|
|
|
'content': json.dumps(trojanGoConfig) |
|
|
|
}, isStart = False) |
|
|
|
|
|
|
|
|
|
|
|
def loadClient(configFile: str, proxyInfo: dict, socksInfo: dict) -> Process: # load client process |
|
|
|
clientFile = os.path.join(settings['workDir'], configFile) |
|
|
|
clientFile = os.path.join(Settings['workDir'], configFile) |
|
|
|
trojanGoCommand, trojanGoConfig, _ = TrojanGo.load(proxyInfo, socksInfo, clientFile) |
|
|
|
return Process(settings['workDir'], cmd = trojanGoCommand, file = { |
|
|
|
return Process(Settings['workDir'], cmd = trojanGoCommand, file = { |
|
|
|
'path': clientFile, |
|
|
|
'content': trojanGoConfig |
|
|
|
}, isStart = False) |
|
|
@ -92,17 +51,17 @@ def loadClient(configFile: str, proxyInfo: dict, socksInfo: dict) -> Process: # |
|
|
|
|
|
|
|
def loadTest(wsObject: dict or None, ssObject: dict or None, plugin: dict or None = None) -> dict: |
|
|
|
proxyInfo = { # connection info |
|
|
|
'server': settings['serverBind'], |
|
|
|
'server': Settings['serverBind'], |
|
|
|
'port': getAvailablePort(), |
|
|
|
'passwd': genFlag(length = 8), # random password |
|
|
|
'sni': settings['host'], |
|
|
|
'sni': Settings['host'], |
|
|
|
'alpn': None, |
|
|
|
'verify': True, |
|
|
|
'ws': wsObject, |
|
|
|
'ss': ssObject, |
|
|
|
} |
|
|
|
socksInfo = { # socks5 interface for test |
|
|
|
'addr': settings['clientBind'], |
|
|
|
'addr': Settings['clientBind'], |
|
|
|
'port': getAvailablePort() |
|
|
|
} |
|
|
|
configName = 'trojan-go%s%s%s' % ( |
|
|
@ -112,11 +71,12 @@ def loadTest(wsObject: dict or None, ssObject: dict or None, plugin: dict or Non |
|
|
|
) |
|
|
|
pluginClient = {'plugin': None if plugin is None else plugin['client']} |
|
|
|
pluginServer = {'plugin': None if plugin is None else plugin['server']} |
|
|
|
testTitle = 'Trojan-Go test: original' + \ |
|
|
|
('' if ssObject is None else ' (with %s encrypt)' % ssObject['method']) + \ |
|
|
|
('' if wsObject is None else ' (with websocket)') + \ |
|
|
|
('' if plugin is None else ' [%s -> %s]' % (plugin['type'], plugin['caption'])) |
|
|
|
testInfo = { # release test info |
|
|
|
'title': 'Trojan-Go test: original' + \ |
|
|
|
('' if ssObject is None else ' (with %s encrypt)' % ssObject['method']) + \ |
|
|
|
('' if wsObject is None else ' (with websocket)') + \ |
|
|
|
('' if plugin is None else ' [%s -> %s]' % (plugin['type'], plugin['caption'])), |
|
|
|
'title': testTitle, |
|
|
|
'client': loadClient(configName + '_client.json', {**proxyInfo, **pluginClient}, socksInfo), |
|
|
|
'server': loadServer(configName + '_server.json', {**proxyInfo, **pluginServer}), |
|
|
|
'socks': socksInfo, # exposed socks5 address |
|
|
@ -140,7 +100,7 @@ def load(): |
|
|
|
except StopIteration: |
|
|
|
break |
|
|
|
wsObject = { |
|
|
|
'host': settings['host'], |
|
|
|
'host': Settings['host'], |
|
|
|
'path': '/' + genFlag(length = 6), |
|
|
|
} |
|
|
|
yield loadTest(None, None, None) |
|
|
|