|
|
@ -4,7 +4,8 @@ |
|
|
|
import re |
|
|
|
from ProxyDecoder import baseFunc |
|
|
|
|
|
|
|
def __trojanCommonDecode(url: str) -> dict: |
|
|
|
|
|
|
|
def __trojanDecode(url: str) -> dict: |
|
|
|
""" |
|
|
|
Trojan标准分享链接解码 |
|
|
|
|
|
|
@ -57,7 +58,7 @@ def __trojanCommonDecode(url: str) -> dict: |
|
|
|
if 'type' not in params: |
|
|
|
params['type'] = 'tcp' # default -> tcp |
|
|
|
stream = { |
|
|
|
'type': params['type'] |
|
|
|
'type': params['type'] if params['type'] != 'http' else 'h2' |
|
|
|
} |
|
|
|
if params['type'] == 'tcp': |
|
|
|
if 'headerType' in params and params['headerType'] == 'http': |
|
|
@ -100,44 +101,34 @@ def __trojanCommonDecode(url: str) -> dict: |
|
|
|
raise Exception('Unknown network type') |
|
|
|
|
|
|
|
if 'security' in params: |
|
|
|
if params['security'] not in ['tls', 'xtls']: |
|
|
|
if params['security'] in ['tls', 'xtls']: |
|
|
|
secure = { |
|
|
|
'type': params['security'] |
|
|
|
} |
|
|
|
if 'sni' in params: |
|
|
|
secure['sni'] = params['sni'] |
|
|
|
if 'alpn' in params: |
|
|
|
secure['alpn'] = params['alpn'] |
|
|
|
if params['security'] == 'xtls' and 'flow' in params: # XTLS flow |
|
|
|
if params['flow'] in ['xtls-rprx-origin', 'xtls-rprx-origin-udp443']: |
|
|
|
secure['flow'] = 'xtls-origin' |
|
|
|
elif params['flow'] in ['xtls-rprx-direct', 'xtls-rprx-direct-udp443']: |
|
|
|
secure['flow'] = 'xtls-direct' |
|
|
|
elif params['flow'] in ['xtls-rprx-splice', 'xtls-rprx-splice-udp443']: |
|
|
|
secure['flow'] = 'xtls-splice' |
|
|
|
elif params['security'] in ['', 'none']: |
|
|
|
secure = None |
|
|
|
else: |
|
|
|
raise Exception('Unknown security type') |
|
|
|
secure = { |
|
|
|
'type': params['security'] |
|
|
|
} |
|
|
|
if 'sni' in params: |
|
|
|
secure['sni'] = params['sni'] |
|
|
|
if 'alpn' in params: |
|
|
|
secure['alpn'] = params['alpn'] |
|
|
|
if params['security'] == 'xtls' and 'flow' in params: # XTLS flow |
|
|
|
if params['flow'] in ['xtls-rprx-origin', 'xtls-rprx-origin-udp443']: |
|
|
|
secure['flow'] = 'xtls-origin' |
|
|
|
elif params['flow'] in ['xtls-rprx-direct', 'xtls-rprx-direct-udp443']: |
|
|
|
secure['flow'] = 'xtls-direct' |
|
|
|
elif params['flow'] in ['xtls-rprx-splice', 'xtls-rprx-splice-udp443']: |
|
|
|
secure['flow'] = 'xtls-splice' |
|
|
|
stream['secure'] = secure |
|
|
|
info['stream'] = stream |
|
|
|
return info |
|
|
|
|
|
|
|
def trojanDecode(url: str) -> dict or None: |
|
|
|
""" |
|
|
|
Trojan分享链接解码 |
|
|
|
|
|
|
|
链接合法: |
|
|
|
return { |
|
|
|
'type': 'trojan', |
|
|
|
... |
|
|
|
} |
|
|
|
|
|
|
|
链接不合法: |
|
|
|
return None |
|
|
|
""" |
|
|
|
if url[0:9] != 'trojan://': |
|
|
|
return None |
|
|
|
try: |
|
|
|
result = __trojanCommonDecode(url) # try Trojan common decode |
|
|
|
except: |
|
|
|
return None |
|
|
|
result['type'] = 'trojan' |
|
|
|
return result |
|
|
|
def decode(url: str) -> dict: |
|
|
|
if url.split('://')[0] != 'trojan': |
|
|
|
raise Exception('Unexpected scheme') |
|
|
|
return { |
|
|
|
**{'type': 'trojan'}, |
|
|
|
**__trojanDecode(url) |
|
|
|
} |
|
|
|