|
@ -2,6 +2,7 @@ |
|
|
# -*- coding: utf-8 -*- |
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
|
|
|
|
import json |
|
|
import json |
|
|
|
|
|
from Basis.Exception import buildException |
|
|
from Basis.Constant import ssMethods, ssAllMethods, mbedtlsMethods |
|
|
from Basis.Constant import ssMethods, ssAllMethods, mbedtlsMethods |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -20,25 +21,25 @@ def loadConfig(proxyInfo: dict, socksInfo: dict) -> dict: # load basic config o |
|
|
return config |
|
|
return config |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pluginUdp(plugin: str, pluginParam: str) -> bool: # whether the plugin uses UDP |
|
|
def pluginUdp(plugin: str, pluginParam: str) -> bool: # whether the plugin uses udp |
|
|
if plugin in ['obfs-local', 'simple-tls', 'ck-client', 'gq-client', 'mtt-client', 'rabbit-plugin']: |
|
|
if plugin in ['obfs-local', 'simple-tls', 'ck-client', 'gq-client', 'mtt-client', 'rabbit-plugin']: |
|
|
return False # UDP is not used |
|
|
return False # UDP is not used |
|
|
if plugin in ['v2ray-plugin', 'xray-plugin', 'gost-plugin']: |
|
|
if plugin in ['v2ray-plugin', 'xray-plugin', 'gost-plugin']: |
|
|
if 'mode=quic' not in pluginParam.split(';'): # non-quic mode does not use UDP |
|
|
if 'mode=quic' not in pluginParam.split(';'): # non-quic mode does not use udp |
|
|
return False |
|
|
return False |
|
|
return True # UDP is assumed by default |
|
|
return True # udp is assumed by default |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ssRust(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list, dict]: |
|
|
def ssRust(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list, dict]: |
|
|
config = loadConfig(proxyInfo, socksInfo) |
|
|
config = loadConfig(proxyInfo, socksInfo) |
|
|
if isUdp: # proxy UDP traffic |
|
|
if isUdp: # proxy udp traffic |
|
|
config['mode'] = 'tcp_and_udp' |
|
|
config['mode'] = 'tcp_and_udp' |
|
|
return config, ['ss-rust-local', '-v'], {'RUST_BACKTRACE': 'full'} |
|
|
return config, ['ss-rust-local', '-v'], {'RUST_BACKTRACE': 'full'} # enable rust trace |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ssLibev(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list, dict]: |
|
|
def ssLibev(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list, dict]: |
|
|
config = loadConfig(proxyInfo, socksInfo) |
|
|
config = loadConfig(proxyInfo, socksInfo) |
|
|
if isUdp: # proxy UDP traffic |
|
|
if isUdp: # proxy udp traffic |
|
|
config['mode'] = 'tcp_and_udp' |
|
|
config['mode'] = 'tcp_and_udp' |
|
|
return config, ['ss-libev-local', '-v'], {} |
|
|
return config, ['ss-libev-local', '-v'], {} |
|
|
|
|
|
|
|
@ -50,7 +51,7 @@ def ssPython(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list, |
|
|
if config['method'] in ['idea-cfb', 'seed-cfb']: # only older versions of openssl are supported |
|
|
if config['method'] in ['idea-cfb', 'seed-cfb']: # only older versions of openssl are supported |
|
|
config['extra_opts'] = '--libopenssl=libcrypto.so.1.0.0' |
|
|
config['extra_opts'] = '--libopenssl=libcrypto.so.1.0.0' |
|
|
if not isUdp: |
|
|
if not isUdp: |
|
|
config['no_udp'] = True # UDP traffic is not proxied |
|
|
config['no_udp'] = True # udp traffic is not proxied |
|
|
config['shadowsocks'] = 'ss-python-local' |
|
|
config['shadowsocks'] = 'ss-python-local' |
|
|
return config, ['ss-bootstrap-local', '--debug', '-vv'], {} |
|
|
return config, ['ss-bootstrap-local', '--debug', '-vv'], {} |
|
|
|
|
|
|
|
@ -58,21 +59,21 @@ def ssPython(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list, |
|
|
def ssPythonLegacy(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list, dict]: |
|
|
def ssPythonLegacy(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list, dict]: |
|
|
config = loadConfig(proxyInfo, socksInfo) |
|
|
config = loadConfig(proxyInfo, socksInfo) |
|
|
if not isUdp: |
|
|
if not isUdp: |
|
|
config['no_udp'] = True # UDP traffic is not proxied |
|
|
config['no_udp'] = True # udp traffic is not proxied |
|
|
config['shadowsocks'] = 'ss-python-legacy-local' |
|
|
config['shadowsocks'] = 'ss-python-legacy-local' |
|
|
return config, ['ss-bootstrap-local', '--debug', '-vv'], {} |
|
|
return config, ['ss-bootstrap-local', '--debug', '-vv'], {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load(proxyInfo: dict, socksInfo: dict, configFile: str) -> tuple[list, str, dict]: |
|
|
def load(proxyInfo: dict, socksInfo: dict, configFile: str) -> tuple[list, str, dict]: |
|
|
isUdp = True if proxyInfo['plugin'] is None else ( # UDP enabled when server without plugin |
|
|
isUdp = True if proxyInfo['plugin'] is None else ( # udp enabled when server without plugin |
|
|
not pluginUdp(proxyInfo['plugin']['type'], proxyInfo['plugin']['param']) # UDP conflict status of plugins |
|
|
not pluginUdp(proxyInfo['plugin']['type'], proxyInfo['plugin']['param']) # udp conflict status of plugins |
|
|
) |
|
|
) |
|
|
if proxyInfo['method'] not in ssAllMethods: # unknown shadowsocks method |
|
|
if proxyInfo['method'] not in ssAllMethods: # unknown shadowsocks method |
|
|
raise RuntimeError('Unknown shadowsocks method') |
|
|
raise buildException('Unknown shadowsocks method') |
|
|
for client in ssMethods: # traverse all shadowsocks client |
|
|
for client in ssMethods: # traverse all shadowsocks client |
|
|
if proxyInfo['method'] not in ssMethods[client]: |
|
|
if proxyInfo['method'] not in ssMethods[client]: |
|
|
continue |
|
|
continue |
|
|
ssConfig, ssClient, ssEnv = { |
|
|
ssConfig, ssClient, ssEnv = { # found appropriate client |
|
|
'ss-rust': ssRust, |
|
|
'ss-rust': ssRust, |
|
|
'ss-libev': ssLibev, |
|
|
'ss-libev': ssLibev, |
|
|
'ss-python': ssPython, |
|
|
'ss-python': ssPython, |
|
|