Browse Source

feat: add shadowsocksr support of Builder

master
dnomd343 2 years ago
parent
commit
be5e476ddb
  1. 29
      Basis/Methods.py
  2. 27
      Builder/ShadowsocksR.py
  3. 4
      Builder/__init__.py
  4. 20
      demo.py

29
Basis/Methods.py

@ -63,4 +63,31 @@ ssMethods = { # methods support of different Shadowsocks project
ssAllMethods = set()
[ssAllMethods.update(ssMethods[x]) for x in ssMethods]
ssAllMethods = list(ssAllMethods)
ssAllMethods = list(ssAllMethods) # methods of Shadowsocks
ssrMethods = [ # methods of ShadowsocksR
'aes-128-ctr', 'aes-192-ctr', 'aes-256-ctr',
'aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm',
'aes-128-ofb', 'aes-192-ofb', 'aes-256-ofb',
'aes-128-cfb', 'aes-192-cfb', 'aes-256-cfb',
'aes-128-cfb1', 'aes-192-cfb1', 'aes-256-cfb1',
'aes-128-cfb8', 'aes-192-cfb8', 'aes-256-cfb8',
'camellia-128-cfb', 'camellia-192-cfb', 'camellia-256-cfb',
'none', 'table', 'rc4', 'rc4-md5', 'rc2-cfb', 'rc4-md5-6',
'bf-cfb', 'cast5-cfb', 'des-cfb', 'idea-cfb', 'seed-cfb',
'salsa20', 'xsalsa20', 'chacha20', 'xchacha20', 'chacha20-ietf',
]
ssrProtocols = [ # protocols of ShadowsocksR
'origin', 'auth_simple',
'verify_sha1', 'verify_simple', 'verify_deflate',
'auth_sha1', 'auth_sha1_v2', 'auth_sha1_v4',
'auth_aes128', 'auth_aes128_md5', 'auth_aes128_sha1',
'auth_chain_a', 'auth_chain_b', 'auth_chain_c',
'auth_chain_d', 'auth_chain_e', 'auth_chain_f',
]
ssrObfuscations = [ # obfuscations of ShadowsocksR (obfs)
'plain', 'http_post', 'http_simple', 'random_head',
'tls_simple', 'tls1.2_ticket_auth', 'tls1.2_ticket_fastauth',
]

27
Builder/ShadowsocksR.py

@ -0,0 +1,27 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
from Basis.Methods import ssrMethods, ssrProtocols, ssrObfuscations
def load(proxyInfo: dict, socksInfo: dict, configFile: str) -> tuple[list, str, dict]:
if proxyInfo['method'] not in ssrMethods:
raise RuntimeError('Unknown shadowsocksr method')
if proxyInfo['protocol'] not in ssrProtocols:
raise RuntimeError('Unknown shadowsocksr protocol')
if proxyInfo['obfs'] not in ssrObfuscations:
raise RuntimeError('Unknown shadowsocksr obfuscation')
ssrConfig = {
'server': proxyInfo['server'],
'server_port': proxyInfo['port'], # type -> int
'local_address': socksInfo['addr'],
'local_port': socksInfo['port'], # type -> int
'password': proxyInfo['passwd'],
'method': proxyInfo['method'],
'protocol': proxyInfo['protocol'],
'protocol_param': proxyInfo['protocolParam'],
'obfs': proxyInfo['obfs'],
'obfs_param': proxyInfo['obfsParam']
}
return ['ssr-local', '-vv', '-c', configFile], json.dumps(ssrConfig), {} # tuple[command, fileContent, envVar]

4
Builder/__init__.py

@ -5,6 +5,7 @@ import os
import copy
from Builder import Shadowsocks
from Builder import ShadowsocksR
from Basis.Logger import logging
from Basis.Process import Process
@ -13,7 +14,7 @@ from Basis.Functions import genFlag, getAvailablePort
default = {
'workDir': '/tmp/ProxyC',
'bindAddr': '127.0.0.1',
'binDir': '/usr/bin',
'binDir': '/bin:/usr/bin:/usr/local/bin',
}
@ -39,6 +40,7 @@ class Builder(object):
def __loadClient(self, isStart: bool):
loadFunction = {
'ss': Shadowsocks.load,
'ssr': ShadowsocksR.load,
}
if self.proxyType not in loadFunction:
raise RuntimeError('Unknown proxy type')

20
demo.py

@ -5,7 +5,7 @@ import time
from Builder import Builder
from Basis.Logger import logging
proxy = {
proxySS = {
'type': 'ss',
'info': {
'server': '127.0.0.1',
@ -16,7 +16,21 @@ proxy = {
}
}
client = Builder(proxy)
proxySSR = {
'type': 'ssr',
'info': {
'server': '127.0.0.1',
'port': 12345,
'passwd': 'dnomd343',
'method': 'aes-128-ctr',
'protocol': 'origin',
'protocolParam': '',
'obfs': 'plain',
'obfsParam': '',
}
}
client = Builder(proxySSR)
logging.critical(client.id)
logging.critical(client.proxyType)
@ -24,7 +38,7 @@ logging.critical(client.proxyInfo)
logging.critical(client.socksAddr)
logging.critical(client.socksPort)
time.sleep(5)
time.sleep(20)
logging.critical(client.status())
client.destroy()

Loading…
Cancel
Save