Skip to content

Commit

Permalink
feat: 支持 Shadowsocks 2022 的 URI 输入/输出
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Dec 15, 2024
1 parent bd87e92 commit 06f3e97
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.442",
"version": "2.14.443",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
24 changes: 18 additions & 6 deletions backend/src/core/proxy-utils/parsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ function URI_SS() {
content = content.split('#')[0]; // strip proxy name
// handle IPV4 and IPV6
let serverAndPortArray = content.match(/@([^/]*)(\/|$)/);
let userInfoStr = Base64.decode(
decodeURIComponent(content.split('@')[0]),
);

let rawUserInfoStr = decodeURIComponent(content.split('@')[0]); // 其实应该分隔之后, 用户名和密码再 decodeURIComponent. 但是问题不大
let userInfoStr;
if (rawUserInfoStr?.startsWith('2022-blake3-')) {
userInfoStr = rawUserInfoStr;
} else {
userInfoStr = Base64.decode(rawUserInfoStr);
}

let query = '';
if (!serverAndPortArray) {
if (content.includes('?')) {
Expand All @@ -73,15 +79,21 @@ function URI_SS() {
userInfoStr = content.split('@')[0];
serverAndPortArray = content.match(/@([^/]*)(\/|$)/);
}

const serverAndPort = serverAndPortArray[1];
const portIdx = serverAndPort.lastIndexOf(':');
proxy.server = serverAndPort.substring(0, portIdx);
proxy.port = `${serverAndPort.substring(portIdx + 1)}`.match(
/\d+/,
)?.[0];
const userInfo = userInfoStr.match(/(^.*?):(.*$)/);
proxy.cipher = userInfo[1];
proxy.password = userInfo[2];
let userInfo = userInfoStr.match(/(^.*?):(.*$)/);
proxy.cipher = userInfo?.[1];
proxy.password = userInfo?.[2];
// if (!proxy.cipher || !proxy.password) {
// userInfo = rawUserInfoStr.match(/(^.*?):(.*$)/);
// proxy.cipher = userInfo?.[1];
// proxy.password = userInfo?.[2];
// }

// handle obfs
const idx = content.indexOf('?plugin=');
Expand Down
10 changes: 7 additions & 3 deletions backend/src/core/proxy-utils/producers/uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ export default function URI_Producer() {
switch (proxy.type) {
case 'ss':
const userinfo = `${proxy.cipher}:${proxy.password}`;
result = `ss://${Base64.encode(userinfo)}@${proxy.server}:${
proxy.port
}${proxy.plugin ? '/' : ''}`;
result = `ss://${
proxy.cipher?.startsWith('2022-blake3-')
? `${encodeURIComponent(
proxy.cipher,
)}:${encodeURIComponent(proxy.password)}`
: Base64.encode(userinfo)
}@${proxy.server}:${proxy.port}${proxy.plugin ? '/' : ''}`;
if (proxy.plugin) {
result += '?plugin=';
const opts = proxy['plugin-opts'];
Expand Down

0 comments on commit 06f3e97

Please sign in to comment.