UNPKG

@push.rocks/smartproxy

Version:

A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.

101 lines (100 loc) 3.22 kB
import { Buffer } from 'buffer'; /** * Interface for logging functions used by the parser */ export type LoggerFunction = (message: string) => void; /** * Result of a session resumption check */ export interface SessionResumptionResult { isResumption: boolean; hasSNI: boolean; } /** * Information about parsed TLS extensions */ export interface ExtensionInfo { type: number; length: number; data: Buffer; } /** * Result of a ClientHello parse operation */ export interface ClientHelloParseResult { isValid: boolean; version?: [number, number]; random?: Buffer; sessionId?: Buffer; hasSessionId: boolean; cipherSuites?: Buffer; compressionMethods?: Buffer; extensions: ExtensionInfo[]; serverNameList?: string[]; hasSessionTicket: boolean; hasPsk: boolean; hasEarlyData: boolean; error?: string; } /** * Fragment tracking information */ export interface FragmentTrackingInfo { buffer: Buffer; timestamp: number; connectionId: string; } /** * Class for parsing TLS ClientHello messages */ export declare class ClientHelloParser { private static fragmentedBuffers; private static fragmentTimeout; /** * Clean up expired fragments */ private static cleanupExpiredFragments; /** * Handles potential fragmented ClientHello messages by buffering and reassembling * TLS record fragments that might span multiple TCP packets. * * @param buffer The current buffer fragment * @param connectionId Unique identifier for the connection * @param logger Optional logging function * @returns A complete buffer if reassembly is successful, or undefined if more fragments are needed */ static handleFragmentedClientHello(buffer: Buffer, connectionId: string, logger?: LoggerFunction): Buffer | undefined; /** * Parses a TLS ClientHello message and extracts all components * * @param buffer The buffer containing the ClientHello message * @param logger Optional logging function * @returns Parsed ClientHello or undefined if parsing failed */ static parseClientHello(buffer: Buffer, logger?: LoggerFunction): ClientHelloParseResult; /** * Parses the server name extension data and extracts hostnames * * @param data Extension data buffer * @param serverNames Array to populate with found server names * @param logger Optional logging function * @returns true if parsing succeeded */ private static parseServerNameExtension; /** * Determines if a ClientHello contains session resumption indicators * * @param buffer The ClientHello buffer * @param logger Optional logging function * @returns Session resumption result */ static hasSessionResumption(buffer: Buffer, logger?: LoggerFunction): SessionResumptionResult; /** * Checks if a ClientHello appears to be from a tab reactivation * * @param buffer The ClientHello buffer * @param logger Optional logging function * @returns true if it appears to be a tab reactivation */ static isTabReactivationHandshake(buffer: Buffer, logger?: LoggerFunction): boolean; }