Websocket服务器的自签名证书的“公用名无效”

时间:2019-01-11 08:35:54

标签: ssl websocket ssl-certificate webrtc ws

我正在尝试运行此webrtc client/signaling server code,但是在使用我按照this tutorial的指示创建的新的自签名证书运行服务器之后,我的chatclient.js无法连接到套接字服务器:

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

这是Chrome控制台显示的错误:

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

然后我从chrome转到https://0.0.0.0:6503/(服务器正在监听端口6503),这是chrome inspector的安全性标签:

enter image description here

我猜想我需要在生成ssl证书的过程中设置正确的通用名称,目前我将其设置为0.0.0.0:6503

我应该设置什么?因为这是网络套接字的地址,我不知道该写哪一部分?

1 个答案:

答案 0 :(得分:2)

将其设置为const regex = /^(?:(?:1[0-7]|[0-9])?[0-9]{5}|1800000)$/; const mustFailTests = [ '9999', '15', '1800001', '9000000', '0', '', ]; const mustWorkTests = [ '10000', '1800000', '200000', '25018', '778410', '1000000', '1205900', ]; const start = Date.now(); mustFailTests.forEach((x) => { const ret = regex.test(x); console.log(`${x} must fail : result ${ret}`); }); console.log('--------------------------------'); mustWorkTests.forEach((x) => { const ret = regex.test(x); console.log(`${x} must succeed : result ${ret}`); }); for (let i = 0; i < 500000; i += 1) { mustWorkTests.forEach(x => regex.test(x)); mustFailTests.forEach(x => regex.test(x)); } console.log(`It took ${Date.now() - start} ms`);,这是您要连接的主机。您不需要包括端口。请注意,您将需要在生产中使用证书。

您可能还想检查一个非常有用的Chrome标志,该标志忽略localhost上的证书错误:chrome:// flags /#allow-insecure-localhost