feat: Mimic browser TLS fingerprint in node

- Fix Unknown Message (maybe)
This commit is contained in:
Elysia 2024-01-25 18:48:00 +07:00
parent 6d41b4e87c
commit 4692e5b7d1
4 changed files with 50 additions and 14 deletions

View File

@ -8,6 +8,7 @@ const makeFetchCookie = require('fetch-cookie');
const FormData = require('form-data');
const fetchOriginal = require('node-fetch');
const { CookieJar } = require('tough-cookie');
const { ciphers } = require('../util/Constants');
const cookieJar = new CookieJar();
const fetch = makeFetchCookie(fetchOriginal, cookieJar);
@ -40,10 +41,19 @@ class APIRequest {
make(captchaKey, captchaRqToken) {
if (!agent) {
if (this.client.options.http.agent instanceof http.Agent) {
this.client.options.http.agent.keepAlive = true;
this.client.options.http.agent.options.keepAlive = true;
this.client.options.http.agent.options.honorCipherOrder = true;
this.client.options.http.agent.options.minVersion = 'TLSv1.2';
this.client.options.http.agent.options.ciphers = ciphers.join(':');
agent = this.client.options.http.agent;
} else {
agent = new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
agent = new https.Agent({
...this.client.options.http.agent,
keepAlive: true,
honorCipherOrder: true,
minVersion: 'TLSv1.2',
ciphers: ciphers.join(':'),
});
}
}
@ -54,7 +64,6 @@ class APIRequest {
const url = API + this.path;
let headers = {
...this.client.options.http.headers,
authority: 'discord.com',
accept: '*/*',
'accept-language': 'en-US',
@ -73,6 +82,7 @@ class APIRequest {
Referer: 'https://discord.com/channels/@me',
origin: 'https://discord.com',
'Referrer-Policy': 'strict-origin-when-cross-origin',
...this.client.options.http.headers,
'User-Agent': this.fullUserAgent,
};

View File

@ -9,7 +9,31 @@ const { Error, RangeError, TypeError } = require('../errors');
exports.MaxBulkDeletableMessageAge = 1_209_600_000;
exports.UserAgent =
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) discord/1.0.9031 Chrome/108.0.5359.215 Electron/22.3.26 Safari/537.36';
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.5359.215 Electron/22.3.26 Safari/537.36';
/**
* Google Chrome v108 TLS ciphers
* @see {@link https://tls.browserleaks.com/tls}
* @see {@link https://github.com/yifeikong/curl-impersonate}
* @typedef {Array<string>} Ciphers
*/
exports.ciphers = [
'TLS_AES_128_GCM_SHA256',
'TLS_AES_256_GCM_SHA384',
'TLS_CHACHA20_POLY1305_SHA256',
'ECDHE-ECDSA-AES128-GCM-SHA256',
'ECDHE-RSA-AES128-GCM-SHA256',
'ECDHE-ECDSA-AES256-GCM-SHA384',
'ECDHE-RSA-AES256-GCM-SHA384',
'ECDHE-ECDSA-CHACHA20-POLY1305',
'ECDHE-RSA-CHACHA20-POLY1305',
'ECDHE-RSA-AES128-SHA',
'ECDHE-RSA-AES256-SHA',
'AES128-GCM-SHA256',
'AES256-GCM-SHA384',
'AES128-SHA',
'AES256-SHA',
];
/**
* The types of WebSocket error codes:

View File

@ -177,17 +177,18 @@ class Options extends null {
capabilities: 0, // https://discord-userdoccers.vercel.app/topics/gateway#gateway-capabilities
properties: {
os: 'Windows',
browser: 'Discord Client',
release_channel: 'stable',
client_version: '1.0.9031',
os_version: '10.0.19045',
os_arch: 'x64',
app_arch: 'ia32',
system_locale: 'en-US',
browser: 'Chrome',
device: '',
system_locale: 'vi-VN',
browser_user_agent: UserAgent,
browser_version: '22.3.26',
client_build_number: 260725,
native_build_number: 42899,
browser_version: '108.0.5359.215',
os_version: '10',
referrer: '',
referring_domain: '',
referrer_current: '',
referring_domain_current: '',
release_channel: 'stable',
client_build_number: 261141,
client_event_source: null,
},
compress: false,

1
typings/index.d.ts vendored
View File

@ -3580,6 +3580,7 @@ export const Constants: {
TextInputStyles: EnumHolder<typeof TextInputStyles>;
ThreadChannelTypes: ThreadChannelTypes[];
UserAgent: string;
ciphers: string[];
VerificationLevels: EnumHolder<typeof VerificationLevels>;
VideoQualityModes: EnumHolder<typeof VideoQualityModes>;
VoiceBasedChannelTypes: VoiceBasedChannelTypes[];