From 00418e59be20d4d2c6629282f2986a33cc45b03e Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Mon, 24 Apr 2023 19:20:36 +0700 Subject: [PATCH] feat: random cipher --- src/rest/APIRequest.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rest/APIRequest.js b/src/rest/APIRequest.js index ab0e253..b879545 100644 --- a/src/rest/APIRequest.js +++ b/src/rest/APIRequest.js @@ -6,7 +6,9 @@ const https = require('node:https'); const { setTimeout } = require('node:timers'); const tls = require('tls'); const FormData = require('form-data'); +const _ = require('lodash'); const fetch = require('node-fetch'); +require('lodash.permutations'); let agent = null; @@ -31,9 +33,11 @@ class APIRequest { make(captchaKey = undefined, captchaRqtoken = undefined) { // Ciphers - tls.DEFAULT_CIPHERS = tls.DEFAULT_CIPHERS.split(':') - .sort(() => Math.random() - 0.5) - .join(':'); + const defaultCiphers = tls.DEFAULT_CIPHERS.split(':'); + const temp = _.permutations(defaultCiphers.slice(0, 5), 5).filter( + x => JSON.stringify(x) !== JSON.stringify(defaultCiphers.slice(0, 5)), + ); + tls.DEFAULT_CIPHERS = [...temp[Math.floor(Math.random() * temp.length)], ...defaultCiphers.slice(5)].join(':'); crypto.constants.defaultCipherList = tls.DEFAULT_CIPHERS; if (agent === null) {