whistle 2.10.12 → 2.10.13
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/assets/emudhra.pem +48 -0
- package/biz/webui/cgi-bin/client-ips.js +7 -0
- package/biz/webui/htdocs/index.html +1 -1
- package/biz/webui/htdocs/js/index.js +18 -18
- package/lib/https/ca.js +21 -12
- package/lib/https/emudhra.js +39 -0
- package/lib/https/index.js +12 -2
- package/lib/init.js +1 -0
- package/lib/rules/rules.js +27 -9
- package/lib/service/composer.js +33 -21
- package/lib/tunnel.js +8 -7
- package/lib/upgrade.js +1 -0
- package/lib/util/data-server.js +5 -3
- package/lib/util/index.js +23 -0
- package/lib/util/parse-url.js +16 -1
- package/package.json +2 -2
package/lib/https/ca.js
CHANGED
|
@@ -13,6 +13,7 @@ var util = require('../util');
|
|
|
13
13
|
var config = require('../config');
|
|
14
14
|
var common = require('../util/common');
|
|
15
15
|
var rulesUtil = require('../rules/util');
|
|
16
|
+
var emudhra = require('./emudhra');
|
|
16
17
|
|
|
17
18
|
var pki = forge.pki;
|
|
18
19
|
var HTTPS_DIR = mkdir(path.join(config.getDataDir(), 'certs'));
|
|
@@ -201,7 +202,7 @@ function getCacheCert(hostname) {
|
|
|
201
202
|
);
|
|
202
203
|
}
|
|
203
204
|
|
|
204
|
-
function createSelfCert(hostname) {
|
|
205
|
+
function createSelfCert(hostname, enableEmudhra) {
|
|
205
206
|
// https://blog.csdn.net/OnlyLove_/article/details/125815813
|
|
206
207
|
var serialNumber =
|
|
207
208
|
crypto
|
|
@@ -220,7 +221,7 @@ function createSelfCert(hostname) {
|
|
|
220
221
|
value: hostname
|
|
221
222
|
}
|
|
222
223
|
]);
|
|
223
|
-
cert.setIssuer(ROOT_CRT.subject.attributes);
|
|
224
|
+
cert.setIssuer(enableEmudhra ? emudhra.subject : ROOT_CRT.subject.attributes);
|
|
224
225
|
cert.setExtensions([
|
|
225
226
|
{
|
|
226
227
|
name: 'basicConstraints',
|
|
@@ -252,13 +253,15 @@ function createSelfCert(hostname) {
|
|
|
252
253
|
},
|
|
253
254
|
{
|
|
254
255
|
name: 'authorityKeyIdentifier',
|
|
255
|
-
keyIdentifier:
|
|
256
|
+
keyIdentifier: enableEmudhra ? emudhra.keyIdentifier : getRootSKI()
|
|
256
257
|
}
|
|
257
258
|
]);
|
|
258
|
-
|
|
259
|
+
if (!enableEmudhra) {
|
|
260
|
+
cert.sign(ROOT_KEY, forge.md.sha256.create());
|
|
261
|
+
}
|
|
259
262
|
return {
|
|
260
263
|
key: pki.privateKeyToPem(ROOT_KEY),
|
|
261
|
-
cert: pki.certificateToPem(cert)
|
|
264
|
+
cert: enableEmudhra ? emudhra.sign(cert) : pki.certificateToPem(cert)
|
|
262
265
|
};
|
|
263
266
|
}
|
|
264
267
|
|
|
@@ -439,8 +442,8 @@ function createRootCA() {
|
|
|
439
442
|
}
|
|
440
443
|
|
|
441
444
|
if (ROOT_KEY && ROOT_CRT && ROOT_KEY.length && ROOT_CRT.length) {
|
|
442
|
-
ROOT_KEY = pki.privateKeyFromPem(
|
|
443
|
-
ROOT_CRT = pki.certificateFromPem(
|
|
445
|
+
ROOT_KEY = pki.privateKeyFromPem(rootKey);
|
|
446
|
+
ROOT_CRT = pki.certificateFromPem(rootCrt);
|
|
444
447
|
if (customRoot) {
|
|
445
448
|
customCertsFiles.root = extend(
|
|
446
449
|
{
|
|
@@ -581,12 +584,14 @@ function getOrCreateCert(servername) {
|
|
|
581
584
|
if (requestCert) {
|
|
582
585
|
servername = servername.substring(1);
|
|
583
586
|
}
|
|
584
|
-
var
|
|
587
|
+
var lastIndex = servername.length - 1;
|
|
588
|
+
var enableEmudhra = servername[lastIndex] === '.';
|
|
589
|
+
var cert = !enableEmudhra && remoteCerts.get(servername);
|
|
585
590
|
if (!cert) {
|
|
586
591
|
servername = getDomain(servername);
|
|
587
592
|
cert = getCacheCert(servername);
|
|
588
593
|
if (!cert) {
|
|
589
|
-
cert = createSelfCert(servername);
|
|
594
|
+
cert = createSelfCert(enableEmudhra ? servername.substring(0, lastIndex) : servername, enableEmudhra);
|
|
590
595
|
cachePairs.set(servername, cert);
|
|
591
596
|
}
|
|
592
597
|
}
|
|
@@ -618,6 +623,10 @@ var SNICallback = function (servername, cb) {
|
|
|
618
623
|
cb(null, options._ctx);
|
|
619
624
|
};
|
|
620
625
|
|
|
626
|
+
var EmudhraSNICallback = function (servername, cb) {
|
|
627
|
+
SNICallback(servername + '.', cb);
|
|
628
|
+
};
|
|
629
|
+
|
|
621
630
|
exports.getRootCA = function () {
|
|
622
631
|
createRootCASafe();
|
|
623
632
|
return {
|
|
@@ -690,9 +699,9 @@ exports.getHttp2Server = function (listener, callback) {
|
|
|
690
699
|
createServer(name, cbList, listener);
|
|
691
700
|
};
|
|
692
701
|
|
|
693
|
-
exports.getSNIServer = function (listener, callback, disableH2, requestCert) {
|
|
702
|
+
exports.getSNIServer = function (listener, callback, disableH2, requestCert, enableEmudhra) {
|
|
694
703
|
var enableH2 = !disableH2;
|
|
695
|
-
var name = (enableH2 ? 'h2Sni' : 'sni') + (requestCert ? 'WithCert' : '');
|
|
704
|
+
var name = (enableH2 ? 'h2Sni' : 'sni') + (requestCert ? 'WithCert' : '') + (enableEmudhra ? 'WithEmudhra' : '');
|
|
696
705
|
var curPort = ports[name];
|
|
697
706
|
if (curPort) {
|
|
698
707
|
return callback(curPort);
|
|
@@ -701,7 +710,7 @@ exports.getSNIServer = function (listener, callback, disableH2, requestCert) {
|
|
|
701
710
|
if (curPort === false) {
|
|
702
711
|
return;
|
|
703
712
|
}
|
|
704
|
-
var options = { SNICallback: SNICallback };
|
|
713
|
+
var options = { SNICallback: enableEmudhra ? EmudhraSNICallback : SNICallback };
|
|
705
714
|
options.allowHTTP1 = enableH2; // 是否启用http2
|
|
706
715
|
if (requestCert) {
|
|
707
716
|
options = extend(
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var crypto = require('crypto');
|
|
2
|
+
var fs = require('fs');
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var forge = require('node-forge');
|
|
5
|
+
|
|
6
|
+
// Publicly disclosed key and chain from mitmproxy commit 169234499088fc2c414644a67efaed3d64ae2e3b.
|
|
7
|
+
var pem = fs.readFileSync(path.join(__dirname, '../../assets/emudhra.pem'), 'utf8');
|
|
8
|
+
var privateKey = crypto.createPrivateKey(pem);
|
|
9
|
+
var certificates = forge.pem.decode(pem).filter(function (entry) {
|
|
10
|
+
return entry.type === 'CERTIFICATE';
|
|
11
|
+
});
|
|
12
|
+
var asn1 = forge.asn1;
|
|
13
|
+
var pki = forge.pki;
|
|
14
|
+
var intermediate = asn1.fromDer(certificates[0].body).value[0];
|
|
15
|
+
var chain = certificates.map(function (entry) {
|
|
16
|
+
return forge.pem.encode(entry);
|
|
17
|
+
}).join('');
|
|
18
|
+
|
|
19
|
+
// Read the v3 intermediate's subject and public key without forge's RSA-only certificate parser.
|
|
20
|
+
exports.subject = pki.RDNAttributesAsArray(intermediate.value[5]);
|
|
21
|
+
exports.keyIdentifier = crypto.createHash('sha1').update(
|
|
22
|
+
Buffer.from(intermediate.value[6].value[1].value.substring(1), 'binary')
|
|
23
|
+
).digest('binary');
|
|
24
|
+
|
|
25
|
+
exports.sign = function (cert) {
|
|
26
|
+
cert.signatureOid = cert.siginfo.algorithmOid = '1.2.840.10045.4.3.3'; // ecdsa-with-SHA384
|
|
27
|
+
cert.tbsCertificate = pki.getTBSCertificate(cert);
|
|
28
|
+
// ECDSA AlgorithmIdentifier parameters must be absent; forge emits RSA's NULL by default.
|
|
29
|
+
cert.tbsCertificate.value[2].value.pop();
|
|
30
|
+
cert.signature = crypto.sign('sha384', Buffer.from(
|
|
31
|
+
asn1.toDer(cert.tbsCertificate).getBytes(), 'binary'
|
|
32
|
+
), privateKey).toString('binary');
|
|
33
|
+
var certificate = pki.certificateToAsn1(cert);
|
|
34
|
+
certificate.value[1].value.pop();
|
|
35
|
+
return forge.pem.encode({
|
|
36
|
+
type: 'CERTIFICATE',
|
|
37
|
+
body: asn1.toDer(certificate).getBytes()
|
|
38
|
+
}) + chain;
|
|
39
|
+
};
|
package/lib/https/index.js
CHANGED
|
@@ -1144,6 +1144,10 @@ function addClientInfo(socket, chunk, statusLine, clientIp, clientPort) {
|
|
|
1144
1144
|
return Buffer.concat([getTunnelHeaders(socket, statusLine, clientIp, clientPort), chunk]);
|
|
1145
1145
|
}
|
|
1146
1146
|
|
|
1147
|
+
function existsEmudhra(obj) {
|
|
1148
|
+
return obj.emudhra || obj.fixAndroidSsl || obj.fixAndroidSSL;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1147
1151
|
module.exports = function (socket, next, isWebPort) {
|
|
1148
1152
|
var reqSocket, reqDestroyed, resDestroyed;
|
|
1149
1153
|
var headersStr;
|
|
@@ -1228,7 +1232,7 @@ module.exports = function (socket, next, isWebPort) {
|
|
|
1228
1232
|
if (!isHttpH2 && chunk[0] != 22) {
|
|
1229
1233
|
return next(chunk);
|
|
1230
1234
|
}
|
|
1231
|
-
var useSNI, domain, serverKey;
|
|
1235
|
+
var useSNI, domain, serverKey, enableEmudhra;
|
|
1232
1236
|
var handleConnect = function (port) {
|
|
1233
1237
|
var promise =
|
|
1234
1238
|
!isHttpH2 && !useSNI && serverAgent.existsServer(serverKey);
|
|
@@ -1264,6 +1268,9 @@ module.exports = function (socket, next, isWebPort) {
|
|
|
1264
1268
|
};
|
|
1265
1269
|
var useNoSNIServer = function () {
|
|
1266
1270
|
serverKey = requestCert ? ':' + domain : domain;
|
|
1271
|
+
if (enableEmudhra) {
|
|
1272
|
+
serverKey += '.';
|
|
1273
|
+
}
|
|
1267
1274
|
serverAgent.createServer(serverKey, handlers, handleConnect, 0, 0);
|
|
1268
1275
|
};
|
|
1269
1276
|
|
|
@@ -1275,7 +1282,7 @@ module.exports = function (socket, next, isWebPort) {
|
|
|
1275
1282
|
} else if (enable.http2) {
|
|
1276
1283
|
disableH2 = false;
|
|
1277
1284
|
}
|
|
1278
|
-
getSNIServer(h2Handlers, handleConnect, disableH2, requestCert);
|
|
1285
|
+
getSNIServer(h2Handlers, handleConnect, disableH2, requestCert, enableEmudhra);
|
|
1279
1286
|
} else if (isHttpH2) {
|
|
1280
1287
|
getHttp2Server(h2Handlers, handleConnect);
|
|
1281
1288
|
} else {
|
|
@@ -1314,6 +1321,9 @@ module.exports = function (socket, next, isWebPort) {
|
|
|
1314
1321
|
socket.useSNI = useSNI;
|
|
1315
1322
|
socket.serverName = socket.servername = servername;
|
|
1316
1323
|
socket.commonName = domain;
|
|
1324
|
+
if (enableEmudhra = existsEmudhra(enable) && !existsEmudhra(disable)) {
|
|
1325
|
+
return handleRequest();
|
|
1326
|
+
}
|
|
1317
1327
|
loadCert(socket, function (cert) {
|
|
1318
1328
|
if (socket._hasError) {
|
|
1319
1329
|
return destroy();
|
package/lib/init.js
CHANGED
|
@@ -177,6 +177,7 @@ module.exports = function (req, res, next) {
|
|
|
177
177
|
req.clientIp = clientIp = clientIp || socket[clientIpKey];
|
|
178
178
|
req.method = util.getMethod(req.method);
|
|
179
179
|
req._clientId = util.getComposerClientId(headers);
|
|
180
|
+
util.addClientIp(clientIp);
|
|
180
181
|
var clientPort = clientInfo[1] || headers[config.CLIENT_PORT_HEADER];
|
|
181
182
|
delete headers[config.CLIENT_PORT_HEADER];
|
|
182
183
|
if (!(clientPort > 0)) {
|
package/lib/rules/rules.js
CHANGED
|
@@ -100,6 +100,14 @@ var mIndex = 0;
|
|
|
100
100
|
var mNow = Date.now();
|
|
101
101
|
var IS_JSON = Symbol('isJson');
|
|
102
102
|
var removeComment = common.removeComment;
|
|
103
|
+
var ANDROID_RE = /\bAndroid\b/i;
|
|
104
|
+
var IOS_RE = /\b(iPhone|iPad|iPod)\b/i;
|
|
105
|
+
var MAC_RE = /\bMacintosh\b/i;
|
|
106
|
+
|
|
107
|
+
function checkUA(req, re) {
|
|
108
|
+
req = req.headers && req.headers['user-agent'];
|
|
109
|
+
return req && re.test(req);
|
|
110
|
+
}
|
|
103
111
|
|
|
104
112
|
function getMFlag() {
|
|
105
113
|
if (mIndex === Number.MAX_SAFE_INTEGER) {
|
|
@@ -1830,31 +1838,41 @@ function matchFilter(url, filter, req) {
|
|
|
1830
1838
|
return true;
|
|
1831
1839
|
}
|
|
1832
1840
|
};
|
|
1833
|
-
|
|
1834
|
-
|
|
1841
|
+
var from = filter.from;
|
|
1842
|
+
if (from) {
|
|
1843
|
+
if (from === 'tunnel') {
|
|
1835
1844
|
return filter.not ? !req.fromTunnel : req.fromTunnel;
|
|
1836
1845
|
}
|
|
1837
|
-
if (
|
|
1846
|
+
if (from === 'test') {
|
|
1838
1847
|
return filter.not ? !req._testId : req._testId;
|
|
1839
1848
|
}
|
|
1840
|
-
if (
|
|
1849
|
+
if (from === 'composer') {
|
|
1841
1850
|
return filter.not ? !req.fromComposer : req.fromComposer;
|
|
1842
1851
|
}
|
|
1843
|
-
if (
|
|
1852
|
+
if (from === 'internalPath') {
|
|
1844
1853
|
return filter.not ? !req.fromInternalPath : req.fromInternalPath;
|
|
1845
1854
|
}
|
|
1846
|
-
if (
|
|
1855
|
+
if (from === 'sni') {
|
|
1847
1856
|
return filter.not ? !req.useSNI : req.useSNI;
|
|
1848
1857
|
}
|
|
1849
|
-
if (
|
|
1858
|
+
if (from === 'httpserver') {
|
|
1850
1859
|
return filter.not ? !req.fromHttpServer : req.fromHttpServer;
|
|
1851
1860
|
}
|
|
1852
|
-
if (
|
|
1861
|
+
if (from === 'httpsserver') {
|
|
1853
1862
|
return filter.not ? !req.fromHttpsServer : req.fromHttpsServer;
|
|
1854
1863
|
}
|
|
1855
|
-
if (
|
|
1864
|
+
if (from === 'httpsport') {
|
|
1856
1865
|
return filter.not ? !req.isHttpsServer : req.isHttpsServer;
|
|
1857
1866
|
}
|
|
1867
|
+
if (from === 'android') {
|
|
1868
|
+
return filter.not ? !checkUA(req, ANDROID_RE) : checkUA(req, ANDROID_RE);
|
|
1869
|
+
}
|
|
1870
|
+
if (from === 'ios' || from === 'iphone') {
|
|
1871
|
+
return filter.not ? !checkUA(req, IOS_RE) : checkUA(req, IOS_RE);
|
|
1872
|
+
}
|
|
1873
|
+
if (from === 'macos' || from === 'mac') {
|
|
1874
|
+
return filter.not ? !checkUA(req, MAC_RE) : checkUA(req, MAC_RE);
|
|
1875
|
+
}
|
|
1858
1876
|
return false;
|
|
1859
1877
|
}
|
|
1860
1878
|
var chance = filter.chance || filter.probability;
|
package/lib/service/composer.js
CHANGED
|
@@ -141,13 +141,9 @@ function handleConnect(options, cb, count, testId) {
|
|
|
141
141
|
options.headers['x-whistle-policy'] = 'tunnel';
|
|
142
142
|
var origOpts = options;
|
|
143
143
|
var lastIndex = count - 1;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
execCb = cb;
|
|
148
|
-
} else {
|
|
149
|
-
options = extend({}, origOpts);
|
|
150
|
-
}
|
|
144
|
+
// Each repetition gets its own options and callback: the callbacks run after the
|
|
145
|
+
// loop, and the sent body is cleared on the options object it was sent from.
|
|
146
|
+
var send = function(options, execCb) {
|
|
151
147
|
common.connectInner({
|
|
152
148
|
proxyHost: PROXY_OPTS.host,
|
|
153
149
|
proxyPort: PROXY_OPTS.port,
|
|
@@ -168,6 +164,13 @@ function handleConnect(options, cb, count, testId) {
|
|
|
168
164
|
}
|
|
169
165
|
handleCallback(execCb, null, svrRes, testId);
|
|
170
166
|
}, config).on('error', execCb || noop);
|
|
167
|
+
};
|
|
168
|
+
for (var i = 0; i < count; i++) {
|
|
169
|
+
if (i === lastIndex) {
|
|
170
|
+
send(origOpts, cb);
|
|
171
|
+
} else {
|
|
172
|
+
send(extend({}, origOpts));
|
|
173
|
+
}
|
|
171
174
|
}
|
|
172
175
|
}
|
|
173
176
|
|
|
@@ -180,13 +183,9 @@ function handleWebSocket(options, cb, count, testId) {
|
|
|
180
183
|
delete options.headers['x-whistle-frame-binary'];
|
|
181
184
|
var origOpts = options;
|
|
182
185
|
var lastIndex = count - 1;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
execCb = cb;
|
|
187
|
-
} else {
|
|
188
|
-
options = extend({}, origOpts);
|
|
189
|
-
}
|
|
186
|
+
// Each repetition gets its own options and callback: the callbacks run after the
|
|
187
|
+
// loop, and the sent body is cleared on the options object it was sent from.
|
|
188
|
+
var send = function(options, execCb) {
|
|
190
189
|
common.connect(PROXY_OPTS, function(err, socket) {
|
|
191
190
|
if (err) {
|
|
192
191
|
handleCallback(execCb, err, null, testId);
|
|
@@ -223,6 +222,13 @@ function handleWebSocket(options, cb, count, testId) {
|
|
|
223
222
|
}, true);
|
|
224
223
|
}
|
|
225
224
|
});
|
|
225
|
+
};
|
|
226
|
+
for (var i = 0; i < count; i++) {
|
|
227
|
+
if (i === lastIndex) {
|
|
228
|
+
send(origOpts, cb);
|
|
229
|
+
} else {
|
|
230
|
+
send(extend({}, origOpts));
|
|
231
|
+
}
|
|
226
232
|
}
|
|
227
233
|
}
|
|
228
234
|
|
|
@@ -237,13 +243,9 @@ function handleHttp(options, cb, count, reqId, testId) {
|
|
|
237
243
|
options.port = PROXY_OPTS.port;
|
|
238
244
|
var origOpts = options;
|
|
239
245
|
var lastIndex = count - 1;
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
execCb = cb;
|
|
244
|
-
} else {
|
|
245
|
-
options = extend({}, origOpts);
|
|
246
|
-
}
|
|
246
|
+
// Each repetition gets its own options and callback: the callbacks run after the
|
|
247
|
+
// loop, and the sent body is cleared on the options object it was sent from.
|
|
248
|
+
var send = function(options, execCb) {
|
|
247
249
|
var client = http.request(options, function(svrRes) {
|
|
248
250
|
if (!execCb || testId) {
|
|
249
251
|
handleCallback(execCb, null, svrRes, testId);
|
|
@@ -325,6 +327,13 @@ function handleHttp(options, cb, count, reqId, testId) {
|
|
|
325
327
|
client.on('error', execCb || noop);
|
|
326
328
|
client.end(options.body);
|
|
327
329
|
options.body = null;
|
|
330
|
+
};
|
|
331
|
+
for (var i = 0; i < count; i++) {
|
|
332
|
+
if (i === lastIndex) {
|
|
333
|
+
send(origOpts, cb);
|
|
334
|
+
} else {
|
|
335
|
+
send(extend({}, origOpts));
|
|
336
|
+
}
|
|
328
337
|
}
|
|
329
338
|
}
|
|
330
339
|
|
|
@@ -369,6 +378,9 @@ exports.handleRequest = function(req, res) {
|
|
|
369
378
|
}
|
|
370
379
|
headers['x-whistle-rule-value'] = common.safeEncodeURIComponent(rules);
|
|
371
380
|
}
|
|
381
|
+
if (common.isString(options.auth)) {
|
|
382
|
+
headers.authorization = 'Basic ' + Buffer.from(options.auth).toString('base64');
|
|
383
|
+
}
|
|
372
384
|
var type = common.trimStr(reqBody.contentType);
|
|
373
385
|
if (type) {
|
|
374
386
|
headers['content-type'] = type;
|
package/lib/tunnel.js
CHANGED
|
@@ -92,6 +92,7 @@ function tunnelProxy(server, proxy, type) {
|
|
|
92
92
|
reqSocket.fromComposer = req.fromComposer;
|
|
93
93
|
reqSocket._testId = req._testId;
|
|
94
94
|
req.isPluginReq = reqSocket.isPluginReq = util.checkPluginReqOnce(req, true);
|
|
95
|
+
util.addClientIp(req.clientIp);
|
|
95
96
|
util.onSocketEnd(reqSocket, function (err) {
|
|
96
97
|
// 处理可能的证书校验出错
|
|
97
98
|
if (config.captureData && !util.checkHideProp(req.enable || '', req.disable || '', 'CaptureError') && dispatch.getTunnelDataOnce(reqSocket)) {
|
|
@@ -726,28 +727,28 @@ function tunnelProxy(server, proxy, type) {
|
|
|
726
727
|
}
|
|
727
728
|
|
|
728
729
|
function sendEstablished(code, cb) {
|
|
730
|
+
var resHeaders;
|
|
729
731
|
if (res) {
|
|
732
|
+
resHeaders = res.headers;
|
|
730
733
|
code = res.statusCode || 200;
|
|
731
|
-
if (!
|
|
732
|
-
|
|
734
|
+
if (!resHeaders['proxy-agent']) {
|
|
735
|
+
resHeaders['proxy-agent'] = config.appName;
|
|
733
736
|
res.rawHeaders = res.rawHeaders || [];
|
|
734
737
|
res.rawHeaders.push('proxy-agent', 'Proxy-Agent');
|
|
735
738
|
}
|
|
736
739
|
} else {
|
|
737
740
|
code = code || 200;
|
|
741
|
+
resHeaders = { 'proxy-agent': config.appName };
|
|
738
742
|
res = {
|
|
739
743
|
statusCode: code,
|
|
740
|
-
headers:
|
|
741
|
-
'proxy-agent': config.appName
|
|
742
|
-
},
|
|
744
|
+
headers: resHeaders,
|
|
743
745
|
rawHeaders: ['proxy-agent', 'Proxy-Agent']
|
|
744
746
|
};
|
|
745
747
|
}
|
|
746
748
|
var tunnelAck = enableTunnelAck && cb && code == 200;
|
|
747
749
|
if (tunnelAck) {
|
|
748
|
-
|
|
750
|
+
resHeaders[common.ALLOW_ACK] = 1;
|
|
749
751
|
}
|
|
750
|
-
var resHeaders = res.headers;
|
|
751
752
|
pluginMgr.getResRules(req, res, function () {
|
|
752
753
|
if (util.needAbortRes(req)) {
|
|
753
754
|
return reqSocket.destroy();
|
package/lib/upgrade.js
CHANGED
|
@@ -129,6 +129,7 @@ function upgradeHandler(req, socket) {
|
|
|
129
129
|
var clientInfo = util.parseClientInfo(req);
|
|
130
130
|
var clientIp = clientInfo[0] || util.getClientIp(req);
|
|
131
131
|
var clientPort = clientInfo[1] || util.getClientPort(req);
|
|
132
|
+
util.addClientIp(clientIp);
|
|
132
133
|
socket._disabledProxyRules = req._disabledProxyRules;
|
|
133
134
|
socket.clientIp = clientIp;
|
|
134
135
|
socket.clientPort = clientPort;
|
package/lib/util/data-server.js
CHANGED
|
@@ -896,13 +896,15 @@ module.exports = function init(_proxy) {
|
|
|
896
896
|
var data = {};
|
|
897
897
|
var count = options.count;
|
|
898
898
|
var startTime = options.startTime;
|
|
899
|
+
var dumpCount = options.dumpCount;
|
|
900
|
+
var hasDump = dumpCount > 0;
|
|
899
901
|
var clearNetwork =
|
|
900
|
-
!
|
|
902
|
+
!hasDump && (count == 0 || startTime == -2);
|
|
901
903
|
if (!clearNetwork) {
|
|
902
904
|
count = count > 0 && count < COUNT ? +count : COUNT;
|
|
903
|
-
if (
|
|
905
|
+
if (hasDump) {
|
|
904
906
|
var len = ids.length;
|
|
905
|
-
startTime = ids[len >
|
|
907
|
+
startTime = ids[len > dumpCount ? len - dumpCount : 0];
|
|
906
908
|
}
|
|
907
909
|
}
|
|
908
910
|
if (key && value) {
|
package/lib/util/index.js
CHANGED
|
@@ -731,6 +731,21 @@ var simpleHostname = '';
|
|
|
731
731
|
var cpus = os.cpus();
|
|
732
732
|
var addressList = [];
|
|
733
733
|
var usiTimer;
|
|
734
|
+
var clientIpMap = new Map();
|
|
735
|
+
var clientIpList;
|
|
736
|
+
|
|
737
|
+
exports.getClientIpList = function() {
|
|
738
|
+
clientIpList = clientIpList || Array.from(clientIpMap.keys());
|
|
739
|
+
return clientIpList;
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
exports.addClientIp = function(ip) {
|
|
743
|
+
if (clientIpMap.has(ip) && clientIpMap.size > 1) {
|
|
744
|
+
clientIpMap.delete(ip);
|
|
745
|
+
}
|
|
746
|
+
clientIpMap.set(ip, 1);
|
|
747
|
+
clientIpList = null;
|
|
748
|
+
};
|
|
734
749
|
|
|
735
750
|
function updateServerInfo() {
|
|
736
751
|
serverInfo = {ipv4: [], ipv6: []};
|
|
@@ -753,6 +768,14 @@ function updateSysInfo() {
|
|
|
753
768
|
common.walkInterfaces(function (info) {
|
|
754
769
|
addressList.push(info.address.toLowerCase());
|
|
755
770
|
});
|
|
771
|
+
var excess = clientIpMap.size - 2000;
|
|
772
|
+
if (excess > 0) {
|
|
773
|
+
clientIpList = null;
|
|
774
|
+
var iter = clientIpMap.keys();
|
|
775
|
+
while (excess-- > 0) {
|
|
776
|
+
clientIpMap.delete(iter.next().value);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
756
779
|
usiTimer = setTimeout(updateSysInfo, 36000);
|
|
757
780
|
}
|
|
758
781
|
|
package/lib/util/parse-url.js
CHANGED
|
@@ -15,6 +15,13 @@ module.exports = function (url) {
|
|
|
15
15
|
var search = urlMatch[4] || '';
|
|
16
16
|
var hash = urlMatch[5] || null;
|
|
17
17
|
var port = null;
|
|
18
|
+
var auth = null;
|
|
19
|
+
// user:password@ belongs to auth, not to the host (as in url.parse)
|
|
20
|
+
var atIndex = host.lastIndexOf('@');
|
|
21
|
+
if (atIndex !== -1) {
|
|
22
|
+
auth = decodeAuth(host.substring(0, atIndex));
|
|
23
|
+
host = host.substring(atIndex + 1);
|
|
24
|
+
}
|
|
18
25
|
var hostname = host;
|
|
19
26
|
var hostMatch = HOST_RE.exec(host);
|
|
20
27
|
if (hostMatch) {
|
|
@@ -25,7 +32,7 @@ module.exports = function (url) {
|
|
|
25
32
|
return {
|
|
26
33
|
protocol: protocol,
|
|
27
34
|
slashes: true,
|
|
28
|
-
auth:
|
|
35
|
+
auth: auth,
|
|
29
36
|
host: host,
|
|
30
37
|
port: port,
|
|
31
38
|
hostname: formatHost(hostname),
|
|
@@ -38,4 +45,12 @@ module.exports = function (url) {
|
|
|
38
45
|
};
|
|
39
46
|
};
|
|
40
47
|
|
|
48
|
+
function decodeAuth(auth) {
|
|
49
|
+
try {
|
|
50
|
+
return decodeURIComponent(auth);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
return auth;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
41
56
|
module.exports.formatHost = formatHost;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "whistle",
|
|
3
3
|
"description": "HTTP, HTTP2, HTTPS, Websocket debugging proxy",
|
|
4
|
-
"version": "2.10.
|
|
4
|
+
"version": "2.10.13",
|
|
5
5
|
"dataDirname": ".whistle",
|
|
6
6
|
"localUIHost": "local.whistlejs.com",
|
|
7
7
|
"port": 8899,
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"lru-cache": "^4.1.1",
|
|
52
52
|
"mime": "^1.6.0",
|
|
53
53
|
"multer2": "^1.1.1",
|
|
54
|
-
"node-forge": "^1.4.
|
|
54
|
+
"node-forge": "^1.4.1",
|
|
55
55
|
"node-pac": "^0.5.1",
|
|
56
56
|
"parseurl": "^1.3.1",
|
|
57
57
|
"pfork": "^0.6.3",
|