advanced-tls-client 3.0.3 → 4.0.0
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 +42 -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();
|
|
@@ -581,7 +339,6 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
581
339
|
const chunks = [];
|
|
582
340
|
const rawChunks = [];
|
|
583
341
|
let finished = false;
|
|
584
|
-
let hasHeaders = false;
|
|
585
342
|
const finish = async (error) => {
|
|
586
343
|
if (finished)
|
|
587
344
|
return;
|
|
@@ -622,9 +379,10 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
622
379
|
response.timing.total = response.timing.end;
|
|
623
380
|
if (!out.writableEnded && !out.destroyed)
|
|
624
381
|
out.end();
|
|
382
|
+
if (callback)
|
|
383
|
+
setImmediate(() => callback(null, response, response.body));
|
|
625
384
|
};
|
|
626
385
|
stream.once('response', (hdrs) => {
|
|
627
|
-
hasHeaders = true;
|
|
628
386
|
response.statusCode = hdrs[':status'];
|
|
629
387
|
response.headers = hdrs;
|
|
630
388
|
if (hdrs['set-cookie'])
|
|
@@ -632,8 +390,6 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
632
390
|
response.timing.response = Date.now() - timingStart;
|
|
633
391
|
out.emit('header', response.statusCode, hdrs);
|
|
634
392
|
out.emit('headers', hdrs);
|
|
635
|
-
if (callback)
|
|
636
|
-
setImmediate(() => callback(null, response));
|
|
637
393
|
});
|
|
638
394
|
stream.on('data', (chunk) => {
|
|
639
395
|
if (finished || out.destroyed || out.writableEnded)
|
|
@@ -686,7 +442,7 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
686
442
|
headers: { host: this.hostname, ...headers },
|
|
687
443
|
createConnection: () => this.tlsSocket
|
|
688
444
|
};
|
|
689
|
-
const req = https.request(reqOptions);
|
|
445
|
+
const req = require('https').request(reqOptions);
|
|
690
446
|
const response = new events_1.EventEmitter();
|
|
691
447
|
response.timing = { socket: timingStart, lookup: 0, connect: 0, secureConnect: 0, response: 0, end: 0, total: 0 };
|
|
692
448
|
response.fingerprints = {
|
|
@@ -697,7 +453,6 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
697
453
|
const chunks = [];
|
|
698
454
|
const rawChunks = [];
|
|
699
455
|
let finished = false;
|
|
700
|
-
let hasHeaders = false;
|
|
701
456
|
const finish = async (error, res) => {
|
|
702
457
|
if (finished)
|
|
703
458
|
return;
|
|
@@ -740,9 +495,10 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
740
495
|
response.timing.total = response.timing.end;
|
|
741
496
|
if (!out.writableEnded && !out.destroyed)
|
|
742
497
|
out.end();
|
|
498
|
+
if (callback)
|
|
499
|
+
setImmediate(() => callback(null, response, response.body));
|
|
743
500
|
};
|
|
744
501
|
req.once('response', (res) => {
|
|
745
|
-
hasHeaders = true;
|
|
746
502
|
response.statusCode = res.statusCode;
|
|
747
503
|
response.headers = res.headers;
|
|
748
504
|
if (res.headers['set-cookie'])
|
|
@@ -750,8 +506,6 @@ class UnifiedClientManager extends events_1.EventEmitter {
|
|
|
750
506
|
response.timing.response = Date.now() - timingStart;
|
|
751
507
|
out.emit('header', response.statusCode, res.headers);
|
|
752
508
|
out.emit('headers', res.headers);
|
|
753
|
-
if (callback)
|
|
754
|
-
setImmediate(() => callback(null, response));
|
|
755
509
|
res.on('data', (chunk) => {
|
|
756
510
|
if (finished || out.destroyed || out.writableEnded)
|
|
757
511
|
return;
|
|
@@ -985,16 +739,43 @@ class AdvancedTLSClient {
|
|
|
985
739
|
config.headers['upgrade-insecure-requests'] = this.profile.upgradeInsecureRequests;
|
|
986
740
|
if (this.profile.priority)
|
|
987
741
|
config.headers['priority'] = this.profile.priority;
|
|
988
|
-
// Override with user headers
|
|
989
742
|
if (options.headers) {
|
|
990
743
|
Object.assign(config.headers, options.headers);
|
|
991
744
|
}
|
|
992
745
|
return config;
|
|
993
746
|
}
|
|
994
|
-
|
|
995
|
-
if (typeof
|
|
996
|
-
|
|
997
|
-
|
|
747
|
+
isRequestOptions(obj) {
|
|
748
|
+
if (typeof obj !== 'object' || obj === null)
|
|
749
|
+
return false;
|
|
750
|
+
if (Buffer.isBuffer(obj) || obj instanceof stream_1.Readable)
|
|
751
|
+
return false;
|
|
752
|
+
const optionKeys = ['method', 'headers', 'proxy', 'decompress', 'stream', 'multipart', 'boundary', 'json', 'timeout'];
|
|
753
|
+
const keys = Object.keys(obj);
|
|
754
|
+
return keys.some(key => optionKeys.includes(key));
|
|
755
|
+
}
|
|
756
|
+
async request(uri, dataOrOptions, optionsOrCallback, callback) {
|
|
757
|
+
let data = null;
|
|
758
|
+
let options = {};
|
|
759
|
+
let cb = undefined;
|
|
760
|
+
if (typeof dataOrOptions === 'function') {
|
|
761
|
+
cb = dataOrOptions;
|
|
762
|
+
}
|
|
763
|
+
else if (dataOrOptions !== undefined && dataOrOptions !== null) {
|
|
764
|
+
if (this.isRequestOptions(dataOrOptions)) {
|
|
765
|
+
options = dataOrOptions;
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
data = dataOrOptions;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
if (typeof optionsOrCallback === 'function') {
|
|
772
|
+
cb = optionsOrCallback;
|
|
773
|
+
}
|
|
774
|
+
else if (optionsOrCallback !== undefined && optionsOrCallback !== null) {
|
|
775
|
+
options = optionsOrCallback;
|
|
776
|
+
}
|
|
777
|
+
if (callback !== undefined) {
|
|
778
|
+
cb = callback;
|
|
998
779
|
}
|
|
999
780
|
if (data && typeof data !== 'object' && !Buffer.isBuffer(data) && !(data instanceof stream_1.Readable)) {
|
|
1000
781
|
throw new Error('Invalid data type');
|
|
@@ -1062,10 +843,10 @@ class AdvancedTLSClient {
|
|
|
1062
843
|
session.clientManager.request(path, options, startTime, config.headers, post_data, out);
|
|
1063
844
|
return out;
|
|
1064
845
|
}
|
|
1065
|
-
if (
|
|
1066
|
-
session.clientManager.request(path, options, startTime, config.headers, post_data, out,
|
|
1067
|
-
if (
|
|
1068
|
-
|
|
846
|
+
if (cb) {
|
|
847
|
+
session.clientManager.request(path, options, startTime, config.headers, post_data, out, cb).catch(err => {
|
|
848
|
+
if (cb)
|
|
849
|
+
cb(err);
|
|
1069
850
|
});
|
|
1070
851
|
return out;
|
|
1071
852
|
}
|