“common name invalid” for a self-signed certificat

2019-09-02 01:54发布

问题:

I'm trying to run this webrtc client/signaling server code, but after running the server with a new self-signed certificate I created by following the instructions of this tutorial, my chatclient.js couldn't connect to socket server:

connection = new WebSocket('wss://localhost:6503/', 'json');

this is the error displayed by chrome's console:

(chatclient.js:106) WebSocket connection to 'wss://localhost:6503/' failed: 
    Error in connection establishment: net::ERR_CERT_COMMON_NAME_INVALID

I then go to https://0.0.0.0:6503/ from chrome (the server is listening on port 6503), and this is the security tab from chrome inspector:

I'm guessing I need to set the correct common name during the generation of ssl certificate, to which I current set as 0.0.0.0:6503.

What should I set? Since this is a websocket's address and I have no idea which part to write?

回答1:

Set it to localhost which is the same host you're trying to connect to. You do not need to include the port. Note that you will need a certificate in production.

You might also want to check the highly useful Chrome flag which ignores certificate errors on localhost: chrome://flags/#allow-insecure-localhost