I
I
im_dimas2020-11-04 12:58:28
JavaScript
im_dimas, 2020-11-04 12:58:28

How to set up a socket connection with SSL?

Good afternoon, dear ones.
I must say right away that I have not yet worked with nodejs and sockets and I can formulate something incorrectly in the question, thanks.

In general, I came across one laravel project that runs on nodejs.
It works like this, nodejs is launched on the server and listens for client connections on a specific port.
Everything works fine without using ssl, but since the site works on SSL, when the client connects to the server, this error occurs:

WebSocket connection to 'wss://domain.com:9031/' failed: Error in connection establishment: net::ERR_CERT_AUTHORITY_INVALID


Do not send to Google, because I've been doing this for more than a day and nothing helps, or I'm doing something wrong.
How did I try to get rid of this error? The one who gave me this project does not really understand himself and wrote the simplest instruction, which I followed. He wrote something like: you need to take the key and .crt from the certificate and write the path to it in the .js script and everything should have worked. I've done all this - it doesn't work.

Below is the code:
var privateKey = fs.readFileSync('ssl/domain.com.key', 'utf8');
var certificate = fs.readFileSync('ssl/domain.com.crt', 'utf8');

var credentials = { key: privateKey, cert: certificate };
var https = require('https');


var httpsServer = https.createServer(credentials);
httpsServer.listen(serverConfig.port);

var WebSocket = require('ws').Server;
var wss = new WebSocket({
    server: httpsServer
});


In the ssl folder - the files are present, the contents of them are read - I checked all this using console.log, the server does not even start if one of these files has an incorrect key or something else, that is, the data in these files is essentially valid.

I connected via telnet, the server is pinging, please help me solve this problem

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question