Skip to content

Commit

Permalink
feat: 读取节点的 ca-str 和 _ca (后端文件路径) 字段, 自动计算 fingerprint
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jun 13, 2024
1 parent 3ad42f2 commit ad3d227
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 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.337",
"version": "2.14.339",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand All @@ -25,6 +25,7 @@
"express": "^4.17.1",
"http-proxy-middleware": "^2.0.6",
"js-base64": "^3.7.2",
"jsrsasign": "^11.1.0",
"lodash": "^4.17.21",
"request": "^2.88.2",
"requests": "^0.3.0",
Expand Down
9 changes: 9 additions & 0 deletions backend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions backend/src/core/proxy-utils/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import rs from '@/utils/rs';
import YAML from '@/utils/yaml';
import download from '@/utils/download';
import {
Expand Down Expand Up @@ -463,6 +464,25 @@ function lastParse(proxy) {
if (['', 'off'].includes(proxy.sni)) {
proxy['disable-sni'] = true;
}
let caStr = proxy['ca_str'];
if (proxy['ca-str']) {
caStr = proxy['ca-str'];
} else if (caStr) {
delete proxy['ca_str'];
proxy['ca-str'] = caStr;
}
try {
if ($.env.isNode && !caStr && proxy['_ca']) {
caStr = $.node.fs.readFileSync(proxy['_ca'], {
encoding: 'utf8',
});
}
} catch (e) {
$.error(`Read ca file failed\nReason: ${e}`);
}
if (!proxy['tls-fingerprint'] && caStr) {
proxy['tls-fingerprint'] = rs.generateFingerprint(caStr);
}
return proxy;
}

Expand Down
11 changes: 11 additions & 0 deletions backend/src/utils/rs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import rs from 'jsrsasign';

export function generateFingerprint(caStr) {
const hex = rs.pemtohex(caStr);
const fingerPrint = rs.KJUR.crypto.Util.hashHex(hex, 'sha256');
return fingerPrint.match(/.{2}/g).join(':').toUpperCase();
}

export default {
generateFingerprint,
};

0 comments on commit ad3d227

Please sign in to comment.