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) {
sniCredentials.forEach(function (sniCredentialsSingle) {
server.addContext(sniCredentialsSingle.name, {
cert: sniCredentialsSingle.cert,
key: sniCredentialsSingle.key
try {
sniCredentials.forEach(function (sniCredentialsSingle) {
server.addContext(sniCredentialsSingle.name, {
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 {
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...
}
});
} catch (err) {
// SNI error
}
}
server.on("request", reqhandler);
server.on("checkExpectation", reqhandler);