Skip to content

Commit 3118d14

Browse files
committed
feat: ProxyUtils.age 新增 derivePublicKey 方便脚本从私钥推导公钥; 支持 $.http.request 方便使用代理 App 不支持的 method
1 parent e3fc958 commit 3118d14

4 files changed

Lines changed: 19 additions & 8 deletions

File tree

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.31.5",
3+
"version": "2.31.6",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"packageManager": "pnpm@11.0.9",

backend/src/core/proxy-utils/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import YAML from '@/utils/yaml';
55
import download, { downloadFile } from '@/utils/download';
66
import {
77
decryptArmorIfPresent,
8+
derivePublicKey,
89
encryptArmor,
910
} from '@/utils/age';
1011
import {
@@ -41,10 +42,11 @@ import JSON5 from 'json5';
4142
import { hex_md5 } from '@/vendor/md5';
4243
import SurgeMac_Producer from './producers/surgemac';
4344

44-
const ageUtils = Object.freeze({
45+
const ageUtils = {
4546
encrypt: encryptArmor,
4647
decrypt: decryptArmorIfPresent,
47-
});
48+
derivePublicKey,
49+
};
4850

4951
function preprocess(raw) {
5052
for (const processor of PROXY_PREPROCESSORS) {

backend/src/test/proxy-processors/process-context.spec.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,12 @@ describe('Process context control', function () {
191191
expect(output.body).to.equal('AC');
192192
});
193193

194-
it('exposes age encrypt/decrypt helpers in script operators', async function () {
194+
it('exposes age helpers in script operators', async function () {
195195
this.timeout(10000);
196196

197197
const pair = await generateKeyPair();
198+
expect(Object.isFrozen(ProxyUtils.age)).to.equal(false);
199+
198200
const operators = [
199201
{
200202
type: 'Script Operator',
@@ -205,17 +207,22 @@ describe('Process context control', function () {
205207
secretKey: pair['age-secret-key'],
206208
},
207209
content: `async function operator(proxies) {
210+
const publicKey = await ProxyUtils.age.derivePublicKey(
211+
$arguments.secretKey,
212+
);
213+
const isExpectedPublicKey =
214+
publicKey === $arguments.publicKey;
208215
const encrypted = await ProxyUtils.age.encrypt(
209216
'hello age',
210-
$arguments.publicKey,
217+
publicKey,
211218
);
212219
const decrypted = await ProxyUtils.age.decrypt(
213220
encrypted,
214221
$arguments.secretKey,
215222
);
216223
return proxies.map((proxy) => ({
217224
...proxy,
218-
name: proxy.name + '-' + decrypted,
225+
name: [proxy.name, decrypted, isExpectedPublicKey].join('-'),
219226
}));
220227
}`,
221228
},
@@ -225,7 +232,7 @@ describe('Process context control', function () {
225232
const output = await ProxyUtils.process([{ name: 'A' }], operators);
226233

227234
expect(output.map((proxy) => proxy.name)).to.deep.equal([
228-
'A-hello age',
235+
'A-hello age-true',
229236
]);
230237
});
231238
});

backend/src/vendor/open-api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,9 @@ export function HTTP(defaultOptions = { baseURL: '' }) {
651651
).then((resp) => events.onResponse(resp));
652652
}
653653

654-
const http = {};
654+
const http = {
655+
request: (options) => send(options.method || 'GET', options),
656+
};
655657
methods.forEach(
656658
(method) =>
657659
(http[method.toLowerCase()] = (options) => send(method, options)),

0 commit comments

Comments
 (0)