File size: 680 Bytes
2276d59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import tls from 'node:tls';

const ORIGINAL_CIPHERS = tls.DEFAULT_CIPHERS;
const TOP_N = 8;
const INTERVAL_MS = 1000 * 60 * 30; // 30 minutes

function shuffle(arr: string[]): string[] {
  for (let i = arr.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [arr[i], arr[j]] = [arr[j], arr[i]];
  }
  return arr;
}

export function randomizeCiphers(): void {
  const list = ORIGINAL_CIPHERS.split(':');
  const shuffled = shuffle(list.slice(0, TOP_N));
  tls.DEFAULT_CIPHERS = [...shuffled, ...list.slice(TOP_N)].join(':');
}

export function startCipherRotation(): void {
  randomizeCiphers();
  setInterval(randomizeCiphers, INTERVAL_MS).unref();
}