|  | @ -1,64 +1,66 @@ | 
			
		
	
		
		
			
				
					|  |  | #!/usr/bin/python |  |  | #!/usr/bin/python | 
			
		
	
		
		
			
				
					|  |  | # -*- coding:utf-8 -*- |  |  | # -*- coding:utf-8 -*- | 
			
		
	
		
		
			
				
					|  |  | import json |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import json | 
			
		
	
		
		
			
				
					|  |  | from ProxyTester import Xray |  |  | from ProxyTester import Xray | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  | config = {} |  |  | testConfig = {} | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | def trojanBasicTest() -> dict: |  |  | def trojanBasicTest() -> dict: | 
			
		
	
		
		
			
				
					|  |  |     serverConfig = { |  |  |     serverConfig = { | 
			
		
	
		
		
			
				
					|  |  |         'run_type': 'server', |  |  |         'run_type': 'server', | 
			
		
	
		
		
			
				
					
					|  |  |         'local_addr': '127.0.0.1', |  |  |         'local_addr': testConfig['bind'], | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         'local_port': config['port'], |  |  |         'local_port': testConfig['port'], | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |         'password': [ |  |  |         'password': [ | 
			
		
	
		
		
			
				
					
					|  |  |             config['passwd'] |  |  |             testConfig['passwd'] | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |         ], |  |  |         ], | 
			
		
	
		
		
			
				
					|  |  |         'ssl': { |  |  |         'ssl': { | 
			
		
	
		
		
			
				
					
					|  |  |             'cert': config['cert'], |  |  |             'cert': testConfig['cert'], | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             'key': config['key'] |  |  |             'key': testConfig['key'] | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  |     return { |  |  |     return { | 
			
		
	
		
		
			
				
					|  |  |         'caption': 'Trojan basic', |  |  |         'caption': 'Trojan basic', | 
			
		
	
		
		
			
				
					|  |  |         'proxy': { |  |  |         'proxy': { | 
			
		
	
		
		
			
				
					|  |  |             'type': 'trojan', |  |  |             'type': 'trojan', | 
			
		
	
		
		
			
				
					
					|  |  |             'server': '127.0.0.1', |  |  |             'server': testConfig['addr'], | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             'port': config['port'], |  |  |             'port': testConfig['port'], | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             'passwd': config['passwd'], |  |  |             'passwd': testConfig['passwd'], | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |             'stream': { |  |  |             'stream': { | 
			
		
	
		
		
			
				
					|  |  |                 'type': 'tcp', |  |  |                 'type': 'tcp', | 
			
		
	
		
		
			
				
					|  |  |                 'secure': { |  |  |                 'secure': { | 
			
		
	
		
		
			
				
					|  |  |                     'type': 'tls', |  |  |                     'type': 'tls', | 
			
		
	
		
		
			
				
					
					|  |  |                     'sni': config['host'] |  |  |                     'sni': testConfig['host'] | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |                 } |  |  |                 } | 
			
		
	
		
		
			
				
					|  |  |             } |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |         }, |  |  |         }, | 
			
		
	
		
		
			
				
					|  |  |         'server': { |  |  |         'server': { | 
			
		
	
		
		
			
				
					
					|  |  |             'startCommand': ['trojan', '-c', config['file']], |  |  |             'startCommand': ['trojan', '-c', testConfig['file']], | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             'fileContent': json.dumps(serverConfig), |  |  |             'fileContent': json.dumps(serverConfig), | 
			
		
	
		
		
			
				
					
					|  |  |             'filePath': config['file'], |  |  |             'filePath': testConfig['file'], | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             'envVar': {} |  |  |             'envVar': {} | 
			
		
	
		
		
			
				
					|  |  |         }, |  |  |         }, | 
			
		
	
		
		
			
				
					|  |  |         'aider': None |  |  |         'aider': None | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | def loadTrojanStream(streamInfo: dict, xtlsFlow: str or None) -> dict: |  |  | def loadTrojanStream(streamInfo: dict, xtlsFlow: str or None) -> dict: | 
			
		
	
		
		
			
				
					|  |  |     proxyInfo = { |  |  |     proxyInfo = { | 
			
		
	
		
		
			
				
					|  |  |         'type': 'trojan', |  |  |         'type': 'trojan', | 
			
		
	
		
		
			
				
					
					|  |  |         'server': '127.0.0.1', |  |  |         'server': testConfig['addr'], | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         'port': config['port'], |  |  |         'port': testConfig['port'], | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         'passwd': config['passwd'], |  |  |         'passwd': testConfig['passwd'], | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |         'stream': streamInfo['client'] |  |  |         'stream': streamInfo['client'] | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  |     inboundConfig = { |  |  |     inboundConfig = { | 
			
		
	
		
		
			
				
					|  |  |         'protocol': 'trojan', |  |  |         'protocol': 'trojan', | 
			
		
	
		
		
			
				
					
					|  |  |         'listen': '127.0.0.1', |  |  |         'listen': testConfig['bind'], | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         'port': config['port'], |  |  |         'port': testConfig['port'], | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |         'settings': { |  |  |         'settings': { | 
			
		
	
		
		
			
				
					|  |  |             'clients': [ |  |  |             'clients': [ | 
			
		
	
		
		
			
				
					|  |  |                 { |  |  |                 { | 
			
		
	
		
		
			
				
					
					|  |  |                     'password': config['passwd'] |  |  |                     'password': testConfig['passwd'] | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |                 } |  |  |                 } | 
			
		
	
		
		
			
				
					|  |  |             ] |  |  |             ] | 
			
		
	
		
		
			
				
					|  |  |         }, |  |  |         }, | 
			
		
	
	
		
		
			
				
					|  | @ -70,79 +72,78 @@ def loadTrojanStream(streamInfo: dict, xtlsFlow: str or None) -> dict: | 
			
		
	
		
		
			
				
					|  |  |         'caption': 'Trojan network ' + streamInfo['caption'], |  |  |         'caption': 'Trojan network ' + streamInfo['caption'], | 
			
		
	
		
		
			
				
					|  |  |         'proxy': proxyInfo, |  |  |         'proxy': proxyInfo, | 
			
		
	
		
		
			
				
					|  |  |         'server': { |  |  |         'server': { | 
			
		
	
		
		
			
				
					
					|  |  |             'startCommand': ['xray', '-c', config['file']], |  |  |             'startCommand': ['xray', '-c', testConfig['file']], | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             'fileContent': Xray.xrayConfig(inboundConfig), |  |  |             'fileContent': Xray.xrayConfig(inboundConfig), | 
			
		
	
		
		
			
				
					
					|  |  |             'filePath': config['file'], |  |  |             'filePath': testConfig['file'], | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             'envVar': {} |  |  |             'envVar': {} | 
			
		
	
		
		
			
				
					|  |  |         }, |  |  |         }, | 
			
		
	
		
		
			
				
					|  |  |         'aider': None |  |  |         'aider': None | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | def trojanTest(trojanConfig: dict) -> list: |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     result = [] |  |  |  | 
			
		
	
		
		
			
				
					|  |  |     for key, value in trojanConfig.items(): # trojanConfig -> config |  |  |  | 
			
		
	
		
		
			
				
					|  |  |         config[key] = value |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(trojanBasicTest()) # basic test |  |  | def test(config: dict) -> list: | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |     global testConfig | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     testConfig = config | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     testList = [trojanBasicTest()] # basic test | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     # TCP stream |  |  |     # TCP stream | 
			
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.loadTcpStream(False, '', '') |  |  |     streamInfo = Xray.loadTcpStream(False, '', '') | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(loadTrojanStream(streamInfo, None)) |  |  |     testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) |  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(loadTrojanStream(streamInfo, None)) |  |  |     testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |     for flow in Xray.xtlsFlowList: |  |  |     for flow in Xray.xtlsFlowList: | 
			
		
	
		
		
			
				
					|  |  |         streamInfo = Xray.loadTcpStream(False, '', '') |  |  |         streamInfo = Xray.loadTcpStream(False, '', '') | 
			
		
	
		
		
			
				
					|  |  |         xtlsFlow, streamInfo = Xray.addXtlsConfig(streamInfo, config['cert'], config['key'], config['host'], flow) |  |  |         xtlsFlow, streamInfo = Xray.addXtlsConfig(streamInfo, config['cert'], config['key'], config['host'], flow) | 
			
		
	
		
		
			
				
					
					|  |  |         result.append(loadTrojanStream(streamInfo, xtlsFlow)) |  |  |         testList.append(loadTrojanStream(streamInfo, xtlsFlow)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.loadTcpStream(True, config['host'], '/') |  |  |     streamInfo = Xray.loadTcpStream(True, config['host'], '/') | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(loadTrojanStream(streamInfo, None)) |  |  |     testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) |  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(loadTrojanStream(streamInfo, None)) |  |  |     testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     # mKCP stream |  |  |     # mKCP stream | 
			
		
	
		
		
			
				
					|  |  |     for obfs in Xray.udpObfsList: |  |  |     for obfs in Xray.udpObfsList: | 
			
		
	
		
		
			
				
					|  |  |         streamInfo = Xray.loadKcpStream(config['passwd'], obfs) |  |  |         streamInfo = Xray.loadKcpStream(config['passwd'], obfs) | 
			
		
	
		
		
			
				
					
					|  |  |         result.append(loadTrojanStream(streamInfo, None)) |  |  |         testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |         streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) |  |  |         streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) | 
			
		
	
		
		
			
				
					
					|  |  |         result.append(loadTrojanStream(streamInfo, None)) |  |  |         testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |         for flow in Xray.xtlsFlowList: |  |  |         for flow in Xray.xtlsFlowList: | 
			
		
	
		
		
			
				
					|  |  |             streamInfo = Xray.loadKcpStream(config['passwd'], obfs) |  |  |             streamInfo = Xray.loadKcpStream(config['passwd'], obfs) | 
			
		
	
		
		
			
				
					|  |  |             xtlsFlow, streamInfo = Xray.addXtlsConfig(streamInfo, config['cert'], config['key'], config['host'], flow) |  |  |             xtlsFlow, streamInfo = Xray.addXtlsConfig(streamInfo, config['cert'], config['key'], config['host'], flow) | 
			
		
	
		
		
			
				
					
					|  |  |             result.append(loadTrojanStream(streamInfo, xtlsFlow)) |  |  |             testList.append(loadTrojanStream(streamInfo, xtlsFlow)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     # WebSocket stream |  |  |     # WebSocket stream | 
			
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.loadWsStream(config['host'], config['path'], False) |  |  |     streamInfo = Xray.loadWsStream(config['host'], config['path'], False) | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(loadTrojanStream(streamInfo, None)) |  |  |     testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) |  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(loadTrojanStream(streamInfo, None)) |  |  |     testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.loadWsStream(config['host'], config['path'], True) |  |  |     streamInfo = Xray.loadWsStream(config['host'], config['path'], True) | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(loadTrojanStream(streamInfo, None)) |  |  |     testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) |  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(loadTrojanStream(streamInfo, None)) |  |  |     testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     # HTTP/2 stream |  |  |     # HTTP/2 stream | 
			
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.loadH2Stream(config['host'], config['path']) |  |  |     streamInfo = Xray.loadH2Stream(config['host'], config['path']) | 
			
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) |  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(loadTrojanStream(streamInfo, None)) |  |  |     testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     # QUIC stream |  |  |     # QUIC stream | 
			
		
	
		
		
			
				
					|  |  |     for method in Xray.quicMethodList: |  |  |     for method in Xray.quicMethodList: | 
			
		
	
		
		
			
				
					|  |  |         for obfs in Xray.udpObfsList: |  |  |         for obfs in Xray.udpObfsList: | 
			
		
	
		
		
			
				
					|  |  |             streamInfo = Xray.loadQuicStream(method, config['passwd'], obfs) |  |  |             streamInfo = Xray.loadQuicStream(method, config['passwd'], obfs) | 
			
		
	
		
		
			
				
					|  |  |             streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) |  |  |             streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) | 
			
		
	
		
		
			
				
					
					|  |  |             result.append(loadTrojanStream(streamInfo, None)) |  |  |             testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     # GRPC stream |  |  |     # GRPC stream | 
			
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.loadGrpcStream(config['service']) |  |  |     streamInfo = Xray.loadGrpcStream(config['service']) | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(loadTrojanStream(streamInfo, None)) |  |  |     testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) |  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(loadTrojanStream(streamInfo, None)) |  |  |     testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.loadGrpcStream(config['service'], multiMode = True) |  |  |     streamInfo = Xray.loadGrpcStream(config['service'], multiMode = True) | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(loadTrojanStream(streamInfo, None)) |  |  |     testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) |  |  |     streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) | 
			
		
	
		
		
			
				
					
					|  |  |     result.append(loadTrojanStream(streamInfo, None)) |  |  |     testList.append(loadTrojanStream(streamInfo, None)) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     return result |  |  |     return testList | 
			
				
				
			
		
	
		
		
	
	
		
		
			
				
					|  | 
 |