diff --git a/Builder/Trojan.py b/Builder/Trojan.py new file mode 100644 index 0000000..e9078fe --- /dev/null +++ b/Builder/Trojan.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import json +from Builder import Xray + + +def load(proxyInfo: dict, socksInfo: dict, configFile: str) -> tuple[list, str, dict]: + outboundConfig = { + 'protocol': 'trojan', + 'settings': { + 'servers': [{**{ + 'address': proxyInfo['server'], + 'port': proxyInfo['port'], + 'password': proxyInfo['passwd'], + }, **Xray.xtlsFlow(proxyInfo['stream'])}] + }, + 'streamSettings': Xray.loadStream(proxyInfo['stream']) + } + trojanConfig = Xray.loadConfig(socksInfo, outboundConfig) # load config file for xray-core + return ['xray', '-c', configFile], json.dumps(trojanConfig), {} diff --git a/Builder/VLESS.py b/Builder/VLESS.py index cf74b2c..e91522f 100644 --- a/Builder/VLESS.py +++ b/Builder/VLESS.py @@ -4,6 +4,7 @@ import json from Builder import Xray + def load(proxyInfo: dict, socksInfo: dict, configFile: str) -> tuple[list, str, dict]: outboundConfig = { 'protocol': 'vless', diff --git a/Builder/Xray.py b/Builder/Xray.py index 624c6f3..49321c1 100644 --- a/Builder/Xray.py +++ b/Builder/Xray.py @@ -61,7 +61,7 @@ def loadStream(streamInfo: dict) -> dict: def xtlsFlow(streamInfo: dict or None) -> dict: - if streamInfo['secure'] is not None: # without TLS / XTLS options + if streamInfo['secure'] is None: # without TLS / XTLS options return {} if streamInfo['secure']['type'] != 'xtls': # not XTLS secure type return {} diff --git a/Builder/__init__.py b/Builder/__init__.py index 0800775..f63116c 100644 --- a/Builder/__init__.py +++ b/Builder/__init__.py @@ -6,6 +6,7 @@ import copy from Builder import VMess from Builder import VLESS +from Builder import Trojan from Builder import Shadowsocks from Builder import ShadowsocksR @@ -18,7 +19,8 @@ clientEntry = { 'ss': [Shadowsocks.load, '.json'], 'ssr': [ShadowsocksR.load, '.json'], 'vmess': [VMess.load, '.json'], - 'vless': [VLESS.load, '.json'] + 'vless': [VLESS.load, '.json'], + 'trojan': [Trojan.load, '.json'], } diff --git a/demo.py b/demo.py index ab84b3a..c627ceb 100755 --- a/demo.py +++ b/demo.py @@ -46,7 +46,6 @@ proxyVLESS = { 'port': 12345, 'method': 'none', 'id': '614d3a56-8a04-4c65-88a2-45896f0bd13c', - 'aid': 0, 'stream': { 'type': 'tcp', 'obfs': None, @@ -61,10 +60,27 @@ proxyVLESS = { } } +proxyTrojan = { + 'server': '127.0.0.1', + 'port': 12345, + 'passwd': 'dnomd343', + 'stream': { + 'type': 'tcp', + 'obfs': None, + 'secure': { + 'type': 'tls', + 'sni': '343.re', + 'alpn': None, + 'verify': True, + }, + } +} + # client = Builder('ss', proxySS) # client = Builder('ssr', proxySSR) # client = Builder('vmess', proxyVMess) -client = Builder('vless', proxyVLESS) +# client = Builder('vless', proxyVLESS) +client = Builder('trojan', proxyTrojan) logging.critical(client.id) logging.critical(client.proxyType)