advanced-tls-client 3.0.3 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -3
- package/dist/index.js +43 -261
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -148,8 +148,6 @@ interface Response extends EventEmitter {
|
|
|
148
148
|
declare class ProfileRegistry {
|
|
149
149
|
private static getGrease;
|
|
150
150
|
static chromeMobile143Android(): ChromeProfile;
|
|
151
|
-
static chrome133PSK(): ChromeProfile;
|
|
152
|
-
static chrome133(): ChromeProfile;
|
|
153
151
|
static get(name: string): ChromeProfile;
|
|
154
152
|
static get latest(): ChromeProfile;
|
|
155
153
|
static get latestMobile(): ChromeProfile;
|
|
@@ -164,7 +162,8 @@ declare class AdvancedTLSClient {
|
|
|
164
162
|
private defaults;
|
|
165
163
|
constructor(profileName?: string);
|
|
166
164
|
private setup;
|
|
167
|
-
|
|
165
|
+
private isRequestOptions;
|
|
166
|
+
request(uri: string, dataOrOptions?: any, optionsOrCallback?: RequestOptions | ((err: any, res?: Response) => void), callback?: (err: any, res?: Response) => void): Promise<FullResponse | PassThrough>;
|
|
168
167
|
private generateJA3;
|
|
169
168
|
private buildMultipart;
|
|
170
169
|
private generateMultipart;
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.ProfileRegistry = exports.AdvancedTLSClient = void 0;
|
|
37
37
|
const tls = __importStar(require("tls"));
|
|
38
38
|
const net = __importStar(require("net"));
|
|
39
|
-
const https = __importStar(require("https"));
|
|
40
39
|
const http2 = __importStar(require("http2"));
|
|
41
40
|
const crypto = __importStar(require("crypto"));
|
|
42
41
|
const events_1 = require("events");
|
|
@@ -178,249 +177,8 @@ class ProfileRegistry {
|
|
|
178
177
|
priority: 'u=0, i'
|
|
179
178
|
};
|
|
180
179
|
}
|
|
181
|
-
static chrome133PSK() {
|
|
182
|
-
const grease1 = this.getGrease();
|
|
183
|
-
const grease2 = this.getGrease();
|
|
184
|
-
const grease3 = this.getGrease();
|
|
185
|
-
const grease4 = this.getGrease();
|
|
186
|
-
return {
|
|
187
|
-
name: 'chrome_133_psk',
|
|
188
|
-
version: '133.0.0.0',
|
|
189
|
-
tls: {
|
|
190
|
-
cipherSuites: [
|
|
191
|
-
grease1,
|
|
192
|
-
4865,
|
|
193
|
-
4866,
|
|
194
|
-
4867,
|
|
195
|
-
49195,
|
|
196
|
-
49199,
|
|
197
|
-
49196,
|
|
198
|
-
49200,
|
|
199
|
-
52393,
|
|
200
|
-
52392,
|
|
201
|
-
49171,
|
|
202
|
-
49172,
|
|
203
|
-
156,
|
|
204
|
-
157,
|
|
205
|
-
47,
|
|
206
|
-
53
|
|
207
|
-
],
|
|
208
|
-
extensions: [
|
|
209
|
-
grease2,
|
|
210
|
-
0,
|
|
211
|
-
23,
|
|
212
|
-
65281,
|
|
213
|
-
10,
|
|
214
|
-
11,
|
|
215
|
-
35,
|
|
216
|
-
16,
|
|
217
|
-
5,
|
|
218
|
-
13,
|
|
219
|
-
18,
|
|
220
|
-
51,
|
|
221
|
-
45,
|
|
222
|
-
43,
|
|
223
|
-
27,
|
|
224
|
-
21,
|
|
225
|
-
grease3
|
|
226
|
-
],
|
|
227
|
-
supportedGroups: [
|
|
228
|
-
grease4,
|
|
229
|
-
25497,
|
|
230
|
-
29,
|
|
231
|
-
23,
|
|
232
|
-
24
|
|
233
|
-
],
|
|
234
|
-
signatureAlgorithms: [
|
|
235
|
-
1027,
|
|
236
|
-
2052,
|
|
237
|
-
1025,
|
|
238
|
-
1283,
|
|
239
|
-
2053,
|
|
240
|
-
1281,
|
|
241
|
-
2054,
|
|
242
|
-
1537
|
|
243
|
-
],
|
|
244
|
-
supportedVersions: [
|
|
245
|
-
grease2,
|
|
246
|
-
772,
|
|
247
|
-
771
|
|
248
|
-
],
|
|
249
|
-
ecPointFormats: [0],
|
|
250
|
-
alpnProtocols: ['h2', 'http/1.1'],
|
|
251
|
-
pskKeyExchangeModes: [1],
|
|
252
|
-
compressionMethods: [0],
|
|
253
|
-
grease: true,
|
|
254
|
-
recordSizeLimit: 16385
|
|
255
|
-
},
|
|
256
|
-
http2: {
|
|
257
|
-
windowUpdate: 15663105,
|
|
258
|
-
headerTableSize: 65536,
|
|
259
|
-
enablePush: 0,
|
|
260
|
-
initialWindowSize: 6291456,
|
|
261
|
-
maxFrameSize: 16384,
|
|
262
|
-
maxHeaderListSize: 262144,
|
|
263
|
-
settingsOrder: [1, 2, 4, 6],
|
|
264
|
-
connectionPreface: Buffer.from('PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n'),
|
|
265
|
-
priorityFrames: [
|
|
266
|
-
{
|
|
267
|
-
streamId: 0,
|
|
268
|
-
weight: 256,
|
|
269
|
-
dependency: 0,
|
|
270
|
-
exclusive: true
|
|
271
|
-
}
|
|
272
|
-
],
|
|
273
|
-
pseudoHeaderOrder: [':method', ':authority', ':scheme', ':path'],
|
|
274
|
-
headerOrder: [
|
|
275
|
-
'cache-control',
|
|
276
|
-
'sec-ch-ua',
|
|
277
|
-
'sec-ch-ua-mobile',
|
|
278
|
-
'sec-ch-ua-platform',
|
|
279
|
-
'upgrade-insecure-requests',
|
|
280
|
-
'user-agent',
|
|
281
|
-
'accept',
|
|
282
|
-
'sec-fetch-site',
|
|
283
|
-
'sec-fetch-mode',
|
|
284
|
-
'sec-fetch-user',
|
|
285
|
-
'sec-fetch-dest',
|
|
286
|
-
'accept-encoding',
|
|
287
|
-
'accept-language'
|
|
288
|
-
]
|
|
289
|
-
},
|
|
290
|
-
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36',
|
|
291
|
-
secChUa: '"Google Chrome";v="133", "Chromium";v="133", "Not_A Brand";v="24"',
|
|
292
|
-
secChUaPlatform: '"Windows"',
|
|
293
|
-
secChUaMobile: '?0',
|
|
294
|
-
secFetchSite: 'none',
|
|
295
|
-
secFetchMode: 'navigate',
|
|
296
|
-
secFetchDest: 'document'
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
static chrome133() {
|
|
300
|
-
const grease1 = this.getGrease();
|
|
301
|
-
const grease2 = this.getGrease();
|
|
302
|
-
const grease3 = this.getGrease();
|
|
303
|
-
const grease4 = this.getGrease();
|
|
304
|
-
return {
|
|
305
|
-
name: 'chrome_133',
|
|
306
|
-
version: '133.0.0.0',
|
|
307
|
-
tls: {
|
|
308
|
-
cipherSuites: [
|
|
309
|
-
grease1,
|
|
310
|
-
4865,
|
|
311
|
-
4866,
|
|
312
|
-
4867,
|
|
313
|
-
49195,
|
|
314
|
-
49199,
|
|
315
|
-
49196,
|
|
316
|
-
49200,
|
|
317
|
-
52393,
|
|
318
|
-
52392,
|
|
319
|
-
49171,
|
|
320
|
-
49172,
|
|
321
|
-
156,
|
|
322
|
-
157,
|
|
323
|
-
47,
|
|
324
|
-
53
|
|
325
|
-
],
|
|
326
|
-
extensions: [
|
|
327
|
-
grease2,
|
|
328
|
-
0,
|
|
329
|
-
23,
|
|
330
|
-
65281,
|
|
331
|
-
10,
|
|
332
|
-
11,
|
|
333
|
-
35,
|
|
334
|
-
16,
|
|
335
|
-
5,
|
|
336
|
-
13,
|
|
337
|
-
18,
|
|
338
|
-
51,
|
|
339
|
-
45,
|
|
340
|
-
43,
|
|
341
|
-
27,
|
|
342
|
-
21,
|
|
343
|
-
grease3
|
|
344
|
-
],
|
|
345
|
-
supportedGroups: [
|
|
346
|
-
grease4,
|
|
347
|
-
25497,
|
|
348
|
-
29,
|
|
349
|
-
23,
|
|
350
|
-
24
|
|
351
|
-
],
|
|
352
|
-
signatureAlgorithms: [
|
|
353
|
-
1027,
|
|
354
|
-
2052,
|
|
355
|
-
1025,
|
|
356
|
-
1283,
|
|
357
|
-
2053,
|
|
358
|
-
1281,
|
|
359
|
-
2054,
|
|
360
|
-
1537
|
|
361
|
-
],
|
|
362
|
-
supportedVersions: [
|
|
363
|
-
grease2,
|
|
364
|
-
772,
|
|
365
|
-
771
|
|
366
|
-
],
|
|
367
|
-
ecPointFormats: [0],
|
|
368
|
-
alpnProtocols: ['h2', 'http/1.1'],
|
|
369
|
-
pskKeyExchangeModes: [1],
|
|
370
|
-
compressionMethods: [0],
|
|
371
|
-
grease: true,
|
|
372
|
-
recordSizeLimit: 16385
|
|
373
|
-
},
|
|
374
|
-
http2: {
|
|
375
|
-
windowUpdate: 15663105,
|
|
376
|
-
headerTableSize: 65536,
|
|
377
|
-
enablePush: 0,
|
|
378
|
-
initialWindowSize: 6291456,
|
|
379
|
-
maxFrameSize: 16384,
|
|
380
|
-
maxHeaderListSize: 262144,
|
|
381
|
-
settingsOrder: [1, 2, 4, 6],
|
|
382
|
-
connectionPreface: Buffer.from('PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n'),
|
|
383
|
-
priorityFrames: [
|
|
384
|
-
{
|
|
385
|
-
streamId: 0,
|
|
386
|
-
weight: 256,
|
|
387
|
-
dependency: 0,
|
|
388
|
-
exclusive: true
|
|
389
|
-
}
|
|
390
|
-
],
|
|
391
|
-
pseudoHeaderOrder: [':method', ':authority', ':scheme', ':path'],
|
|
392
|
-
headerOrder: [
|
|
393
|
-
'cache-control',
|
|
394
|
-
'sec-ch-ua',
|
|
395
|
-
'sec-ch-ua-mobile',
|
|
396
|
-
'sec-ch-ua-platform',
|
|
397
|
-
'upgrade-insecure-requests',
|
|
398
|
-
'user-agent',
|
|
399
|
-
'accept',
|
|
400
|
-
'sec-fetch-site',
|
|
401
|
-
'sec-fetch-mode',
|
|
402
|
-
'sec-fetch-user',
|
|
403
|
-
'sec-fetch-dest',
|
|
404
|
-
'accept-encoding',
|
|
405
|
-
'accept-language'
|
|
406
|
-
]
|
|
407
|
-
},
|
|
408
|
-
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36',
|
|
409
|
-
secChUa: '"Google Chrome";v="133", "Chromium";v="133", "Not_A Brand";v="24"',
|
|
410
|
-
secChUaPlatform: '"Windows"',
|
|
411
|
-
secChUaMobile: '?0',
|
|
412
|
-
secFetchSite: 'none',
|
|
413
|
-
secFetchMode: 'navigate',
|
|
414
|
-
secFetchDest: 'document'
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
180
|
static get(name) {
|
|
418
|
-
|
|
419
|
-
case 'chrome_mobile_143_android': return this.chromeMobile143Android();
|
|
420
|
-
case 'chrome_133_psk': return this.chrome133PSK();
|
|
421
|
-
case 'chrome_133': return this.chrome133();
|
|
422
|
-
default: return this.chromeMobile143Android();
|
|
423
|
-
}
|
|
181
|
+
return this.chromeMobile143Android();
|
|
424
182
|
}
|
|
425
183
|
static get latest() {
|
|
426
184
|
return this.chromeMobile143Android();
|
|
@@ -570,6 +328,7 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
570
328
|
':path': normalizedPath,
|
|
571
329
|
...headers
|
|
572
330
|
};
|
|
331
|
+
console.log('Sending HTTP/2 Request Headers:', reqHeaders);
|
|
573
332
|
const stream = this.http2Client.request(reqHeaders);
|
|
574
333
|
const response = new events_1.EventEmitter();
|
|
575
334
|
response.timing = { socket: timingStart, lookup: 0, connect: 0, secureConnect: 0, response: 0, end: 0, total: 0 };
|
|
@@ -581,7 +340,6 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
581
340
|
const chunks = [];
|
|
582
341
|
const rawChunks = [];
|
|
583
342
|
let finished = false;
|
|
584
|
-
let hasHeaders = false;
|
|
585
343
|
const finish = async (error) => {
|
|
586
344
|
if (finished)
|
|
587
345
|
return;
|
|
@@ -622,9 +380,10 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
622
380
|
response.timing.total = response.timing.end;
|
|
623
381
|
if (!out.writableEnded && !out.destroyed)
|
|
624
382
|
out.end();
|
|
383
|
+
if (callback)
|
|
384
|
+
setImmediate(() => callback(null, response, response.body));
|
|
625
385
|
};
|
|
626
386
|
stream.once('response', (hdrs) => {
|
|
627
|
-
hasHeaders = true;
|
|
628
387
|
response.statusCode = hdrs[':status'];
|
|
629
388
|
response.headers = hdrs;
|
|
630
389
|
if (hdrs['set-cookie'])
|
|
@@ -632,8 +391,6 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
632
391
|
response.timing.response = Date.now() - timingStart;
|
|
633
392
|
out.emit('header', response.statusCode, hdrs);
|
|
634
393
|
out.emit('headers', hdrs);
|
|
635
|
-
if (callback)
|
|
636
|
-
setImmediate(() => callback(null, response));
|
|
637
394
|
});
|
|
638
395
|
stream.on('data', (chunk) => {
|
|
639
396
|
if (finished || out.destroyed || out.writableEnded)
|
|
@@ -686,7 +443,7 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
686
443
|
headers: { host: this.hostname, ...headers },
|
|
687
444
|
createConnection: () => this.tlsSocket
|
|
688
445
|
};
|
|
689
|
-
const req = https.request(reqOptions);
|
|
446
|
+
const req = require('https').request(reqOptions);
|
|
690
447
|
const response = new events_1.EventEmitter();
|
|
691
448
|
response.timing = { socket: timingStart, lookup: 0, connect: 0, secureConnect: 0, response: 0, end: 0, total: 0 };
|
|
692
449
|
response.fingerprints = {
|
|
@@ -697,7 +454,6 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
697
454
|
const chunks = [];
|
|
698
455
|
const rawChunks = [];
|
|
699
456
|
let finished = false;
|
|
700
|
-
let hasHeaders = false;
|
|
701
457
|
const finish = async (error, res) => {
|
|
702
458
|
if (finished)
|
|
703
459
|
return;
|
|
@@ -740,9 +496,10 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
740
496
|
response.timing.total = response.timing.end;
|
|
741
497
|
if (!out.writableEnded && !out.destroyed)
|
|
742
498
|
out.end();
|
|
499
|
+
if (callback)
|
|
500
|
+
setImmediate(() => callback(null, response, response.body));
|
|
743
501
|
};
|
|
744
502
|
req.once('response', (res) => {
|
|
745
|
-
hasHeaders = true;
|
|
746
503
|
response.statusCode = res.statusCode;
|
|
747
504
|
response.headers = res.headers;
|
|
748
505
|
if (res.headers['set-cookie'])
|
|
@@ -750,8 +507,6 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
750
507
|
response.timing.response = Date.now() - timingStart;
|
|
751
508
|
out.emit('header', response.statusCode, res.headers);
|
|
752
509
|
out.emit('headers', res.headers);
|
|
753
|
-
if (callback)
|
|
754
|
-
setImmediate(() => callback(null, response));
|
|
755
510
|
res.on('data', (chunk) => {
|
|
756
511
|
if (finished || out.destroyed || out.writableEnded)
|
|
757
512
|
return;
|
|
@@ -985,16 +740,43 @@ class AdvancedTLSClient {
|
|
|
985
740
|
config.headers['upgrade-insecure-requests'] = this.profile.upgradeInsecureRequests;
|
|
986
741
|
if (this.profile.priority)
|
|
987
742
|
config.headers['priority'] = this.profile.priority;
|
|
988
|
-
// Override with user headers
|
|
989
743
|
if (options.headers) {
|
|
990
744
|
Object.assign(config.headers, options.headers);
|
|
991
745
|
}
|
|
992
746
|
return config;
|
|
993
747
|
}
|
|
994
|
-
|
|
995
|
-
if (typeof
|
|
996
|
-
|
|
997
|
-
|
|
748
|
+
isRequestOptions(obj) {
|
|
749
|
+
if (typeof obj !== 'object' || obj === null)
|
|
750
|
+
return false;
|
|
751
|
+
if (Buffer.isBuffer(obj) || obj instanceof stream_1.Readable)
|
|
752
|
+
return false;
|
|
753
|
+
const optionKeys = ['method', 'headers', 'proxy', 'decompress', 'stream', 'multipart', 'boundary', 'json', 'timeout'];
|
|
754
|
+
const keys = Object.keys(obj);
|
|
755
|
+
return keys.some(key => optionKeys.includes(key));
|
|
756
|
+
}
|
|
757
|
+
async request(uri, dataOrOptions, optionsOrCallback, callback) {
|
|
758
|
+
let data = null;
|
|
759
|
+
let options = {};
|
|
760
|
+
let cb = undefined;
|
|
761
|
+
if (typeof dataOrOptions === 'function') {
|
|
762
|
+
cb = dataOrOptions;
|
|
763
|
+
}
|
|
764
|
+
else if (dataOrOptions !== undefined && dataOrOptions !== null) {
|
|
765
|
+
if (this.isRequestOptions(dataOrOptions)) {
|
|
766
|
+
options = dataOrOptions;
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
data = dataOrOptions;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
if (typeof optionsOrCallback === 'function') {
|
|
773
|
+
cb = optionsOrCallback;
|
|
774
|
+
}
|
|
775
|
+
else if (optionsOrCallback !== undefined && optionsOrCallback !== null) {
|
|
776
|
+
options = optionsOrCallback;
|
|
777
|
+
}
|
|
778
|
+
if (callback !== undefined) {
|
|
779
|
+
cb = callback;
|
|
998
780
|
}
|
|
999
781
|
if (data && typeof data !== 'object' && !Buffer.isBuffer(data) && !(data instanceof stream_1.Readable)) {
|
|
1000
782
|
throw new Error('Invalid data type');
|
|
@@ -1062,10 +844,10 @@ class AdvancedTLSClient {
|
|
|
1062
844
|
session.clientManager.request(path, options, startTime, config.headers, post_data, out);
|
|
1063
845
|
return out;
|
|
1064
846
|
}
|
|
1065
|
-
if (
|
|
1066
|
-
session.clientManager.request(path, options, startTime, config.headers, post_data, out,
|
|
1067
|
-
if (
|
|
1068
|
-
|
|
847
|
+
if (cb) {
|
|
848
|
+
session.clientManager.request(path, options, startTime, config.headers, post_data, out, cb).catch(err => {
|
|
849
|
+
if (cb)
|
|
850
|
+
cb(err);
|
|
1069
851
|
});
|
|
1070
852
|
return out;
|
|
1071
853
|
}
|