feat: 调整 sing-box SSH 密钥逻辑

This commit is contained in:
xream committed 2026-09-26 12:10:19 +08:00
1 parent 7b9d822722
commit 04f44c2ae2
4 files changed
+79 -13

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.41.0",
"version": "2.41.2",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"packageManager": "pnpm@11.0.9",
@@ -431,9 +431,15 @@ const sshParser = (proxy = {}) => {
if (proxy.password) parsedProxy.password = proxy.password;
// https://wiki.metacubex.one/config/proxies/ssh
// https://sing-box.sagernet.org/zh/configuration/outbound/ssh
if (proxy['privateKey']) parsedProxy.private_key_path = proxy['privateKey'];
if (proxy['private-key'])
parsedProxy.private_key_path = proxy['private-key'];
const privateKey = proxy['private-key'] || proxy.privateKey;
if (privateKey) {
// 不严谨 但是跟 mihomo 判断逻辑一致
parsedProxy[
privateKey.includes('PRIVATE KEY')
? 'private_key'
: 'private_key_path'
] = privateKey;
}
if (proxy['private-key-passphrase'])
parsedProxy.private_key_passphrase = proxy['private-key-passphrase'];
if (proxy['server-fingerprint']) {
@@ -4029,6 +4029,60 @@ describe('Proxy structured producers', function () {
expect(errors).to.have.length(0);
});
it('distinguishes sing-box SSH private key content from paths', function () {
const privateKey =
'-----BEGIN OPENSSH PRIVATE KEY-----\ntest-key-data\n-----END OPENSSH PRIVATE KEY-----';
const encryptedKey =
'-----BEGIN ENCRYPTED PRIVATE KEY-----\ntest-key-data\n-----END ENCRYPTED PRIVATE KEY-----';
for (const [options, expected] of [
[{ 'private-key': privateKey }, { private_key: privateKey }],
[{ 'private-key': encryptedKey }, { private_key: encryptedKey }],
[{ 'private-key': './id_rsa' }, { private_key_path: './id_rsa' }],
[
{ 'private-key': '/keys/id_ed25519' },
{ private_key_path: '/keys/id_ed25519' },
],
[{ privateKey }, { private_key: privateKey }],
[{ privateKey: './id_rsa' }, { private_key_path: './id_rsa' }],
[
{ 'private-key': privateKey, privateKey: './id_rsa' },
{ private_key: privateKey },
],
[
{ 'private-key': './id_rsa', privateKey },
{ private_key_path: './id_rsa' },
],
[
{ 'private-key': '', privateKey: './id_rsa' },
{ private_key_path: './id_rsa' },
],
[{ 'private-key': '' }, {}],
[{}, {}],
]) {
const output = loadProducedJson('sing-box', {
type: 'ssh',
name: 'SSH',
server: 'ssh.example.com',
port: 22,
username: 'user',
'private-key-passphrase': 'test-passphrase',
...options,
});
expect(output.outbounds).to.deep.equal([
{
type: 'ssh',
tag: 'SSH',
server: 'ssh.example.com',
server_port: 22,
user: 'user',
private_key_passphrase: 'test-passphrase',
...expected,
},
]);
}
});
it('preserves supported HTTP root headers for sing-box and JSON outputs', function () {
const buildProxy = (name) => ({
type: 'http',
+15 -9
View File
@@ -864,7 +864,9 @@ describe('Proxy text producers', function () {
},
]);
expect(output.match(/tls-profile=chrome147(?=,|$)/gm)).to.have.length(9);
expect(output.match(/tls-profile=chrome147(?=,|$)/gm)).to.have.length(
9,
);
expect(output.match(/alpn="http\/1\.1,h2,h3"/g)).to.have.length(9);
});
@@ -906,7 +908,9 @@ describe('Proxy text producers', function () {
expect(output).to.include('tls-profile=ios18');
expect(output).to.include('tls-profile=default');
expect(output).to.match(/tls-profile=chrome(?=,|$)/m);
expect(output.match(/tls-profile=chrome147(?=,|$)/gm)).to.have.length(2);
expect(output.match(/tls-profile=chrome147(?=,|$)/gm)).to.have.length(
2,
);
expect(output).to.include('tls-profile=ios26');
expect(output.match(/tls-profile=/g)).to.have.length(6);
});
@@ -1079,8 +1083,10 @@ describe('Proxy text producers', function () {
? [`,udp-relay=${udp}`]
: [];
expect(output.match(/,udp-relay=[^,\n]+/g) || [], output)
.to.deep.equal(expected);
expect(
output.match(/,udp-relay=[^,\n]+/g) || [],
output,
).to.deep.equal(expected);
}
}
}
@@ -2474,7 +2480,7 @@ describe('Proxy text producers', function () {
expect(output).to.equal(
`ss://${Base64.encode(
'aes-128-gcm:secret',
)}@ss.example.com:443/?plugin=${plugin}#SS%20V2ray%20Flags`,
)}@ss.example.com:443/?plugin=${plugin}&udp=0#SS%20V2ray%20Flags`,
);
});
@@ -2534,7 +2540,7 @@ describe('Proxy text producers', function () {
expect(output).to.equal(
`ss://${Base64.encode(
'aes-128-gcm:secret',
)}@ss-upgrade.example.com:443?sni=ss-upgrade.example.com&type=httpupgrade&path=%2Fupgrade%3Fa%3D1%26b%3D2%26ed%3D1024&host=upgrade.example.com&security=tls#SS%20Upgrade`,
)}@ss-upgrade.example.com:443?udp=0&sni=ss-upgrade.example.com&type=httpupgrade&path=%2Fupgrade%3Fa%3D1%26b%3D2%26ed%3D1024&host=upgrade.example.com&security=tls#SS%20Upgrade`,
);
const reparsed = ProxyUtils.parse(output)[0];
@@ -2572,7 +2578,7 @@ describe('Proxy text producers', function () {
expect(output).to.equal(
`ss://${Base64.encode(
'aes-128-gcm:secret',
)}@ss-ws.example.com:443?sni=ss-ws.example.com&type=ws&path=%2Fws%3Fa%3D1%26b%3D2%26ed%3D2048&host=cdn.example.com&security=tls#SS%20WS%20Early`,
)}@ss-ws.example.com:443?udp=0&sni=ss-ws.example.com&type=ws&path=%2Fws%3Fa%3D1%26b%3D2%26ed%3D2048&host=cdn.example.com&security=tls#SS%20WS%20Early`,
);
const reparsed = ProxyUtils.parse(output)[0];
@@ -2700,12 +2706,12 @@ describe('Proxy text producers', function () {
expect(muxOnOutput).to.equal(
`ss://${Base64.encode(
'aes-128-gcm:secret',
)}@ss.example.com:443/?plugin=${muxOnPlugin}#SS%20Boolean%20Mux%20On`,
)}@ss.example.com:443/?plugin=${muxOnPlugin}&udp=0#SS%20Boolean%20Mux%20On`,
);
expect(muxOffOutput).to.equal(
`ss://${Base64.encode(
'aes-128-gcm:secret',
)}@ss.example.com:443/?plugin=${muxOffPlugin}#SS%20Boolean%20Mux%20Off`,
)}@ss.example.com:443/?plugin=${muxOffPlugin}&udp=0#SS%20Boolean%20Mux%20Off`,
);
});