Nodejs Secure Websocket failing with SSL_ERROR_BAD_CERT_DOMAIN

222 Views Asked by At

I created some ssl certificates with certbot.

This is how I'm creating the server in nodejs:

var WebSocketServer = require("websocket").server;
var https = require("https");
global.fs = require("fs");

var PORT = 1349;

var certContent = fs.readFileSync("/etc/letsencrypt/live/www.mywebsite.com/fullchain.pem", "utf8");
var keysContent = fs.readFileSync("/etc/letsencrypt/live/www.mywebsite.com/privkey.pem", "utf8");

console.log("Cert content:",  certContent,  keysContent);

var server = https.createServer(
{
    key: keysContent,
    cert:certContent

}, function(request, response)
{
    
});

server.listen(PORT, function() { });

var wsServer = new WebSocketServer({
    httpServer: server
});

This is how I'm attempting to connect to the server:

var ip = "123.123.123.123";

connection = new WebSocket("wss://" + ip + ":1349?foo=fee");

In the network tab in the security section of firefox's web dev tools. It says:

An error occurred:  SSL_ERROR_BAD_CERT_DOMAIN

When I check the certificate through the terminal it says:

root@s123-123-123-123 [/usr/local/bin]# certbot-auto certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: www.mywebsite.com
    Serial Number: 123123123123123123123123123123123
    Domains: www.mywebsite.com mywebsite2.com mywebsite3.com
    Expiry Date: 2021-01-02 14:03:57+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/www.mywebsite.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/www.mywebsite.com/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

I am using this node script on mywebsite2.com

How can I create a secure websocket server in nodejs using certbot ssl certificates?

0

There are 0 best solutions below