@push.rocks/smartproxy 3.41.8 → 4.1.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_ts/00_commitinfo_data.js +2 -2
- package/dist_ts/classes.pp.acmemanager.d.ts +34 -0
- package/dist_ts/classes.pp.acmemanager.js +123 -0
- package/dist_ts/classes.pp.connectionhandler.d.ts +39 -0
- package/dist_ts/classes.pp.connectionhandler.js +693 -0
- package/dist_ts/classes.pp.connectionmanager.d.ts +78 -0
- package/dist_ts/classes.pp.connectionmanager.js +378 -0
- package/dist_ts/classes.pp.domainconfigmanager.d.ts +55 -0
- package/dist_ts/classes.pp.domainconfigmanager.js +103 -0
- package/dist_ts/classes.pp.interfaces.d.ts +109 -0
- package/dist_ts/classes.pp.interfaces.js +2 -0
- package/dist_ts/classes.pp.networkproxybridge.d.ts +43 -0
- package/dist_ts/classes.pp.networkproxybridge.js +211 -0
- package/dist_ts/classes.pp.portproxy.d.ts +48 -0
- package/dist_ts/classes.pp.portproxy.js +268 -0
- package/dist_ts/classes.pp.portrangemanager.d.ts +56 -0
- package/dist_ts/classes.pp.portrangemanager.js +179 -0
- package/dist_ts/classes.pp.securitymanager.d.ts +47 -0
- package/dist_ts/classes.pp.securitymanager.js +126 -0
- package/dist_ts/classes.pp.snihandler.d.ts +198 -0
- package/dist_ts/classes.pp.snihandler.js +1210 -0
- package/dist_ts/classes.pp.timeoutmanager.d.ts +47 -0
- package/dist_ts/classes.pp.timeoutmanager.js +154 -0
- package/dist_ts/classes.pp.tlsmanager.d.ts +57 -0
- package/dist_ts/classes.pp.tlsmanager.js +132 -0
- package/dist_ts/index.d.ts +2 -2
- package/dist_ts/index.js +3 -3
- package/package.json +1 -1
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.pp.acmemanager.ts +149 -0
- package/ts/classes.pp.connectionhandler.ts +982 -0
- package/ts/classes.pp.connectionmanager.ts +446 -0
- package/ts/classes.pp.domainconfigmanager.ts +123 -0
- package/ts/classes.pp.interfaces.ts +136 -0
- package/ts/classes.pp.networkproxybridge.ts +258 -0
- package/ts/classes.pp.portproxy.ts +344 -0
- package/ts/classes.pp.portrangemanager.ts +214 -0
- package/ts/classes.pp.securitymanager.ts +147 -0
- package/ts/{classes.snihandler.ts → classes.pp.snihandler.ts} +1 -1
- package/ts/classes.pp.timeoutmanager.ts +190 -0
- package/ts/classes.pp.tlsmanager.ts +206 -0
- package/ts/index.ts +2 -2
- package/ts/classes.portproxy.ts +0 -2503
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import type { IPortProxySettings } from './classes.pp.interfaces.js';
|
|
3
|
+
import { SniHandler } from './classes.pp.snihandler.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Interface for connection information used for SNI extraction
|
|
7
|
+
*/
|
|
8
|
+
interface IConnectionInfo {
|
|
9
|
+
sourceIp: string;
|
|
10
|
+
sourcePort: number;
|
|
11
|
+
destIp: string;
|
|
12
|
+
destPort: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Manages TLS-related operations including SNI extraction and validation
|
|
17
|
+
*/
|
|
18
|
+
export class TlsManager {
|
|
19
|
+
constructor(private settings: IPortProxySettings) {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Check if a data chunk appears to be a TLS handshake
|
|
23
|
+
*/
|
|
24
|
+
public isTlsHandshake(chunk: Buffer): boolean {
|
|
25
|
+
return SniHandler.isTlsHandshake(chunk);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Check if a data chunk appears to be a TLS ClientHello
|
|
30
|
+
*/
|
|
31
|
+
public isClientHello(chunk: Buffer): boolean {
|
|
32
|
+
return SniHandler.isClientHello(chunk);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Extract Server Name Indication (SNI) from TLS handshake
|
|
37
|
+
*/
|
|
38
|
+
public extractSNI(
|
|
39
|
+
chunk: Buffer,
|
|
40
|
+
connInfo: IConnectionInfo,
|
|
41
|
+
previousDomain?: string
|
|
42
|
+
): string | undefined {
|
|
43
|
+
// Use the SniHandler to process the TLS packet
|
|
44
|
+
return SniHandler.processTlsPacket(
|
|
45
|
+
chunk,
|
|
46
|
+
connInfo,
|
|
47
|
+
this.settings.enableTlsDebugLogging || false,
|
|
48
|
+
previousDomain
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Handle session resumption attempts
|
|
54
|
+
*/
|
|
55
|
+
public handleSessionResumption(
|
|
56
|
+
chunk: Buffer,
|
|
57
|
+
connectionId: string,
|
|
58
|
+
hasSNI: boolean
|
|
59
|
+
): { shouldBlock: boolean; reason?: string } {
|
|
60
|
+
// Skip if session tickets are allowed
|
|
61
|
+
if (this.settings.allowSessionTicket !== false) {
|
|
62
|
+
return { shouldBlock: false };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Check for session resumption attempt
|
|
66
|
+
const resumptionInfo = SniHandler.hasSessionResumption(
|
|
67
|
+
chunk,
|
|
68
|
+
this.settings.enableTlsDebugLogging || false
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// If this is a resumption attempt without SNI, block it
|
|
72
|
+
if (resumptionInfo.isResumption && !hasSNI && !resumptionInfo.hasSNI) {
|
|
73
|
+
if (this.settings.enableTlsDebugLogging) {
|
|
74
|
+
console.log(
|
|
75
|
+
`[${connectionId}] Session resumption detected without SNI and allowSessionTicket=false. ` +
|
|
76
|
+
`Terminating connection to force new TLS handshake.`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
shouldBlock: true,
|
|
81
|
+
reason: 'session_ticket_blocked'
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return { shouldBlock: false };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Check for SNI mismatch during renegotiation
|
|
90
|
+
*/
|
|
91
|
+
public checkRenegotiationSNI(
|
|
92
|
+
chunk: Buffer,
|
|
93
|
+
connInfo: IConnectionInfo,
|
|
94
|
+
expectedDomain: string,
|
|
95
|
+
connectionId: string
|
|
96
|
+
): { hasMismatch: boolean; extractedSNI?: string } {
|
|
97
|
+
// Only process if this looks like a TLS ClientHello
|
|
98
|
+
if (!this.isClientHello(chunk)) {
|
|
99
|
+
return { hasMismatch: false };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
// Extract SNI with renegotiation support
|
|
104
|
+
const newSNI = SniHandler.extractSNIWithResumptionSupport(
|
|
105
|
+
chunk,
|
|
106
|
+
connInfo,
|
|
107
|
+
this.settings.enableTlsDebugLogging || false
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
// Skip if no SNI was found
|
|
111
|
+
if (!newSNI) return { hasMismatch: false };
|
|
112
|
+
|
|
113
|
+
// Check for SNI mismatch
|
|
114
|
+
if (newSNI !== expectedDomain) {
|
|
115
|
+
if (this.settings.enableTlsDebugLogging) {
|
|
116
|
+
console.log(
|
|
117
|
+
`[${connectionId}] Renegotiation with different SNI: ${expectedDomain} -> ${newSNI}. ` +
|
|
118
|
+
`Terminating connection - SNI domain switching is not allowed.`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return { hasMismatch: true, extractedSNI: newSNI };
|
|
122
|
+
} else if (this.settings.enableTlsDebugLogging) {
|
|
123
|
+
console.log(
|
|
124
|
+
`[${connectionId}] Renegotiation detected with same SNI: ${newSNI}. Allowing.`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
} catch (err) {
|
|
128
|
+
console.log(
|
|
129
|
+
`[${connectionId}] Error processing ClientHello: ${err}. Allowing connection to continue.`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return { hasMismatch: false };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Create a renegotiation handler function for a connection
|
|
138
|
+
*/
|
|
139
|
+
public createRenegotiationHandler(
|
|
140
|
+
connectionId: string,
|
|
141
|
+
lockedDomain: string,
|
|
142
|
+
connInfo: IConnectionInfo,
|
|
143
|
+
onMismatch: (connectionId: string, reason: string) => void
|
|
144
|
+
): (chunk: Buffer) => void {
|
|
145
|
+
return (chunk: Buffer) => {
|
|
146
|
+
const result = this.checkRenegotiationSNI(chunk, connInfo, lockedDomain, connectionId);
|
|
147
|
+
if (result.hasMismatch) {
|
|
148
|
+
onMismatch(connectionId, 'sni_mismatch');
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Analyze TLS connection for browser fingerprinting
|
|
155
|
+
* This helps identify browser vs non-browser connections
|
|
156
|
+
*/
|
|
157
|
+
public analyzeClientHello(chunk: Buffer): {
|
|
158
|
+
isBrowserConnection: boolean;
|
|
159
|
+
isRenewal: boolean;
|
|
160
|
+
hasSNI: boolean;
|
|
161
|
+
} {
|
|
162
|
+
// Default result
|
|
163
|
+
const result = {
|
|
164
|
+
isBrowserConnection: false,
|
|
165
|
+
isRenewal: false,
|
|
166
|
+
hasSNI: false
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
// Check if it's a ClientHello
|
|
171
|
+
if (!this.isClientHello(chunk)) {
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Check for session resumption
|
|
176
|
+
const resumptionInfo = SniHandler.hasSessionResumption(
|
|
177
|
+
chunk,
|
|
178
|
+
this.settings.enableTlsDebugLogging || false
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
// Extract SNI
|
|
182
|
+
const sni = SniHandler.extractSNI(
|
|
183
|
+
chunk,
|
|
184
|
+
this.settings.enableTlsDebugLogging || false
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
// Update result
|
|
188
|
+
result.isRenewal = resumptionInfo.isResumption;
|
|
189
|
+
result.hasSNI = !!sni;
|
|
190
|
+
|
|
191
|
+
// Browsers typically:
|
|
192
|
+
// 1. Send SNI extension
|
|
193
|
+
// 2. Have a variety of extensions (ALPN, etc.)
|
|
194
|
+
// 3. Use standard cipher suites
|
|
195
|
+
// ...more complex heuristics could be implemented here
|
|
196
|
+
|
|
197
|
+
// Simple heuristic: presence of SNI suggests browser
|
|
198
|
+
result.isBrowserConnection = !!sni;
|
|
199
|
+
|
|
200
|
+
return result;
|
|
201
|
+
} catch (err) {
|
|
202
|
+
console.log(`Error analyzing ClientHello: ${err}`);
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
package/ts/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './classes.iptablesproxy.js';
|
|
2
2
|
export * from './classes.networkproxy.js';
|
|
3
|
-
export * from './classes.portproxy.js';
|
|
3
|
+
export * from './classes.pp.portproxy.js';
|
|
4
4
|
export * from './classes.port80handler.js';
|
|
5
5
|
export * from './classes.sslredirect.js';
|
|
6
|
-
export * from './classes.snihandler.js';
|
|
6
|
+
export * from './classes.pp.snihandler.js';
|