@push.rocks/smartproxy 3.41.6 → 3.41.7

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.
@@ -1321,6 +1321,7 @@ export class SniHandler {
1321
1321
  * @param cachedSni - Optional cached SNI from previous connections (for racing detection)
1322
1322
  * @returns The extracted server name or undefined if not found or more data needed
1323
1323
  */
1324
+
1324
1325
  public static processTlsPacket(
1325
1326
  buffer: Buffer,
1326
1327
  connectionInfo: {
@@ -1373,6 +1374,74 @@ export class SniHandler {
1373
1374
  return undefined;
1374
1375
  }
1375
1376
 
1377
+ // Enhanced session resumption detection
1378
+ if (this.isClientHello(buffer)) {
1379
+ const resumptionInfo = this.hasSessionResumption(buffer, enableLogging);
1380
+
1381
+ if (resumptionInfo.isResumption) {
1382
+ log(`Session resumption detected in TLS packet`);
1383
+
1384
+ // Always try standard SNI extraction first
1385
+ const standardSni = this.extractSNI(buffer, enableLogging);
1386
+ if (standardSni) {
1387
+ log(`Found standard SNI in session resumption: ${standardSni}`);
1388
+
1389
+ // Cache this SNI
1390
+ this.cacheSession(connectionInfo.sourceIp, standardSni);
1391
+ return standardSni;
1392
+ }
1393
+
1394
+ // Enhanced session resumption SNI extraction
1395
+ // Try extracting from PSK identity
1396
+ const pskSni = this.extractSNIFromPSKExtension(buffer, enableLogging);
1397
+ if (pskSni) {
1398
+ log(`Extracted SNI from PSK extension: ${pskSni}`);
1399
+ this.cacheSession(connectionInfo.sourceIp, pskSni);
1400
+ return pskSni;
1401
+ }
1402
+
1403
+ // Additional check for SNI in session tickets
1404
+ if (enableLogging) {
1405
+ log(`Checking for session ticket information to extract server name...`);
1406
+ // Log more details for debugging
1407
+ try {
1408
+ // Look at the raw buffer for patterns
1409
+ log(`Buffer hexdump (first 100 bytes): ${buffer.slice(0, 100).toString('hex')}`);
1410
+
1411
+ // Try to find hostname-like patterns in the buffer
1412
+ const bufferStr = buffer.toString('utf8', 0, buffer.length);
1413
+ const hostnamePattern =
1414
+ /([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?/gi;
1415
+ const hostMatches = bufferStr.match(hostnamePattern);
1416
+
1417
+ if (hostMatches && hostMatches.length > 0) {
1418
+ log(`Possible hostnames found in buffer: ${hostMatches.join(', ')}`);
1419
+
1420
+ // Check if any match looks like a valid domain
1421
+ for (const match of hostMatches) {
1422
+ if (match.includes('.') && match.length > 3) {
1423
+ log(`Potential SNI found in session data: ${match}`);
1424
+ // Don't automatically use this - just log for debugging
1425
+ }
1426
+ }
1427
+ }
1428
+ } catch (e) {
1429
+ log(`Error scanning for patterns: ${e}`);
1430
+ }
1431
+ }
1432
+
1433
+ // If we still don't have SNI, check for cached sessions
1434
+ const cachedSni = this.getCachedSession(connectionInfo.sourceIp);
1435
+ if (cachedSni) {
1436
+ log(`Using cached SNI for session resumption: ${cachedSni}`);
1437
+ return cachedSni;
1438
+ }
1439
+
1440
+ log(`Session resumption without extractable SNI`);
1441
+ // If allowSessionTicket=false, should be rejected by caller
1442
+ }
1443
+ }
1444
+
1376
1445
  // For handshake messages, try the full extraction process
1377
1446
  const sni = this.extractSNIWithResumptionSupport(buffer, connectionInfo, enableLogging);
1378
1447