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