1
0
Fork 0
forked from svrjs/svrjs

Errors that occurred while adding SNI context to a server are now ignored.

This commit is contained in:
Dorian Niemiec 2024-04-27 06:45:16 +02:00
parent 9eb982dc92
commit 7dfdc7209e

28
svr.js
View file

@ -2177,19 +2177,23 @@ if (!cluster.isPrimary) {
} }
} }
if (secure) { if (secure) {
sniCredentials.forEach(function (sniCredentialsSingle) { try {
server.addContext(sniCredentialsSingle.name, { sniCredentials.forEach(function (sniCredentialsSingle) {
cert: sniCredentialsSingle.cert, server.addContext(sniCredentialsSingle.name, {
key: sniCredentialsSingle.key cert: sniCredentialsSingle.cert,
key: sniCredentialsSingle.key
});
try {
var snMatches = sniCredentialsSingle.name.match(/^([^:[]*|\[[^]]*\]?)((?::.*)?)$/);
if (!snMatches[1][0].match(/^\.+$/)) snMatches[1][0] = snMatches[1][0].replace(/\.+$/, "");
server._contexts[server._contexts.length - 1][0] = new RegExp("^" + snMatches[1].replace(/([.^$+?\-\\[\]{}])/g, "\\$1").replace(/\*/g, "[^.:]*") + ((snMatches[1][0] == "[" || snMatches[1].match(/^(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/)) ? "" : "\.?") + snMatches[2].replace(/([.^$+?\-\\[\]{}])/g, "\\$1").replace(/\*/g, "[^.]*") + "$", "i");
} catch (ex) {
// Can't replace regex, ignoring...
}
}); });
try { } catch (err) {
var snMatches = sniCredentialsSingle.name.match(/^([^:[]*|\[[^]]*\]?)((?::.*)?)$/); // SNI error
if (!snMatches[1][0].match(/^\.+$/)) snMatches[1][0] = snMatches[1][0].replace(/\.+$/, ""); }
server._contexts[server._contexts.length - 1][0] = new RegExp("^" + snMatches[1].replace(/([.^$+?\-\\[\]{}])/g, "\\$1").replace(/\*/g, "[^.:]*") + ((snMatches[1][0] == "[" || snMatches[1].match(/^(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/)) ? "" : "\.?") + snMatches[2].replace(/([.^$+?\-\\[\]{}])/g, "\\$1").replace(/\*/g, "[^.]*") + "$", "i");
} catch (ex) {
// Can't replace regex, ignoring...
}
});
} }
server.on("request", reqhandler); server.on("request", reqhandler);
server.on("checkExpectation", reqhandler); server.on("checkExpectation", reqhandler);