I have a NodeJS server running which is sucessfully acessed by 2 domains though HTTP.
Now those 2 sites have different SSL certificates.
What I want now, is to allow those 2 sites to connect to the node server via HTTPS.
I have sucessfully added one of the certificates… How should I procede to add the other one, or in other words, add 2 certificates to the same node server?
Here’s the code I have so far:
var options = {
key: fs.readFileSync("keys/cer1.key"),
cert: fs.readFileSync("certs/cer2.crt"),
ca: fs.readFileSync("ca/ca.crt")
};
https.createServer(options, function (req, res) {
...
}).listen(8000);
Thanks!
There is a chicken and egg problem here: the server needs to decrypt the request to know which certificate to use – to decrypt the request 😉
There is SNI which is designed to solve this – but I am not sure how that is implemented in node. Without this, you need to have a one to one mapping of port to certificate (this is the same issue every web server faces – hopefully SNI support will become the norm one day).