fix some sni and vhost stuff
This commit is contained in:
parent
5ddd85e14e
commit
31932002c9
|
@ -44,7 +44,7 @@ module.exports.create = function (state) {
|
||||||
|
|
||||||
// Probably something that needs to be redirected to https
|
// Probably something that needs to be redirected to https
|
||||||
function redirectHttpsAndClose(req, res) {
|
function redirectHttpsAndClose(req, res) {
|
||||||
//res.setHeader('Connection', 'close');
|
res.setHeader('Connection', 'close');
|
||||||
redirectHttps(req, res);
|
redirectHttps(req, res);
|
||||||
}
|
}
|
||||||
state.httpInsecureServer = http.createServer(
|
state.httpInsecureServer = http.createServer(
|
||||||
|
@ -217,8 +217,8 @@ module.exports.create = function (state) {
|
||||||
state.httpVhost.emit('connection', tlsSocket);
|
state.httpVhost.emit('connection', tlsSocket);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
state.tlsVhost.on('tlsClientError', function () {
|
state.tlsVhost.on('tlsClientError', function (e) {
|
||||||
console.error('tlsClientError Vhost');
|
console.error('tlsClientError Vhost', e);
|
||||||
});
|
});
|
||||||
state.httpsVhost = function (servername, socket) {
|
state.httpsVhost = function (servername, socket) {
|
||||||
if (state.debug) { console.log('[vhost] httpsVhost (local) for', servername); }
|
if (state.debug) { console.log('[vhost] httpsVhost (local) for', servername); }
|
||||||
|
|
|
@ -52,7 +52,8 @@ module.exports.create = function (state) {
|
||||||
conn.once('data', function (firstChunk) {
|
conn.once('data', function (firstChunk) {
|
||||||
if (state.debug) { console.log("[DynTcp]", serviceport, "examining firstChunk from", Packer.socketToId(conn)); }
|
if (state.debug) { console.log("[DynTcp]", serviceport, "examining firstChunk from", Packer.socketToId(conn)); }
|
||||||
conn.pause();
|
conn.pause();
|
||||||
conn.unshift(firstChunk);
|
//conn.unshift(firstChunk);
|
||||||
|
conn._handle.onread(firstChunk.length, firstChunk);
|
||||||
|
|
||||||
var servername;
|
var servername;
|
||||||
var hostname;
|
var hostname;
|
||||||
|
|
|
@ -62,13 +62,13 @@ module.exports.createTcpConnectionHandler = function (state) {
|
||||||
console.log("TODO: use www bare redirect");
|
console.log("TODO: use www bare redirect");
|
||||||
}
|
}
|
||||||
|
|
||||||
function run() {
|
|
||||||
if (!servername) {
|
if (!servername) {
|
||||||
if (state.debug) { console.log("No SNI was given, so there's nothing we can do here"); }
|
if (state.debug) { console.log("No SNI was given, so there's nothing we can do here"); }
|
||||||
deferData('httpsInvalid');
|
deferData('httpsInvalid');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function run() {
|
||||||
var nextDevice = Devices.next(state.deviceLists, servername);
|
var nextDevice = Devices.next(state.deviceLists, servername);
|
||||||
if (!nextDevice) {
|
if (!nextDevice) {
|
||||||
if (state.debug) { console.log("No devices match the given servername"); }
|
if (state.debug) { console.log("No devices match the given servername"); }
|
||||||
|
@ -84,14 +84,15 @@ module.exports.createTcpConnectionHandler = function (state) {
|
||||||
// TODO don't run an fs check if we already know this is working elsewhere
|
// TODO don't run an fs check if we already know this is working elsewhere
|
||||||
//if (!state.validHosts) { state.validHosts = {}; }
|
//if (!state.validHosts) { state.validHosts = {}; }
|
||||||
if (state.config.vhost) {
|
if (state.config.vhost) {
|
||||||
vhost = state.config.vhost.replace(/:hostname/, (servername||''));
|
vhost = state.config.vhost.replace(/:hostname/, (servername||'reallydoesntexist'));
|
||||||
if (state.debug) { console.log("[tcp] [vhost]", state.config.vhost, "=>", vhost); }
|
if (state.debug) { console.log("[tcp] [vhost]", state.config.vhost, "=>", vhost); }
|
||||||
//state.httpsVhost(servername, conn);
|
//state.httpsVhost(servername, conn);
|
||||||
//return;
|
//return;
|
||||||
require('fs').readdir(vhost, function (err, nodes) {
|
require('fs').readdir(vhost, function (err, nodes) {
|
||||||
if (state.debug && err) { console.log("VHOST error", err); }
|
if (state.debug && err) { console.log("VHOST error", err); }
|
||||||
if (err) { run(); return; }
|
if (err) { run(); return; }
|
||||||
if (nodes) { deferData('httpsVhost'); }
|
//if (nodes) { deferData('httpsVhost'); return; }
|
||||||
|
deferData('httpsVhost');
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +104,7 @@ module.exports.createTcpConnectionHandler = function (state) {
|
||||||
if (22 === firstChunk[0]) {
|
if (22 === firstChunk[0]) {
|
||||||
// TLS
|
// TLS
|
||||||
service = 'https';
|
service = 'https';
|
||||||
servername = (sni(firstChunk)||'').toLowerCase();
|
servername = (sni(firstChunk)||'').toLowerCase().trim();
|
||||||
if (state.debug) { console.log("[tcp] tls hello from '" + servername + "'"); }
|
if (state.debug) { console.log("[tcp] tls hello from '" + servername + "'"); }
|
||||||
tryTls();
|
tryTls();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -50,5 +50,9 @@
|
||||||
"serve-static": "^1.13.2",
|
"serve-static": "^1.13.2",
|
||||||
"sni": "^1.0.0",
|
"sni": "^1.0.0",
|
||||||
"ws": "^5.1.1"
|
"ws": "^5.1.1"
|
||||||
|
},
|
||||||
|
"engineStrict" : true,
|
||||||
|
"engines": {
|
||||||
|
"node": "10.2.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue