mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-08 00:02:20 +03:00
- Add TlsClient module (Chrome 124 fingerprint via wreq-js) - Integrate TLS client as opt-in layer in proxyFetch.js (ENABLE_TLS_FINGERPRINT) - Add per-request TLS tracking via AsyncLocalStorage - Add TLS fingerprint column and badge to Proxy Logger dashboard - Add TLS Fingerprint section to ProxyLogDetail modal - Add wreq-js dependency - Document ENABLE_TLS_FINGERPRINT in .env.example Adapted from upstream PR decolua/9router#137, preserving all OmniRoute-specific proxy features (AsyncLocalStorage context, proxyDispatcher, SOCKS5, Symbol-based patch state).
95 lines
2.3 KiB
JavaScript
95 lines
2.3 KiB
JavaScript
import { createRequire } from "module";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
let createSession;
|
|
try {
|
|
({ createSession } = require("wreq-js"));
|
|
} catch {
|
|
createSession = null;
|
|
}
|
|
|
|
/**
|
|
* Get proxy URL from environment variables.
|
|
* Priority: HTTPS_PROXY > HTTP_PROXY > ALL_PROXY
|
|
*/
|
|
function getProxyFromEnv() {
|
|
return (
|
|
process.env.HTTPS_PROXY ||
|
|
process.env.https_proxy ||
|
|
process.env.HTTP_PROXY ||
|
|
process.env.http_proxy ||
|
|
process.env.ALL_PROXY ||
|
|
process.env.all_proxy ||
|
|
undefined
|
|
);
|
|
}
|
|
|
|
/**
|
|
* TLS Client — Chrome 124 TLS fingerprint spoofing via wreq-js
|
|
* Singleton instance used to disguise Node.js TLS handshake as Chrome browser.
|
|
*
|
|
* wreq-js natively supports proxy — TLS fingerprinting works through proxy.
|
|
* Proxy URL is read from environment variables (HTTPS_PROXY, HTTP_PROXY, ALL_PROXY).
|
|
*/
|
|
class TlsClient {
|
|
constructor() {
|
|
this.session = null;
|
|
this.available = !!createSession;
|
|
}
|
|
|
|
async getSession() {
|
|
if (!this.available) return null;
|
|
if (this.session) return this.session;
|
|
|
|
const proxy = getProxyFromEnv();
|
|
const sessionOpts = {
|
|
browser: "chrome_124",
|
|
os: "macos",
|
|
};
|
|
if (proxy) {
|
|
sessionOpts.proxy = proxy;
|
|
console.log(`[TlsClient] Using proxy: ${proxy}`);
|
|
}
|
|
|
|
this.session = await createSession(sessionOpts);
|
|
console.log("[TlsClient] Session created (Chrome 124 TLS fingerprint)");
|
|
return this.session;
|
|
}
|
|
|
|
/**
|
|
* Fetch with Chrome 124 TLS fingerprint.
|
|
* wreq-js Response is already fetch-compatible (headers, text(), json(), clone(), body).
|
|
*/
|
|
async fetch(url, options = {}) {
|
|
const session = await this.getSession();
|
|
if (!session) throw new Error("wreq-js not available");
|
|
|
|
const method = (options.method || "GET").toUpperCase();
|
|
|
|
const wreqOptions = {
|
|
method,
|
|
headers: options.headers,
|
|
body: options.body,
|
|
redirect: options.redirect === "manual" ? "manual" : "follow",
|
|
};
|
|
|
|
// Pass signal through if available
|
|
if (options.signal) {
|
|
wreqOptions.signal = options.signal;
|
|
}
|
|
|
|
const response = await session.fetch(url, wreqOptions);
|
|
return response;
|
|
}
|
|
|
|
async exit() {
|
|
if (this.session) {
|
|
await this.session.close();
|
|
this.session = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
export default new TlsClient();
|