From 4692e5b7d12cbd170e8bb19379e1ed1eb3baaee9 Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Thu, 25 Jan 2024 18:48:00 +0700 Subject: [PATCH] feat: Mimic browser TLS fingerprint in node - Fix Unknown Message (maybe) --- src/rest/APIRequest.js | 16 +++++++++++++--- src/util/Constants.js | 26 +++++++++++++++++++++++++- src/util/Options.js | 21 +++++++++++---------- typings/index.d.ts | 1 + 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/rest/APIRequest.js b/src/rest/APIRequest.js index a095209..22108a2 100644 --- a/src/rest/APIRequest.js +++ b/src/rest/APIRequest.js @@ -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, }; diff --git a/src/util/Constants.js b/src/util/Constants.js index 42acd79..e058743 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -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} 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: diff --git a/src/util/Options.js b/src/util/Options.js index 04cb991..f5c87a1 100644 --- a/src/util/Options.js +++ b/src/util/Options.js @@ -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, diff --git a/typings/index.d.ts b/typings/index.d.ts index 2ea0a4c..59d00c1 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3580,6 +3580,7 @@ export const Constants: { TextInputStyles: EnumHolder; ThreadChannelTypes: ThreadChannelTypes[]; UserAgent: string; + ciphers: string[]; VerificationLevels: EnumHolder; VideoQualityModes: EnumHolder; VoiceBasedChannelTypes: VoiceBasedChannelTypes[];