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