fix some sni and vhost stuff

This commit is contained in:
AJ ONeal 2018-06-14 09:59:19 +00:00
parent 5ddd85e14e
commit 31932002c9
4 changed files with 19 additions and 13 deletions

View File

@ -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); }

View File

@ -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;

View File

@ -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;
}
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;

View File

@ -50,5 +50,9 @@
"serve-static": "^1.13.2",
"sni": "^1.0.0",
"ws": "^5.1.1"
},
"engineStrict" : true,
"engines": {
"node": "10.2.1"
}
}