From 5c4e863560cce247e46078916b3b30493023a78c Mon Sep 17 00:00:00 2001 From: tokumeikoi Date: Fri, 18 Nov 2022 03:25:02 +0800 Subject: [PATCH] update: new cipher --- .../Controllers/Client/Protocols/Shadowrocket.php | 12 ++++++++++++ app/Http/Controllers/Server/UniProxyController.php | 7 +++++++ app/Utils/Helper.php | 8 +++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Client/Protocols/Shadowrocket.php b/app/Http/Controllers/Client/Protocols/Shadowrocket.php index 67cceec4..12d9e455 100644 --- a/app/Http/Controllers/Client/Protocols/Shadowrocket.php +++ b/app/Http/Controllers/Client/Protocols/Shadowrocket.php @@ -2,6 +2,8 @@ namespace App\Http\Controllers\Client\Protocols; +use App\Utils\Helper; + class Shadowrocket { public $flag = 'shadowrocket'; @@ -43,6 +45,16 @@ class Shadowrocket public static function buildShadowsocks($password, $server) { + if ($server['cipher'] === '2022-blake3-aes-128-gcm') { + $serverKey = Helper::getShadowsocksServerKey($server['created_at'], 16); + $userKey = Helper::uuidToBase64($password, 16); + $password = "{$serverKey}:{$userKey}"; + } + if ($server['cipher'] === '2022-blake3-aes-256-gcm') { + $serverKey = Helper::getShadowsocksServerKey($server['created_at'], 32); + $userKey = Helper::uuidToBase64($password, 32); + $password = "{$serverKey}:{$userKey}"; + } $name = rawurlencode($server['name']); $str = str_replace( ['+', '/', '='], diff --git a/app/Http/Controllers/Server/UniProxyController.php b/app/Http/Controllers/Server/UniProxyController.php index 5e523b20..9d145134 100644 --- a/app/Http/Controllers/Server/UniProxyController.php +++ b/app/Http/Controllers/Server/UniProxyController.php @@ -99,6 +99,13 @@ class UniProxyController extends Controller 'obfs' => $this->nodeInfo->obfs, 'obfs_settings' => $this->nodeInfo->obfs_settings ]; + + if ($this->nodeInfo->cipher === '2022-blake3-aes-128-gcm') { + $response['server_key'] = Helper::getShadowsocksServerKey($this->nodeInfo->created_at, 16); + } + if ($this->nodeInfo->cipher === '2022-blake3-aes-256-gcm') { + $response['server_key'] = Helper::getShadowsocksServerKey($this->nodeInfo->created_at, 32); + } break; case 'v2ray': $response = [ diff --git a/app/Utils/Helper.php b/app/Utils/Helper.php index 4cac1988..f3e79b0c 100644 --- a/app/Utils/Helper.php +++ b/app/Utils/Helper.php @@ -6,8 +6,14 @@ class Helper { public static function uuidToBase64($uuid, $length) { - return base64_encode(substr(str_replace('-', '', $uuid), 0, $length - 6)); + return base64_encode(substr($uuid, 0, $length)); } + + public static function getShadowsocksServerKey($timestamp, $length) + { + return base64_encode(substr(md5($timestamp), 0, $length)); + } + public static function guid($format = false) { if (function_exists('com_create_guid') === true) {