gitscope
https://dev.kronoz.win/r/marzneshin.git
app/utils/keygen.py · v0.3.0-alpha10
Source
1 a47eb4c Dawsh 2y ago # import hashlib
2 a47eb4c Dawsh 2y ago import xxhash
3 a47eb4c Dawsh 2y ago import uuid
4 a47eb4c Dawsh 2y ago from app.models.proxy import ProxyTypes
5 a47eb4c Dawsh 2y ago
6 01cdf2e Dawsh 2y ago
7 a47eb4c Dawsh 2y ago def gen_uuid(key: str) -> str:
8 a47eb4c Dawsh 2y ago return str(uuid.UUID(bytes=xxhash.xxh128(key.encode()).digest()))
9 a47eb4c Dawsh 2y ago
10 01cdf2e Dawsh 2y ago
11 a47eb4c Dawsh 2y ago def gen_password(key: str) -> str:
12 a47eb4c Dawsh 2y ago return xxhash.xxh128(key.encode()).hexdigest()
13 a47eb4c Dawsh 2y ago
14 01cdf2e Dawsh 2y ago
15 a47eb4c Dawsh 2y ago def generate_settings(key: str, protocol: ProxyTypes) -> dict:
16 a47eb4c Dawsh 2y ago if protocol in (ProxyTypes.Trojan, ProxyTypes.Shadowsocks):
17 01cdf2e Dawsh 2y ago return (
18 01cdf2e Dawsh 2y ago ProxyTypes(protocol)
19 01cdf2e Dawsh 2y ago .settings_model(password=gen_password(key))
20 01cdf2e Dawsh 2y ago .dict(no_obj=True)
21 01cdf2e Dawsh 2y ago )
22 a47eb4c Dawsh 2y ago elif protocol in (ProxyTypes.VMess, ProxyTypes.VLESS):
23 a47eb4c Dawsh 2y ago return ProxyTypes(protocol).settings_model(id=gen_uuid(key)).dict(no_obj=True)