diff --git a/app/Protocols/Clash.php b/app/Protocols/Clash.php index a7be5e3..b87daa5 100644 --- a/app/Protocols/Clash.php +++ b/app/Protocols/Clash.php @@ -47,7 +47,7 @@ class Clash 'chacha20-ietf-poly1305' ]) ) { - array_push($proxy, self::buildShadowsocks($user['uuid'], $item)); + array_push($proxy, self::buildShadowsocks($item['password'], $item)); array_push($proxies, $item['name']); } if ($item['type'] === 'vmess') { diff --git a/app/Protocols/ClashMeta.php b/app/Protocols/ClashMeta.php index 57fac82..a212e12 100644 --- a/app/Protocols/ClashMeta.php +++ b/app/Protocols/ClashMeta.php @@ -38,7 +38,7 @@ class ClashMeta foreach ($servers as $item) { if ($item['type'] === 'shadowsocks') { - array_push($proxy, self::buildShadowsocks($user['uuid'], $item)); + array_push($proxy, self::buildShadowsocks($item['password'], $item)); array_push($proxies, $item['name']); } if ($item['type'] === 'vmess') { @@ -97,16 +97,6 @@ class ClashMeta public static function buildShadowsocks($password, $server) { - if ($server['cipher'] === '2022-blake3-aes-128-gcm') { - $serverKey = Helper::getServerKey($server['created_at'], 16); - $userKey = Helper::uuidToBase64($password, 16); - $password = "{$serverKey}:{$userKey}"; - } - if ($server['cipher'] === '2022-blake3-aes-256-gcm') { - $serverKey = Helper::getServerKey($server['created_at'], 32); - $userKey = Helper::uuidToBase64($password, 32); - $password = "{$serverKey}:{$userKey}"; - } $array = []; $array['name'] = $server['name']; $array['type'] = 'ss'; diff --git a/app/Protocols/General.php b/app/Protocols/General.php index cc508c6..7de9186 100644 --- a/app/Protocols/General.php +++ b/app/Protocols/General.php @@ -31,7 +31,7 @@ class General $uri .= self::buildVless($user['uuid'], $item); } if ($item['type'] === 'shadowsocks') { - $uri .= self::buildShadowsocks($user['uuid'], $item); + $uri .= self::buildShadowsocks($item['password'], $item); } if ($item['type'] === 'trojan') { $uri .= self::buildTrojan($user['uuid'], $item); @@ -42,16 +42,6 @@ class General public static function buildShadowsocks($password, $server) { - if ($server['cipher'] === '2022-blake3-aes-128-gcm') { - $serverKey = Helper::getServerKey($server['created_at'], 16); - $userKey = Helper::uuidToBase64($password, 16); - $password = "{$serverKey}:{$userKey}"; - } - if ($server['cipher'] === '2022-blake3-aes-256-gcm') { - $serverKey = Helper::getServerKey($server['created_at'], 32); - $userKey = Helper::uuidToBase64($password, 32); - $password = "{$serverKey}:{$userKey}"; - } $name = rawurlencode($server['name']); $str = str_replace( ['+', '/', '='], diff --git a/app/Protocols/Loon.php b/app/Protocols/Loon.php index fb9e389..570a380 100644 --- a/app/Protocols/Loon.php +++ b/app/Protocols/Loon.php @@ -30,7 +30,7 @@ class Loon 'chacha20-ietf-poly1305' ]) ) { - $uri .= self::buildShadowsocks($user['uuid'], $item); + $uri .= self::buildShadowsocks($item['password'], $item); } if ($item['type'] === 'vmess') { $uri .= self::buildVmess($user['uuid'], $item); diff --git a/app/Protocols/Passwall.php b/app/Protocols/Passwall.php index ef3335c..66efd33 100644 --- a/app/Protocols/Passwall.php +++ b/app/Protocols/Passwall.php @@ -29,7 +29,7 @@ class Passwall $uri .= self::buildVless($user['uuid'], $item); } if ($item['type'] === 'shadowsocks') { - $uri .= self::buildShadowsocks($user['uuid'], $item); + $uri .= self::buildShadowsocks($item['password'], $item); } if ($item['type'] === 'trojan') { $uri .= self::buildTrojan($user['uuid'], $item); diff --git a/app/Protocols/QuantumultX.php b/app/Protocols/QuantumultX.php index 8e96aa7..b89e03d 100644 --- a/app/Protocols/QuantumultX.php +++ b/app/Protocols/QuantumultX.php @@ -22,7 +22,7 @@ class QuantumultX $uri = ''; foreach ($servers as $item) { if ($item['type'] === 'shadowsocks') { - $uri .= self::buildShadowsocks($user['uuid'], $item); + $uri .= self::buildShadowsocks($item['password'], $item); } if ($item['type'] === 'vmess') { $uri .= self::buildVmess($user['uuid'], $item); diff --git a/app/Protocols/SSRPlus.php b/app/Protocols/SSRPlus.php index 3a214e5..1d32a61 100644 --- a/app/Protocols/SSRPlus.php +++ b/app/Protocols/SSRPlus.php @@ -29,7 +29,7 @@ class SSRPlus $uri .= self::buildVless($user['uuid'], $item); } if ($item['type'] === 'shadowsocks') { - $uri .= self::buildShadowsocks($user['uuid'], $item); + $uri .= self::buildShadowsocks($item['password'], $item); } if ($item['type'] === 'trojan') { $uri .= self::buildTrojan($user['uuid'], $item); diff --git a/app/Protocols/SagerNet.php b/app/Protocols/SagerNet.php index 781e811..65f5fdd 100644 --- a/app/Protocols/SagerNet.php +++ b/app/Protocols/SagerNet.php @@ -25,7 +25,7 @@ class SagerNet $uri .= self::buildVmess($user['uuid'], $item); } if ($item['type'] === 'shadowsocks') { - $uri .= self::buildShadowsocks($user['uuid'], $item); + $uri .= self::buildShadowsocks($item['password'], $item); } if ($item['type'] === 'trojan') { $uri .= self::buildTrojan($user['uuid'], $item); diff --git a/app/Protocols/Shadowrocket.php b/app/Protocols/Shadowrocket.php index d1c34a3..57ab17f 100644 --- a/app/Protocols/Shadowrocket.php +++ b/app/Protocols/Shadowrocket.php @@ -31,7 +31,7 @@ class Shadowrocket $uri .= "STATUS=🚀↑:{$upload}GB,↓:{$download}GB,TOT:{$totalTraffic}GB💡Expires:{$expiredDate}\r\n"; foreach ($servers as $item) { if ($item['type'] === 'shadowsocks') { - $uri .= self::buildShadowsocks($user['uuid'], $item); + $uri .= self::buildShadowsocks($item['password'], $item); } if ($item['type'] === 'vmess') { $uri .= self::buildVmess($user['uuid'], $item); @@ -52,16 +52,6 @@ class Shadowrocket public static function buildShadowsocks($password, $server) { - if ($server['cipher'] === '2022-blake3-aes-128-gcm') { - $serverKey = Helper::getServerKey($server['created_at'], 16); - $userKey = Helper::uuidToBase64($password, 16); - $password = "{$serverKey}:{$userKey}"; - } - if ($server['cipher'] === '2022-blake3-aes-256-gcm') { - $serverKey = Helper::getServerKey($server['created_at'], 32); - $userKey = Helper::uuidToBase64($password, 32); - $password = "{$serverKey}:{$userKey}"; - } $name = rawurlencode($server['name']); $str = str_replace( ['+', '/', '='], diff --git a/app/Protocols/SingBox.php b/app/Protocols/SingBox.php index fb7304a..7de8e13 100644 --- a/app/Protocols/SingBox.php +++ b/app/Protocols/SingBox.php @@ -44,7 +44,7 @@ class SingBox $proxies = []; foreach ($this->servers as $item) { if ($item['type'] === 'shadowsocks') { - $ssConfig = $this->buildShadowsocks($this->user['uuid'], $item); + $ssConfig = $this->buildShadowsocks($item['password'], $item); $proxies[] = $ssConfig; } if ($item['type'] === 'trojan') { @@ -77,16 +77,6 @@ class SingBox protected function buildShadowsocks($password, $server) { - if ($server['cipher'] === '2022-blake3-aes-128-gcm') { - $serverKey = Helper::getServerKey($server['created_at'], 16); - $userKey = Helper::uuidToBase64($password, 16); - $password = "{$serverKey}:{$userKey}"; - } - if ($server['cipher'] === '2022-blake3-aes-256-gcm') { - $serverKey = Helper::getServerKey($server['created_at'], 32); - $userKey = Helper::uuidToBase64($password, 32); - $password = "{$serverKey}:{$userKey}"; - } $array = []; $array['tag'] = $server['name']; $array['type'] = 'shadowsocks'; diff --git a/app/Protocols/Stash.php b/app/Protocols/Stash.php index aba157e..7e004c7 100644 --- a/app/Protocols/Stash.php +++ b/app/Protocols/Stash.php @@ -45,7 +45,7 @@ class Stash 'chacha20-ietf-poly1305' ]) ) { - array_push($proxy, self::buildShadowsocks($user['uuid'], $item)); + array_push($proxy, self::buildShadowsocks($item['password'], $item)); array_push($proxies, $item['name']); } if ($item['type'] === 'vmess') { diff --git a/app/Protocols/Surfboard.php b/app/Protocols/Surfboard.php index ebfeadf..007e3eb 100644 --- a/app/Protocols/Surfboard.php +++ b/app/Protocols/Surfboard.php @@ -36,7 +36,7 @@ class Surfboard ]) ) { // [Proxy] - $proxies .= self::buildShadowsocks($user['uuid'], $item); + $proxies .= self::buildShadowsocks($item['password'], $item); // [Proxy Group] $proxyGroup .= $item['name'] . ', '; } diff --git a/app/Protocols/Surge.php b/app/Protocols/Surge.php index 8e74029..4e09b82 100644 --- a/app/Protocols/Surge.php +++ b/app/Protocols/Surge.php @@ -36,7 +36,7 @@ class Surge ]) ) { // [Proxy] - $proxies .= self::buildShadowsocks($user['uuid'], $item); + $proxies .= self::buildShadowsocks($item['password'], $item); // [Proxy Group] $proxyGroup .= $item['name'] . ', '; } diff --git a/app/Protocols/V2rayN.php b/app/Protocols/V2rayN.php index e498e48..cb353f4 100644 --- a/app/Protocols/V2rayN.php +++ b/app/Protocols/V2rayN.php @@ -31,7 +31,7 @@ class V2rayN $uri .= self::buildVless($user['uuid'], $item); } if ($item['type'] === 'shadowsocks') { - $uri .= self::buildShadowsocks($user['uuid'], $item); + $uri .= self::buildShadowsocks($item['password'], $item); } if ($item['type'] === 'trojan') { $uri .= self::buildTrojan($user['uuid'], $item); @@ -46,16 +46,6 @@ class V2rayN public static function buildShadowsocks($password, $server) { - if ($server['cipher'] === '2022-blake3-aes-128-gcm') { - $serverKey = Helper::getServerKey($server['created_at'], 16); - $userKey = Helper::uuidToBase64($password, 16); - $password = "{$serverKey}:{$userKey}"; - } - if ($server['cipher'] === '2022-blake3-aes-256-gcm') { - $serverKey = Helper::getServerKey($server['created_at'], 32); - $userKey = Helper::uuidToBase64($password, 32); - $password = "{$serverKey}:{$userKey}"; - } $name = rawurlencode($server['name']); $str = str_replace( ['+', '/', '='], diff --git a/app/Protocols/V2rayNG.php b/app/Protocols/V2rayNG.php index 56b64c5..c758cfb 100644 --- a/app/Protocols/V2rayNG.php +++ b/app/Protocols/V2rayNG.php @@ -26,7 +26,7 @@ class V2rayNG $uri .= self::buildVmess($user['uuid'], $item); } if ($item['type'] === 'shadowsocks') { - $uri .= self::buildShadowsocks($user['uuid'], $item); + $uri .= self::buildShadowsocks($item['password'], $item); } if ($item['type'] === 'trojan') { $uri .= self::buildTrojan($user['uuid'], $item); diff --git a/app/Services/ServerService.php b/app/Services/ServerService.php index 26299b2..6973556 100644 --- a/app/Services/ServerService.php +++ b/app/Services/ServerService.php @@ -139,6 +139,28 @@ class ServerService $shadowsocks[$key]['last_check_at'] = Cache::get(CacheKey::get('SERVER_SHADOWSOCKS_LAST_CHECK_AT', $v['parent_id'])); $shadowsocks[$key]['created_at'] = $shadowsocks[$v['parent_id']]['created_at']; } + // 处理ss2022密码 + $cipherConfiguration = [ + '2022-blake3-aes-128-gcm' => [ + 'serverKeySize' => 16, + 'userKeySize' => 16, + ], + '2022-blake3-aes-256-gcm' => [ + 'serverKeySize' => 32, + 'userKeySize' => 32, + ], + '2022-blake3-chacha20-poly1305' => [ + 'serverKeySize' => 32, + 'userKeySize' => 32, + ] + ]; + $shadowsocks[$key]['password'] = $user['uuid']; + if (array_key_exists($cipher = $v['cipher'], $cipherConfiguration)) { + $config = $cipherConfiguration[$cipher]; + $serverKey = Helper::getServerKey($v['created_at'], $config['serverKeySize']); + $userKey = Helper::uuidToBase64($user['uuid'], $config['userKeySize']); + $shadowsocks[$key]['password'] = "{$serverKey}:{$userKey}"; + } $servers[] = $shadowsocks[$key]->toArray(); } return $servers;