Skip to content

Commit

Permalink
fix: SSR URI 中包含 ipv6 地址解析错误
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed May 5, 2020
1 parent b96489b commit 1cd8436
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/utils/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@ export const parseSSRUri = (str: string): ShadowsocksrNodeConfig => {

const extraString = configArray.join('/');
const extras = extraString ? getUrlParameters(extraString) : {};
const password = fromUrlSafeBase64(basicInfo.pop() as string);
const obfs = basicInfo.pop() as string;
const method = basicInfo.pop() as string;
const protocol = basicInfo.pop() as string;
const port = basicInfo.pop() as string;
const hostname = basicInfo.join(':');
const nodeName = extras.remarks ?
fromUrlSafeBase64(extras.remarks) :
`${basicInfo[0]}:${basicInfo[1]}`;
`${hostname}:${port}`;

return {
type: NodeTypeEnum.Shadowsocksr,
nodeName,
hostname: basicInfo[0],
port: basicInfo[1],
protocol: basicInfo[2],
method: basicInfo[3],
obfs: basicInfo[4],
password: fromUrlSafeBase64(basicInfo[5]),
hostname,
port,
protocol,
method,
obfs,
password,
protoparam: fromUrlSafeBase64(extras.protoparam ?? '').replace(/\s/g, ''),
obfsparam: fromUrlSafeBase64(extras.obfsparam ?? '').replace(/\s/g, ''),
};
Expand Down
19 changes: 19 additions & 0 deletions test/utils/ssr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,22 @@ test('parseSSRUri 4 - standard base64', t => {
obfsparam: ''
});
});

test('parseSSRUri ipv6', t => {
// 2404:6800:4005:801::2003:80:auth_aes128_sha1:chacha20:plain:ZXhhbXBsZQ==/?obfsparam=&protoparam=MTIzNDU2ICAgICA6MTIzNDVxd2VydHl1&remarks=8J+Hr/Cfh7UgSlA=&group=U3VyZ2lv
const uri = 'ssr://MjQwNDo2ODAwOjQwMDU6ODAxOjoyMDAzOjgwOmF1dGhfYWVzMTI4X3NoYTE6Y2hhY2hhMjA6cGxhaW46WlhoaGJYQnNaUT09Lz9vYmZzcGFyYW09JnByb3RvcGFyYW09TVRJek5EVTJJQ0FnSUNBNk1USXpORFZ4ZDJWeWRIbDEmcmVtYXJrcz04SitIci9DZmg3VWdTbEE9Jmdyb3VwPVUzVnlaMmx2';
const conf = parseSSRUri(uri);

t.deepEqual(conf, {
type: NodeTypeEnum.Shadowsocksr,
nodeName: '🇯🇵 JP',
hostname: '2404:6800:4005:801::2003',
port: '80',
protocol: 'auth_aes128_sha1',
method: 'chacha20',
obfs: 'plain',
password: 'example',
protoparam: '123456:12345qwertyu',
obfsparam: ''
});
});

0 comments on commit 1cd8436

Please sign in to comment.